/* Palette follows nautical chart conventions: magenta marks regulated areas and
   anything needing attention; water blues and chart ink carry everything else.
   Night mode mirrors the dimmed palette used on ECDIS bridge displays. */
:root {
  --ink: #14233a;
  --ink-2: #4b5b71;
  --paper: #ffffff;
  --sea: #e9f1f7;
  --shoal: #a9cbe3;
  --rule: #cbd8e4;
  --magenta: #a8126f;
  --magenta-wash: #f8e4f0;
  --amber: #8f5400;
  --amber-wash: #fbefd9;
  --slate-wash: #eef2f6;
  --focus: #1f6fd1;
  --chart-filter: none;
  --font: "Public Sans", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

:root[data-theme="night"] {
  --ink: #d5e1ed;
  --ink-2: #93a6bc;
  --paper: #0f1a28;
  --sea: #09121c;
  --shoal: #29506f;
  --rule: #223447;
  --magenta: #e45db3;
  --magenta-wash: #3a1431;
  --amber: #e3ab4d;
  --amber-wash: #33260d;
  --slate-wash: #17263a;
  --focus: #6fb0ff;
  --chart-filter: invert(1) hue-rotate(180deg) brightness(0.72) contrast(0.95);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font: 400 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--sea);
  display: flex;
  flex-direction: column;
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* --- top bar ------------------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

.run-form { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.run-form label, .speed { display: flex; flex-direction: column; align-items: flex-start; font-size: 12px; color: var(--ink-2); gap: 2px; }

select, input[type="search"] {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 6px 8px;
}

.topbar-status { margin-left: auto; display: flex; align-items: center; gap: 14px; }

.marsec {
  font-weight: 700;
  padding: 3px 10px;
  border: 2px solid var(--ink);
  border-radius: 3px;
}
.marsec[data-level="2"] { border-color: var(--amber); color: var(--amber); }
.marsec[data-level="3"] { border-color: var(--magenta); background: var(--magenta); color: var(--paper); }

.model-status { font-size: 13px; color: var(--ink-2); }
.model-status::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--ink-2);
}
.model-status[data-ok="true"]::before { background: #2e8b57; }
.model-status[data-ok="false"]::before { background: var(--amber); }

.btn {
  font: 600 14px/1 var(--font);
  border-radius: 4px;
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn-link { background: none; border: none; color: var(--focus); padding: 0; font-weight: 500; }
.btn-model { background: var(--paper); color: var(--magenta); border-color: var(--magenta); }

/* --- layout ------------------------------------------------------------------- */

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
}

.chart-area { display: flex; flex-direction: column; min-height: 0; }

#map { flex: 1; min-height: 320px; background: var(--sea); }
.chart-tiles { filter: var(--chart-filter); }

/* --- timeline: the one bold element. Findings sit on it as magenta marks. ------ */

.timeline {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 16px;
  padding: 12px 20px 14px;
  background: var(--paper);
  border-top: 1px solid var(--rule);
}

.btn-play { background: var(--ink); color: var(--paper); min-width: 72px; }

.timeline-track { position: relative; height: 44px; }

.timeline-ticks { position: absolute; inset: 0 0 18px 0; pointer-events: none; }

.tick {
  position: absolute;
  bottom: 0;
  transform: translateX(-50%);
  pointer-events: auto;
  border: none;
  padding: 0;
  cursor: pointer;
}
.tick-finding {
  width: 4px;
  height: 24px;
  background: var(--magenta);
  border-radius: 1px;
}
.tick-finding[data-severity="medium"], .tick-finding[data-severity="low"] { background: var(--amber); }
.tick-finding[aria-current="true"] { width: 8px; outline: 2px solid var(--paper); box-shadow: 0 0 0 4px var(--magenta); }
.tick-radio { width: 2px; height: 10px; background: var(--shoal); pointer-events: none; }
.tick-marsec { width: 2px; height: 26px; background: var(--ink); pointer-events: none; }

#scrubber {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  width: 100%;
  margin: 0;
  accent-color: var(--ink);
}

.clock { font-size: 20px; font-weight: 600; min-width: 108px; text-align: right; }

/* --- side panel ---------------------------------------------------------------- */

.panel {
  background: var(--paper);
  border-left: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tabs { display: flex; border-bottom: 1px solid var(--rule); }
.tab {
  flex: 1;
  font: 600 14px var(--font);
  color: var(--ink-2);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 12px 8px 9px;
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  margin-left: 4px;
  border-radius: 10px;
  background: var(--slate-wash);
  font-size: 12px;
}

.view { flex: 1; overflow-y: auto; padding: 16px 20px 24px; }

.scenario-note, .hint { color: var(--ink-2); font-size: 13px; margin: 0 0 12px; }

ol { list-style: none; margin: 0; padding: 0; }

/* findings */

.finding {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  border-bottom: 1px solid var(--rule);
  padding: 12px 4px;
  cursor: pointer;
}
.finding:hover { background: var(--slate-wash); }
.finding[data-future="true"] { opacity: 0.45; }
.finding-time { grid-row: span 2; font-weight: 600; padding-top: 1px; }
.finding-rule { font-size: 13px; color: var(--ink-2); }
.finding-summary { grid-column: 2; }

.sev {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 0 6px;
  border-radius: 3px;
  margin-right: 6px;
  border: 1px solid currentColor;
}
.sev-critical { background: var(--magenta); border-color: var(--magenta); color: var(--paper); }
.sev-high { color: var(--magenta); background: var(--magenta-wash); }
.sev-medium { color: var(--amber); background: var(--amber-wash); }
.sev-low, .sev-info { color: var(--ink-2); background: var(--slate-wash); }

/* finding detail */

.detail h2 { font-size: 17px; line-height: 1.35; margin: 8px 0 12px; }
.detail h3 { font-size: 14px; margin: 20px 0 6px; }
.detail p { margin: 0 0 8px; }
.detail ul { margin: 0; padding-left: 18px; }
.detail li { margin-bottom: 6px; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 16px; margin: 0; font-size: 14px; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; font-weight: 600; }

.requirement {
  border-left: 3px solid var(--ink);
  padding: 4px 0 4px 12px;
  margin: 0;
}
.citation { font-weight: 600; white-space: nowrap; }

.draft-note {
  font-size: 13px;
  color: var(--amber);
  background: var(--amber-wash);
  padding: 6px 10px;
  border-radius: 3px;
  margin-top: 8px;
}

.explanation-box {
  margin-top: 8px;
  padding: 12px 14px;
  background: var(--slate-wash);
  border-radius: 4px;
}
.explanation-box[data-model="true"] { border-left: 3px solid var(--magenta); }
.explanation-meta { font-size: 12px; color: var(--ink-2); margin-top: 8px; }

.warnings { margin-top: 10px; }
.warnings li { color: var(--magenta); font-size: 13px; }

.sources li { font-size: 13px; }

details summary { cursor: pointer; color: var(--ink-2); font-size: 13px; margin-top: 16px; }

.working { font-size: 13px; color: var(--ink-2); margin-top: 8px; }

/* radio */

.radio-item { padding: 10px 0; border-bottom: 1px solid var(--rule); }
.radio-item[data-future="true"] { opacity: 0.4; }
.radio-head { font-size: 13px; color: var(--ink-2); }
.channel { font-weight: 700; color: var(--ink); margin-right: 6px; }
.radio-text { margin: 2px 0 0; }

/* regulations */

.search { display: flex; gap: 8px; margin-bottom: 8px; }
.search input { flex: 1; min-width: 0; }
.reg { padding: 12px 0; border-bottom: 1px solid var(--rule); }
.reg-head { font-weight: 600; }
.reg-place { font-size: 12px; color: var(--magenta); margin-left: 6px; }
.reg-text { white-space: pre-wrap; font-size: 14px; margin: 6px 0 0; }
.reg-text[data-clamped="true"] { max-height: 6.2em; overflow: hidden; }

.empty { color: var(--ink-2); padding: 16px 0; }
.error { color: var(--magenta); }

/* --- map marks ------------------------------------------------------------------ */

.vessel-icon { background: none; border: none; }
.vessel-icon svg { overflow: visible; }
.leaflet-tooltip.vessel-label {
  font: 600 12px var(--font);
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  box-shadow: none;
  padding: 1px 6px;
}
.leaflet-tooltip.vessel-label::before { display: none; }
.leaflet-container { font-family: var(--font); }

/* Leaflet sets stroke/fill as SVG attributes; these rules override them so map
   marks follow the theme tokens. */
.map-bounds { stroke: var(--ink-2); stroke-width: 1.5; stroke-dasharray: 2 6; }
.map-zone-security { stroke: var(--magenta); stroke-width: 2.5; stroke-dasharray: 10 4 2 4; fill: var(--magenta); fill-opacity: 0.1; }
.map-zone-other { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 6 4; fill: none; }
.map-berth { stroke: var(--paper); stroke-width: 1.5; fill: var(--ink); fill-opacity: 1; }
.map-trail { stroke: var(--ink); stroke-width: 2; stroke-opacity: 0.45; fill: none; }
.map-finding { stroke: var(--magenta); stroke-width: 2; fill: var(--magenta); fill-opacity: 0.12; }
.map-finding-medium, .map-finding-low { stroke: var(--amber); fill: var(--amber); }
.map-finding-selected { stroke-width: 4; fill-opacity: 0.25; }

.vessel path, .vessel rect { fill: var(--ink); stroke: var(--paper); stroke-width: 1.5; }
.vessel-flagged path, .vessel-flagged rect { fill: var(--magenta); }
.vessel-stale path, .vessel-stale rect { fill: var(--paper); stroke: var(--magenta); stroke-width: 2; stroke-dasharray: 3 2; }
.vessel-ring { fill: none; stroke: var(--magenta); stroke-width: 2; }

.cite { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }

/* --- narrow screens --------------------------------------------------------------- */

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: 60vh auto; }
  .run-form { width: 100%; }
  .run-form label { flex: 1 1 140px; min-width: 0; }
  .run-form select { width: 100%; }
  .panel { border-left: none; border-top: 1px solid var(--rule); }
  .topbar { gap: 12px; padding: 10px 16px; }
  .topbar-status { margin-left: 0; }
  .timeline { grid-template-columns: auto minmax(0, 1fr); padding: 10px 16px; }
  .clock { text-align: left; }
  .view { padding: 12px 16px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
