/* POPA Recon — the public site's only stylesheet. */

:root {
  --bg: #121211;
  --bg-raised: #1b1b19;
  --line: #2c2b28;
  --text: #e9e7e2;
  --muted: #a3a097;
  --accent: #e2a54b;
  --on-accent: #1a1405;
  --focus: #e9e7e2;

  --fs-1: 0.8125rem;
  --fs-2: 1rem;
  --fs-3: 1.25rem;
  --fs-4: 1.75rem;

  --column: 720px;
  --rail: 256px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafaf8;
    --bg-raised: #f0efeb;
    --line: #e0ded8;
    --text: #1c1b19;
    --muted: #5f5c55;
    --accent: #9a5a00;
    --on-accent: #ffffff;
    --focus: #1c1b19;
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-2)/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, p, ul { margin: 0; }

a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

button, textarea { font: inherit; color: inherit; }

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.skip { position: absolute; left: 1rem; top: -3rem; padding: 0.5rem 0.75rem; background: var(--bg); z-index: 10; }
.skip:focus { top: 1rem; }

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  color: var(--text);
  font-size: var(--fs-2);
  font-weight: 650;
  letter-spacing: -0.01em;
  text-decoration: none;
}
/* logo.png is 48 px: 2x of this 1.5em (24 px) mark. */
.wordmark img { flex: none; width: 1.5em; height: 1.5em; }

/* ---------- App: rail + stage ---------- */

.app {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1.25rem 0.75rem 1rem;
  border-right: 1px solid var(--line);
  background: var(--bg);
}

.rail-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.5rem 1.25rem;
}

.new-chat {
  color: var(--muted);
  font-size: var(--fs-1);
  text-decoration: none;
}
.new-chat:hover { color: var(--text); }

.chats {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  padding: 0;
}

.chats a {
  display: block;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  color: var(--muted);
  font-size: var(--fs-1);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chats a:hover { color: var(--text); }
.chats a[aria-current="page"] { color: var(--text); background: var(--bg-raised); }

.account {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem 0.5rem;
  border-top: 1px solid var(--line);
  font-size: var(--fs-1);
}
.account-link { color: var(--text); text-decoration: none; padding: 0.2rem 0; }
button.account-link { border: 0; background: none; font-size: inherit; text-align: left; cursor: pointer; }
.account-link:hover { text-decoration: underline; }
.account-name { color: var(--text); }
button.account-danger { color: var(--muted); }

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar { display: none; }

.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2.5rem 1.25rem 1.5rem;
}

/* The conversation keeps one reading width, whatever the window. */
.column {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--column);
  min-height: 100%;
  margin: 0 auto;
}

/* ---------- Empty state ---------- */

.empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  padding-bottom: 2rem;
}

.empty h1 {
  font-size: var(--fs-4);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.empty p {
  margin-top: 0.5rem;
  color: var(--muted);
}

.examples {
  list-style: none;
  padding: 0;
  margin-top: 2rem;
  border-top: 1px solid var(--line);
}

.examples li { border-bottom: 1px solid var(--line); }

.examples button {
  display: block;
  width: 100%;
  padding: 0.8rem 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.examples button:hover { color: var(--accent); }

/* ---------- Conversation ---------- */

/* The person's words: a bubble on the right. The answer: full-width prose. */
.question {
  align-self: flex-end;
  max-width: min(85%, 36rem);
  margin-top: 2.5rem;
  padding: 0.6rem 1rem;
  border-radius: 18px;
  background: var(--bg-raised);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.column > .question:first-child,
.page-main > .question:first-child { margin-top: 0; }
.page-main > .question { display: table; margin-left: auto; }

.progress, .error {
  margin-top: 1.25rem;
  font-size: var(--fs-1);
}
.progress { color: var(--muted); }
.error { color: var(--text); }

.steps {
  margin-top: 1.25rem;
  color: var(--muted);
  font-size: var(--fs-1);
}
.steps summary {
  width: fit-content;
  cursor: pointer;
  list-style: none;
}
.steps summary::-webkit-details-marker { display: none; }
.steps summary::after { content: " \203A"; display: inline-block; margin-left: 0.25rem; transition: transform 0.15s ease; }
.steps[open] summary::after { transform: rotate(90deg); }
.steps[role="status"] summary { color: var(--text); }
.steps[role="status"] summary::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 0.6rem;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }
.steps ol {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0 0 0 0.9rem;
  border-left: 1px solid var(--line);
}
.steps ol p + p { margin-top: 0.25rem; }

.answer {
  min-width: 0;
  margin-top: 1.25rem;
  line-height: 1.65;
  overflow-wrap: break-word;
}
.steps + .answer { margin-top: 0.75rem; }

.answer-head {
  font-size: var(--fs-3);
  font-weight: 620;
  line-height: 1.35;
  letter-spacing: -0.01em;
}
.answer-section {
  margin-top: 1.5rem;
  font-size: var(--fs-2);
  font-weight: 620;
}

.answer > * + * { margin-top: 0.75rem; }
.answer ul, .answer ol { padding-left: 1.25rem; }
.answer li + li { margin-top: 0.35rem; }
.answer li::marker { color: var(--muted); }

.answer .answer-time { color: var(--muted); font-size: var(--fs-1); }

.answer-table-scroll { max-width: 100%; overflow-x: auto; }
.answer-table { width: 100%; border-collapse: collapse; overflow-wrap: normal; }
.answer-table th, .answer-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.answer-table th { color: var(--muted); font-weight: 620; white-space: nowrap; }
.answer-table td { min-width: 7rem; }
.answer-table td:first-child { min-width: 9rem; }

.answer-breakdown {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

/* Sources: one quiet row of chips under the prose. */
.answer .answer-source {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1rem;
  color: var(--muted);
  font-size: var(--fs-1);
}
.answer-source > span { margin-right: 0.15rem; }
.chip {
  padding: 0.15rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.chip:hover { border-color: var(--muted); }

/* Actions: small quiet icon buttons, labelled only where the icon alone would not say it. */
.answer .answer-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.75rem;
  margin-left: -0.45rem;
}

.action {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2rem;
  padding: 0 0.45rem;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font-size: var(--fs-1);
  text-decoration: none;
  cursor: pointer;
}
.action:hover:not(:disabled) { color: var(--text); background: var(--bg-raised); }
.action:disabled { opacity: 0.5; cursor: default; }
.action .icon { width: 16px; height: 16px; }
.action-note { margin-left: 0.45rem; color: var(--muted); font-size: var(--fs-1); }

/* ---------- Composer ---------- */

.dock {
  width: 100%;
  max-width: calc(var(--column) + 2.5rem);
  margin: 0 auto;
  padding: 0 1.25rem max(0.75rem, env(safe-area-inset-bottom));
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem 0.5rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--bg-raised);
}
.composer:focus-within { border-color: var(--muted); }

.composer textarea {
  flex: 1;
  min-height: 2.25rem;
  max-height: 12rem;
  padding: 0.4rem 0;
  border: 0;
  background: none;
  line-height: 1.5;
  resize: none;
  outline: none;
}
.composer textarea::placeholder { color: var(--muted); opacity: 1; }

.send {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}
.send .icon { width: 18px; height: 18px; }
.send:disabled { background: var(--line); color: var(--muted); cursor: default; }
.answering .send { background: var(--text); color: var(--bg); }
.answering .send .icon-send { --icon: url("/static/icons/stop.svg"); }

.verify { margin-top: 0.5rem; }

/* ---------- Footer ---------- */

.site-footer {
  font-size: var(--fs-1);
  color: var(--muted);
}

.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--text); }

.footer-links { list-style: none; padding: 0; }
.footer-links li { display: flex; align-items: center; gap: 0.5rem; padding: 0.2rem 0; }
.footer-links li > a { display: inline-flex; align-items: center; gap: 0.5rem; }
.channels a { margin-left: 0.1rem; }

.footer-legal { display: flex; gap: 1rem; margin-top: 0.5rem; }

.icon {
  display: inline-block;
  flex: none;
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.icon-x { --icon: url("/static/icons/x.svg"); }
.icon-telegram { --icon: url("/static/icons/telegram.svg"); }
.icon-globe { --icon: url("/static/icons/globe.svg"); }
.icon-copy { --icon: url("/static/icons/copy.svg"); }
.icon-link { --icon: url("/static/icons/link.svg"); }
.icon-expand { --icon: url("/static/icons/expand.svg"); }
.icon-bell { --icon: url("/static/icons/bell.svg"); }
.icon-send { --icon: url("/static/icons/send.svg"); }

.rail .site-footer { padding: 1rem 0.5rem 0; border-top: 1px solid var(--line); }

/* ---------- Plain pages: shared answer, terms, policy ---------- */

.page-frame {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: calc(var(--column) + 2.5rem);
  margin: 0 auto;
  padding: 0 1.25rem;
}

.page-header { padding: 1.5rem 0 3rem; }

.page-main { flex: 1; }

.page-frame .site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem 2rem;
  margin-top: 4rem;
  padding: 1.25rem 0 2rem;
  border-top: 1px solid var(--line);
}
.page-frame .footer-links { display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; }
.page-frame .footer-legal { margin-top: 0; align-items: center; }

.ask-own { margin-top: 3rem; }
.ask-own a { font-weight: 600; }

.prose { line-height: 1.6; max-width: 65ch; }
.prose h1 { font-size: var(--fs-4); font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.prose h2 { font-size: var(--fs-3); font-weight: 620; margin-top: 2rem; }
.prose > * + * { margin-top: 1rem; }
.prose ul { padding-left: 1.25rem; }
.placeholder { color: var(--muted); }

/* ---------- Connect Telegram: one panel, a page and a dialog over the chat ---------- */

.connect {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 24rem;
  margin: 0 auto;
  text-align: center;
}
.connect[hidden], .connect [hidden] { display: none; }

.connect-mark {
  display: grid;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  margin-bottom: 1.25rem;
  border-radius: 50%;
  background: var(--bg-raised);
  color: var(--accent);
  overflow: hidden;
}
.connect-mark .icon { width: 1.75rem; height: 1.75rem; }
.connect-avatar { font-size: var(--fs-3); font-weight: 620; color: var(--text); }
.connect-avatar img { width: 100%; height: 100%; object-fit: cover; }
.connect-done { background: var(--accent); }
.connect-done::after {
  content: "";
  width: 0.75rem;
  height: 1.4rem;
  margin-top: -0.3rem;
  border: solid var(--on-accent);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}

.connect h1, .connect h2 {
  font-size: var(--fs-4);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.connect-lead, .connect-status { margin-top: 0.5rem; color: var(--muted); }
.connect-status { color: var(--text); }
.connect-status::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 0.6rem;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
  animation: pulse 1.2s ease-in-out infinite;
}
.connect-status.offline { color: var(--muted); }
.connect-status.offline::before { background: var(--muted); animation: none; }
.connect-refused:not(:empty) { margin-top: 1rem; font-size: var(--fs-1); }
.connect-who { margin-top: 0.25rem; }
.connect-who span { color: var(--muted); }

.connect-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  min-height: 3rem;
  margin-top: 1.75rem;
  padding: 0 1.25rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.connect-primary:hover { filter: brightness(1.08); }
.connect-primary:disabled { opacity: 0.6; cursor: default; }
.connect-primary .icon { width: 18px; height: 18px; }

.connect-quiet {
  margin-top: 0.75rem;
  padding: 0.25rem;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: var(--fs-1);
  cursor: pointer;
}
.connect-quiet:hover { color: var(--text); }

/* The two taps in the bot, then the way back: numbered so a stranger knows where he is. */
.connect-steps {
  counter-reset: step;
  align-self: stretch;
  margin-top: 1.75rem;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
  text-align: left;
  font-size: var(--fs-1);
}
.connect-steps li {
  counter-increment: step;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.connect-steps li::before { content: counter(step); flex: none; width: 1rem; color: var(--accent); font-weight: 600; }
.connect-steps b { color: var(--text); font-weight: 600; }
[data-state="waiting"] .connect-steps li { color: var(--text); }

.connect-note { margin-top: 1.25rem; color: var(--muted); font-size: var(--fs-1); }
.connect-back { margin-top: 2.5rem; text-align: center; font-size: var(--fs-1); }
.page-main > .connect { padding-top: 2rem; }

.connect-dialog {
  width: min(100% - 2rem, 28rem);
  max-height: calc(100% - 2rem);
  padding: 2.5rem 2rem 2rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
}
.connect-dialog::backdrop { background: rgb(0 0 0 / 0.55); }
.connect-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.connect-close:hover { color: var(--text); background: var(--bg-raised); }

/* ---------- Mobile: the rail becomes a drawer ---------- */

@media (max-width: 800px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  .rail {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(84vw, 300px);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  .rail.open {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease;
  }

  .scrim {
    position: fixed;
    inset: 0;
    z-index: 15;
    background: rgb(0 0 0 / 0.5);
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: max(0.75rem, env(safe-area-inset-top)) 1.25rem 0.75rem;
    border-bottom: 1px solid var(--line);
  }

  .menu {
    padding: 0.25rem 0;
    border: 0;
    background: none;
    color: var(--muted);
    font-size: var(--fs-1);
    cursor: pointer;
  }

  .thread { padding: 1.5rem 1rem 1rem; }
  .dock { padding-left: 0.75rem; padding-right: 0.75rem; }
  .question { max-width: 90%; }
  .page-header { padding-bottom: 2rem; }

  /* On a phone the dialog is a sheet at the thumb, above the home indicator. */
  .connect-dialog {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    padding: 2.25rem 1.25rem max(1.5rem, env(safe-area-inset-bottom));
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
