/* ── Tokens ───────────────────────────────────────────────────────────
   Roles, not raw hex, so the light/dark swap happens in one place.
   Values are the validated reference palette; the tide line is
   categorical slot 1 (blue), the only series on the chart.            */
:root {
  color-scheme: light;
  --surface-1:   #fcfcfb;
  --plane:       #f9f9f7;
  --text-1:      #0b0b0b;
  --text-2:      #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --axis:        #c3c2b7;
  --border:      rgba(11,11,11,0.10);
  --series-1:    #2a78d6;
  --good:        #0ca30c;
  --warning:     #fab219;
  --critical:    #d03b3b;
  --radius:      14px;
  --shadow:      0 1px 2px rgba(11,11,11,.04), 0 8px 24px rgba(11,11,11,.06);
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --plane:     #0d0d0d;
    --text-1:    #ffffff;
    --text-2:    #c3c2b7;
    --muted:     #898781;
    --grid:      #2c2c2a;
    --axis:      #383835;
    --border:    rgba(255,255,255,0.10);
    --series-1:  #3987e5;
    --good:      #0ca30c;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --plane:     #0d0d0d;
  --text-1:    #ffffff;
  --text-2:    #c3c2b7;
  --muted:     #898781;
  --grid:      #2c2c2a;
  --axis:      #383835;
  --border:    rgba(255,255,255,0.10);
  --series-1:  #3987e5;
  --good:      #0ca30c;
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* A display rule on a component would otherwise beat the hidden attribute,
   which is how the admin form leaked into read-only mode. */
[hidden] { display: none !important; }

body {
  font-family: var(--sans);
  background: var(--plane);
  color: var(--text-1);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ── Top bar ─────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .85rem 1.25rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 900;
}
.brand { display: flex; align-items: center; gap: .75rem; }
.brand h1 { font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em; }
.sub { font-size: .78rem; color: var(--text-2); }
.mark {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: var(--series-1);
  -webkit-mask: radial-gradient(circle at 50% 130%, transparent 58%, #000 59%);
          mask: radial-gradient(circle at 50% 130%, transparent 58%, #000 59%);
}
.topbar-right { display: flex; align-items: center; gap: .6rem; }

.pill {
  font-size: .72rem; padding: .2rem .55rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-2); white-space: nowrap;
}
.pill-ok { color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, transparent); }
.pill-warn { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 35%, transparent); }

/* ── Layout ──────────────────────────────────────────────────────── */
.layout {
  display: grid; gap: 1.1rem; padding: 1.1rem;
  max-width: 1500px; margin: 0 auto;
  grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
  grid-template-areas: "map chart" "admin chart";
  align-items: start;
}
.panel-map   { grid-area: map; }
.panel-chart { grid-area: chart; }
.panel-admin { grid-area: admin; }
@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "map" "chart" "admin"; }
}

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem 1.1rem;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: .75rem; flex-wrap: wrap; margin-bottom: .8rem;
}
.panel-head h2 { font-size: .95rem; font-weight: 650; letter-spacing: -.005em; }
.hint, .note { font-size: .78rem; color: var(--text-2); }
.note { margin-bottom: .8rem; }

/* ── Controls ────────────────────────────────────────────────────── */
.btn {
  font: inherit; font-size: .82rem; padding: .4rem .8rem; cursor: pointer;
  border-radius: 9px; border: 1px solid var(--border);
  background: var(--plane); color: var(--text-1);
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--axis); }
.btn-primary { background: var(--series-1); color: #fff; border-color: transparent; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; }

input, select {
  font: inherit; font-size: .82rem; padding: .38rem .55rem;
  border-radius: 9px; border: 1px solid var(--border);
  background: var(--plane); color: var(--text-1); width: 100%;
}
input:focus-visible, select:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 1px;
}

.search { display: flex; gap: .5rem; margin-bottom: .7rem; }
.coords { display: grid; grid-template-columns: 1fr 1fr auto; gap: .5rem; align-items: end; margin-top: .7rem; }
.coords label, .ctl { display: flex; flex-direction: column; gap: .2rem; font-size: .72rem; color: var(--text-2); }
.controls { display: flex; gap: .55rem; flex-wrap: wrap; }
.ctl select, .ctl input { min-width: 7.5rem; }

.places { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .7rem; }
.chip {
  font: inherit; font-size: .74rem; padding: .22rem .6rem; cursor: pointer;
  border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--text-2);
}
.chip:hover { color: var(--text-1); border-color: var(--axis); }

#map {
  height: 340px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); background: var(--plane);
}
.leaflet-container { font-family: var(--sans); background: var(--plane); }

/* ── Stat tiles ──────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.tile { border: 1px solid var(--border); border-radius: 11px; padding: .6rem .75rem; }
.tile .k { font-size: .7rem; color: var(--text-2); display: block; }
.tile .v { font-size: 1.3rem; font-weight: 600; letter-spacing: -.02em; display: block; }
.tile .m { font-size: .72rem; color: var(--muted); }
.tile-hero .v { font-size: 1.75rem; }

/* ── Chart ───────────────────────────────────────────────────────── */
.figure { margin: 0; }
.figcap { font-size: .8rem; color: var(--text-2); margin-bottom: .45rem; }
.chart-wrap { position: relative; width: 100%; }
#chart { width: 100%; height: 340px; display: block; overflow: visible; }

/* Marks: 2px line, 10% area wash, hairline solid grid — never dashed. */
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-line { stroke: var(--axis); stroke-width: 1; }
.tick-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.tide-area { fill: var(--series-1); opacity: .10; }
.tide-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.extreme-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.extreme-label { fill: var(--text-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.ref-line { stroke: var(--axis); stroke-width: 1; }
.ref-label { fill: var(--muted); font-size: 10px; }
.now-line { stroke: var(--critical); stroke-width: 1; }
.now-label { fill: var(--critical); font-size: 10px; }
.cursor-line { stroke: var(--axis); stroke-width: 1; }
.cursor-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 10;
  background: var(--surface-1); color: var(--text-1);
  border: 1px solid var(--border); border-radius: 9px;
  padding: .4rem .6rem; font-size: .76rem; box-shadow: var(--shadow);
  white-space: nowrap; transform: translate(-50%, -130%);
}
.tooltip .tv { font-weight: 650; font-variant-numeric: tabular-nums; }
.tooltip .tt { color: var(--text-2); }

/* ── Datum card & messages ───────────────────────────────────────── */
.datum-card {
  margin-top: 1rem; padding: .7rem .85rem; font-size: .8rem;
  border: 1px solid var(--border); border-radius: 11px; background: var(--plane);
}
.datum-card h3 { font-size: .78rem; font-weight: 650; margin-bottom: .2rem; }
.datum-card .warn { color: var(--critical); margin-top: .35rem; font-size: .76rem; }
.datum-card dl { display: grid; grid-template-columns: auto 1fr; gap: .1rem .6rem; margin-top: .3rem; }
.datum-card dt { color: var(--text-2); }
.datum-card dd { font-variant-numeric: tabular-nums; }

.message {
  margin-top: 1rem; padding: .7rem .85rem; font-size: .82rem;
  border-radius: 11px; border: 1px solid color-mix(in srgb, var(--critical) 35%, transparent);
  color: var(--critical); background: color-mix(in srgb, var(--critical) 7%, transparent);
}
.message.info { border-color: var(--border); color: var(--text-2); background: var(--plane); }

/* ── Table view ──────────────────────────────────────────────────── */
.table-view { margin-top: 1rem; font-size: .8rem; }
.table-view summary { cursor: pointer; color: var(--text-2); }
.table-scroll { overflow-x: auto; max-height: 300px; overflow-y: auto; margin-top: .5rem; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .3rem .6rem; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--text-2); font-weight: 600; position: sticky; top: 0; background: var(--surface-1); }

/* ── Registry ────────────────────────────────────────────────────── */
.token-row { display: flex; gap: .5rem; margin-bottom: .8rem; }
.datum-form { display: flex; flex-direction: column; gap: .55rem; margin-bottom: .9rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; }
.datum-form label { display: flex; flex-direction: column; gap: .2rem; font-size: .72rem; color: var(--text-2); }
.form-actions { display: flex; gap: .5rem; }

.datum-list { display: flex; flex-direction: column; gap: .45rem; max-height: 340px; overflow-y: auto; }
.datum-item {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 10px; font-size: .8rem;
}
.datum-item .nm { font-weight: 600; }
.datum-item .meta { font-size: .72rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.datum-item .acts { display: flex; gap: .3rem; flex: none; }
.tag { font-size: .66rem; padding: .1rem .4rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); }
.tag-manual { color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, transparent); }

/* ── Footer ──────────────────────────────────────────────────────── */
.foot {
  max-width: 1500px; margin: 0 auto; padding: 1.2rem 1.35rem 2rem;
  font-size: .76rem; color: var(--text-2);
}
.foot .attrib { margin-top: .4rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
