/* ===== Tokens ===== */
:root {
  --navy: #0a2342;
  --navy-hi: #0d2c56;

  /* Accent. --gold is the source of truth; the rest are derived tones.
     The states canvas recomputes all five from a single picked hue. */
  --gold: #ffc629;        /* primary accent: FAB badge, avatar, focus rings */
  --gold-soft: #ffde7a;   /* lighter end of the header rule gradient */
  --gold-deep: #c99a12;   /* accent on white — source/chip icons */
  --gold-tint: #fffdf5;   /* barely-there wash: source chip hover */
  --gold-sel: #ffe08a;    /* text selection */
  --gold-rgb: 255, 198, 41; /* for rgba() in the FAB pulse */
  --on-accent: var(--navy); /* ink for text/icons sitting on the accent */

  --ink: #1a2230;
  --ink-2: #213351;
  --muted: #5b6676;
  --muted-2: #9aa6bd;
  --muted-3: #aeb8c9;
  --line: #e7ebf2;
  --line-2: #e2e7f0;
  --surface: #fff;
  --canvas: #f5f7fb;
  --page: #eef1f6;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--ink);
  background: var(--page);
  overflow: hidden;
}
a { color: #1d4ed8; }
a:hover { color: #12308f; }
button, textarea { font-family: inherit; }
::selection { background: var(--gold-sel); }

/* ===== Backdrop page ===== */
.page { position: absolute; inset: 0; overflow: hidden; }
.topbar {
  height: 60px; background: var(--navy); color: #eaf0fb;
  display: flex; align-items: center; gap: 18px;
  padding: 0 clamp(16px, 5vw, 56px);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 7px; background: var(--gold);
  display: flex; align-items: center; justify-content: center;
  color: var(--on-accent); font-weight: 800; font-size: 15px;
}
.brand-name { font-weight: 700; font-size: 14.5px; letter-spacing: .2px; }
.brand-name span { opacity: .6; font-weight: 500; }
.topnav { margin-left: auto; display: flex; gap: 22px; font-size: 13px; color: #b7c4de; font-weight: 500; }

.hero { padding: clamp(28px, 6vw, 64px) clamp(16px, 5vw, 56px); max-width: 1000px; }
.eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--muted-2); }
.hero h1 {
  font-size: clamp(30px, 4.4vw, 48px); font-weight: 800; line-height: 1.08;
  color: var(--navy); margin: 12px 0 16px; max-width: 16ch;
}
.hero p { font-size: 16px; line-height: 1.6; color: var(--muted); max-width: 56ch; margin: 0; }
.states-link {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 22px;
  font-size: 13.5px; font-weight: 700; color: var(--navy); text-decoration: none;
  background: #fff; border: 1px solid var(--line-2); border-radius: 11px; padding: 10px 15px;
  box-shadow: 0 1px 3px rgba(16,42,76,.04); transition: border-color .15s, transform .12s;
}
.states-link:hover { border-color: var(--gold); color: var(--navy); transform: translateY(-1px); }
.states-link:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
.states-link svg { color: var(--gold-deep); }

.cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px; margin-top: 34px; max-width: 760px;
}
.cards > div {
  height: 104px; border-radius: 14px; background: #fff;
  border: 1px solid #e3e8f0; box-shadow: 0 2px 8px rgba(16, 42, 76, .04);
}

/* ===== Animations ===== */
@keyframes wisPanelIn { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes wisFabIn   { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes wisPulse {
  0%   { box-shadow: 0 10px 26px rgba(10,35,66,.28), 0 0 0 0 rgba(var(--gold-rgb), .5); }
  70%  { box-shadow: 0 10px 26px rgba(10,35,66,.28), 0 0 0 14px rgba(var(--gold-rgb), 0); }
  100% { box-shadow: 0 10px 26px rgba(10,35,66,.28), 0 0 0 0 rgba(var(--gold-rgb), 0); }
}
@keyframes wisDot   { 0%,80%,100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-4px); opacity: 1; } }
@keyframes wisRise  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes wisTip   { from { opacity: 0; transform: translateY(6px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes wisCaret { 0%,100% { opacity: 0; } 50% { opacity: 1; } }

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

/* ===== FAB ===== */
.fab-wrap {
  position: fixed;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 40; display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
}
.tooltip {
  position: relative; background: #fff; color: var(--navy);
  font-size: 13px; font-weight: 600; padding: 9px 13px; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(16,42,76,.16); border: 1px solid var(--line);
  animation: wisTip .25s ease-out;
}
.tooltip::after {
  content: ''; position: absolute; right: 26px; bottom: -5px;
  width: 10px; height: 10px; background: #fff;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  transform: rotate(45deg);
}
.fab {
  display: inline-flex; align-items: center; gap: 10px;
  height: 52px; padding: 0 20px 0 16px; border: none; border-radius: 26px;
  background: var(--navy); color: #fff; cursor: pointer; font-size: 15px; font-weight: 700;
  box-shadow: 0 10px 26px rgba(10,35,66,.28);
  animation: wisPulse 2.6s ease-out 1s 2, wisFabIn .3s ease-out;
  transition: transform .16s ease, background .16s ease;
}
.fab:hover { transform: translateY(-2px); background: var(--navy-hi); }
.fab:active { transform: translateY(0); }
.fab:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.fab-badge {
  width: 30px; height: 30px; border-radius: 50%; background: var(--gold); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center;
}

/* ===== Panel ===== */
.panel {
  position: fixed; right: 24px; bottom: 24px; z-index: 50;
  width: 404px; height: min(660px, calc(100vh - 48px));
  display: flex; flex-direction: column; background: var(--canvas);
  border-radius: 20px; overflow: hidden;
  box-shadow: 0 24px 64px rgba(10,35,66,.28), 0 2px 10px rgba(10,35,66,.14);
  animation: wisPanelIn .24s cubic-bezier(.2,.8,.2,1);
}
@media (max-width: 559px) {
  .panel {
    inset: 0; right: auto; bottom: auto; width: auto; height: auto;
    border-radius: 0; box-shadow: none; animation: wisPanelIn .22s ease-out;
  }
}

/* Header */
.panel-head {
  background: var(--navy); color: #fff; padding: 15px 16px 14px;
  display: flex; align-items: flex-start; gap: 12px; position: relative; flex: none;
}
.panel-avatar {
  width: 40px; height: 40px; border-radius: 12px; background: var(--gold); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center; flex: none;
}
.panel-title-wrap { flex: 1; min-width: 0; padding-top: 1px; }
.panel-title { font-weight: 700; font-size: 15.5px; letter-spacing: .1px; }
.panel-status { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: #a9b8d6; margin-top: 2px; }
.dot-online { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.2); }
.head-btn {
  width: 34px; height: 34px; border-radius: 9px; border: none; background: transparent;
  color: #c3d0ea; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.head-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.head-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.gold-rule { height: 3px; background: linear-gradient(90deg, var(--gold), var(--gold-soft)); flex: none; }

/* Overflow menu */
.menu {
  position: absolute; top: 52px; right: 12px; z-index: 5;
  background: #fff; color: var(--ink); border-radius: 12px;
  box-shadow: 0 12px 34px rgba(16,42,76,.22); border: 1px solid var(--line);
  padding: 6px; width: 200px; animation: wisTip .16s ease-out;
}
.menu button {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border: none; border-radius: 8px; background: transparent; cursor: pointer;
  font-size: 13.5px; font-weight: 600; color: var(--ink); text-align: left;
}
.menu button.secondary { color: var(--muted); }
.menu button:hover { background: #f2f5fa; }
.menu .flag { width: 16px; text-align: center; }

/* Messages */
.messages {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  background: var(--canvas); padding: 16px; position: relative;
}
.msg-list { display: flex; flex-direction: column; gap: 14px; }

.empty { animation: wisRise .3s ease-out; padding-top: 6px; }
.empty-title { font-size: 22px; font-weight: 800; color: var(--navy); }
.empty-sub { font-size: 14.5px; line-height: 1.6; color: var(--muted); margin-top: 8px; max-width: 34ch; }
.empty-label {
  font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted-2); margin: 22px 0 10px;
}
.chips { display: flex; flex-direction: column; gap: 9px; }
.chip {
  display: flex; align-items: center; gap: 10px; text-align: left; width: 100%;
  padding: 12px 14px; border-radius: 13px; border: 1px solid var(--line-2);
  background: #fff; cursor: pointer; font-size: 13.7px; font-weight: 600; color: var(--ink-2);
  box-shadow: 0 1px 3px rgba(16,42,76,.04); transition: border-color .15s, transform .12s;
}
.chip:hover { border-color: var(--gold); transform: translateX(2px); }
.chip:focus-visible { outline: 2px solid var(--navy); outline-offset: 1px; }
.chip .spark { color: var(--gold-deep); flex: none; display: flex; }

.row { display: flex; }
.row.user { justify-content: flex-end; }
.row.ai, .row.error { justify-content: flex-start; }

.bubble-user {
  max-width: 82%; background: var(--navy); color: #fff; padding: 11px 15px;
  border-radius: 16px 16px 4px 16px; font-size: 14.5px; line-height: 1.5;
  box-shadow: 0 2px 6px rgba(10,35,66,.14); white-space: pre-wrap; word-wrap: break-word;
}
.ai-stack { max-width: 90%; display: flex; flex-direction: column; gap: 10px; animation: wisRise .28s ease-out; }
.bubble-ai {
  background: #fff; color: var(--ink); padding: 13px 16px; border: 1px solid var(--line);
  border-radius: 16px 16px 16px 4px; font-size: 14.5px; line-height: 1.62;
  box-shadow: 0 2px 10px rgba(16,42,76,.05); white-space: pre-wrap; word-wrap: break-word;
}
.caret {
  display: inline-block; width: 2px; height: 1.05em; background: var(--navy);
  margin-left: 1px; vertical-align: -2px; animation: wisCaret 1s steps(1) infinite;
}

/* Sources */
.src-label {
  font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted-2); margin-bottom: 7px;
}
.src-list { display: flex; flex-wrap: wrap; gap: 7px; }
.src {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px;
  border-radius: 9px; border: 1px solid var(--line-2); background: #fff; color: var(--ink-2);
  font-size: 12.3px; font-weight: 600; text-decoration: none;
  transition: border-color .15s, background .15s;
}
.src:hover { border-color: var(--gold); background: var(--gold-tint); color: var(--ink-2); }
.src .lead { color: var(--gold-deep); flex: none; display: flex; }
.src .trail { color: var(--muted-3); flex: none; display: flex; }

/* Message actions */
.actions { display: flex; align-items: center; gap: 7px; }
.act {
  width: 34px; height: 32px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; transition: all .14s;
}
.act:hover { border-color: #c9d3e2; color: var(--ink-2); }
.act.like-on { border-color: #bce6c8; background: #eaf7ee; color: #1f9d54; }
.act.like-on:hover { border-color: #bce6c8; color: #1f9d54; }
.act.dislike-on { border-color: #f3ccd3; background: #fdeef0; color: #d5405a; }
.act.dislike-on:hover { border-color: #f3ccd3; color: #d5405a; }
.act-sep { width: 1px; height: 20px; background: var(--line-2); margin: 0 2px; }

/* Dislike form */
.fb-form {
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px;
  box-shadow: 0 4px 16px rgba(16,42,76,.06); animation: wisRise .2s ease-out;
}
.fb-form h4 { font-size: 13.5px; font-weight: 700; color: var(--ink); margin: 0; }
.fb-reasons { display: flex; flex-wrap: wrap; gap: 7px; margin: 11px 0 12px; }
.reason {
  padding: 7px 13px; border-radius: 999px; border: 1px solid #dbe1ea; background: #fff;
  color: #3a4557; font-size: 12.5px; font-weight: 600; cursor: pointer; transition: all .14s;
}
.reason[aria-pressed="true"] { border-color: var(--navy); background: var(--navy); color: #fff; }
.fb-form textarea {
  width: 100%; resize: none; border: 1px solid #dbe1ea; border-radius: 10px;
  padding: 9px 11px; font-size: 13.3px; line-height: 1.5; color: var(--ink);
  outline: none; background: #fbfcfe;
}
.fb-form textarea:focus { border-color: var(--navy); background: #fff; }
.fb-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 11px; }
.btn-ghost {
  height: 34px; padding: 0 14px; border-radius: 9px; border: 1px solid #dbe1ea;
  background: #fff; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-ghost:hover { background: var(--canvas); }
.btn-solid {
  height: 34px; padding: 0 16px; border-radius: 9px; border: none;
  background: var(--navy); color: #fff; font-size: 13px; font-weight: 700; cursor: pointer;
}
.btn-solid:hover { background: var(--navy-hi); }
.fb-thanks {
  display: inline-flex; align-items: center; gap: 8px; align-self: flex-start;
  background: #f2f5fa; border: 1px solid var(--line-2); border-radius: 10px;
  padding: 8px 12px; font-size: 12.8px; font-weight: 600; color: #3a4557;
  animation: wisRise .2s ease-out;
}

/* Error */
.err-stack { max-width: 88%; display: flex; flex-direction: column; gap: 10px; animation: wisRise .3s ease-out; }
.err-box {
  display: flex; gap: 11px; align-items: flex-start;
  background: #fff6f6; border: 1px solid #f4d2d2; border-radius: 16px 16px 16px 4px; padding: 13px 15px;
}
.err-box .icon { color: #d5405a; flex: none; margin-top: 1px; display: flex; }
.err-box p { font-size: 14px; line-height: 1.55; color: #7a3540; margin: 0; }
.btn-retry {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--navy);
  background: var(--navy); color: #fff; cursor: pointer; font-size: 13px; font-weight: 700;
}
.btn-retry:hover { background: var(--navy-hi); }

/* Typing */
.typing { display: flex; justify-content: flex-start; animation: wisRise .2s ease-out; }
.typing-bubble {
  display: flex; align-items: center; gap: 5px; background: #fff; border: 1px solid var(--line);
  border-radius: 16px 16px 16px 4px; padding: 14px 16px; box-shadow: 0 2px 10px rgba(16,42,76,.05);
}
.typing-bubble span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); animation: wisDot 1.3s infinite; }
.typing-bubble span:nth-child(2) { animation-delay: .18s; }
.typing-bubble span:nth-child(3) { animation-delay: .36s; }

/* Scroll-to-latest */
.scroll-latest {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 88px; z-index: 6;
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 13px;
  border-radius: 18px; border: 1px solid var(--line-2); background: #fff; color: var(--ink-2);
  font-size: 12.5px; font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 18px rgba(16,42,76,.14); animation: wisRise .18s ease-out;
}
.scroll-latest:hover { border-color: var(--gold); }

/* Composer */
.composer {
  flex: none; padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--page);
}
.composer-box {
  display: flex; align-items: flex-end; gap: 8px; background: var(--canvas);
  border: 1.5px solid #e6eaf1; border-radius: 16px; padding: 6px 6px 6px 14px;
  transition: border-color .15s;
}
.composer-box:focus-within { border-color: var(--navy); }
.composer textarea {
  flex: 1; border: none; outline: none; background: transparent; resize: none;
  font-size: 14.5px; line-height: 1.45; color: var(--ink);
  padding: 10px 0; max-height: 120px; min-height: 24px;
}
.icon-btn {
  width: 40px; height: 40px; flex: none; border-radius: 12px; border: none;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.btn-send { background: var(--navy); color: #fff; cursor: pointer; box-shadow: 0 3px 8px rgba(10,35,66,.22); }
.btn-send:hover { background: var(--navy-hi); }
.btn-send:disabled { background: #e6eaf1; color: var(--muted-3); cursor: not-allowed; box-shadow: none; }
.btn-stop { background: var(--navy); color: #fff; cursor: pointer; }
.btn-stop:hover { background: var(--navy-hi); }
.composer-hint { text-align: center; font-size: 11px; color: var(--muted-3); margin-top: 8px; }
.composer-hint b { color: #8a94a6; }

[hidden] { display: none !important; }
