:root {
  --navy: #0b2545;
  --navy-2: #13315c;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f6f8fb;
  --card: #ffffff;
  --accent: #1e88e5;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.06);
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
}
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
}
.brand-title {
  font-weight: 600;
  font-size: 15px;
}
.brand-sub {
  font-size: 12px;
  opacity: 0.7;
}
.division-switch {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px;
  border-radius: 8px;
}
.div-btn {
  background: transparent;
  border: 0;
  color: #cbd5e1;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.div-btn.active {
  background: #fff;
  color: var(--navy);
  font-weight: 600;
}
.topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  opacity: 0.85;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
}
.dot.live {
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.2);
}

@media (max-width: 820px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px 16px;
    padding: 12px 16px;
  }
  .division-switch {
    order: 3;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }
  .div-btn {
    flex: 1 1 auto;
    text-align: center;
    white-space: nowrap;
  }
  .topbar-meta {
    margin-left: auto;
  }
}
@media (max-width: 480px) {
  .brand-title {
    font-size: 14px;
  }
  .brand-sub {
    display: none;
  }
  .topbar-meta span:last-child {
    display: none;
  }
  .disclaimer {
    padding: 10px 16px;
    font-size: 12px;
    text-align: left;
  }
}

.disclaimer {
  background: #fff7ed;
  border-bottom: 1px solid #fed7aa;
  color: #7c2d12;
  padding: 10px 24px;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}
.disclaimer strong {
  color: #9a3412;
}

.main {
  flex: 1;
  padding: 24px;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

.cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}
@media (max-width: 1100px) {
  .cards {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.card > header {
  padding: 18px 20px 0;
}
.card-tag {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--navy-2);
  background: #e8eef7;
  padding: 3px 8px;
  border-radius: 999px;
  margin-bottom: 8px;
}
.card h2 {
  margin: 0 0 4px;
  font-size: 18px;
  color: var(--navy);
}
.card-sub {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}
.card-body {
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.kpi {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcfe;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kpi.warn {
  border-color: #fde68a;
  background: #fffbeb;
}
.kpi-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.1;
}
.kpi-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
@media (max-width: 560px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .kpi-value {
    font-size: 20px;
  }
}

.chart-wrap {
  position: relative;
  height: 180px;
}

.narrative {
  background: #f1f5fb;
  border-left: 3px solid var(--accent);
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.55;
  border-radius: 4px;
  color: #1f2937;
}
.narrative .src {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.link-btn {
  background: transparent;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  align-self: flex-start;
  padding: 0;
}
.link-btn:hover {
  text-decoration: underline;
}

.ask {
  margin-top: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.ask > header h2 {
  margin: 0 0 4px;
  font-size: 18px;
  color: var(--navy);
}
.ask > header p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.chip {
  background: #eef2f7;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--navy-2);
  cursor: pointer;
}
.chip:hover {
  background: #e2e8f0;
}

.ask-form {
  display: flex;
  gap: 8px;
}
.ask-form input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}
.ask-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.ask-form button {
  background: var(--navy);
  color: #fff;
  border: 0;
  padding: 0 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}
.ask-form button:hover {
  background: var(--navy-2);
}

.answer {
  margin-top: 14px;
  min-height: 0;
  font-size: 14px;
  line-height: 1.6;
  color: #1f2937;
  white-space: pre-wrap;
}
.answer:empty {
  display: none;
}
.answer .src {
  color: var(--muted);
  font-size: 12px;
}
.answer .cursor {
  display: inline-block;
  width: 8px;
  height: 14px;
  background: var(--accent);
  vertical-align: -2px;
  animation: blink 1s steps(2) infinite;
  margin-left: 2px;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

.answer-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.ghost-btn {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--navy);
}
.ghost-btn:hover {
  background: #f1f5f9;
}

.raw {
  margin-top: 12px;
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 12px;
  max-height: 240px;
  overflow: auto;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal[hidden] {
  display: none;
}
.modal-card {
  background: #fff;
  border-radius: var(--radius);
  width: min(900px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-card > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-card > header h3 {
  margin: 0;
  color: var(--navy);
  font-size: 16px;
}
.modal-card > header button {
  background: transparent;
  border: 0;
  font-size: 22px;
  color: var(--muted);
  cursor: pointer;
}
#modalBody {
  padding: 14px 18px;
  overflow: auto;
}

table.dt {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.dt th,
table.dt td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
table.dt th {
  background: #f8fafc;
  color: var(--navy);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
table.dt td.bad {
  color: var(--bad);
  font-weight: 600;
}
table.dt td.warn {
  color: var(--warn);
  font-weight: 600;
}
table.dt td.good {
  color: var(--good);
}

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 18px;
}

@media print {
  .topbar,
  .disclaimer,
  .ask-form,
  .prompt-chips,
  .answer-actions,
  .division-switch,
  .topbar-meta,
  .link-btn,
  .modal {
    display: none !important;
  }
  body {
    background: #fff;
  }
}
