/* TIDELINE — base + components. Uses semantic tokens only (see tokens.css). */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: var(--weight-regular) var(--text-md)/var(--leading-normal) var(--font-sans);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
h1, h2, h3, h4 { line-height: var(--leading-tight); margin: 0; font-weight: var(--weight-bold); }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
p { margin: 0 0 var(--s-3); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-muted); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.mono { font-family: var(--font-mono); font-size: .92em; }
.row { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: var(--s-3); }
.grow { flex: 1 1 auto; min-width: 0; }
.hidden { display: none !important; }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100%; }
.rail {
  position: sticky; top: 0; height: 100vh; background: var(--brand-band); color: #DCE8F0;
  display: flex; flex-direction: column; align-items: center; padding: var(--s-3) 0; gap: var(--s-1);
  z-index: var(--z-nav);
}
.brand-mark { width: 44px; height: 44px; margin-bottom: var(--s-4); }
.nav-btn {
  width: 72px; min-height: 60px; border: 0; background: transparent; color: inherit; cursor: pointer;
  display: grid; place-items: center; gap: 2px; padding: var(--s-2) 0; border-radius: var(--radius-md);
  font: var(--weight-medium) 11px/1.1 var(--font-sans); letter-spacing: .02em;
  transition: background var(--dur-fast) var(--ease);
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn:hover { background: rgba(255,255,255,.08); }
.nav-btn[aria-current="page"] { background: rgba(255,255,255,.14); color: #fff; box-shadow: inset 3px 0 0 var(--gold-500); }
.rail .spacer { flex: 1; }

main { min-width: 0; }
.view { padding: var(--s-6) var(--s-6) var(--s-8); max-width: var(--content-max); width: 100%; margin: 0 auto; }
.view.full { max-width: none; width: 100%; padding: 0; height: 100vh; position: relative; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-5); flex-wrap: wrap; }
.eyebrow { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: var(--tracking-caps); color: var(--text-muted); font-weight: var(--weight-bold); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    flex-direction: row; justify-content: space-around; padding: 0 var(--s-1) env(safe-area-inset-bottom);
  }
  .brand-mark, .rail .spacer { display: none; }
  .nav-btn { width: auto; flex: 1; min-height: var(--tabbar-h); }
  .nav-btn[aria-current="page"] { box-shadow: inset 0 3px 0 var(--gold-500); }
  .view { padding: var(--s-4) var(--s-4) calc(var(--tabbar-h) + var(--s-8)); }
  .view.full { height: calc(100vh - var(--tabbar-h)); padding: 0; }
  h1 { font-size: var(--text-xl); }
}

/* ---------- Buttons ---------- */
.btn {
  --_bg: var(--surface); --_fg: var(--text); --_bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--tap); padding: 0 var(--s-4); border-radius: var(--radius-md);
  background: var(--_bg); color: var(--_fg); border: 1px solid var(--_bd);
  font: var(--weight-medium) var(--text-sm)/1 var(--font-sans); cursor: pointer; text-decoration: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { --_bg: var(--primary); --_fg: var(--on-primary); --_bd: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.accent { --_bg: var(--accent); --_fg: var(--on-accent); --_bd: var(--accent); }
.btn.ghost { --_bg: transparent; --_bd: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 34px; padding: 0 var(--s-3); font-size: var(--text-xs); }
.btn.icon { padding: 0; width: var(--tap); }

/* ---------- Inputs ---------- */
.field { display: grid; gap: var(--s-1); }
.field label, .label { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.input, select.input, textarea.input {
  min-height: var(--tap); width: 100%; padding: 0 var(--s-3); border-radius: var(--radius-md);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: var(--text-md) var(--font-sans);
}
textarea.input { padding: var(--s-3); min-height: 96px; resize: vertical; line-height: var(--leading-normal); }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search {
  position: relative; display: flex; align-items: center; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  padding-left: var(--s-4);
}
.search svg { width: 20px; height: 20px; color: var(--text-muted); flex: none; }
.search input { border: 0; background: transparent; min-height: 56px; flex: 1; font-size: var(--text-lg); padding: 0 var(--s-3); color: var(--text); min-width: 0; }
.search input:focus { outline: none; }
.search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft), var(--shadow-md); }
.suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg); list-style: none; margin: 0; padding: var(--s-1); z-index: var(--z-overlay);
}
.suggest li { padding: var(--s-3); border-radius: var(--radius-sm); cursor: pointer; display: flex; justify-content: space-between; gap: var(--s-3); }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--primary-soft); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--s-5); box-shadow: var(--shadow-sm); min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); margin-bottom: var(--s-3); }
.card-head h3 { display: flex; align-items: center; gap: var(--s-2); }
.card-head h3 svg { width: 20px; height: 20px; color: var(--primary); }
.grid { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
@media (max-width: 860px) { .grid, .grid.two { grid-template-columns: 1fr; } }

/* ---------- Stat ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--s-3); }
.stat { background: var(--surface-2); border-radius: var(--radius-md); padding: var(--s-3) var(--s-4); }
.stat .v { font-size: var(--text-2xl); font-weight: var(--weight-bold); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .k { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--s-1); }

/* ---------- Chips, badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 var(--s-3); border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--text); font-size: var(--text-xs); font-weight: var(--weight-medium);
  border: 1px solid var(--border); text-decoration: none; white-space: nowrap;
}
button.chip { cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.source { font-size: var(--text-xs); color: var(--text-muted); display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; margin-top: var(--s-3); padding-top: var(--s-3); border-top: 1px dashed var(--border); }
.source a { color: var(--text-muted); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-bold); }
.badge svg { width: 12px; height: 12px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: var(--s-3); padding: var(--s-2) 0; border-bottom: 1px solid var(--border); font-size: var(--text-sm); }
.list li:last-child { border-bottom: 0; }
.list .d { color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- Status / empty / skeleton ---------- */
.note { padding: var(--s-3) var(--s-4); border-radius: var(--radius-md); font-size: var(--text-sm); display: flex; gap: var(--s-2); align-items: flex-start; }
.note svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.note.info { background: var(--info-soft); }
.note.warn { background: var(--warn-soft); }
.note.danger { background: var(--danger-soft); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: var(--radius-sm); height: 14px; margin: 8px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { text-align: center; padding: var(--s-8) var(--s-4); color: var(--text-muted); }

/* ---------- Hero ---------- */
.hero {
  background: radial-gradient(1200px 300px at 0% 0%, rgba(227,161,47,.18), transparent 60%), var(--brand-band);
  color: #E8F1F7; border-radius: var(--radius-lg); padding: var(--s-7) var(--s-6); margin-bottom: var(--s-5);
  position: relative;
}
.hero h1 { font-size: var(--text-3xl); color: #fff; letter-spacing: -.01em; }
.hero p { color: #BBD0DE; max-width: 60ch; }
.hero .search { margin-top: var(--s-5); max-width: 720px; }
@media (max-width: 860px) { .hero { padding: var(--s-5) var(--s-4); } .hero h1 { font-size: var(--text-2xl); } }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-md); max-height: 420px; }
table.data { border-collapse: collapse; width: 100%; font-size: var(--text-sm); }
table.data th, table.data td { padding: var(--s-2) var(--s-3); text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { position: sticky; top: 0; background: var(--surface-2); font-weight: var(--weight-bold); z-index: 1; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Map ---------- */
#map { position: absolute; inset: 0; z-index: var(--z-map); background: var(--surface-sunk); }
.mini-map { height: 260px; border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border); }
.map-panel {
  position: absolute; top: var(--s-4); left: var(--s-4); width: 340px; max-height: calc(100% - 2 * var(--s-4)); overflow: auto;
  z-index: var(--z-overlay); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: var(--s-4);
}
.map-panel h2 { font-size: var(--text-lg); margin-bottom: var(--s-2); }
.layer-row { display: flex; align-items: center; gap: var(--s-2); padding: 6px 0; font-size: var(--text-sm); }
.layer-row input { width: 18px; height: 18px; accent-color: var(--primary); }
.layer-row .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
@media (max-width: 860px) {
  .map-panel { top: auto; bottom: var(--s-3); left: var(--s-3); right: var(--s-3); width: auto; max-height: 45%; }
  .map-panel.collapsed .panel-body { display: none; }
}
.leaflet-container { font-family: var(--font-sans); }
.leaflet-popup-content { font-size: var(--text-sm); }

/* ---------- Sheet (dialog) ---------- */
dialog.sheet {
  border: 0; padding: 0; border-radius: var(--radius-lg); background: var(--surface); color: var(--text);
  width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 48px); box-shadow: var(--shadow-lg);
}
dialog.sheet::backdrop { background: var(--scrim); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.sheet-body { padding: var(--s-5); overflow: auto; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--s-6) + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink-900); color: #fff; padding: var(--s-3) var(--s-4); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); z-index: var(--z-toast); font-size: var(--text-sm); max-width: 90vw;
}
@media (max-width: 860px) { .toast { bottom: calc(var(--tabbar-h) + var(--s-4)); } }

/* ---------- Tabs (segmented) ---------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-md); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--text); min-height: 34px; padding: 0 var(--s-3); border-radius: 8px; font: var(--weight-medium) var(--text-sm) var(--font-sans); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow-sm); }

/* ---------- Charts ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .bar { fill: var(--viz-series-1); }
.chart .bar:hover, .chart .bar.hl { opacity: .8; }
.chart .grid line { stroke: var(--viz-grid); stroke-width: 1; }
.chart text { fill: var(--viz-axis); font: 12px var(--font-sans); }
.chart text.lbl { fill: var(--text); }
.chart .line { fill: none; stroke: var(--viz-series-1); stroke-width: 2; }
.chart .dot { fill: var(--viz-series-1); stroke: var(--viz-surface); stroke-width: 2; }
.tip {
  position: absolute; pointer-events: none; background: var(--ink-900); color: #fff; font-size: var(--text-xs);
  padding: 6px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); z-index: 5; box-shadow: var(--shadow-md);
}

/* ---------- AI panel ---------- */
.ai-card { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.ai-out { white-space: pre-wrap; font-size: var(--text-sm); line-height: 1.6; background: var(--surface-2); border-radius: var(--radius-md); padding: var(--s-3) var(--s-4); min-height: 48px; }
.ai-out:empty { display: none; }
.prompt-chips { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--primary); width: 0; transition: width var(--dur) var(--ease); }

/* nav visibility by breakpoint */
.nav-btn { text-decoration: none; }
.nav-btn.mob { display: none; }
@media (max-width: 860px) { .nav-btn.desk { display: none; } .nav-btn.mob { display: grid; } }
