/* ===========================================================================
   Privacy-First AI Finance Intelligence Assistant
   Theme: blue / white / yellow.  Mobile-first, responsive.
   =========================================================================== */

:root {
  --blue-900: #0b2545;
  --blue-800: #12325c;
  --blue-700: #1d4ed8;
  --blue-600: #2563eb;
  --blue-500: #3b82f6;
  --blue-100: #dbeafe;
  --blue-50: #eff6ff;

  --yellow-600: #ca8a04;
  --yellow-500: #eab308;
  --yellow-400: #facc15;
  --yellow-100: #fef9c3;

  --white: #ffffff;
  --ink: #16233a;
  --ink-soft: #4a5a72;
  --ink-muted: #6b7a90;
  --line: #dbe4f0;
  --line-soft: #eaf0f8;
  --bg: #f4f7fc;

  --green: #12855a;
  --green-bg: #e7f7ef;
  --red: #b91c1c;
  --red-bg: #fdeaea;
  --amber: #a16207;
  --amber-bg: #fef3c7;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 35, 65, 0.06);
  --shadow: 0 4px 14px rgba(16, 35, 65, 0.08);
  --shadow-lg: 0 14px 40px rgba(16, 35, 65, 0.14);
  --max: 1180px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; color: var(--blue-900); }
h1 { font-size: 1.65rem; letter-spacing: -.02em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.03rem; }
p { margin: 0 0 .85em; }
a { color: var(--blue-700); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { margin: 0 0 .85em; padding-left: 1.15rem; }
code, kbd { font-family: var(--mono); font-size: .86em; background: var(--blue-50); padding: .1em .35em; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.4rem 0; }

.muted { color: var(--ink-muted); }
.small { font-size: .82rem; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.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;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 200;
  background: var(--blue-700); color: #fff; padding: .6rem 1rem;
  border-radius: var(--radius-sm); transition: top .18s;
}
.skip-link:focus { top: 8px; }

/* ---------------------------------------------------------------- header -- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--blue-900);
  border-bottom: 3px solid var(--yellow-400);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: var(--max); margin: 0 auto; padding: .6rem 1rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; flex: 0 0 34px;
  background: var(--yellow-400); color: var(--blue-900);
  border-radius: 9px; font-weight: 800; font-size: 1.15rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: .97rem; letter-spacing: -.01em; }
.brand-text small { font-size: .69rem; color: #9fb6d8; text-transform: uppercase; letter-spacing: .07em; }

.nav-toggle {
  margin-left: auto; display: inline-flex; flex-direction: column; gap: 4px;
  background: transparent; border: 1px solid rgba(255,255,255,.28);
  border-radius: 8px; padding: .5rem .55rem; cursor: pointer;
}
.nav-toggle span { display: block; width: 18px; height: 2px; background: #fff; border-radius: 2px; }
.nav-toggle:focus-visible { outline: 2px solid var(--yellow-400); outline-offset: 2px; }

.primary-nav {
  display: none; width: 100%;
  flex-direction: column; gap: .1rem;
  padding: .4rem 0 .6rem;
}
.primary-nav.open { display: flex; }
.primary-nav a {
  color: #cfe0f5; padding: .55rem .7rem; border-radius: 8px;
  font-size: .9rem; font-weight: 500; white-space: nowrap;
}
.primary-nav a:hover { background: rgba(255,255,255,.09); color: #fff; text-decoration: none; }
.primary-nav a.active {
  background: var(--yellow-400); color: var(--blue-900); font-weight: 700;
}

@media (min-width: 900px) {
  .nav-toggle { display: none; }
  .primary-nav {
    display: flex; width: auto; flex-direction: row; gap: .15rem;
    margin-left: auto; padding: 0; align-items: center;
  }
  .primary-nav a { padding: .45rem .62rem; font-size: .855rem; }
}

/* ------------------------------------------------------- privacy banner -- */
.privacy-banner {
  background: var(--yellow-100);
  border-bottom: 1px solid #f2e3a0;
  display: flex; gap: .55rem; align-items: flex-start;
  padding: .6rem 1rem;
}
.privacy-banner p {
  margin: 0; font-size: .8rem; color: #6b4e02; max-width: var(--max);
  margin-inline: auto;
}
.privacy-banner-icon { font-size: .95rem; line-height: 1.4; }

/* ------------------------------------------------------------------ main -- */
.site-main { max-width: var(--max); margin: 0 auto; padding: 1.25rem 1rem 2.5rem; outline: none; }

/* ---------------------------------------------------------------- footer -- */
.site-footer {
  background: var(--blue-900); color: #b9cbe4;
  padding: 1.5rem 1rem; margin-top: 2rem;
  border-top: 3px solid var(--yellow-400);
}
.footer-inner { max-width: var(--max); margin: 0 auto; }
.site-footer p { margin: 0 0 .5rem; font-size: .8rem; }
.site-footer strong { color: #fff; }
.site-footer .muted { color: #8fa6c4; }

/* ------------------------------------------------------------ primitives -- */
.card {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.card-head h2, .card-head h3 { margin: 0; }

.section-title { display: flex; align-items: center; gap: .6rem; margin: 0 0 .9rem; }
.section-title h1 { margin: 0; }

.page-head { margin-bottom: 1.2rem; }
.page-head h1 { margin-bottom: .25rem; }
.page-head .lede { color: var(--ink-soft); max-width: 70ch; margin: 0; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: 1fr; }
@media (min-width: 620px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 980px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; font-size: .875rem;
  padding: .55rem .95rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .06s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--yellow-400); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--blue-700); color: #fff; }
.btn-primary:hover { background: var(--blue-800); }
.btn-accent { background: var(--yellow-400); color: var(--blue-900); }
.btn-accent:hover { background: var(--yellow-500); }
.btn-ghost { background: #fff; color: var(--blue-700); border-color: var(--line); }
.btn-ghost:hover { background: var(--blue-50); }
.btn-sm { padding: .34rem .7rem; font-size: .8rem; }

.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .71rem; font-weight: 700; letter-spacing: .03em;
  padding: .16rem .5rem; border-radius: 999px;
  background: var(--blue-50); color: var(--blue-700);
  border: 1px solid var(--blue-100); text-transform: uppercase;
}
.badge-bank { background: var(--yellow-100); color: var(--amber); border-color: #f0df9c; }
.badge-derived { background: var(--amber-bg); color: var(--amber); border-color: #f5e3ac; }
.badge-ok { background: var(--green-bg); color: var(--green); border-color: #bfe8d2; }
.badge-warn { background: var(--red-bg); color: var(--red); border-color: #f6cccc; }
.badge-neutral { background: #f1f5f9; color: var(--ink-soft); border-color: var(--line); }

/* --------------------------------------------------------------- inputs -- */
.field { display: flex; flex-direction: column; gap: .3rem; }
.field label { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted); }
input[type="text"], input[type="search"], select, textarea {
  font: inherit; font-size: .9rem; color: var(--ink);
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: .55rem .7rem; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(59,130,246,.16);
}
textarea { resize: vertical; min-height: 74px; }

.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.toolbar .grow { flex: 1 1 240px; min-width: 0; }

/* --------------------------------------------------------------- tables -- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: .855rem; min-width: 620px; }
thead th {
  background: var(--blue-50); color: var(--blue-900);
  text-align: left; font-size: .74rem; text-transform: uppercase;
  letter-spacing: .05em; padding: .6rem .7rem; white-space: nowrap;
  border-bottom: 1px solid var(--line); position: sticky; top: 0;
}
tbody td { padding: .58rem .7rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfdff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------------------------------------------------------------- stats -- */
.stat-grid { display: grid; gap: .8rem; grid-template-columns: 1fr; }
@media (min-width: 560px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1rem; box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--blue-600);
}
.stat.accent { border-left-color: var(--yellow-400); }
.stat .stat-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-muted); font-weight: 700; }
.stat .stat-value { font-size: 1.5rem; font-weight: 800; color: var(--blue-900); letter-spacing: -.02em; line-height: 1.15; margin-top: .1rem; }
.stat .stat-note { font-size: .74rem; color: var(--ink-muted); }

/* --------------------------------------------------------- company cards -- */
.company-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow-sm); display: flex; flex-direction: column;
  gap: .55rem; transition: box-shadow .16s, border-color .16s, transform .16s;
}
.company-card:hover { box-shadow: var(--shadow); border-color: var(--blue-100); transform: translateY(-1px); }
.company-card header { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.company-card h3 { margin: 0; font-size: 1rem; }
.company-card .ticker { font-family: var(--mono); font-size: .72rem; color: var(--ink-muted); }
.company-card .company-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem .6rem; margin-top: .2rem; }
.company-card .company-metrics div { font-size: .8rem; }
.company-card .company-metrics span { display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted); }
.company-card .company-metrics strong { font-variant-numeric: tabular-nums; }
.company-card footer { margin-top: auto; padding-top: .5rem; border-top: 1px solid var(--line-soft); display: flex; justify-content: space-between; align-items: center; gap: .5rem; }

.selectable { position: relative; }
.selectable input[type="checkbox"] { position: absolute; top: .85rem; right: .85rem; width: 18px; height: 18px; accent-color: var(--blue-700); cursor: pointer; }
.selectable.selected { border-color: var(--blue-600); box-shadow: 0 0 0 3px rgba(59,130,246,.14); }

/* ---------------------------------------------------------------- charts -- */
.chart-block { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow-sm); }
.chart-block h3 { margin-bottom: .2rem; }
.chart-block .chart-sub { font-size: .76rem; color: var(--ink-muted); margin-bottom: .7rem; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-svg text { font-family: var(--font); }
.bar-label { font-size: 9px; fill: #46566e; }
.axis-label { font-size: 9px; fill: #7b8aa0; }
.grid-line { stroke: #eef2f8; stroke-width: 1; }
.chart-empty { padding: 1.6rem; text-align: center; color: var(--ink-muted); font-size: .85rem; }

.legend { display: flex; flex-wrap: wrap; gap: .45rem 1rem; margin-top: .6rem; font-size: .76rem; color: var(--ink-soft); }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ------------------------------------------------------------------- chat -- */
.chat { display: flex; flex-direction: column; height: 520px; max-height: 70vh; }
.chat-log { flex: 1; overflow-y: auto; padding: .3rem .2rem; display: flex; flex-direction: column; gap: .75rem; }
.msg { display: flex; gap: .55rem; align-items: flex-start; }
.msg .avatar {
  flex: 0 0 28px; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: .78rem; font-weight: 800;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: var(--yellow-400); color: var(--blue-900); }
.msg.bot .avatar { background: var(--blue-700); color: #fff; }
.bubble {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: .65rem .85rem; font-size: .875rem; max-width: 78%;
  box-shadow: var(--shadow-sm); overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--blue-700); color: #fff; border-color: var(--blue-700); }
.msg.bot .bubble { border-top-left-radius: 4px; }
.msg.user .bubble { border-top-right-radius: 4px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble .bubble-meta { font-size: .72rem; color: var(--ink-muted); margin-top: .45rem; padding-top: .4rem; border-top: 1px dashed var(--line); }
.msg.user .bubble .bubble-meta { color: #dbeafe; border-color: rgba(255,255,255,.25); }

.chat-input { display: flex; gap: .5rem; margin-top: .7rem; }
.chat-input textarea { min-height: 46px; max-height: 130px; }

.examples { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.example-chip {
  font: inherit; font-size: .78rem; text-align: left;
  background: var(--blue-50); color: var(--blue-800);
  border: 1px solid var(--blue-100); border-radius: 999px;
  padding: .35rem .75rem; cursor: pointer; transition: background .14s;
}
.example-chip:hover { background: var(--yellow-100); border-color: #f0df9c; color: #6b4e02; }

.typing { display: inline-flex; gap: 3px; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--blue-500); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ------------------------------------------------------------- citations -- */
.citations { list-style: none; padding: 0; margin: .5rem 0 0; display: flex; flex-direction: column; gap: .4rem; }
.citations li {
  font-size: .78rem; background: var(--blue-50); border: 1px solid var(--blue-100);
  border-radius: var(--radius-sm); padding: .45rem .6rem;
}
.citations li .cite-doc { font-weight: 700; color: var(--blue-900); }
.citations li a { word-break: break-all; }

/* ----------------------------------------------------------------- trace -- */
.trace { list-style: none; padding: 0; margin: 0; position: relative; }
.trace::before {
  content: ""; position: absolute; left: 15px; top: 6px; bottom: 6px;
  width: 2px; background: var(--line);
}
.trace-step { position: relative; padding: 0 0 1rem 42px; }
.trace-step:last-child { padding-bottom: 0; }
.trace-dot {
  position: absolute; left: 4px; top: 1px;
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: .68rem; font-weight: 800;
  background: var(--blue-100); color: var(--blue-800);
  border: 2px solid #fff; box-shadow: 0 0 0 2px var(--blue-100);
}
.trace-step[data-stage="tool_call"] .trace-dot,
.trace-step[data-stage="tool_result"] .trace-dot { background: var(--yellow-400); color: var(--blue-900); box-shadow: 0 0 0 2px var(--yellow-400); }
.trace-step[data-stage="llm"] .trace-dot { background: var(--green); color: #fff; box-shadow: 0 0 0 2px var(--green); }
.trace-step[data-stage="answer"] .trace-dot { background: var(--blue-700); color: #fff; box-shadow: 0 0 0 2px var(--blue-700); }
.trace-step[data-stage="warning"] .trace-dot { background: var(--red); color: #fff; box-shadow: 0 0 0 2px var(--red); }
.trace-title { font-weight: 700; font-size: .875rem; color: var(--blue-900); }
.trace-detail { font-size: .82rem; color: var(--ink-soft); }
.trace-meta { font-size: .72rem; color: var(--ink-muted); font-family: var(--mono); }
.trace pre {
  background: var(--blue-900); color: #d6e4f7; font-family: var(--mono);
  font-size: .72rem; line-height: 1.5; padding: .65rem .75rem; border-radius: var(--radius-sm);
  overflow-x: auto; margin: .4rem 0 0; max-height: 240px;
}
.trace details summary { cursor: pointer; font-size: .76rem; color: var(--blue-700); font-weight: 600; }

/* --------------------------------------------------------------- notices -- */
.notice {
  border-radius: var(--radius-sm); padding: .7rem .85rem; font-size: .82rem;
  border: 1px solid var(--line); background: var(--blue-50); color: var(--blue-900);
  display: flex; gap: .5rem; align-items: flex-start;
}
.notice-warn { background: var(--amber-bg); border-color: #f5e3ac; color: var(--amber); }
.notice-error { background: var(--red-bg); border-color: #f6cccc; color: var(--red); }
.notice-ok { background: var(--green-bg); border-color: #bfe8d2; color: var(--green); }
.notice strong { font-weight: 800; }

.kv { display: grid; grid-template-columns: 1fr; gap: .35rem .9rem; font-size: .855rem; }
@media (min-width: 560px) { .kv { grid-template-columns: minmax(140px, 220px) 1fr; } }
.kv dt { color: var(--ink-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.kv dd { margin: 0; color: var(--ink); }

.figure-list { list-style: none; padding: 0; margin: 0; }
.figure-list li {
  display: flex; justify-content: space-between; align-items: baseline; gap: .75rem;
  padding: .5rem 0; border-bottom: 1px solid var(--line-soft); font-size: .88rem;
}
.figure-list li:last-child { border-bottom: 0; }
.figure-list .fig-label { color: var(--ink-soft); }
.figure-list .fig-value { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--blue-900); white-space: nowrap; }
.figure-list .fig-sub { display: block; font-size: .72rem; color: var(--ink-muted); font-weight: 400; }

/* ---------------------------------------------------------------- states -- */
.loading-state { display: grid; place-items: center; gap: .8rem; padding: 3.5rem 1rem; color: var(--ink-muted); }
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--blue-100); border-top-color: var(--blue-700);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 2.4rem 1rem; color: var(--ink-muted); }
.empty-state h3 { color: var(--ink-soft); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px);
  background: var(--blue-900); color: #fff; font-size: .84rem;
  padding: .6rem 1rem; border-radius: 999px; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 300;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); }

/* --------------------------------------------------------------- tables -- */
.pill-row { display: flex; flex-wrap: wrap; gap: .4rem; }
.pill {
  font: inherit; font-size: .78rem; cursor: pointer;
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: .3rem .7rem; color: var(--ink-soft);
}
.pill:hover { border-color: var(--blue-500); color: var(--blue-700); }
.pill[aria-pressed="true"] { background: var(--blue-700); border-color: var(--blue-700); color: #fff; font-weight: 600; }

/* ------------------------------------------------------------- accordion -- */
details.disclosure {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; padding: .65rem .85rem; margin-bottom: .55rem;
}
details.disclosure > summary { cursor: pointer; font-weight: 700; font-size: .86rem; color: var(--blue-900); }
details.disclosure[open] > summary { margin-bottom: .5rem; }

/* -------------------------------------------------------------- responsive */
@media (max-width: 420px) {
  h1 { font-size: 1.4rem; }
  .site-main { padding: 1rem .75rem 2rem; }
  .stat .stat-value { font-size: 1.25rem; }
  .bubble { max-width: 88%; }
  .chat { height: 460px; }
}

@media print {
  .site-header, .privacy-banner, .site-footer, .chat-input, .examples, .btn { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  html { scroll-behavior: auto; }
}
