:root {
  --blue: #005ca8;
  --blue-dark: #003f73;
  --blue-soft: #e9f3fb;
  --yellow: #ffcb05;
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #17283a;
  --muted: #68798b;
  --border: #dce5ed;
  --shadow: 0 16px 46px rgba(0, 63, 115, .10);
}
[data-theme="dark"] {
  --bg: #0d1723;
  --surface: #142131;
  --surface-soft: #19293c;
  --text: #edf5fc;
  --muted: #a8bacb;
  --border: #2c4053;
  --blue-soft: #18334b;
  --shadow: 0 18px 48px rgba(0, 0, 0, .28);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; color: var(--text); background: var(--bg); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
[hidden] { display: none !important; }
.topbar { position: sticky; z-index: 50; top: 0; min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px clamp(18px, 4vw, 48px); color: #fff; background: linear-gradient(120deg, var(--blue-dark), var(--blue)); box-shadow: 0 8px 28px rgba(0, 63, 115, .22); }
.brand { display: flex; align-items: center; gap: 14px; color: inherit; text-decoration: none; }
.logo { width: min(270px, 55vw); height: 56px; }
.brand-copy { display: grid; gap: 2px; padding-left: 14px; border-left: 1px solid rgba(255,255,255,.22); }
.brand-copy small { color: rgba(255,255,255,.7); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.brand-copy strong { font-size: 17px; }
.top-actions { display: flex; align-items: center; gap: 9px; }
.button, .icon-button { border: 0; border-radius: 11px; font-weight: 800; transition: transform .16s ease, box-shadow .16s ease; }
.button:hover:not(:disabled), .icon-button:hover { transform: translateY(-1px); }
.button { min-height: 43px; padding: 10px 16px; }
.button-primary { width: 100%; color: #fff; background: linear-gradient(120deg, var(--blue), #1579bc); box-shadow: 0 10px 24px rgba(0, 92, 168, .22); }
.button-light, .icon-button { color: var(--blue-dark); background: #fff; }
.icon-button { width: 43px; height: 43px; }
main { min-height: calc(100vh - 132px); }
.selection-view { min-height: calc(100vh - 132px); display: grid; place-items: center; padding: 42px 18px; background: radial-gradient(circle at 12% 10%, rgba(255,203,5,.20), transparent 28rem), linear-gradient(145deg, #f7fbff, #e9f3fb); }
.selection-card { width: min(620px, 100%); padding: clamp(28px, 5vw, 48px); border: 1px solid #cfe0ed; border-radius: 25px; background: #fff; box-shadow: 0 25px 70px rgba(0,63,115,.16); }
.selection-card h1 { margin: 5px 0 12px; color: var(--blue-dark); font-size: clamp(32px, 5vw, 48px); line-height: 1.05; }
.selection-card > p { margin: 0; color: #65798c; line-height: 1.6; }
.selection-card form { margin-top: 28px; }
.field { display: grid; gap: 8px; margin-bottom: 18px; }
.field span { font-size: 13px; font-weight: 800; }
select, input { width: 100%; height: 47px; padding: 0 13px; color: var(--text); border: 1px solid var(--border); border-radius: 10px; outline: none; background: var(--surface-soft); }
select:focus, input:focus { border-color: #5e98c6; box-shadow: 0 0 0 4px rgba(0,92,168,.12); }
.connection-status { display: flex; align-items: center; gap: 11px; margin-top: 22px; padding: 13px; border: 1px solid #dce8f1; border-radius: 13px; background: #f6f9fc; }
.connection-status strong, .connection-status small { display: block; }
.connection-status strong { font-size: 12px; }
.connection-status small { color: #6d8193; font-size: 11px; }
.status-dot { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 99px; background: #ad6b00; box-shadow: 0 0 0 5px rgba(173,107,0,.12); }
.connection-status.connected .status-dot { background: #198754; box-shadow: 0 0 0 5px rgba(25,135,84,.12); }
.report-view { width: min(1800px, 100%); margin: 0 auto; padding: 28px clamp(16px, 3vw, 36px) 45px; }
.hero { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: clamp(24px, 4vw, 38px); color: #fff; border-radius: 24px; background: radial-gradient(circle at 92% 8%, rgba(255,203,5,.25), transparent 26%), linear-gradient(125deg, var(--blue-dark), var(--blue)); box-shadow: var(--shadow); }
.hero h1 { margin: 5px 0 7px; font-size: clamp(28px, 4vw, 46px); line-height: 1.05; }
.hero p { margin: 0; color: rgba(255,255,255,.78); }
.eyebrow { display: block; color: var(--blue); font-size: 11px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.eyebrow-light { color: var(--yellow); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.chip { padding: 5px 10px; border: 1px solid rgba(255,255,255,.22); border-radius: 99px; color: #fff; background: rgba(255,255,255,.10); font-size: 11px; font-weight: 800; }
.updated-card { flex: 0 0 auto; padding: 13px 16px; text-align: right; border: 1px solid rgba(255,255,255,.18); border-radius: 13px; background: rgba(255,255,255,.08); }
.updated-card span, .updated-card strong { display: block; }
.updated-card span { color: rgba(255,255,255,.65); font-size: 11px; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 15px; margin: 18px 0 28px; }
.kpi-card { position: relative; overflow: hidden; min-width: 0; padding: 20px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.kpi-card::after { content: ""; position: absolute; top: 0; right: 0; width: 60px; height: 5px; border-radius: 0 0 0 8px; background: var(--yellow); }
.kpi-card span, .kpi-card small { display: block; color: var(--muted); }
.kpi-card span { font-size: 11px; font-weight: 850; letter-spacing: .04em; text-transform: uppercase; }
.kpi-card strong { display: block; overflow: hidden; margin-top: 8px; font-size: clamp(22px, 2vw, 31px); text-overflow: ellipsis; white-space: nowrap; }
.kpi-card small { margin-top: 5px; font-size: 11px; }
.section-heading { display: flex; justify-content: space-between; gap: 20px; margin: 10px 0 15px; }
.section-heading h2, .rankings-header h2, .notes-panel h2 { margin: 4px 0 5px; font-size: 25px; }
.section-heading p, .rankings-header p, .notes-panel p { margin: 0; color: var(--muted); }
.charts-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.panel { min-width: 0; border: 1px solid var(--border); border-radius: 21px; background: var(--surface); box-shadow: var(--shadow); }
.chart-panel { padding: 20px; }
.chart-panel-wide { grid-column: span 2; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; margin-bottom: 15px; }
.panel-heading h3 { margin: 3px 0 0; font-size: 18px; }
.tag { flex: 0 0 auto; padding: 5px 8px; border-radius: 99px; color: var(--blue-dark); background: var(--blue-soft); font-size: 10px; font-weight: 850; }
.chart-box { position: relative; min-height: 300px; }
.chart-box-tall { min-height: 440px; }
.chart-box-books { min-height: 560px; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 30px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 13px; background: var(--surface-soft); }
.rankings-panel { margin-top: 20px; overflow: hidden; }
.rankings-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; padding: 22px; }
.search-field input { min-width: 260px; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 0 22px 16px; }
.tab { flex: 0 0 auto; min-height: 38px; padding: 8px 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 9px; background: var(--surface-soft); font-weight: 800; }
.tab.is-active { color: #fff; border-color: var(--blue); background: var(--blue); }
.table-scroll { max-height: 760px; overflow: auto; border-top: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; z-index: 2; top: 0; color: var(--muted); background: var(--surface-soft); font-size: 10px; letter-spacing: .04em; text-transform: uppercase; }
tbody tr:hover { background: var(--blue-soft); }
td.wrap { min-width: 260px; white-space: normal; }
td.muted { color: var(--muted); }
.notes-panel { margin-top: 18px; padding: 22px; }
.footer { padding: 25px 20px 34px; color: var(--blue-dark); text-align: center; font-size: 14px; font-weight: 800; }
.loading-overlay { position: fixed; z-index: 1000; inset: 0; place-items: center; background: rgba(4,19,34,.68); backdrop-filter: blur(5px); }
.loading-overlay:not([hidden]) { display: grid; }
.loading-card { width: min(390px, calc(100% - 30px)); display: grid; justify-items: center; gap: 9px; padding: 30px; text-align: center; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.loading-card small { color: var(--muted); }
.spinner { width: 44px; height: 44px; border: 4px solid var(--blue-soft); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
.toast { position: fixed; z-index: 1200; right: 20px; bottom: 20px; max-width: min(430px, calc(100% - 40px)); padding: 14px 17px; color: #fff; border-radius: 12px; background: var(--blue-dark); box-shadow: var(--shadow); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; clip-path: inset(50%); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 1050px) { .kpi-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } }
@media (max-width: 820px) {
  .topbar { position: relative; flex-wrap: wrap; }
  .brand-copy { display: none; }
  .top-actions { width: 100%; display: grid; grid-template-columns: repeat(4,1fr); }
  .icon-button { width: 100%; }
  .hero, .rankings-header { align-items: flex-start; flex-direction: column; }
  .updated-card { text-align: left; }
  .charts-grid { grid-template-columns: 1fr; }
  .chart-panel-wide { grid-column: span 1; }
  .search-field, .search-field input { width: 100%; min-width: 0; }
}
@media (max-width: 560px) {
  .top-actions { grid-template-columns: repeat(2,1fr); }
  .logo { width: 220px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .report-view { padding-inline: 12px; }
  .chart-box-tall { min-height: 360px; }
  .chart-box-books { min-height: 460px; }
}
@media print {
  .no-print, .topbar, .footer { display: none !important; }
  body, .report-view { background: #fff; }
  .report-view { width: 100%; padding: 0; }
  .panel, .kpi-card, .hero { box-shadow: none; break-inside: avoid; }
  .table-scroll { max-height: none; overflow: visible; }
  th { position: static; }
}
