:root {
  --bg: #0b1220;
  --panel: #101a2e;
  --panel-2: #16233c;
  --border: #24344f;
  --text: #dbe6f5;
  --muted: #8aa0bd;
  --accent: #38bdf8;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --warn: #eab308;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body { display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 22px; }
.brand h1 { font-size: 18px; margin: 0; }
.brand .tag {
  font-size: 11px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 20px;
}
.stats { display: flex; gap: 18px; }
.stat { display: flex; flex-direction: column; align-items: center; }
.stat label { font-size: 10px; text-transform: uppercase; color: var(--muted); letter-spacing: .06em; }
.stat b { font-size: 15px; font-variant-numeric: tabular-nums; }
.badge { padding: 2px 8px; border-radius: 12px; font-size: 12px; }
.badge.ok { background: rgba(34,197,94,.15); color: var(--accent-2); }
.badge.warn { background: rgba(234,179,8,.15); color: var(--warn); }
.badge.err { background: rgba(239,68,68,.15); color: var(--danger); }
.badge.demo { background: rgba(168,85,247,.18); color: #c084fc; }

/* ---------- layout ---------- */
#layout { flex: 1; display: flex; min-height: 0; }

#sidebar {
  width: 320px;
  min-width: 260px;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#map { flex: 1; z-index: 1; position: relative; background: #0a1020; }
#map.rtl-wrapped { direction: ltr; }

/* Leaflet's own chrome, restyled for the dark chart */
.leaflet-control-zoom a {
  background: var(--panel);
  color: var(--text);
  border-color: var(--border);
}
.leaflet-control-zoom a:hover { background: var(--panel-2); }
.leaflet-control-attribution {
  background: rgba(11,18,32,.78) !important;
  color: var(--muted) !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
}

/* ---------- vessel detail panel ---------- */
#detail {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 290px;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  z-index: 900;
  background: rgba(16,26,46,.96);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
}
.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px 10px 0 0;
}
.detail-head h3 { margin: 0; font-size: 15px; line-height: 1.25; }
.detail-sub { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
#detail-close {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  padding: 0;
  font-size: 17px; line-height: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}
.detail-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.detail-table tr { border-bottom: 1px solid rgba(36,52,79,.5); }
.detail-table tr:last-child { border-bottom: none; }
.detail-table th {
  text-align: left; font-weight: 500; color: var(--muted);
  padding: 5px 8px 5px 12px; white-space: nowrap; width: 40%;
}
.detail-table td {
  font-weight: 600; padding: 5px 12px 5px 0;
  font-variant-numeric: tabular-nums; word-break: break-word;
}
.detail-actions { padding: 10px 12px; }
button.small { padding: 6px 8px; font-size: 12px; }
.detail-demo {
  margin: 0; padding: 8px 12px;
  font-size: 11px; color: #c084fc;
  background: rgba(168,85,247,.1);
  border-top: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
}

/* ---------- empty state ---------- */
#empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* NB: z-index cannot lower this beneath Leaflet's popups — the map pane carries
     a CSS transform, which puts every Leaflet pane in its own stacking context
     that this card never competes with. The card is hidden on popupopen instead. */
  z-index: 850;
  width: min(420px, calc(100% - 48px));
  padding: 18px 20px;
  text-align: center;
  background: rgba(16,26,46,.94);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
}
#empty-state h2 {
  margin: 0 0 8px;
  font-size: 15px;
  letter-spacing: .02em;
  color: var(--text);
}
#empty-state p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
}
.empty-actions { margin-top: 14px; display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.empty-actions button { flex: 0 0 auto; }

/* ---------- panels ---------- */
.panel {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.panel h2 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
}
.panel h2 .hint { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }

.field { margin-bottom: 8px; }
.field label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }

input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: #5b6f8a; }

.row { display: flex; gap: 8px; }
.row .field { flex: 1; }
.row .field input { min-width: 0; }

.actions { display: flex; gap: 8px; margin-top: 4px; }
button {
  flex: 1;
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
}
button:hover { filter: brightness(1.15); }
button.primary { background: var(--accent); border-color: var(--accent); color: #04222e; font-weight: 600; }
button.ghost { background: transparent; }

.note { font-size: 12px; color: var(--muted); margin: 8px 0 0; min-height: 16px; }
.note.err { color: var(--danger); }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; cursor: pointer; }
.check input { accent-color: var(--accent); }

.checklist { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; }
.checklist .check { font-size: 12px; }

/* ---------- legend ---------- */
#legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 7px 14px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.legend-title { text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-size: 10px; }
.legend-items { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-item i {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(255,255,255,.35);
}
.legend-sep { width: 1px; height: 16px; background: var(--border); }

/* marker-shape swatches — mirror the canvas painter in vessel-layer.js */
.legend-item i.shape-arrow {
  width: 0; height: 0; border: none; border-radius: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 11px solid var(--muted);
}
.legend-item i.shape-dot { background: var(--muted); }
.legend-item i.shape-diamond {
  background: var(--muted); border-radius: 2px;
  transform: rotate(45deg); width: 8px; height: 8px;
}

/* ---------- conditions block in the detail panel ---------- */
.wx-head {
  margin: 0;
  padding: 8px 12px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  border-top: 1px solid var(--border);
}
.wx-note {
  margin: 0;
  padding: 6px 12px 8px;
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--muted);
}

.layer-note { margin-left: auto; font-size: 10.5px; color: var(--muted); }

/* ---------- 24h wind outlook strip ---------- */
.wx-outlook { padding: 4px 12px 10px; }
.wx-outlook-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin-bottom: 5px;
}
.wx-outlook-head span { text-transform: none; letter-spacing: 0; color: var(--warn); }
.wx-bars {
  display: flex; align-items: flex-end; gap: 3px;
  height: 34px; padding-top: 2px;
}
.wx-bar {
  position: relative; flex: 1; height: 100%;
  display: flex; align-items: flex-end; justify-content: center;
}
.wx-bar i { position: absolute; bottom: 0; width: 100%; border-radius: 1px; }
.wx-gust { background: rgba(234,179,8,.35); }
.wx-wind { background: var(--accent); opacity: .85; }


/* ==========================================================================
   Panel toggle, weather controls and responsive layout
   ========================================================================== */

.icon-btn {
  flex: 0 0 auto;
  /* Shown at every width. It was previously revealed only under 900px, which
     meant the collapse feature existed but had no control on a laptop — the
     one place a 320px panel costs the most chart. */
  display: flex;
  width: 34px; height: 34px;
  padding: 0;
  flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.icon-btn span {
  display: block; width: 16px; height: 2px;
  background: var(--text); border-radius: 2px;
}

/* Collapse by width, not negative margin. A negative margin on this flex item
   was silently ignored — even set inline it computed back to 0 — because the
   item also carries min-width, so the row never gave up the space. Zeroing
   width, min-width, padding and border is what actually reflows it, and the
   sidebar keeps its DOM so scroll position and a half-typed search survive. */
#sidebar {
  transition: width .2s ease, min-width .2s ease, padding .2s ease, opacity .15s ease;
}
body.panel-closed #sidebar {
  width: 0;
  min-width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-width: 0;
  overflow: hidden;
  opacity: 0;
}

/* ---------- segmented control (weather mode, track range) ---------- */
.seg { display: flex; gap: 0; }
.seg button {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg);
  color: var(--muted);
}
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button + button { border-left: none; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: #04222e; font-weight: 600; }
.seg-sm { display: inline-flex; margin-left: auto; }
.seg-sm button { padding: 2px 7px; font-size: 10.5px; }
.wx-field { margin-top: 10px; }
.hint-sm { margin: 6px 0 0; font-size: 10.5px; color: var(--muted); }
.wx-head { display: flex; align-items: center; gap: 8px; }

/* ---------- weather glyphs on the map ---------- */
.wx-barb svg { overflow: visible; }
.wx-wave-glyph {
  display: flex; flex-direction: column; align-items: center;
  font-size: 10px; line-height: 1; text-shadow: 0 1px 3px rgba(0,0,0,.9);
}
.wx-wave-glyph span { font-size: 13px; display: block; }
.wx-wave-glyph b { font-size: 10px; color: var(--text); }

/* `display:flex` below would otherwise beat the [hidden] attribute's
   display:none, leaving an empty pill on the chart when no overlay is on. */
.map-legend[hidden] { display: none; }

.map-legend {
  position: absolute;
  left: 12px; bottom: 12px;
  z-index: 690;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  max-width: calc(100% - 24px);
  padding: 6px 10px;
  font-size: 11px;
  background: rgba(16,26,46,.92);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.map-legend i {
  width: 12px; height: 8px; border-radius: 2px;
  display: inline-block; margin-right: 4px;
}

/* ---------- sea meteogram popup ---------- */
.meteo { min-width: min(250px, calc(100vw - 110px)); }   /* 250px plus popup chrome overflowed 320px phones */
.meteo-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--accent);
}
.meteo-head span { text-transform: none; letter-spacing: 0; color: var(--muted); }
.meteo-now { margin: 4px 0 8px; font-size: 13px; }
.meteo-eca { margin-top: 6px; font-size: 10.5px; color: #2dd4bf; }
.meteo-loading { padding: 6px 2px; font-size: 12px; color: var(--muted); }
.mg-bars { display: flex; align-items: flex-end; gap: 2px; height: 56px; }
.mg-col { position: relative; flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.mg-col i { position: absolute; bottom: 0; border-radius: 1px; }
.mg-gust { width: 100%; background: rgba(234,179,8,.3); }
.mg-wind { width: 100%; }
.mg-wave { width: 40%; background: rgba(45,212,191,.75); }
.mg-col u {
  position: absolute; bottom: -14px; font-size: 9px; color: var(--muted); text-decoration: none;
}
.mg-key { margin-top: 18px; font-size: 10px; color: var(--muted); }
.mg-key i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin: 0 3px 0 8px; }
.mg-k-wind { background: #7dd3fc; }
.mg-k-gust { background: rgba(234,179,8,.5); }
.mg-k-wave { background: rgba(45,212,191,.75); }

/* ==========================================================================
   Responsive — the sidebar becomes an overlay drawer and the detail panel a
   bottom sheet. On a phone the previous fixed 320px sidebar left barely 100px
   of chart, which is the whole point of the app.
   ========================================================================== */

@media (max-width: 1100px) {
  .checklist { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  #topbar { padding: 8px 10px; gap: 8px; }
  .brand h1 { font-size: 15px; }
  .brand .tag { display: none; }
  .stats { gap: 12px; }
  .stat label { font-size: 9px; }
  .stat b { font-size: 13px; }

  /* Drawer, not a column: it floats over the chart so collapsing it gives the
     map the whole width instead of merely a bit more. */
  #layout { position: relative; }
  #sidebar {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: min(88vw, 330px);
    z-index: 1000;
    margin-left: 0;
    box-shadow: 6px 0 24px rgba(0,0,0,.5);
  }
  body.panel-closed #sidebar {
    margin-left: 0;
    transform: translateX(-102%);
  }

  #detail {
    top: auto; left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 55%;
    border-radius: 14px 14px 0 0;
    border-left: none; border-right: none; border-bottom: none;
  }
  .detail-head { border-radius: 14px 14px 0 0; }

  #legend { font-size: 10.5px; padding: 6px 10px; gap: 8px; }
  #legend .legend-sep { display: none; }
  .map-legend { bottom: 8px; left: 8px; font-size: 10px; }
}

@media (max-width: 560px) {
  /* Only the two numbers worth a glance survive; the rest is in the panel. */
  .stat:nth-child(2), .stat:nth-child(4) { display: none; }
  #legend .legend-item:nth-child(n+7) { display: none; }
  .meteo { min-width: 0; }
  /* Comfortable touch targets — 8px rows are a desktop affordance. */
  .check { padding: 7px 0; }
  .seg button { padding: 9px 8px; }
  button { padding: 10px; }
  #detail { max-height: 62%; }
}

/* Fine pointers only: hover styling on touch leaves buttons stuck "active". */
@media (hover: none) {
  button:hover { filter: none; }
}

/* ---------- CPA / TCPA ---------- */
.cpa-table { margin-top: 6px; font-size: 11.5px; }
.cpa-table th { padding: 3px 6px 3px 0; width: auto; font-size: 10px; text-transform: uppercase; }
.cpa-table td { padding: 4px 6px 4px 0; font-weight: 500; }
.cpa-table tr[data-mmsi] { cursor: pointer; }
.cpa-table tr[data-mmsi]:hover { background: rgba(56,189,248,.08); }
.cpa-units td { font-size: 9px; color: var(--muted); padding-top: 0; }
tr.cpa-danger td:nth-child(2), tr.cpa-danger td:nth-child(3) { color: var(--danger); font-weight: 700; }
tr.cpa-warn td:nth-child(2), tr.cpa-warn td:nth-child(3) { color: var(--warn); font-weight: 600; }

/* ---------- ECA crossing log ---------- */
.eca-ev {
  display: flex; align-items: baseline; gap: 7px;
  padding: 4px 0; font-size: 11.5px;
  border-bottom: 1px solid rgba(36,52,79,.5);
  cursor: pointer;
}
.eca-ev:hover { background: rgba(56,189,248,.07); }
.eca-ev-t { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 10.5px; }
.eca-ev-n { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eca-ev-z { color: var(--muted); font-size: 10.5px; white-space: nowrap; }
.eca-ev.enter .eca-ev-z { color: var(--warn); }
.eca-ev.exit .eca-ev-z { color: var(--accent-2); }

.detail-actions-row { display: flex; flex-wrap: wrap; gap: 6px; }
.detail-actions-row button { flex: 1 1 auto; min-width: 74px; }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%; bottom: 74px;
  transform: translateX(-50%);
  z-index: 2000;
  max-width: min(420px, calc(100% - 32px));
  padding: 10px 16px;
  font-size: 13px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
}
#toast[hidden] { display: none; }

/* Coverage legend swatch — the same hatch the layer paints, so the footer key
   and the map agree without the reader having to infer it. */
.legend-item i.shape-nocover {
  display: inline-block;
  width: 14px;
  height: 10px;
  border-radius: 2px;
  background-color: rgba(96, 116, 142, 0.45);
  background-image: repeating-linear-gradient(
    45deg,
    rgba(150, 168, 190, 0.85) 0 1px,
    transparent 1px 4px
  );
}

/* CII band badge. The A-E scale is conventionally green-to-red, so the colours
   carry the meaning for anyone who already knows the scale. */
.cii-badge {
  display: inline-block;
  min-width: 1.35em;
  padding: 1px 6px;
  margin-right: 6px;
  border-radius: 4px;
  color: #0b1220;
  font-weight: 700;
  text-align: center;
}
.em-details { margin-top: 6px; }
.em-details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted, #8ba0b8);
}
.em-details ul { margin: 6px 0 4px 16px; padding: 0; }
.em-details li { font-size: 12px; color: var(--muted, #8ba0b8); line-height: 1.5; }

/* AIS gap list. Currently-dark vessels are the live signal and lead; closed
   gaps are history and sit quieter. */
.gap-list { list-style: none; margin: 0; padding: 0; }
.gap-row {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line, #1e293b);
}
.gap-row:last-child { border-bottom: 0; }
.gap-name { font-size: 12px; color: var(--fg, #e2e8f0); }
.gap-meta { font-size: 11px; color: var(--muted, #8ba0b8); }
.gap-dark .gap-name { color: #fbbf24; }
.gap-suspect .gap-name { color: #f87171; }
.gap-flag {
  display: inline-block;
  padding: 0 4px;
  border-radius: 3px;
  background: #7f1d1d;
  color: #fecaca;
  font-size: 10px;
  font-weight: 700;
}

/* Watchlist alerts. Compact rows: this panel competes for height with the
   filters and the ECA log, and a watchlist is scanned, not read. */
.wl-alerts { margin-top: 6px; }
.wl-alert {
  display: grid;
  grid-template-columns: 34px 14px 1fr;
  grid-template-areas: "t i n" ". . x";
  gap: 0 5px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line, #1e293b);
  cursor: pointer;
  font-size: 11px;
}
.wl-alert:last-child { border-bottom: 0; }
.wl-alert:hover { background: rgba(148, 163, 184, 0.08); }
.wl-a-t { grid-area: t; color: var(--muted, #8ba0b8); font-variant-numeric: tabular-nums; }
.wl-a-i { grid-area: i; }
.wl-a-n { grid-area: n; color: var(--fg, #e2e8f0); }
.wl-a-x { grid-area: x; color: var(--muted, #8ba0b8); }
#wl-share { font-size: 11px; }

/* Port calls. Arrivals and departures read as a log, so the time and direction
   arrow lead and the port name carries the rest. */
.pc-list { margin-top: 2px; }
.pc-row {
  display: grid;
  grid-template-columns: 34px 12px 1fr;
  grid-template-areas: "t a n" ". . p";
  gap: 0 5px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line, #1e293b);
  cursor: pointer;
  font-size: 11px;
}
.pc-row:last-child { border-bottom: 0; }
.pc-row:hover { background: rgba(148, 163, 184, 0.08); }
.pc-t { grid-area: t; color: var(--muted, #8ba0b8); font-variant-numeric: tabular-nums; }
.pc-a { grid-area: a; font-weight: 700; }
.pc-arrival .pc-a { color: #4ade80; }
.pc-departure .pc-a { color: #60a5fa; }
.pc-n { grid-area: n; color: var(--fg, #e2e8f0); }
.pc-p { grid-area: p; color: var(--muted, #8ba0b8); }

/* Fleet controls sit above the alert list, so they stay compact. */
.fleet-actions { gap: 6px; flex-wrap: wrap; }
.fleet-actions .danger { color: #f87171; border-color: rgba(248, 113, 113, 0.35); }
.fleet-actions .danger:hover { background: rgba(248, 113, 113, 0.12); }

/* Link to the biography page. Sits with the tagline rather than in the stats
   row: it is not a statistic, and the stats row is what the eye scans. */
.about-link {
  margin-left: 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.about-link:hover { color: var(--accent); }

/* ---------- collapsible sidebar sections ---------- */
.group {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  flex-shrink: 0;
}
.group > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  border-radius: 10px;
  user-select: none;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before {
  content: "";
  width: 6px; height: 6px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform .15s ease;
  flex-shrink: 0;
}
.group[open] > summary::before { transform: rotate(45deg); }
.group > summary:hover { background: var(--panel-2); }
.group > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.group[open] > summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.group-title {
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text);
}
.group-sub {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.group-dot {
  display: none;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--warn);
  flex-shrink: 0;
}
.group.has-news:not([open]) .group-dot { display: inline-block; }
.group-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 8px 8px;
}

/* ---------- account (Sign in with LinkedIn) ---------- */
.account { position: relative; display: flex; align-items: center; }
.signin-btn, .acct-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.signin-btn:hover, .acct-btn:hover { border-color: var(--accent); }
.in-logo {
  display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 3px;
  background: #0a66c2; color: #fff; font: 700 11px/1 Arial, sans-serif;
}
.acct-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 2000; width: 230px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.45);
  display: flex; flex-direction: column; gap: 6px;
}
/* Same trap as .map-legend and #toast above: display:flex beats the [hidden]
   attribute, so the menu stayed open for good. */
.account[hidden], .acct-menu[hidden] { display: none; }
.acct-menu .acct-note { margin: 0 0 4px; font-size: 12px; color: var(--muted); line-height: 1.4; }
.acct-menu button, .acct-menu a {
  text-align: left; background: none; border: 0; color: var(--text); font-size: 13px;
  padding: 6px 4px; border-radius: 6px; cursor: pointer; text-decoration: none;
}
.acct-menu button:hover, .acct-menu a:hover { background: var(--panel-2); }
.acct-menu .danger { color: var(--danger); }

/* ---------- public map, private tools ---------- */
.signin-panel { display: none; }
body.anon .signin-panel { display: block; }
body.anon #sidebar details.group { display: none; }
body.anon #detail-own, body.anon #detail-watch { display: none; }
.signin-lead { margin: 0 0 8px; font-size: 13px; color: var(--text); }
.signin-list { margin: 0 0 14px; padding-left: 18px; font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.signin-big {
  width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: #0a66c2; color: #fff; border: 0; border-radius: 8px; padding: 10px 12px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.signin-big .in-logo { background: #fff; color: #0a66c2; }
.signin-big:hover { background: #0958a8; }
.signin-small { margin: 10px 0 0; font-size: 11px; color: var(--muted); text-align: center; }
.signin-small a, .detail-cta a, .cta-pop a { color: var(--accent); }
.detail-cta {
  margin-top: 10px; padding: 10px; border: 1px dashed var(--border); border-radius: 8px;
  font-size: 12px; color: var(--muted); line-height: 1.5;
}
.cta-pop { font-size: 12.5px; line-height: 1.5; }

/* ---------- IMF PortWatch popups (portwatch-layer.js) ---------- */
.pw-title { font-size: 14px; font-weight: 600; margin: 3px 0 2px; }
.pw-title span { margin-left: 6px; font-weight: 400; font-size: 12px; color: var(--muted); }
.pw-sub { font-size: 11.5px; color: var(--muted); margin-bottom: 2px; }
.pw-kpis { margin: 7px 0 6px; font-size: 12.5px; line-height: 1.6; }
.pw-kpis span { font-size: 11px; margin-left: 4px; }
.pw-down2 { color: #f87171; }
.pw-down { color: #fbbf24; }
.pw-up { color: #4ade80; }
.pw-flat { color: var(--muted); }
.pw-spark { display: block; margin-top: 4px; background: rgba(255, 255, 255, .03); border-radius: 4px; }
.pw-k-all, .pw-k-tank { display: inline-block; width: 10px; height: 3px; margin: 0 3px 2px 6px; vertical-align: middle; }
.pw-k-all { background: #38bdf8; }
.pw-k-tank { background: #eab308; }

/* ---------- live AIS section of the PortWatch port popup ---------- */
.pw-sec {
  margin: 9px 0 3px; padding-top: 7px; border-top: 1px solid var(--border);
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--accent);
}
.pw-cats { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11.5px; margin-bottom: 5px; }
.pw-cat i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 0; }
.pw-ships { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; font-size: 12px; margin-bottom: 5px; }
.pw-ships span { color: var(--muted); font-size: 11px; text-align: right; }
.pw-ship { color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pw-ship:hover { color: var(--accent); text-decoration: underline; }
.pw-calls { font-size: 12px; line-height: 1.55; }
.pw-calls span { color: var(--muted); font-size: 11px; }

/* ---------- last-known ships (lastknown.js) ---------- */
.lk-results { margin-top: 6px; }
.lk-head { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.lk-row { display: block; padding: 6px 8px; margin-bottom: 4px; border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); text-decoration: none; font-size: 12.5px; line-height: 1.4; }
.lk-row:hover { border-color: var(--accent); }
.lk-row span { display: block; color: var(--muted); font-size: 11px; }
.lk-row .lk-live { display: inline; margin-left: 4px; padding: 0 5px; border-radius: 3px; font-size: 10px;
  background: #dcfce7; color: #166534; }

/* ---------- port search (portwatch-layer.js) ---------- */
.port-field { position: relative; }
.port-suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 1200;
  max-height: 280px; overflow-y: auto; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.pw-ports-only[hidden] { display: none !important; }
.port-suggest[hidden] { display: none; }   /* an explicit display rule would otherwise beat [hidden] */
.ps-item { padding: 7px 10px; cursor: pointer; font-size: 12.5px; border-bottom: 1px solid var(--border); }
.ps-item:last-child { border-bottom: 0; }
.ps-item span { display: block; color: var(--muted); font-size: 11px; }
.ps-item.on, .ps-item:hover { background: rgba(56, 189, 248, .12); }
.ps-empty { padding: 8px 10px; font-size: 12px; color: var(--muted); }

/* ---------- Ask the captain (assistant.js), in the style of FPMS "Ask the fleet" ---------- */
#captain { --cap-bottom: 56px; }
.cap-dock {
  position: fixed; right: 14px; bottom: var(--cap-bottom); z-index: 1100;
  display: flex; align-items: center; gap: 8px;
}
#captain.is-open .cap-dock { display: none; }
.cap-plate {
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  color: var(--text); background: var(--panel); border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}
.cap-trigger {
  flex: 0 0 auto; padding: 0; border: 0; background: transparent; border-radius: 50%;
  width: 96px; height: 96px; cursor: pointer;
}
.cap-trigger:hover { filter: none; }
.cap-trigger:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

/* No bubble: the captain stands on the map. On a dark page a drop shadow under a
   dark figure does nothing, so a faint rim of light separates him instead. */
.cap-stage { display: inline-flex; width: 100%; height: 100%; }
.cap-avatar--big { width: 96px; height: 96px; }
.cap-avatar--small { width: 44px; height: 44px; flex: 0 0 44px; }
.cap-glance { display: inline-flex; width: 100%; height: 100%; }
.cap-roll {
  width: 100%; height: 100%; object-fit: contain; user-select: none;
  filter: drop-shadow(0 0 1px rgba(255, 255, 255, .45)) drop-shadow(0 6px 10px rgba(0, 0, 0, .55));
}

/* Float, glance and roll on three elements, with unequal periods (5.5 s, 13 s,
   4 s) so they drift against each other and never settle into a visible loop. */
.cap-stage { animation: cap-enter .62s cubic-bezier(.2, 1.3, .4, 1) 1, cap-float 5.5s ease-in-out .62s infinite; }
.cap-glance { animation: cap-glance 13s ease-in-out infinite; }
.cap-roll { transform-origin: 50% 80%; animation: cap-roll 4s ease-in-out infinite; }
.cap-stage[data-mood="listening"] { animation: cap-float 3.4s ease-in-out infinite; }
.cap-stage[data-mood="listening"] .cap-roll { animation-duration: 2.4s; }
/* Two nods when a figure comes back, a head shake for a refusal: signals, not states. */
.cap-stage[data-mood="answering"] .cap-roll { animation: cap-nod .9s ease-out 1; }
.cap-stage[data-mood="declining"] .cap-roll { animation: cap-shake .75s ease-in-out 1; }
.cap-trigger:hover .cap-stage { animation: cap-float 2.4s ease-in-out infinite; }
.cap-trigger:hover .cap-roll { animation-duration: 2s; }
.cap-trigger:active .cap-stage { transform: scale(.94); }

@keyframes cap-roll { 0%, 100% { transform: rotate(-2.5deg); } 50% { transform: rotate(2.5deg); } }
@keyframes cap-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes cap-enter { 0% { transform: translateY(22px) scale(.8); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes cap-glance {
  0%, 88%, 100% { transform: translateX(0) scale(1); }
  92% { transform: translateX(-2px) scale(1.05); }
  96% { transform: translateX(2px) scale(1.05); }
}
@keyframes cap-nod { 0%, 50%, 100% { transform: translateY(0) rotate(0); } 25%, 75% { transform: translateY(3px) rotate(4deg); } }
@keyframes cap-shake { 0%, 100% { transform: rotate(0); } 20%, 60% { transform: rotate(-7deg); } 40%, 80% { transform: rotate(7deg); } }

@media (prefers-reduced-motion: reduce) {
  .cap-stage, .cap-glance, .cap-roll,
  .cap-stage[data-mood] .cap-roll, .cap-trigger:hover .cap-stage, .cap-trigger:hover .cap-roll { animation: none !important; }
}

/* ---- the panel ---- */
.cap-panel {
  position: fixed; right: 14px; bottom: var(--cap-bottom); z-index: 1100;
  width: min(27rem, calc(100vw - 28px)); max-height: min(40rem, calc(100vh - var(--cap-bottom) - 80px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}
.cap-panel[hidden] { display: none; }
.cap-head { display: flex; align-items: flex-start; gap: 10px; padding: 12px 12px 10px 14px; border-bottom: 1px solid var(--border); }
.cap-head-text { flex: 1; min-width: 0; }
.cap-head h2 { margin: 2px 0 2px; font-size: 14px; color: var(--text); }
.cap-head p { margin: 0; font-size: 11.5px; line-height: 1.4; color: var(--muted); }
.cap-close { flex: 0 0 auto; width: 30px; height: 30px; padding: 0; font-size: 20px; line-height: 1; border-radius: 8px; background: transparent; }

.cap-log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; }
.cap-q {
  align-self: flex-end; max-width: 85%; margin: 0 0 6px auto; padding: 6px 10px; border-radius: 12px 12px 2px 12px;
  font-size: 13px; color: #04222e; background: var(--accent); overflow-wrap: anywhere;
}
.cap-turn { display: flex; flex-direction: column; }
.cap-card {
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg);
  font-size: 12.5px; line-height: 1.5; color: var(--text); overflow-wrap: anywhere;
}
/* The refusal has the same weight as an answer: declining is designed behaviour, not an error. */
.cap-refusal, .cap-clarify { background: var(--panel-2); }
.cap-error, .cap-busy, .cap-limit { background: var(--panel-2); color: var(--muted); }
.cap-wait { color: var(--muted); }
.cap-wait b { font-weight: 600; color: var(--text); }
.cap-understood { margin: 0 0 3px; font-size: 11px; font-style: italic; color: var(--muted); }
.cap-headline { margin: 0; font-size: 13.5px; font-weight: 600; line-height: 1.45; }
.cap-facts { margin: 8px 0 0; }
.cap-fact { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; padding: 5px 0; border-top: 1px solid rgba(36, 52, 79, .7); }
.cap-fact:first-child { border-top: 0; }
.cap-fact dt { font-size: 12px; color: var(--muted); }
.cap-fact dd { margin: 0; font-size: 12.5px; font-weight: 600; text-align: end; font-variant-numeric: tabular-nums; }
.cap-fact p { grid-column: 1 / -1; margin: 1px 0 0; font-size: 11px; line-height: 1.4; color: var(--muted); }
.cap-fh { margin: 10px 0 3px; font-size: 10.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--accent); }
.cap-rows { display: flex; flex-direction: column; }
.cap-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 5px 6px; margin: 0 -6px; border: 0; border-radius: 6px; background: transparent;
  text-align: start; font-size: 12.5px; color: var(--text);
}
.cap-row-text { min-width: 0; }
.cap-row-text small { display: block; font-size: 11px; color: var(--muted); }
.cap-row-val { flex: 0 0 auto; font-weight: 600; font-variant-numeric: tabular-nums; }
button.cap-act { cursor: pointer; }
button.cap-act:hover, button.cap-act:focus-visible { background: var(--panel-2); filter: none; }
/* The "acts on the map" mark sits by the value: after the text it fell onto its own
   line whenever the row had a detail line. */
button.cap-act .cap-row-val::before { content: "↗ "; color: var(--accent); font-size: 11px; font-weight: 400; }
.cap-basis { margin: 8px 0 0; padding: 7px 0 0; border-top: 1px solid var(--border); list-style: none; }
.cap-basis li { font-size: 11px; line-height: 1.4; color: var(--muted); margin: 2px 0; }
.cap-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cap-chip {
  flex: 0 0 auto; padding: 4px 10px; font-size: 11.5px; border-radius: 999px;
  color: var(--text); background: transparent; border: 1px solid var(--border);
}
.cap-chip:hover { border-color: var(--accent); filter: none; }
.cap-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.cap-foot span { font-size: 10.5px; color: var(--muted); }
.cap-map { flex: 0 0 auto; padding: 4px 10px; font-size: 12px; font-weight: 600; color: var(--accent); background: transparent; border-color: transparent; }
.cap-map:hover { border-color: var(--accent); filter: none; }
.cap-empty p { margin: 0 0 6px; font-size: 12.5px; color: var(--text); }
.cap-empty .cap-scope { margin-top: 10px; font-size: 11px; color: var(--muted); }
.cap-clear { align-self: center; padding: 3px 10px; font-size: 11px; color: var(--muted); background: transparent; border-color: transparent; }
.cap-signin .cap-sub { margin: 6px 0 10px; font-size: 12px; color: var(--muted); }
.cap-signin-btn { display: inline-flex; align-items: center; gap: 8px; width: auto; padding: 8px 14px; font-weight: 600; color: #fff; background: #0a66c2; border-color: #0a66c2; }
.cap-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.cap-form[hidden] { display: none; }
.cap-input {
  flex: 1; min-width: 0; resize: none; max-height: 96px; padding: 8px 10px; font: inherit; font-size: 13px;
  color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.cap-input:focus { border-color: var(--accent); }
.cap-input::placeholder { color: #5b6f8a; }
.cap-send { flex: 0 0 auto; font-weight: 600; color: #04222e; background: var(--accent); border-color: var(--accent); }
.cap-send:disabled { opacity: .5; cursor: default; }

/* A phone: the face stays a face (72 px, not a smudge), the plate goes, and the
   panel becomes a sheet across the bottom of the screen. */
@media (max-width: 640px), (max-height: 560px) {
  .cap-head p { display: none; }
  .cap-head { align-items: center; padding: 8px 10px 8px 12px; }
  .cap-avatar--small { width: 36px; height: 36px; flex-basis: 36px; }
}
.cap-log { min-height: 120px; }
@media (max-width: 640px) {
  .cap-plate { display: none; }
  .cap-trigger, .cap-avatar--big { width: 72px; height: 72px; }
  .cap-panel { right: 8px; left: 8px; width: auto; bottom: 8px; max-height: calc(100vh - 90px); }
}

/* ---- charts in the captain's answers (assistant.js chartHtml) ---- */
.cap-chart { position: relative; margin: 10px 0 2px; }
.cap-unit { font-size: 10.5px; color: var(--muted); margin: 0 0 2px; }
.cap-svg { display: block; width: 100%; height: auto; overflow: visible; }
.cap-svg text { font-size: 10px; fill: var(--muted); font-family: inherit; }
.cap-svg text.l { fill: var(--text); font-size: 10.5px; }
.cap-svg text.v { fill: var(--text); font-size: 10.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cap-svg line.g { stroke: var(--border); stroke-width: .6; }
.cap-svg line.z { stroke: var(--muted); stroke-width: 1; }
.cap-svg .cap-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 2; pointer-events: none; }
.cap-svg g.cap-act { cursor: pointer; }
.cap-svg g.cap-act:hover .cap-bar-hit, .cap-svg g.cap-act:focus .cap-bar-hit { fill: rgba(56, 189, 248, .08); }
.cap-svg g.cap-act:focus { outline: none; }
.cap-svg g.cap-act:hover text.l { fill: var(--accent); }
.cap-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 4px; font-size: 11px; color: var(--text); }
.cap-legend span, .cap-tip span { display: inline-flex; align-items: center; gap: 5px; }
.cap-legend i, .cap-tip i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; }
.cap-tip {
  position: absolute; top: 18px; z-index: 2; pointer-events: none; display: flex; flex-direction: column; gap: 2px;
  padding: 6px 8px; font-size: 11px; color: var(--text); white-space: nowrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, .45);
}
.cap-tip[hidden] { display: none; }
.cap-chart figcaption { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.cap-tbl { margin-top: 4px; font-size: 11px; }
.cap-tbl summary { cursor: pointer; color: var(--muted); }
.cap-tbl table { width: 100%; margin-top: 4px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.cap-tbl th, .cap-tbl td { padding: 2px 4px; text-align: end; border-bottom: 1px solid var(--border); }
.cap-tbl th:first-child, .cap-tbl td:first-child { text-align: start; }
.cap-tbl tbody { display: block; max-height: 160px; overflow-y: auto; }
.cap-tbl thead, .cap-tbl tbody tr { display: table; width: 100%; table-layout: fixed; }
