:root {
  color-scheme: dark;
  --bg: #0c1520;
  --panel: #142230;
  --panel-2: #1b2d3d;
  --line: #2d4356;
  --text: #e5eef5;
  --muted: #9bb0c1;
  --accent: #63c7d6;
  --accent-bright: #9ceaff;
  --warning: #f2b366;
  --danger: #ef7d7d;
  /* Ship-type colours are shared by markers, filters and the legend. */
  --type-cargo: #63c7d6;
  --type-tanker: #c9a0f0;
  --type-passenger: #7ee0a0;
  --type-fishing: #f2b366;
  --type-tug: #f08d8d;
  --type-military: #d0d6dd;
  --type-leisure: #e6e37a;
  --type-other: #8fa8bb;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: .4rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: relative;
}
.brand { display: flex; align-items: baseline; flex-wrap: wrap; gap: .6rem; min-width: 0; }
h1 { margin: 0; font-size: 1.1rem; white-space: nowrap; }
.brand-icon { width: 1.4rem; height: 1.4rem; vertical-align: -.25rem; margin-right: .25rem; }
h2 { margin: 0 0 .6rem; font-size: 1rem; }
h3 { margin: 1rem 0 .4rem; font-size: .9rem; color: var(--muted); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.section-head h3 { margin-bottom: .4rem; }
.dismiss-button { padding: .2rem .5rem; font-size: .75rem; }
.subtitle { margin: 0; color: var(--muted); font-size: .76rem; }
.pill {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  background: var(--accent); color: #06222a; border-radius: 999px; padding: .1rem .45rem;
  vertical-align: middle;
}
.header-meta { display: flex; align-items: center; gap: .45rem; }
.health { font-size: .72rem; line-height: 1.3; color: var(--muted); text-align: right; }
.health strong { color: var(--text); }
.source-error { color: var(--danger); }
.icon-button { min-width: 1.9rem; padding: .25rem .45rem; line-height: 1; }
.menu.about-menu { top: 100%; right: 1rem; left: auto; width: min(24rem, calc(100vw - 2rem)); z-index: 20; }
.about-menu p { margin: .4rem 0; font-size: .78rem; color: var(--muted); }
.about-menu .menu-actions { justify-content: flex-end; }
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem;
  height: calc(100vh - 3rem);
  min-height: 420px;
}
.map-wrap, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .75rem;
}
.map-wrap { display: flex; flex-direction: column; min-height: 0; position: relative; }
.map-toolbar { display: flex; gap: .5rem; align-items: flex-start; margin-bottom: .5rem; flex-wrap: wrap; }
.slider-wrap { position: relative; flex: 1 1 220px; min-width: 180px; padding-bottom: .9rem; }
.slider-wrap input[type=range] { width: 100%; }
.time-ticks { position: absolute; left: .45rem; right: .45rem; top: 1.15rem; height: .8rem; }
.time-tick, .time-event {
  position: absolute; transform: translateX(-50%);
  font-size: .62rem; color: var(--muted); white-space: nowrap;
}
.time-tick::before, .time-event::before {
  content: ""; display: block; width: 1px; height: .3rem;
  background: var(--line); margin: 0 auto .1rem;
}
.time-event::before { height: .4rem; background: var(--danger); }
.usage-meter {
  display: inline-flex; align-items: center; gap: .25rem;
  margin-left: .5rem; white-space: nowrap; vertical-align: middle;
}
.meter-label { font-size: .65rem; font-weight: 700; color: var(--muted); }
.meter-value { font-size: .65rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.db-meter {
  display: inline-block; vertical-align: middle;
  height: .3rem; width: 5rem; max-width: 100%;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
}
.db-bar { display: block; height: 100%; background: var(--accent); transition: width .25s ease; }
.db-bar.warn { background: var(--warning); }
.db-bar.full { background: var(--danger); }
.ram-bar { display: block; height: 100%; background: var(--accent-bright); transition: width .25s ease; }
.ram-bar.warn { background: var(--warning); }
.ram-bar.full { background: var(--danger); }
button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: .35rem .7rem; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, li:focus-visible, svg#map:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.time-label { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 11rem; }
.muted { color: var(--muted); font-size: .8rem; }
.menu {
  position: absolute; z-index: 10; top: 3rem; left: .75rem;
  width: min(22rem, calc(100% - 1.5rem));
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: .8rem; box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.menu-title { font-weight: 600; margin-bottom: .6rem; }
.menu label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: .6rem; }
.menu input[type=search], .menu input[type=number], .menu select {
  display: block; width: 100%; margin-top: .2rem; padding: .3rem .4rem;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 5px;
}
.menu label.check { display: flex; align-items: center; gap: .4rem; color: var(--text); }
.menu label.check input { width: auto; margin: 0; }
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.filter-types { margin-bottom: .6rem; }
.filter-label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: .35rem; }
.type-options {
  display: grid; grid-template-columns: 1fr 1fr; gap: .25rem .5rem;
  max-height: 10rem; overflow-y: auto;
}
.type-option {
  display: flex; align-items: center; gap: .35rem;
  font-size: .78rem; color: var(--text); cursor: pointer;
}
.type-option input { width: auto; margin: 0; }
.type-icon {
  display: inline-block; width: .7rem; height: .7rem; flex: 0 0 auto;
  clip-path: polygon(50% 0, 100% 100%, 50% 72%, 0 100%);
}
.menu-actions { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; }

.map-stage { position: relative; flex: 1; min-height: 0; }
svg#map {
  width: 100%; height: 100%; background: #0a121a; border-radius: 6px;
  border: 1px solid var(--line); touch-action: none; cursor: grab; display: block;
  /* Inverse viewBox zoom; set once per zoom in app.js. All constant-size
     decorations derive their transform and geometry from this variable. */
  --marker-scale: 1;
}
/* CSS transforms need an origin at the shape's local zero point, matching the
   old SVG transform attribute. */
svg#map .city, svg#map .vessel-marker, svg#map .current-position { transform-origin: 0 0; }
svg#map.dragging { cursor: grabbing; }
.map-controls {
  position: absolute; top: .5rem; right: .5rem;
  display: flex; flex-direction: column; gap: .3rem;
}
.map-controls button { min-width: 2.2rem; font-weight: 700; line-height: 1; }
.legend {
  position: absolute; left: .5rem; bottom: .5rem;
  background: rgba(10, 18, 26, .86); border: 1px solid var(--line); border-radius: 6px;
  padding: .4rem .55rem; font-size: .72rem; color: var(--muted);
  display: grid; gap: .18rem; pointer-events: none;
}
.key { display: inline-block; width: .85rem; height: .5rem; margin-right: .35rem; vertical-align: middle; }
/* Swatches reuse the exact colours of the SVG classes they describe. */
.key-vessel {
  background: linear-gradient(90deg, var(--type-cargo) 0 33%, var(--type-tanker) 33% 66%, var(--type-passenger) 66%);
  clip-path: polygon(50% 0, 100% 100%, 50% 72%, 0 100%);
}
.key-stale {
  background: var(--type-cargo); opacity: .4;
  clip-path: polygon(50% 0, 100% 100%, 50% 72%, 0 100%);
}
.key-point {
  width: .55rem; height: .55rem; border-radius: 50%;
  background: var(--accent-bright); box-shadow: 0 0 0 1px #0a121a;
}
.key-flag-track { border-top: 2px dashed var(--danger); }
.key-reviewed { border-top: 2px dashed #799a91; }
.key-flag-event { width: .55rem; height: .55rem; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 1px #0a121a; }
.key-selected { border-top: 3px solid var(--accent-bright); }
.map-note { color: var(--muted); font-size: .75rem; margin: .45rem 0 0; }

.sidebar { display: flex; flex-direction: column; gap: 1rem; height: 100%; min-height: 0; overflow-y: auto; }
.sidebar > * { flex-shrink: 0; }
.sidebar > .card:last-child {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.sidebar > .card:last-child .tabs { flex: 0 0 auto; }
#panel-vessels, #panel-flagged, #panel-thresholds {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.count { color: var(--muted); font-weight: normal; }
.tabs { display: flex; gap: .35rem; margin-bottom: .6rem; border-bottom: 1px solid var(--line); }
.tab {
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  border-radius: 0; padding: .35rem .6rem; color: var(--muted); font: inherit;
}
.tab:hover { color: var(--text); border-bottom-color: var(--line); }
.tab[aria-selected="true"], .tab[aria-selected="true"]:hover {
  color: var(--text); border-bottom-color: var(--accent);
}
.tab .count, .tab .badge { margin-left: .3rem; }
.badge {
  display: inline-block; min-width: 1.25rem; padding: .05rem .35rem;
  border-radius: 999px; background: rgba(239, 125, 125, .18); color: var(--danger);
  font-size: .75rem; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums;
}
.badge.empty { background: var(--panel-2); color: var(--muted); }
.vessel-list, .anomaly-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.vessel-list { flex: 1 1 auto; min-height: 0; }
.anomaly-list { max-height: 22rem; }
.vessel-list li { padding: .4rem .5rem; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 4px; }
.vessel-list li:hover, .vessel-list li.selected { background: var(--panel-2); }
.vessel-list .mmsi { color: var(--muted); font-variant-numeric: tabular-nums; }
.vessel-list .sog { float: right; color: var(--accent); }
.vessel-list .type { color: var(--muted); font-size: .78rem; }
.vessel-list .flag { font-size: 1.05rem; }
.vessel-list .severity { color: var(--danger); font-weight: 600; }
.vessel-list .flags { color: var(--muted); font-size: .78rem; }
.vessel-list li.reviewed { opacity: .65; }
.vessel-list li.reviewed .severity { color: var(--muted); }
.vessel-list li.pending { border-left: 3px solid var(--danger); padding-left: .4rem; }
.vessel-list li.reviewed { border-left: 3px solid #4f7d6d; padding-left: .4rem; }
.review-button { margin-top: .35rem; padding: .15rem .45rem; font-size: .75rem; }
.reviewed-label { color: #7ee0a0; font-size: .78rem; font-weight: 600; }
.catalog { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-right: .4rem; }
.catalog-note { color: var(--muted); font-size: .76rem; margin: 0 0 .6rem; }
.catalog-card { border: 1px solid var(--line); border-radius: 5px; padding: .5rem .6rem; margin-bottom: .5rem; }
.catalog-card.active { border-left: 3px solid var(--accent); }
.catalog-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.catalog-head h4 { margin: 0; font-size: .85rem; }
.catalog-status { flex: 0 0 auto; font-size: .65rem; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.catalog-card.active .catalog-status { color: var(--accent-bright); }
.catalog-code { color: var(--accent); font-size: .7rem; font-variant-numeric: tabular-nums; }
.catalog-summary { color: var(--muted); font-size: .75rem; margin: .25rem 0 .4rem; }
.catalog-codes { color: var(--warning); font-size: .68rem; overflow-wrap: anywhere; }
.catalog-rules { display: block; margin: .4rem 0 0; }
.catalog-rules > div { display: block; padding: .25rem 0; border-top: 1px solid var(--line); }
.catalog-rules dt { color: var(--muted); font-size: .7rem; font-weight: 600; }
.catalog-rules dd {
  margin: .1rem 0 0; font-size: .75rem; line-height: 1.35;
  overflow-wrap: anywhere; font-variant-numeric: tabular-nums;
}
.catalog-bands { margin-top: .7rem; border-top: 1px solid var(--line); padding-top: .4rem; }
.catalog-bands h4 { margin: 0 0 .3rem; font-size: .8rem; color: var(--muted); }
dl { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
.detail-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  grid-template-rows: repeat(2, auto);
  grid-auto-flow: column;
  gap: .1rem 1rem;
  align-items: start;
}
.detail-group { padding: .1rem 0 .5rem; border-top: 1px solid var(--line); }
.detail-group:first-child { border-top: 0; }
.detail-group h3 { margin: .45rem 0 .35rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.point-controls { display: flex; gap: .3rem; align-items: center; }
.point-controls button { padding: .2rem .5rem; font-size: .78rem; }
.point-controls button:disabled { opacity: .4; cursor: default; }
.past-warning {
  margin: 0 0 .6rem; padding: .4rem .55rem; border: 1px solid var(--warning);
  border-radius: 6px; background: rgba(242, 179, 102, .1); color: var(--warning); font-size: .78rem;
}
.anomaly-list li { padding: .5rem 0; border-top: 1px solid var(--line); cursor: pointer; }
.anomaly-list li:hover { background: var(--panel-2); }
.anomaly-list .code { color: var(--warning); font-weight: 600; }
.anomaly-list .related-vessel { color: var(--warning); font-size: .82rem; }
.anomaly-list .evidence { color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; }
.attribution { color: var(--muted); font-size: .78rem; }

/* A zoomed viewBox must not magnify strokes or marker outlines. */
svg#map path, svg#map line, svg#map polyline, svg#map circle, svg#map rect {
  vector-effect: non-scaling-stroke;
}
/* Flagged polylines are the exception: with a fixed dash pattern,
   non-scaling-stroke makes the browser lay out more dashes the further the
   viewBox is zoomed in. Their stroke width and dash length are multiplied by
   --marker-scale instead, so they keep a constant on-screen size. */
svg#map .flagged-track { vector-effect: none; }
.grid-line { fill: none; stroke: #213648; stroke-width: 1; }
.grid-label { fill: #6d879b; font-size: calc(10px * var(--marker-scale)); }
.land { fill: #17303a; stroke: #457785; stroke-width: 1; }
.trail { fill: none; stroke: var(--accent); stroke-width: 1.5; opacity: .8; }
.flagged-track {
  fill: none; stroke: var(--danger); opacity: .7;
  stroke-width: calc(1.6px * var(--marker-scale));
  stroke-dasharray: calc(5px * var(--marker-scale)) calc(4px * var(--marker-scale));
}
.flagged-track.reviewed { stroke: #799a91; opacity: .45; }
.flag-event.reviewed .flag-point { fill: #799a91; stroke: #06131b; }
.flag-event.reviewed .flag-segment { stroke: #799a91; opacity: .5; }
.city-label {
  fill: #8ea6b8; font-size: 11px; paint-order: stroke; stroke: #0a121a;
  stroke-width: 3px; pointer-events: none;
}
.city-dot { fill: #6d879b; stroke: none; }
/* Wider invisible stroke so thin track lines are easy to click. */
.track-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.flag-segment { stroke: var(--warning); stroke-width: 2.6; opacity: .9; }
/* The trigger fix is a solid orange dot, the same size as the green
   start-of-track spot, so it identifies a location rather than a score. */
.flag-point {
  fill: var(--warning); stroke: #06131b; stroke-width: 1;
  r: calc(3.5px * var(--marker-scale));
}
.flag-point.trigger-spot { pointer-events: none; }
/* A wide translucent stroke gives the track the same soft halo without a
   filter. CSS/SVG filters run in user space here, so the drop-shadow blur
   radius grew with the viewBox zoom factor and made deep zoom extremely slow. */
.selected-track-glow { fill: none; stroke: rgba(156, 234, 255, .35); stroke-width: 6; }
.selected-track {
  fill: none; stroke: var(--accent-bright); stroke-width: 2.6;
  marker-mid: url(#track-arrow);
}
.selected-track-glow.stale { opacity: .35; }
.selected-track.stale { opacity: .35; }
.track-start.stale { opacity: .4; }
.track-start {
  fill: #7ee0a0; stroke: #06222a; stroke-width: 1;
  r: calc(3.5px * var(--marker-scale));
}
.current-position { cursor: pointer; }
.current-ring { fill: none; stroke: var(--accent-bright); stroke-width: 2.5; animation: pulse 1.6s ease-out infinite; }
.current-dot { fill: #fff; stroke: #0a121a; stroke-width: 1.5; }
.current-label { fill: var(--accent-bright); font-size: 11px; paint-order: stroke; stroke: #0a121a; stroke-width: 3; }
.current-cross { stroke: var(--accent-bright); stroke-width: 2; }
/* Point markers live above the invisible track hits so they stay clickable. */
.track-point {
  fill: var(--accent-bright); stroke: #06131b; stroke-width: 1;
  r: calc(var(--point-r, 3.2px) * var(--marker-scale));
  opacity: .8; cursor: pointer; pointer-events: all;
}
.track-point:hover { fill: #fff; opacity: 1; }
.track-point.selected { fill: #fff; stroke: var(--accent); stroke-width: 2; opacity: 1; }
.track-point.latest { fill: transparent; stroke: none; opacity: 1; }
.vessel-marker { cursor: pointer; }
.vessel-marker .vessel-shape { fill: var(--type-cargo); stroke: #06131b; stroke-width: 1; }
.vessel-marker.cargo .vessel-shape { fill: var(--type-cargo); }
.vessel-marker.tanker .vessel-shape { fill: var(--type-tanker); }
.vessel-marker.passenger .vessel-shape { fill: var(--type-passenger); }
.vessel-marker.fishing .vessel-shape { fill: var(--type-fishing); }
.vessel-marker.tug .vessel-shape { fill: var(--type-tug); }
.vessel-marker.military .vessel-shape { fill: var(--type-military); }
.vessel-marker.leisure .vessel-shape { fill: var(--type-leisure); }
.vessel-marker.other .vessel-shape, .vessel-marker.unknown .vessel-shape { fill: var(--type-other); }
/* Stale fixes keep their ship-type hue but fade into the background. */
.vessel-marker.stale .vessel-shape { fill-opacity: .38; stroke-opacity: .55; }
.vessel-marker.active .vessel-shape { stroke: #fff; stroke-width: 2; }
.type-icon.cargo { background: var(--type-cargo); }
.type-icon.tanker { background: var(--type-tanker); }
.type-icon.passenger { background: var(--type-passenger); }
.type-icon.fishing { background: var(--type-fishing); }
.type-icon.tug { background: var(--type-tug); }
.type-icon.military { background: var(--type-military); }
.type-icon.leisure { background: var(--type-leisure); }
.type-icon.other, .type-icon.unknown { background: var(--type-other); }
@keyframes pulse {
  0% { r: 10; opacity: .95; }
  100% { r: 28; opacity: 0; }
}

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; }
  .map-wrap { min-height: 60vh; }
  .map-stage { min-height: 24rem; }
  .sidebar { height: auto; max-height: none; overflow: visible; }
  .vessel-list, .catalog { flex: 0 0 auto; max-height: 26rem; }
  .header-meta { flex-wrap: wrap; justify-content: flex-start; }
  .health { text-align: left; }
}
