:root {
  --navy: #062642; --deep: #041C33; --panel: #0D3358; --panel-2: #123E68; --line: #1F4A75;
  --ink: #F3EFE6; --muted: #A9B6C6; --soft: #D5DCE5; --gold: #C9A96E; --gold-hi: #E2C68F;
  --good: #9ED3A6; --bad: #F2A39A;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --display: "Sora", "Segoe UI", system-ui, sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--navy);
}
*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; margin: 0; }
body { background: var(--navy); color: var(--ink); font: 400 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--gold-hi); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.app { display: flex; height: 100%; }
.sidebar { display: none; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }

/* ---------- sign-in / status ---------- */
.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 32px; text-align: center; }
.center h1 { font: 600 28px/1.2 var(--display); margin: 0; }
.center p { color: var(--muted); margin: 0; max-width: 34ch; }
.btn-primary { height: 52px; padding: 0 26px; border-radius: 26px; border: 0; background: var(--ink); color: var(--navy); font-weight: 600; }
.btn-ghost { height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: transparent; color: var(--soft); font-size: 13px; }
.mark { width: 64px; height: 64px; }

/* ---------- loading ---------- */
body.loading .sidebar { display: none !important; }
.loader-mark { width: 72px; height: 72px; animation: settle 1.6s ease-in-out infinite; }
.loader-mark svg { width: 100%; height: 100%; }
.loader-mark svg rect:last-child { animation: stone 1.6s ease-in-out infinite; }
@keyframes settle { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes stone { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
#loader-step { color: var(--soft); }
.loader-slow { font-size: 13px; color: var(--muted); }

/* ---------- home ---------- */
.home { flex: 1; overflow-y: auto; padding: 24px 20px 32px; display: flex; flex-direction: column; gap: 24px; max-width: 720px; width: 100%; margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; font: 600 18px var(--display); }
.brand svg { width: 30px; height: 30px; }
.avatar { width: 40px; height: 40px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel); font: 600 15px var(--display); }
.greet h1 { font: 600 30px/1.15 var(--display); margin: 0 0 6px; }
.greet p { margin: 0; color: var(--muted); }
.ask { display: flex; align-items: center; gap: 12px; height: 60px; padding: 0 8px 0 20px; border-radius: 30px; background: var(--ink); color: var(--navy); border: 0; width: 100%; text-align: left; font-weight: 500; font-size: 16px; }
.ask span { flex: 1; }
.mic-dot { width: 44px; height: 44px; border-radius: 22px; background: var(--navy); display: grid; place-items: center; }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 10px; }
.agent-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.agent-tile { display: flex; flex-direction: column; justify-content: space-between; gap: 18px; min-height: 100px; padding: 14px; border-radius: 18px; background: var(--panel); border: 1px solid transparent; text-align: left; }
.agent-tile.wide { grid-column: 1 / -1; flex-direction: row; align-items: center; min-height: 76px; border-color: var(--gold); }
.agent-tile .name { font-weight: 600; display: block; }
.agent-tile .blurb { font-size: 12px; color: var(--muted); }
.chip { width: 36px; height: 36px; border-radius: 10px; flex: none; }

/* ---------- chat ---------- */
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #143D66; }
.chat-head .title { flex: 1; display: flex; flex-direction: column; }
.chat-head .title b { font: 600 16px var(--display); }
.chat-head .title small { color: var(--muted); font-size: 12px; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; border: 0; background: transparent; display: grid; place-items: center; color: var(--ink); }
.thread { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 16px; }
.thread-inner { max-width: 1180px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.msg-user { align-self: flex-end; max-width: 80%; padding: 10px 14px; border-radius: 18px 18px 4px 18px; background: var(--ink); color: var(--navy); white-space: pre-wrap; }
.msg-agent { max-width: 100%; line-height: 1.55; }
.msg-agent p { margin: 0 0 8px; }
.msg-agent ul { margin: 0 0 8px; padding-left: 20px; }
.msg-agent table { border-collapse: collapse; font-size: 13px; margin: 6px 0 10px; }
.msg-agent th, .msg-agent td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.msg-agent th { color: var(--muted); font-weight: 500; }
.tablewrap { overflow-x: auto; }
.msg-meta { display: flex; gap: 8px; margin-top: 6px; }
.thinking { color: var(--muted); font-size: 14px; }
.thinking::after { content: " ."; animation: dots 1.2s steps(3) infinite; }
@keyframes dots { 33% { content: " .."; } 66% { content: " ..."; } }
.err { color: var(--bad); }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; }
.suggest button { height: 36px; padding: 0 14px; border-radius: 18px; border: 0; background: var(--panel-2); color: var(--ink); font-size: 13px; }
.composer { display: flex; gap: 10px; align-items: flex-end; padding: 10px 16px 14px; max-width: 1212px; width: 100%; margin: 0 auto; }
.composer textarea { flex: 1; min-height: 50px; max-height: 160px; resize: none; padding: 13px 18px; border-radius: 25px; background: var(--panel); border: 1px solid var(--line); outline: none; line-height: 1.4; }
.send { width: 50px; height: 50px; border-radius: 25px; border: 0; background: var(--gold); display: grid; place-items: center; flex: none; }
.send.listening { background: #D64545; color: #fff; animation: rec 1.4s ease-in-out infinite; }
@keyframes rec { 0%, 100% { box-shadow: 0 0 0 0 rgba(214, 69, 69, .55); } 50% { box-shadow: 0 0 0 8px rgba(214, 69, 69, 0); } }

/* ---------- dashboards ---------- */
.dash { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 16px; background: var(--deep); border: 1px solid #143D66; }
.dash h3 { margin: 0; font: 600 16px var(--display); }
.dash .sub { color: var(--muted); font-size: 12px; margin-top: -6px; }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.card { padding: 14px; border-radius: 14px; background: var(--panel); display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card.span { grid-column: 1 / -1; }
.card .lbl { font-size: 12px; color: var(--muted); }
.card .big { font: 600 clamp(18px, 1.6vw + 8px, 26px)/1.15 var(--display); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 38%) 1fr auto; gap: 8px; align-items: center; font-size: 12px; }
.bar-row .track { height: 10px; border-radius: 5px; background: var(--panel-2); }
.bar-row .fill { height: 10px; border-radius: 5px; background: var(--gold); }
.sources { font-size: 11px; color: var(--muted); }

/* ---------- wide screens: sidebar ---------- */
@media (min-width: 900px) {
  .sidebar { display: flex; flex-direction: column; gap: 22px; width: 270px; flex: none; padding: 28px 16px; background: var(--deep); border-right: 1px solid #143D66; overflow-y: auto; }
  .side-agent { display: flex; align-items: center; gap: 12px; height: 46px; padding: 0 10px; border-radius: 12px; border: 0; background: transparent; width: 100%; text-align: left; font-size: 14px; }
  .side-agent[aria-current="page"] { background: var(--panel); font-weight: 600; }
  .side-agent .chip { width: 28px; height: 28px; border-radius: 8px; }
  .home .agent-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- new answer waiting on another agent ---------- */
.side-agent.unread, .agent-tile.unread { position: relative; }
.side-agent.unread::after, .agent-tile.unread::after {
  content: ""; position: absolute; top: 10px; right: 10px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 0 3px var(--deep);
}

/* ---------- wide answers: text keeps a readable measure, dashboards use the full width ---------- */
.msg-agent > p, .msg-agent > ul, .msg-agent > .tablewrap { max-width: 760px; }
.msg-user { max-width: min(80%, 760px); }
.dash { width: 100%; }
.dash .card.span, .dash .card.half { grid-column: 1 / -1; }
.bar-row { grid-template-columns: minmax(90px, 22%) 1fr minmax(64px, auto); }
.bar-row b { text-align: right; font-variant-numeric: tabular-nums; }
.card .lbl { overflow-wrap: anywhere; }
@media (min-width: 1300px) {
  .dash-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .dash-grid .card.half { grid-column: span 2; }
}


/* ---------- recent conversations ---------- */
.recent-list { display: flex; flex-direction: column; gap: 4px; }
.recent-item { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 12px; min-height: 48px; padding: 8px 14px; border-radius: 12px; border: 0; background: #0B2E50; text-align: left; }
.recent-item .dot { width: 8px; height: 8px; border-radius: 4px; }
.recent-item .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.recent-item .w { font-size: 12px; color: var(--muted); white-space: nowrap; }