:root {
  --page: #090d16;
  --surface-1: #101a2c;
  --surface-2: #0c1422;
  --ink-1: #edf2fb;
  --ink-2: #9fadc7;
  --muted: #64748f;
  --grid: #1b2436;
  --baseline: #2b3a55;
  --border: rgba(148, 170, 210, 0.14);
  --s1: #3987e5;  /* BC Ferries */
  --s2: #199e70;  /* Hullo */
  --s3: #c98500;  /* Black Ball */
  --s4: #008300;  /* FRS Clipper */
  --pos: #e66767; /* diverging warm pole (late) */
  --neg: #3987e5; /* diverging cool pole (early) */
  --divmid: #2b3a55;
  --good: #0ca30c;
  --warn: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --accent-glow: rgba(57, 135, 229, 0.16);
  --tile-grad: rgba(57, 135, 229, 0.08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--page); color: var(--ink-1);
  font: 13.5px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: grid; grid-template-columns: 198px minmax(0, 1fr);
}

/* ---------- sidebar ---------- */
#sidebar {
  position: sticky; top: 0; height: 100vh; padding: 16px 12px;
  background: var(--surface-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
#sidebar .logo {
  font-size: 16px; font-weight: 700; letter-spacing: 0.01em;
  padding: 4px 10px 14px; display: flex; gap: 8px; align-items: center;
}
#sidebar .logo .wave { color: var(--s1); font-size: 19px; }
#sidebar a {
  color: var(--ink-2); text-decoration: none; padding: 8px 10px;
  border-radius: 8px; font-size: 13px; display: flex; gap: 9px; align-items: center;
}
#sidebar a:hover { background: var(--surface-1); color: var(--ink-1); }
#sidebar a.active { background: var(--accent-glow); color: var(--ink-1); font-weight: 600; }
#sidebar .side-foot { margin-top: auto; font-size: 11px; color: var(--muted); padding: 10px; }
#sidebar .side-foot .dotlive { color: var(--good); }

/* ---------- header ---------- */
main { min-width: 0; }
header {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 14px 20px 10px; flex-wrap: wrap;
}
h1 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.sub { margin: 1px 0 0; color: var(--ink-2); font-size: 12px; }
.head-right { text-align: right; }
#clock { font-size: 13px; color: var(--ink-1); font-weight: 600; }
#clock-date { font-size: 11.5px; color: var(--ink-2); }
.hero-mini { font-size: 11.5px; color: var(--ink-2); margin-top: 2px; }
.hero-mini b { color: var(--ink-1); font-size: 13px; }

.filters {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 8px 20px; position: sticky; top: 0; background: var(--page);
  z-index: 1000; border-bottom: 1px solid var(--grid);
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; color: var(--ink-2); padding: 5px 11px;
  cursor: pointer; font: inherit; font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--surface-1); color: var(--ink-1); font-weight: 600; }
.seg button:hover:not(.on) { background: rgba(148,170,210,0.06); }
.key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
#op-seg button:not(.on) .key { opacity: 0.25; }
.fresh { color: var(--muted); font-size: 11.5px; margin-left: auto; }

/* ---------- KPI strip ---------- */
#ops-kpis {
  display: grid; gap: 12px; padding: 12px 20px 0;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.kcard {
  background: linear-gradient(180deg, var(--tile-grad), transparent 65%), var(--surface-1);
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  display: flex; justify-content: space-between; gap: 8px; min-height: 92px;
}
.kcard .klabel { color: var(--ink-2); font-size: 11.5px; }
.kcard .kvalue { font-size: 27px; font-weight: 650; line-height: 1.15; margin-top: 3px; }
.kcard .kvalue small { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.kcard .kdelta { font-size: 11px; margin-top: 3px; color: var(--muted); }
.kcard .kdelta.up-good { color: var(--good); }
.kcard .kdelta.up-bad { color: var(--critical); }
.kcard svg { align-self: flex-end; flex: none; }

/* ---------- layout ---------- */
.grid {
  display: grid; gap: 14px; padding: 14px 20px;
  grid-template-columns: minmax(0, 2.15fr) minmax(300px, 1fr);
}
.grid3 {
  display: grid; gap: 14px; padding: 0 20px 14px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px 15px; min-width: 0;
}
.card h2 { margin: 0 0 4px; font-size: 14px; }
.card h3 { margin: 13px 0 4px; font-size: 12.5px; color: var(--ink-2); }
.win { color: var(--muted); font-weight: 400; font-size: 11.5px; }
.desc { margin: 0 0 8px; color: var(--ink-2); font-size: 12px; }
.src {
  font-size: 10px; font-weight: 600; letter-spacing: 0.02em;
  padding: 2px 7px; border-radius: 99px; vertical-align: 2px;
  border: 1px solid var(--border); color: var(--ink-2);
  margin: 0 4px 0 1px;   /* following words must not touch the pill */
  white-space: nowrap;   /* a pill wraps as a unit, never mid-word */
}
.src-ais { background: rgba(57,135,229,0.14); }
.src-pub { background: rgba(201,133,0,0.14); }

/* ---------- map ---------- */
.map-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
#map { height: 520px; width: 100%; background: var(--page); }
.leaflet-container { font: inherit; background: #0b1220; }
.scrub-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; flex-wrap: wrap; }
.scrub-row button {
  border: 1px solid var(--border); background: transparent; color: var(--ink-1);
  border-radius: 7px; padding: 4px 10px; cursor: pointer; font: inherit;
}
.scrub-row button.on { background: var(--s1); color: #fff; border-color: transparent; }
#scrub { flex: 1; min-width: 160px; accent-color: var(--s1); }
.mono { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 12px; min-width: 110px; text-align: right; }
.trail-label { color: var(--muted); font-size: 12px; }
.seg-sm button { padding: 3px 9px; font-size: 12px; }
.mapctl-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 0 12px 9px; font-size: 12.5px; color: var(--ink-2);
}
.mapctl select {
  font: inherit; color: var(--ink-1); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px; margin-left: 4px;
}
.mapctl-row > button {
  border: 1px solid var(--border); background: transparent; color: var(--ink-2);
  border-radius: 6px; padding: 3px 10px; cursor: pointer; font: inherit; font-size: 12.5px;
}
.dd { position: relative; }
.dd summary {
  list-style: none; cursor: pointer; border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 10px; color: var(--ink-1); user-select: none;
}
.dd summary::-webkit-details-marker { display: none; }
.dd[open] summary { background: var(--surface-2); }
.dd-menu {
  position: absolute; z-index: 1200; bottom: calc(100% + 6px); left: 0;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 26px rgba(0,0,0,0.5); padding: 8px 10px;
  max-height: 280px; overflow-y: auto; min-width: 230px;
}
.dd-menu label { display: flex; align-items: center; gap: 7px; padding: 3px 2px; cursor: pointer; white-space: nowrap; color: var(--ink-2); }
.dd-menu label.dd-all { border-bottom: 1px solid var(--grid); margin-bottom: 4px; padding-bottom: 6px; font-weight: 600; color: var(--ink-1); }
.dd-menu input { accent-color: var(--s1); }

.vmark { background: transparent; }
.vmark .dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid #0b1220; box-shadow: 0 0 6px rgba(120,180,255,0.55);
}
.vmark .stale { opacity: 0.4; }
.speed-legend {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 9px; font: 11px/1.3 system-ui, sans-serif;
  color: var(--ink-2); box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
.maplegend { position: absolute; left: 10px; bottom: 10px; z-index: 5; }
.maplibregl-popup-content {
  background: var(--surface-2); color: var(--ink-1); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 12px; font: 12.5px/1.4 system-ui, sans-serif;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
.maplibregl-popup-tip { border-top-color: var(--surface-2) !important; border-bottom-color: var(--surface-2) !important; }
.maplibregl-popup-close-button { color: var(--ink-2); font-size: 16px; }
.maplibregl-ctrl-attrib { background: rgba(9,13,22,0.7) !important; }
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }
.maplibregl-ctrl-group { background: var(--surface-1); border: 1px solid var(--border); }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--border); }
.maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(0.85); }
.speed-legend .sl-title { color: var(--ink-1); font-weight: 600; margin-bottom: 4px; }
.speed-legend .sl-row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.speed-legend .sl-sw { width: 16px; height: 4px; border-radius: 2px; }

/* ---------- tables ---------- */
.scrolltable { overflow: auto; max-height: 520px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; position: sticky; top: 0; background: var(--surface-1); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
#health-card th, #health-card td { padding: 5px 4px; font-size: 11.5px; }
#health-card td:nth-child(2) {
  max-width: 86px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.opdot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 7px; }
#vessel-table td:nth-child(3) { white-space: normal; word-break: break-word; max-width: 150px; font-size: 12px; }
td .late-red { color: var(--pos); }
td .early-ok { color: var(--good); }
.hchip { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; font-variant-numeric: tabular-nums; }
.hdot { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 6px currentColor; }

/* ---------- misc panels ---------- */
.kpis { display: none; }
.tile {
  background: linear-gradient(180deg, var(--tile-grad), transparent 70%), var(--surface-1);
  border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px;
}
.tile .label { color: var(--ink-2); font-size: 11.5px; }
.tile .value { font-size: 23px; font-weight: 650; margin-top: 2px; }
.tile .note { color: var(--muted); font-size: 11px; margin-top: 2px; }
#impact-tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
#cost-tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
#cost-tiles .tile .value { color: var(--ink-1); }
.method { color: var(--muted); font-size: 11px; margin: 8px 2px 0; }

#unusual-list { list-style: none; margin: 4px 0 0; padding: 0; }
#unusual-list li { display: flex; gap: 9px; padding: 7px 2px; border-bottom: 1px solid var(--grid); font-size: 12.5px; color: var(--ink-2); align-items: baseline; }
#unusual-list li:last-child { border-bottom: 0; }
#unusual-list .u-icon { flex: none; }
#unusual-list .u-tag { margin-left: auto; flex: none; font-size: 10.5px; font-weight: 650; }
.imp-High { color: var(--critical); }
.imp-Medium { color: var(--warn); }
.imp-Low { color: var(--ink-2); }

.gauge-wrap { display: flex; gap: 16px; align-items: center; padding: 6px 0; }
.gauge-meta .gv { font-size: 26px; font-weight: 650; }
.gauge-meta .gs { color: var(--ink-2); font-size: 12px; }

.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
details { margin-top: 8px; }
summary { color: var(--ink-2); font-size: 12px; cursor: pointer; }
details table { margin-top: 6px; }
details p { color: var(--ink-2); }

.tip {
  position: absolute; pointer-events: none; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
  font-size: 12px; box-shadow: 0 6px 18px rgba(0,0,0,0.55); z-index: 500;
  min-width: 120px; color: var(--ink-2);
}
.tip .t-head { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.tip .t-row { display: flex; align-items: center; gap: 7px; }
.tip .t-key { width: 12px; height: 2px; border-radius: 1px; }
.tip .t-val { font-weight: 650; margin-left: auto; font-variant-numeric: tabular-nums; color: var(--ink-1); }
.tip .t-name { color: var(--ink-2); }

#conditions-card { grid-column: 1 / -1; }
.cond-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 6px 22px; align-items: start; }
.cond-cols h3 { margin-top: 6px; }
#conditions-card ul { margin: 4px 0; padding-left: 18px; max-height: 300px; overflow-y: auto; }
#conditions-card li { margin: 4px 0; font-size: 12px; color: var(--ink-2); }
#conditions-card li b { color: var(--ink-1); font-weight: 600; }
.warnflag { color: var(--critical); font-weight: 600; }
#marine-box p { margin: 4px 0; font-size: 12px; color: var(--ink-2); }
#marine-box b { color: var(--ink-1); }

footer { color: var(--muted); font-size: 11px; padding: 4px 20px 26px; }

#nav-toggle {
  display: none; border: 1px solid var(--border); background: var(--surface-1);
  color: var(--ink-1); border-radius: 8px; font-size: 17px; padding: 5px 11px;
  cursor: pointer; line-height: 1;
}
#nav-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(4,7,13,0.6); z-index: 1900;
}
@media (max-width: 1080px) {
  body { grid-template-columns: 1fr; }
  #nav-toggle { display: inline-block; }
  #sidebar {
    position: fixed; left: 0; top: 0; height: 100vh; width: 232px; z-index: 2000;
    transform: translateX(-105%); transition: transform 0.22s ease;
    box-shadow: 8px 0 30px rgba(0,0,0,0.5);
  }
  #sidebar.open { transform: none; }
  body.nav-open #nav-backdrop { display: block; }
  .grid { grid-template-columns: 1fr; }
  #map { height: 400px; }
  .scrolltable { max-height: 320px; }
}

@media (max-width: 700px) {
  /* wind time-series stays wide and scrolls; bar charts render 1:1 at any width */
  .chart { overflow-x: auto; }
  #wind-chart svg { min-width: 620px; }
}

#operators-tbody td:first-child {
  max-width: 118px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- drill-down drawer ---------- */
.drl-backdrop {
  position: fixed; inset: 0; background: rgba(4,7,13,0.55); z-index: 2900;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.drl-backdrop.open { opacity: 1; pointer-events: auto; }
.drl {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw);
  background: var(--surface-2); border-left: 1px solid var(--border); z-index: 3000;
  transform: translateX(105%); transition: transform 0.24s ease;
  display: flex; flex-direction: column; box-shadow: -12px 0 40px rgba(0,0,0,0.5);
}
.drl.open { transform: none; }
.drl-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--grid);
}
.drl-title { font-size: 17px; font-weight: 700; }
.drl-sub { color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.drl-close {
  border: 1px solid var(--border); background: transparent; color: var(--ink-2);
  border-radius: 8px; font-size: 14px; padding: 6px 10px; cursor: pointer; flex: none;
}
.drl-body { padding: 14px 18px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; }
.drl-body h3 { margin: 18px 0 8px; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em; }
.drl-kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.drl-kv div { background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 11px; }
.drl-kv span { display: block; color: var(--muted); font-size: 11px; }
.drl-kv b { font-size: 15px; font-weight: 650; }
.drl-row { padding: 8px 2px; border-bottom: 1px solid var(--grid); font-size: 12.5px;
  color: var(--ink-2); }
.drl-row b { margin-left: 4px; }
.drl-click { cursor: pointer; }
.drl-click:hover { color: var(--ink-1); }
.drl-btn {
  margin: 12px 0 2px; border: 1px solid var(--border); background: var(--surface-1);
  color: var(--ink-1); border-radius: 8px; padding: 8px 14px; cursor: pointer; font: inherit;
}
.drl-note { color: var(--muted); font-size: 11.5px; margin: 6px 0 0; }
.drl svg { width: 100%; height: auto; }
#health-tbody tr, #rel-tbody tr, #vessel-table tbody tr { cursor: pointer; }
#health-tbody tr:hover td, #rel-tbody tr:hover td { background: rgba(148,170,210,0.05); }
@media (max-width: 700px) {
  .drl {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%;
    max-height: 80vh; border-left: none; border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0; transform: translateY(105%);
  }
  .drl.open { transform: none; }
}

/* ---- quick wins 2026-07-17: freshness stamps, so-what lines, skeletons ---- */
.grid, .grid3 { gap: 16px; }
.upd { color: var(--muted); font-weight: 400; font-size: 10.5px; margin-left: auto;
  white-space: nowrap; }
.sowhat { color: var(--ink-2); font-size: 11.5px; font-style: italic; margin: 8px 0 0;
  line-height: 1.5; opacity: 0.85; }
.more { color: var(--s1); font-size: 11px; text-decoration: none; font-weight: 500;
  white-space: nowrap; }
.more:hover { text-decoration: underline; }
.skel { color: var(--muted); font-size: 12px; padding: 8px 2px;
  animation: skel-pulse 1.4s ease-in-out infinite; }
@keyframes skel-pulse { 0%,100% { opacity: .9 } 50% { opacity: .35 } }
.kcard[data-href] { cursor: pointer; }
.kcard[data-href]:hover { border-color: var(--s1); }

/* today's insight box */
.insight { margin: 14px 20px 0; padding: 13px 18px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-glow), var(--surface-1));
  border: 1px solid var(--border); border-left: 3px solid var(--s1); }
.insight .ins-head { font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--s1); display: flex; gap: 10px; align-items: center; }
.insight .ins-tag { font-weight: 500; letter-spacing: normal; text-transform: none;
  color: var(--ink-2); font-size: 11px; border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 9px; }
.insight p { margin: 6px 0 0; font-size: 13.5px; line-height: 1.55; color: var(--ink-1);
  max-width: 110ch; }

/* sidebar section headers */
#sidebar .side-sec { margin: 12px 10px 3px; font-size: 10px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
  border-top: 1px solid var(--grid); padding-top: 11px; }


/* layout tweaks 2026-07-17: scroll areas fill their card instead of leaving
   dead space; long destinations ellipsize instead of forcing a 5px sideways scroll */
@media (min-width: 1081px) {
  .card:has(> .scrolltable) { display: flex; flex-direction: column; }
  .card:has(> .scrolltable) > .scrolltable { flex: 1 1 auto; min-height: 0; }
  #health-card > .scrolltable { max-height: none; }  /* row height comes from the map card */
  .scrolltable:has(> #vessel-table) { max-height: 352px; } /* fills its row, never defines it */
}
#vessel-table td:first-child, #vessel-table td:nth-child(3) {
  max-width: 128px; overflow: hidden; text-overflow: ellipsis; }
