/* chat.css — the public web chat surface.
 *
 * Design direction: Telegram's conversation rhythm (a quiet full-bleed
 * transcript, tight two-tone bubbles, a flat composer pinned to the bottom)
 * rendered in the calm white + deep-green palette the landing pages already
 * established, rather than Telegram's blue. Mobile-first; on a wide screen the
 * column simply centres instead of becoming a desktop layout.
 *
 * Self-contained: no CDN, no web fonts, no images, no build step — the same
 * constraints landing.css works under, and required by the page's strict CSP.
 */

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --surface: #ffffff;
  --bubble-in: #f2f4f3;
  --bubble-out: #166e46;
  --bubble-out-text: #ffffff;
  --text: #17181c;
  --text-2: #565b63;
  --text-3: #8b9098;
  --border: #e6e8eb;
  --accent: #166e46;
  --accent-press: #0f5433;
  --accent-soft: #f1f8f4;
  --danger: #b3261e;
  --radius: 18px;
  --radius-sm: 10px;
  --bar-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1b1f23;
    --bubble-in: #23282d;
    --bubble-out: #1f7a4f;
    --bubble-out-text: #f4fbf7;
    --text: #e9ecef;
    --text-2: #a8b0b8;
    --text-3: #7c848c;
    --border: #2a3037;
    --accent: #2f9c68;
    --accent-press: #257e54;
    --accent-soft: #18251f;
  }
}

* { box-sizing: border-box; }

/* The panels below are laid out with `display: flex`, which outranks the UA's
 * `[hidden] { display: none }`. Without this the signed-out page would show an
 * empty transcript and a live composer underneath the sign-in gate. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

#app {
  display: flex;
  flex-direction: column;
  /* dvh keeps the composer above the mobile keyboard as it opens. */
  height: 100dvh;
  max-width: 46rem;
  margin: 0 auto;
  background: var(--surface);
}

/* ---- top bar ------------------------------------------------------------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: var(--bar-h);
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 2;
  padding-top: env(safe-area-inset-top);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  letter-spacing: 0.2px;
}
.brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  background: var(--accent);
}
.ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  border-radius: 999px;
  padding: 5px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.ghost:hover { color: var(--text); border-color: var(--text-3); }

/* ---- transcript ---------------------------------------------------------- */

.log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row { display: flex; }
.row.out { justify-content: flex-end; }
.row.in { justify-content: flex-start; }

/* Consecutive bubbles from the same side tuck together, Telegram-style: only
   the last one in a run keeps the large outer corner. */
.row + .row.same { margin-top: -4px; }

.bubble {
  max-width: min(80%, 34rem);
  padding: 8px 12px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.row.in .bubble {
  background: var(--bubble-in);
  color: var(--text);
  border-bottom-left-radius: var(--radius-sm);
}
.row.out .bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: var(--radius-sm);
}
.bubble b { font-weight: 650; }

/* ---- listing cards ------------------------------------------------------- */

.card {
  max-width: min(88%, 34rem);
  background: var(--bubble-in);
  border-radius: var(--radius);
  border-bottom-left-radius: var(--radius-sm);
  overflow: hidden;
}
/* The listing photo sits above the title, inside the card's own rounded clip.
 * The box is reserved before the lazy image resolves so an arriving card never
 * shoves the transcript, and the placeholder is a themed surface rather than a
 * white flash in dark mode. */
.card figure {
  margin: 0;
  background: var(--border);
  aspect-ratio: 16 / 10;
  max-height: 260px;
}
.card img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 260px;
  object-fit: cover;
}
.card .body { padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.card .title { font-weight: 650; }
.card .source {
  display: block;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
.card .source:hover { background: var(--accent-soft); }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 4px;
  max-width: min(88%, 34rem);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.gallery img { width: 100%; height: 96px; object-fit: cover; display: block; }

/* A listing's extra photos INSIDE its card: a thumbnail strip under the text,
 * not a second grid the width of the card. The strip scrolls sideways rather
 * than reflowing, so three photos and ten photos give the card the same height,
 * and each thumbnail keeps its own small radius so the strip reads as part of
 * the card instead of a flush-cut mosaic. Both rules restate the geometry the
 * standalone `.gallery` sets, because `.card img` above would otherwise stretch
 * every thumbnail to the full card width. */
.card .gallery {
  display: flex;
  gap: 4px;
  padding: 0 12px 10px;
  max-width: none;
  border-radius: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.card .gallery::-webkit-scrollbar { display: none; }
.card .gallery img {
  flex: 0 0 auto;
  width: 76px;
  height: 56px;
  max-height: 56px;
  border-radius: var(--radius-sm);
}

/* ---- choice buttons ------------------------------------------------------ */

/* One column of server-decided rows, not one wrapping pile. The runtime lays a
 * guided step out as: primary options two per row, the wide step button, then
 * Back + Start over, then Cancel — so the navigation controls land in the same
 * place on every step regardless of how many options that step offers. */
.choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 2px 0 8px;
  max-width: min(88%, 34rem);
}
.choice-row { display: flex; gap: 6px; }
/* Equal shares of the row, so a one-button row renders wide — which is exactly
 * the emphasis the server meant by putting it alone on its own row. */
.choice-row button { flex: 1; min-width: 0; }
.choices button {
  font: inherit;
  font-size: 14px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  /* A long Armenian marz name must wrap rather than overflow the row. */
  text-align: left;
  overflow-wrap: anywhere;
}
.choices button:hover:not(:disabled) { background: var(--accent); color: #fff; }
.choices button:disabled { opacity: 0.45; cursor: default; }

/* ---- typing indicator ---------------------------------------------------- */

.typing { display: flex; gap: 4px; padding: 12px; }
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 60%, 100% { opacity: 0.25; }
  30% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .typing span { animation: none; opacity: 0.5; }
}

.notice {
  align-self: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 6px 10px;
  text-align: center;
}
.notice.error { color: var(--danger); }

/* ---- sign-in gate -------------------------------------------------------- */

.gate {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 24px 20px calc(28px + env(safe-area-inset-bottom));
}
.gate h1 { font-size: 21px; margin: 0; font-weight: 650; }
.gate p { margin: 0; color: var(--text-2); max-width: 26rem; }
.gate .fine { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.providers {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 20rem;
  margin-top: 14px;
}
.providers a, .providers button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font: inherit;
  font-weight: 600;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.providers a:hover, .providers button:hover { border-color: var(--text-3); }
.providers svg { flex: none; }

/* ---- composer ------------------------------------------------------------ */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.composer textarea {
  flex: 1;
  resize: none;
  font: inherit;
  color: var(--text);
  background: var(--bubble-in);
  border: 1px solid transparent;
  border-radius: 20px;
  padding: 9px 14px;
  max-height: 8.5rem;
  overflow-y: auto;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.composer button {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.composer button:hover:not(:disabled) { background: var(--accent-press); }
.composer button:disabled { opacity: 0.4; cursor: default; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
