:root {
  --bg: #f7f8fa; --surface: #ffffff; --surface-2: #f1f3f6; --border: #e3e6eb;
  --text: #0f172a; --muted: #64748b; --accent: #1d4ed8; --accent-2: #1e40af; --accent-soft: #e0e7ff;
  --pos: #15803d; --neg: #b91c1c; --warn: #b45309; --warn-soft: #fef3c7; --danger: #b91c1c;
  --gov: #7c3aed; --gov-soft: #ede9fe;
  --radius: 8px; --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020; --surface: #121a2e; --surface-2: #19223a; --border: #26304a;
    --text: #e5e9f2; --muted: #94a3b8; --accent: #6d8dff; --accent-2: #8aa4ff; --accent-soft: #1e2a52;
    --pos: #4ade80; --neg: #f87171; --warn: #fbbf24; --warn-soft: #3a2f10; --danger: #f87171;
    --gov: #a78bfa; --gov-soft: #2a2150;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.invisible { visibility: hidden; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: 500 14px var(--font); cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.inline { display: inline; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-weight: 500; }
.form label.check, label.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; cursor: pointer; }
label.check input { margin-top: 3px; }

/* chrome */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
.brand { font-weight: 700; font-size: 16px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.logo { flex: none; }
.topnav { display: flex; align-items: center; gap: 16px; }
.topnav a { color: var(--text); white-space: nowrap; }
.brand { white-space: nowrap; }
.show-sm { display: none; }
@media (max-width: 560px) { .hide-sm { display: none; } .show-sm { display: inline; } }
.flashes { max-width: 720px; margin: 16px auto 0; padding: 0 16px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; background: var(--accent-soft); }
.flash-error { background: #fee2e2; color: #7f1d1d; }
.flash-success { background: #dcfce7; color: #14532d; }
.footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 24px 20px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); margin-top: 48px; }
.page { max-width: 1100px; margin: 32px auto; padding: 0 16px; }
.page.narrow { max-width: 680px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.danger { border-color: #fecaca; }
.prose p { max-width: 68ch; }

/* landing */
.landing { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.hero { padding: 80px 0 48px; max-width: 800px; }
.hero h1 { font-size: clamp(32px, 5.4vw, 54px); letter-spacing: -.025em; line-height: 1.1; margin-bottom: 20px; }
.eyebrow { color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; font-size: 12px; margin: 0 0 8px; }
.lede { font-size: 19px; line-height: 1.6; color: var(--muted); max-width: 64ch; }
.cta-row { display: flex; gap: 12px; margin: 28px 0 8px; flex-wrap: wrap; }
.btn-lg { padding: 11px 18px; font-size: 15px; }
.proof { color: var(--muted); font-size: 13px; margin: 16px 0 0; font-variant-numeric: tabular-nums; }
.example { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px 0 16px; margin-bottom: 48px; scroll-margin-top: 72px; }
.example-head { padding: 0 24px 16px; }
.example-head h2 { font-size: clamp(20px, 2.6vw, 26px); letter-spacing: -.01em; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-size: 12px; font-weight: 500; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-2); }
.chip-gov { background: var(--gov-soft); color: var(--gov); }
:root[data-theme="dark"] .chip { color: var(--accent); }
.example-grid tbody tr { cursor: default; }
.example-grid th { cursor: default; position: static; }
.example-grid th:first-child, .example-grid td:first-child { padding-left: 24px; }
.example-grid th:last-child, .example-grid td:last-child { padding-right: 24px; }
.example-grid .co { font-weight: 500; }
.example-grid td.gov { color: var(--gov); font-weight: 600; }
.example-foot { padding: 14px 24px 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; }
.signals { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 16px; margin-bottom: 56px; }
.signal { padding: 4px 0; }
.signal-n { font-size: 40px; font-weight: 700; letter-spacing: -.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.signal-k { color: var(--muted); font-size: 13px; margin: 6px 0 16px; min-height: 2.6em; }
.signal h3 { font-size: 17px; }
.signal p { color: var(--muted); margin: 0; font-size: 15px; }
.why { max-width: 720px; margin: 0 0 56px; }
.why h2 { font-size: clamp(22px, 3vw, 30px); letter-spacing: -.015em; }
.why p { font-size: 16px; color: var(--muted); line-height: 1.65; }
.cta-band { text-align: center; padding: 40px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.cta-band p { color: var(--muted); }
@media (max-width: 560px) {
  .topbar { padding: 10px 16px; }
  .topnav { gap: 12px; }
  .hero { padding: 48px 0 32px; }
  .lede { font-size: 17px; }
  .example-head { padding: 0 16px 12px; }
  .example-grid th:first-child, .example-grid td:first-child { padding-left: 16px; }
  .example-foot { padding: 12px 16px 0; }
}

/* auth */
.g-signin { min-height: 44px; margin: 8px 0 4px; display: flex; justify-content: center; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; margin: 12px 0; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.auth-wrap { display: flex; justify-content: center; padding: 48px 16px; }
.auth-card { width: 100%; max-width: 420px; }

/* admin */
.stat-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; min-width: 130px; }
.stat-v { font-size: 24px; font-weight: 700; }
.stat-k { color: var(--muted); font-size: 12px; }

/* app */
.app-body { overflow-x: hidden; }
.app { padding: 16px 20px 28px; max-width: 1680px; margin: 0 auto; }
/* one control height across the toolbar */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .btn, .toolbar select, .toolbar .search { height: 34px; }
.toolbar .btn { padding: 0 12px; white-space: nowrap; }
.toolbar select { padding: 0 8px; }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 8px; height: 34px; }
.tab { border: 0; background: transparent; padding: 0 14px; border-radius: 6px; cursor: pointer; font: 500 13px var(--font); color: var(--muted); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.search { flex: 1 1 260px; max-width: 460px; padding: 0 12px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
/* screens: category tabs, then that category's presets on one aligned row */
.screens { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0 14px 12px; margin-bottom: 16px; }
.screen-cats { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 -14px 12px; padding: 0 8px; overflow-x: auto; scrollbar-width: none; }
.screen-cats::-webkit-scrollbar { display: none; }
.pcat { border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; padding: 11px 10px 9px; font: 500 13px var(--font); color: var(--muted); cursor: pointer; white-space: nowrap; }
.pcat:hover { color: var(--text); }
.pcat.active { color: var(--text); border-bottom-color: var(--accent); }
.pcat.gov.active { color: var(--gov); border-bottom-color: var(--gov); }
.pcount { margin-left: 6px; font-size: 11px; font-weight: 400; color: var(--muted); }
.pcat.has-active::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; background: var(--accent); vertical-align: 2px; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.preset { height: 30px; padding: 0 12px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; font: 13px var(--font); color: var(--text); cursor: pointer; white-space: nowrap; }
.preset:hover { border-color: var(--accent); color: var(--accent); }
.preset.active, .preset.active:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.layout { display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: 16px; align-items: start; }
.filters { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.filters-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--text); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; padding: 0 4px; }
.quick { display: grid; gap: 4px; padding: 6px 0 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.fgroup { border-bottom: 1px solid var(--border); }
.fgroup summary { cursor: pointer; padding: 9px 2px; font-weight: 600; font-size: 13px; list-style: none; display: flex; align-items: center; gap: 6px; }
.fgroup summary::-webkit-details-marker { display: none; }
.fgroup summary::after { content: ""; margin-left: auto; width: 6px; height: 6px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; }
.fgroup[open] summary::after { transform: rotate(45deg); }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; font-weight: 600; }
.frow { display: grid; grid-template-columns: 1fr 64px 64px; gap: 4px; align-items: center; margin-bottom: 4px; }
.frow .flabel { font-size: 12px; }
.frow input, .frow select { padding: 4px 6px; font-size: 12px; min-width: 0; }
.frow select, .frow .fdate { grid-column: span 2; }
.multi { display: grid; gap: 2px; max-height: 260px; overflow: auto; padding-bottom: 8px; font-size: 12px; }
.frow-multi { grid-template-columns: 1fr; }
.frow-multi .multi { padding-bottom: 4px; }
.results { min-width: 0; }
.results-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 2px 0 10px; }
.count { font-weight: 600; font-size: 15px; }
/* column sets: a single-line tab strip fused to the top of the table */
.views { display: flex; gap: 2px; padding: 0 8px; overflow-x: auto; scrollbar-width: none; background: var(--surface);
  border: 1px solid var(--border); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; }
.views::-webkit-scrollbar { display: none; }
.views.invisible { display: none; }
.view { border: 0; border-bottom: 2px solid transparent; background: none; padding: 10px 10px 8px; cursor: pointer; font: 13px var(--font); color: var(--muted); white-space: nowrap; }
.view:hover { color: var(--text); }
.view.active { color: var(--text); font-weight: 500; border-bottom-color: var(--accent); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
#panel-screener, #panel-watchlist { border-top-left-radius: 0; border-top-right-radius: 0; }
#panel-map, #panel-watchlist { padding: 12px; }
.table-scroll { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
.grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; vertical-align: middle; }
.grid th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; }
.grid th.num, .grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--surface-2); }
.grid td.empty { text-align: center; color: var(--muted); padding: 32px; cursor: default; }
.grid td.code { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.namecell { min-width: 220px; }
.namecell > div { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.35; }
.namecell .nm { display: flex; align-items: center; gap: 4px; font-weight: 500; }
.namecell .nmt { overflow: hidden; text-overflow: ellipsis; }
.jp { color: var(--muted); font-size: 12px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.flag { display: inline-block; font-size: 10px; font-weight: 700; border-radius: 3px; padding: 0 4px; margin-left: 2px; vertical-align: 1px; }
.flag-act { background: var(--gov-soft); color: var(--gov); }
.flag-coil { background: var(--warn-soft); color: var(--warn); }
.flag-pill { background: #fee2e2; color: #991b1b; }
.flag-watch { color: #d97706; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 12px; }
.map-controls { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; font-size: 13px; }
.chart-box { position: relative; height: 560px; }

/* drawer */
.drawer { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 50; display: flex; justify-content: flex-end; }
.drawer-inner { width: min(860px, 100%); height: 100%; overflow: auto; background: var(--bg); padding: 24px; position: relative; box-shadow: var(--shadow); }
.drawer-close { position: absolute; top: 12px; right: 16px; border: 0; background: none; font-size: 28px; cursor: pointer; color: var(--muted); }
body.drawer-open { overflow: hidden; }
.drawer section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-top: 14px; }
.drawer h3 { font-size: 14px; }
.co-head { display: flex; justify-content: space-between; gap: 16px; padding-right: 32px; flex-wrap: wrap; }
.co-head h2 { font-size: 22px; margin: 2px 0; }
.co-code { color: var(--muted); font-size: 12px; }
.co-price { text-align: right; }
.co-price .px { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.co-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; }
.watch-btn.on { color: #d97706; border-color: #fcd34d; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { display: inline-block; font-size: 12px; background: var(--surface-2); border-radius: 4px; padding: 2px 8px; margin: 0 4px 4px 0; }
a.tag { color: inherit; text-decoration: none; }
a.tag:hover { text-decoration: underline; }
.tag-act { background: var(--gov-soft); color: var(--gov); }
.tag-coil, .tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-pill { background: #fee2e2; color: #991b1b; }
.sec-head { display: flex; justify-content: space-between; align-items: center; }
.ranges { display: flex; gap: 2px; }
.rng { border: 1px solid var(--border); background: var(--surface); padding: 2px 8px; font-size: 12px; border-radius: 4px; cursor: pointer; color: var(--muted); }
.rng.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chart-sm { position: relative; height: 240px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 2px 18px; margin-bottom: 8px; }
.kv > div { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.kv span { color: var(--muted); }
.kv b { font-weight: 600; font-variant-numeric: tabular-nums; }
table.compact td, table.compact th { padding: 5px 8px; }
table.compact tbody tr { cursor: default; }
.purpose { white-space: normal !important; font-size: 12px; min-width: 200px; }
tr.warn td { background: var(--warn-soft); }
.obar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; margin: 6px 0; background: var(--surface-2); }
.olegend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; margin-bottom: 8px; }
.olegend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; }
.links { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.colpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.colpick fieldset { border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.colpick legend { font-weight: 600; font-size: 12px; }
.drawer-actions { margin-top: 16px; display: flex; justify-content: flex-end; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; font-size: 13px; max-width: 90vw; box-shadow: var(--shadow); }
.filters-toggle { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .filters { display: none; position: fixed; inset: 56px 0 0 0; z-index: 40; max-height: none; border-radius: 0; }
  body.show-filters .filters { display: block; }
  .filters-toggle { display: inline-flex; position: fixed; bottom: 16px; right: 16px; z-index: 45; box-shadow: var(--shadow); }
  .toolbar-right { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .toolbar-right select { flex: 1 1 100%; }
  .search { max-width: none; }
  .presets { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; }
  .presets::-webkit-scrollbar { display: none; }
  .topbar { padding: 10px 16px; }
  .topnav { gap: 10px; font-size: 13px; }
  .chart-box { height: 420px; }
  .drawer-inner { padding: 16px; }
}

/* admin */
.page.wide { max-width: 1280px; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.grid-2 .card { margin-bottom: 0; }
.grid-2 + .card, .card + .grid-2 { margin-top: 16px; }
.code { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.copybox { width: 100%; font-family: var(--mono); font-size: 12px; }
ul.plain { list-style: none; padding: 0; margin: 0 0 8px; }
ul.plain li { padding: 3px 0; }
.linkrow td { cursor: default; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.grid tr.superseded td { color: var(--muted); }
