/* chat.beneschtech.com — a two-person chat.
   Light and dark are both first-class; the palette flips on prefers-color-scheme. */

:root {
  --bg: #f5f4fa;
  --surface: #ffffff;
  --surface-2: #eeecf6;
  --text: #191626;
  --muted: #6c6885;
  --border: #e2dff0;
  --accent: #6d5bd8;
  --accent-text: #ffffff;
  --own-bg: linear-gradient(135deg, #6d5bd8, #8b5fd0);
  --danger: #c8324f;
  --shadow: 0 1px 2px rgba(24, 20, 44, .07), 0 6px 20px rgba(24, 20, 44, .06);
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131120;
    --surface: #1d1a2b;
    --surface-2: #262236;
    --text: #ecebf5;
    --muted: #9995b0;
    --border: #2f2b40;
    --accent: #8a78ef;
    --own-bg: linear-gradient(135deg, #6d5bd8, #9b5fd6);
    --danger: #ff7a92;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Sign in ---------- */
.signin {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
}
.signin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 40px 32px;
  text-align: center;
  max-width: 380px;
  width: 100%;
}
.signin-logo { border-radius: 20px; }
.signin h1 { margin: 16px 0 4px; font-size: 1.6rem; }
.signin p { margin: 0 0 24px; }
#google-button { display: flex; justify-content: center; min-height: 44px; }
.signin-error {
  margin-top: 18px;
  color: var(--danger);
  font-size: .9rem;
}

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-main { flex: 1; min-width: 0; }
.topbar-title { margin: 0; font-size: 1.05rem; font-weight: 650; }
.topbar-presence { margin: 0; font-size: .78rem; }
.topbar-actions { display: flex; gap: 4px; }

/* ---------- Messages ---------- */
.messages {
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 12px 14px 4px;
  scrollbar-width: thin;
}
.message-list { display: flex; flex-direction: column; }

.msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-top: 12px;
  max-width: 100%;
}
.msg.own { align-items: flex-end; }
/* Consecutive messages from the same person tuck together. */
.msg.grouped { margin-top: 2px; }

/* Day separator, driven by data-day + .show-day from the relayout pass. */
.msg.show-day::before {
  content: attr(data-day);
  align-self: center;
  margin: 18px 0 14px;
  padding: 4px 12px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
}

.msg-author {
  font-size: .74rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0 6px 3px;
}
.msg.grouped .msg-author { display: none; }

.bubble {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 13px;
  max-width: min(68ch, 82%);
  box-shadow: var(--shadow);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg.own .bubble {
  background: var(--own-bg);
  border-color: transparent;
  color: var(--accent-text);
}
.msg.own .bubble a { color: #fff; }

.bubble a { color: var(--accent); }
.bubble a:hover { text-decoration-thickness: 2px; }

/* All-emoji messages get to be big and lose the bubble entirely. */
.msg.emoji-only .bubble {
  background: none;
  border: none;
  box-shadow: none;
  padding: 2px 6px;
  font-size: 2.9rem;
  line-height: 1.18;
}
.msg.emoji-only.own .bubble { color: var(--text); }

.bubble.deleted {
  font-style: italic;
  color: var(--muted);
  background: var(--surface-2);
  border-style: dashed;
  box-shadow: none;
}
.msg.own .bubble.deleted { background: var(--surface-2); color: var(--muted); }

.msg-meta {
  font-size: .68rem;
  color: var(--muted);
  margin: 3px 8px 0;
  display: flex;
  gap: 6px;
  align-items: center;
}
.msg.own .msg-meta { flex-direction: row-reverse; }
.msg-pending { opacity: .55; }
.msg-failed .bubble { border-color: var(--danger); }

/* Images */
.msg-images { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg-images:first-child { margin-top: 0; }
.msg-image {
  display: block;
  max-width: min(300px, 70vw);
  max-height: 340px;
  width: auto;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  background: var(--surface-2);
}

/* Reactions */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 4px 0; }
.reaction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  font-size: .85rem;
  line-height: 1.6;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.reaction.mine { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.reaction-count { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Hover / long-press action bar */
.msg-actions {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s;
  align-self: flex-start;
  margin: 2px 4px 0;
}
.msg.own .msg-actions { align-self: flex-end; }
.msg:hover .msg-actions,
.msg.actions-open .msg-actions { opacity: 1; pointer-events: auto; }
@media (hover: none) {
  /* No hover on touch — the bar is toggled by long-press instead. */
  .msg:hover .msg-actions { opacity: 0; pointer-events: none; }
  .msg.actions-open .msg-actions { opacity: 1; pointer-events: auto; }
}
.msg-action {
  border: 0;
  background: none;
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 999px;
  color: var(--text);
}
.msg-action:hover { background: var(--surface-2); }
.msg-action svg { width: 16px; height: 16px; fill: currentColor; display: block; }

/* Typing indicator */
.typing { display: flex; align-items: center; gap: 8px; padding: 10px 6px 4px; font-size: .8rem; color: var(--muted); }
.dots { display: inline-flex; gap: 3px; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.3s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: .6; } }

.load-older { display: flex; justify-content: center; padding: 8px 0; }
.text-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: .8rem;
  cursor: pointer;
}

.jump-bottom {
  position: absolute;
  right: 16px;
  bottom: 96px;
  z-index: 15;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.jump-bottom svg { width: 22px; height: 22px; fill: var(--text); }

/* ---------- Composer ---------- */
.composer {
  position: relative;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.composer-row { display: flex; align-items: flex-end; gap: 6px; }

.input-wrap { flex: 1; min-width: 0; }
.input {
  width: 100%;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  padding: 9px 14px;
  font: inherit;
  line-height: 1.45;
  max-height: 40vh;
  overflow-y: auto;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.icon-btn {
  flex: none;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 0;
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

.send-btn {
  flex: none;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: opacity .15s, transform .1s;
}
.send-btn svg { width: 20px; height: 20px; fill: currentColor; }
.send-btn:disabled { opacity: .35; cursor: default; }
.send-btn:not(:disabled):active { transform: scale(.92); }

/* Staged image chips */
.attachments { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 2px 8px; }
.chip {
  position: relative;
  width: 64px; height: 64px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chip.uploading img { opacity: .45; }
.chip-spinner {
  position: absolute; inset: 0;
  display: grid; place-items: center;
}
.chip-spinner::after {
  content: '';
  width: 18px; height: 18px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.chip-remove {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px;
  border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .62);
  color: #fff;
  font-size: 13px; line-height: 1;
  cursor: pointer;
}

/* Drag-and-drop */
.app.dragging::after {
  content: 'Drop image to send';
  position: absolute; inset: 0;
  z-index: 40;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 3px dashed var(--accent);
  border-radius: 12px;
  font-weight: 600;
  color: var(--text);
  pointer-events: none;
}

/* ---------- Emoji ---------- */
.emoji-popover {
  position: fixed;
  z-index: 60;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
emoji-picker {
  --background: var(--surface);
  --border-color: var(--border);
  --input-border-color: var(--border);
  --input-font-color: var(--text);
  --input-placeholder-color: var(--muted);
  --category-font-color: var(--muted);
  --button-hover-background: var(--surface-2);
  --num-columns: 8;
  height: 340px;
}
@media (max-width: 480px) {
  emoji-picker { --num-columns: 7; width: 100%; }
  .emoji-popover { left: 8px !important; right: 8px; width: auto !important; }
}

/* :shortcode: autocomplete */
.autocomplete {
  position: absolute;
  bottom: calc(100% - 4px);
  left: 10px;
  right: 10px;
  max-width: 320px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 50;
  padding: 4px;
}
.ac-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .9rem;
}
.ac-item[aria-selected="true"] { background: var(--surface-2); }
.ac-emoji { font-size: 1.3rem; }
.ac-code { color: var(--muted); font-size: .8rem; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, .9);
  display: grid; place-items: center;
  padding: 20px;
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 200;
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: .85rem;
  box-shadow: var(--shadow);
}
