/* ══════════════════════════════════════════════════════════
   WASDL Debate Assistant — design system + chat
   Shared tokens live here; admin.css builds on them.
   ══════════════════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────────────────── */
:root {
  color-scheme: light;

  /* Brand */
  --navy:        #1a2744;
  --navy-600:    #243460;
  --navy-400:    #3b4d7d;
  --gold:        #c9a227;
  --gold-soft:   #f4e9c6;

  /* Surfaces */
  --bg:          #f6f7fb;
  --surface:     #ffffff;
  --surface-2:   #f1f3f9;
  --surface-3:   #e8ebf4;

  /* Ink */
  --text:        #161d2e;
  --text-2:      #4a5568;
  --text-3:      #77839a;

  --border:      #e2e6f0;
  --border-2:    #cfd6e6;

  /* Status */
  --red:         #d64545;
  --red-bg:      #fdeaea;
  --green:       #1f9254;
  --green-bg:    #e6f6ec;
  --amber:       #9a6b00;
  --amber-bg:    #fdf4e0;
  --info:        #2d5bd1;
  --info-bg:     #ecf1fe;

  --radius:      14px;
  --radius-sm:   9px;
  --radius-pill: 999px;

  --shadow-sm:   0 1px 2px rgba(16, 24, 40, .05);
  --shadow:      0 4px 16px rgba(16, 24, 40, .07);
  --shadow-lg:   0 18px 48px rgba(16, 24, 40, .16);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --pill-on: var(--navy);
  --header-h: 60px;
  --col: 780px;              /* reading column width */
}

/* Dark palette — follows the OS unless an explicit theme is set. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:        #0d1220;
    --surface:   #141b2c;
    --surface-2: #1b2438;
    --surface-3: #243048;
    --text:      #eef1f8;
    --text-2:    #b3bcd0;
    --text-3:    #8490ab;
    --border:    #26304a;
    --border-2:  #35415f;
    --navy:      #0a0f1c;
    --navy-600:  #1d2942;
    --navy-400:  #48598a;
    --gold:      #d9b23f;
    --gold-soft: #3a3220;
    --red:       #f08a8a;
    --red-bg:    #3a1f22;
    --green:     #64d195;
    --green-bg:  #16331f;
    --amber:     #e6b95c;
    --amber-bg:  #352a12;
    --info:      #8fb0ff;
    --info-bg:   #1a2545;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow:    0 4px 16px rgba(0, 0, 0, .45);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);
    --pill-on:   #3f5493;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:        #0d1220;
  --surface:   #141b2c;
  --surface-2: #1b2438;
  --surface-3: #243048;
  --text:      #eef1f8;
  --text-2:    #b3bcd0;
  --text-3:    #8490ab;
  --border:    #26304a;
  --border-2:  #35415f;
  --navy:      #0a0f1c;
  --navy-600:  #1d2942;
  --navy-400:  #48598a;
  --gold:      #d9b23f;
  --gold-soft: #3a3220;
  --red:       #f08a8a;
  --red-bg:    #3a1f22;
  --green:     #64d195;
  --green-bg:  #16331f;
  --amber:     #e6b95c;
  --amber-bg:  #352a12;
  --info:      #8fb0ff;
  --info-bg:   #1a2545;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow:    0 4px 16px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);
  --pill-on:   #3f5493;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

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

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── Header ─────────────────────────────────────────────── */
header {
  background: var(--navy);
  color: #fff;
  height: var(--header-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo-icon {
  height: 34px; display: flex; align-items: center;
  flex-shrink: 0; opacity: .97;
}
.logo-icon img { height: 34px; width: auto; object-fit: contain; display: block; }
.brand { min-width: 0; }
.brand h1 {
  font-size: 15px; font-weight: 650; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand p { font-size: 11.5px; color: rgba(255,255,255,.62); margin-top: -1px; }
.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.status-pill {
  display: flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,.1); border-radius: var(--radius-pill);
  padding: 5px 12px; font-size: 12px; color: rgba(255,255,255,.85);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #98a2b3; flex-shrink: 0; }
.status-dot.online  { background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,.18); }
.status-dot.offline { background: #f87171; box-shadow: 0 0 0 3px rgba(248,113,113,.18); }

.icon-btn {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,.8); background: rgba(255,255,255,.08);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.18); color: #fff; }
.icon-btn svg { width: 17px; height: 17px; }

/* ── Layout ─────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-area { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  padding: 28px 20px 8px;
}
.thread {
  max-width: var(--col);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ── Messages ───────────────────────────────────────────── */
.msg { display: flex; flex-direction: column; animation: rise .22s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Person: compact bubble, right aligned */
.msg.user { align-items: flex-end; }
.msg.user .body {
  background: var(--navy-600);
  color: #fff;
  padding: 11px 16px;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  max-width: min(100%, 560px);
  box-shadow: var(--shadow-sm);
  overflow-wrap: anywhere;
}

/* Assistant: no bubble — long answers read better as plain prose */
.msg.bot { align-items: stretch; }
.msg-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--gold); color: #2b2202;
  font-size: 10px; font-weight: 800; letter-spacing: .02em;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.msg-who { font-size: 12.5px; font-weight: 650; color: var(--text-2); }
.msg-time { font-size: 11.5px; color: var(--text-3); margin-left: auto; }

.msg.bot .body { color: var(--text); overflow-wrap: anywhere; }
.msg.bot .body > *:first-child { margin-top: 0; }
.msg.bot .body > *:last-child { margin-bottom: 0; }
.msg.bot .body p { margin-bottom: 12px; }
.msg.bot .body ul, .msg.bot .body ol { padding-left: 22px; margin: 8px 0 14px; }
.msg.bot .body li { margin-bottom: 5px; }
.msg.bot .body li::marker { color: var(--text-3); }
.msg.bot .body strong { font-weight: 680; }
.msg.bot .body h1, .msg.bot .body h2, .msg.bot .body h3 {
  font-size: 15px; font-weight: 680; margin: 18px 0 8px;
}
.msg.bot .body code {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 5px; font-family: var(--mono); font-size: .88em;
}
.msg.bot .body pre {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px; overflow-x: auto; margin: 10px 0 14px;
}
.msg.bot .body pre code { background: none; border: none; padding: 0; }
.msg.bot .body blockquote {
  border-left: 3px solid var(--border-2); padding-left: 14px;
  color: var(--text-2); margin: 10px 0 14px;
}
.msg.bot .body table {
  width: 100%; border-collapse: collapse; margin: 10px 0 14px; font-size: 14px;
}
.msg.bot .body th, .msg.bot .body td {
  border: 1px solid var(--border); padding: 7px 10px; text-align: left;
}
.msg.bot .body th { background: var(--surface-2); font-weight: 650; }
.msg.bot .body a { color: var(--info); }

.msg.error .body {
  background: var(--red-bg); border: 1px solid var(--red);
  color: var(--red); border-radius: var(--radius-sm); padding: 12px 14px;
  font-size: 14px;
}

/* ── Sources ────────────────────────────────────────────── */
.sources { margin-top: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.sources-label {
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-3); margin-right: 2px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--info-bg); color: var(--info);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 3px 11px; font-size: 12px; font-weight: 550;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; opacity: .55; flex-shrink: 0;
}
.chip.muted { background: var(--surface-2); color: var(--text-3); }

.consulted { margin-top: 9px; }
.consulted summary {
  font-size: 12px; color: var(--text-3); cursor: pointer;
  list-style: none; display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 0;
}
.consulted summary::-webkit-details-marker { display: none; }
.consulted summary::before {
  content: "›"; display: inline-block; transition: transform .15s; font-size: 14px;
}
.consulted[open] summary::before { transform: rotate(90deg); }
.consulted summary:hover { color: var(--text-2); }
.consulted-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ── Message actions ────────────────────────────────────── */
.actions { display: flex; align-items: center; gap: 4px; margin-top: 12px; }
.act {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 4px 10px; font-size: 12px; color: var(--text-3);
  background: var(--surface); transition: all .14s;
}
.act:hover { color: var(--text); border-color: var(--border-2); }
.act svg { width: 13px; height: 13px; }
.act.on-up   { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.act.on-down { background: var(--red-bg);   border-color: var(--red);   color: var(--red); }
.act.dim { opacity: .35; pointer-events: none; }
.act.copied { color: var(--green); border-color: var(--green); }

/* ── Typing ─────────────────────────────────────────────── */
.typing { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 13.5px; }
.dots { display: inline-flex; gap: 4px; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  animation: pulse 1.3s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes pulse { 0%, 70%, 100% { opacity: .25; } 35% { opacity: 1; } }

/* ── Welcome ────────────────────────────────────────────── */
.welcome { text-align: center; padding: 28px 0 8px; }
.welcome .logo-lg { height: 60px; width: auto; margin: 0 auto 20px; display: block; }
.welcome h2 { font-size: 22px; font-weight: 680; letter-spacing: -.02em; margin-bottom: 8px; }
.welcome p { color: var(--text-2); max-width: 46ch; margin: 0 auto; font-size: 14.5px; }

.starters {
  margin-top: 26px; display: grid; gap: 9px;
  grid-template-columns: repeat(auto-fit, minmax(258px, 1fr));
  text-align: left;
}
.starter {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px;
  font-size: 13.5px; color: var(--text-2); line-height: 1.5;
  display: flex; align-items: center; gap: 10px;
  transition: all .15s; box-shadow: var(--shadow-sm); text-align: left;
}
.starter:hover {
  border-color: var(--navy-400); color: var(--text);
  transform: translateY(-1px); box-shadow: var(--shadow);
}
.starter::after {
  content: "→"; margin-left: auto; color: var(--text-3);
  opacity: 0; transition: opacity .15s, transform .15s; flex-shrink: 0;
}
.starter:hover::after { opacity: 1; transform: translateX(2px); }

/* ── Banner ─────────────────────────────────────────────── */
.banner {
  max-width: var(--col); margin: 16px auto 0;
  background: var(--amber-bg); border: 1px solid var(--amber);
  color: var(--amber); border-radius: var(--radius-sm);
  padding: 11px 15px; font-size: 13.5px;
}

/* ── Composer ───────────────────────────────────────────── */
.composer-wrap {
  flex-shrink: 0;
  padding: 10px 20px calc(14px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to bottom, transparent, var(--bg) 22%);
}
.composer { max-width: var(--col); margin: 0 auto; }

.input-box {
  display: flex; align-items: flex-end; gap: 9px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 9px 9px 9px 15px;
  box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.input-box:focus-within { border-color: var(--navy-400); box-shadow: var(--shadow); }
#user-input {
  flex: 1; border: none; background: none; outline: none; resize: none;
  font-size: 15px; line-height: 1.5; max-height: 168px; min-height: 26px;
  padding: 3px 0; color: var(--text);
}
#user-input::placeholder { color: var(--text-3); }
.send {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: var(--pill-on); color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background .14s, opacity .14s;
}
.send:hover:not(:disabled) { filter: brightness(1.15); }
.send:disabled { opacity: .35; cursor: not-allowed; }
.send svg { width: 17px; height: 17px; }

.fineprint {
  margin-top: 10px; font-size: 11.5px; color: var(--text-3);
  text-align: center; line-height: 1.55;
}
.fineprint summary {
  cursor: pointer; list-style: none; display: inline-flex; gap: 5px; align-items: center;
}
.fineprint summary::-webkit-details-marker { display: none; }
.fineprint summary::after { content: "\24D8"; font-size: 11px; opacity: .7; }
.fineprint summary:hover { color: var(--text-2); }
.fineprint .detail {
  margin-top: 7px; max-width: 62ch; margin-inline: auto; text-align: center;
}
.fineprint a { color: inherit; }

/* Sponsor credit stays visible — it is an acknowledgement, not fine print. */
.fineprint .sponsor {
  margin-top: 7px; padding-top: 7px;
  border-top: 1px solid var(--border);
  max-width: 56ch; margin-inline: auto; text-wrap: balance;
  color: var(--text-2); font-size: 11.5px;
}
.fineprint .sponsor a {
  color: var(--text-2); font-weight: 600; text-decoration: none;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-2);
}
.fineprint .sponsor a:hover { color: var(--text); border-bottom-color: var(--text-3); }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  header { padding: 0 14px; }
  .brand p { display: none; }
  .status-pill span { display: none; }
  .status-pill { padding: 6px; }
  .chat-messages { padding: 20px 14px 4px; }
  .thread { gap: 22px; }
  .composer-wrap { padding: 8px 14px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .starters { grid-template-columns: 1fr; }
  .welcome .logo-lg { height: 54px; }
  .welcome h2 { font-size: 19px; }
}

/* ── Screen-reader only ─────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Theme-specific assets ──────────────────────────────── */
/* The mark is navy artwork, so it needs a knockout copy on dark ground. */
.only-dark { display: none !important; }
.only-light { display: block !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .only-dark  { display: block !important; }
  :root:not([data-theme="light"]) .only-light { display: none !important; }
}
:root[data-theme="dark"]  .only-dark  { display: block !important; }
:root[data-theme="dark"]  .only-light { display: none !important; }
:root[data-theme="light"] .only-light { display: block !important; }
:root[data-theme="light"] .only-dark  { display: none !important; }

/* ── Weekly digest card (admin) ─────────────────────────── */
.digest-lead { font-size: 13.5px; color: var(--text-2); line-height: 1.6; margin-bottom: 16px; max-width: 68ch; }
.digest-when { font-size: 11.5px; color: var(--text-3); }
.digest-last { margin-top: 14px; font-size: 12px; color: var(--text-3); }
.rcpt-add { display: flex; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.rcpt-add input {
  flex: 1; min-width: 220px; padding: 9px 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; outline: none; background: var(--surface); color: var(--text);
}
.rcpt-add input:focus { border-color: var(--navy-400); }
.rcpt-list { margin-top: 14px; display: grid; gap: 7px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.rcpt {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px;
}
.rcpt-email { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
