:root {
  --bg: #071320;
  --panel: rgba(9, 24, 40, 0.94);
  --panel-solid: #0d1f33;
  --line: rgba(148, 197, 255, 0.16);
  --text: #e8f1fb;
  --muted: #93aec9;
  --accent: #38bdf8;
  --warn: #f97316;
  --good: #22c55e;
  --sheet-collapsed: 132px;
  --sheet-expanded: min(62vh, 520px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
/* Author display rules must not beat the hidden attribute. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
}

#map { position: fixed; inset: 0; background: #0a1725; }
.leaflet-container { background: #0a1725; font: inherit; }
.leaflet-control-attribution { background: rgba(7, 19, 32, 0.75) !important; color: #7f98b1 !important; }
.leaflet-control-attribution a { color: #9fc4e6 !important; }

/* ---- top bar ---- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: linear-gradient(180deg, rgba(7, 19, 32, 0.95), rgba(7, 19, 32, 0));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: 0.2px; }
.brand-mark { font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.icon-btn.is-on { border-color: var(--good); box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25); }
.icon-btn:disabled { opacity: 0.45; }

.pill {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--panel);
  white-space: nowrap;
}
.pill-live { color: var(--good); border-color: rgba(34, 197, 94, 0.5); }
.pill-sim  { color: #fbbf24; border-color: rgba(251, 191, 36, 0.5); }
.pill-down { color: #f87171; border-color: rgba(248, 113, 113, 0.5); }
.pill-idle { color: var(--muted); }

/* ---- in-zone banner ---- */
.banner {
  position: fixed;
  z-index: 800;
  top: calc(58px + var(--safe-top));
  left: 12px; right: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(249, 115, 22, 0.94);
  color: #1a0d02;
  font-weight: 650;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* ---- bottom sheet ---- */
.sheet {
  position: fixed;
  z-index: 800;
  left: 0; right: 0; bottom: 0;
  height: var(--sheet-expanded);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  transition: height 0.22s ease;
  padding-bottom: var(--safe-bottom);
}
.sheet.is-collapsed { height: calc(var(--sheet-collapsed) + var(--safe-bottom)); }

.sheet-grip {
  all: unset;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 9px 14px 6px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.grip-bar { width: 40px; height: 4px; border-radius: 999px; background: rgba(148, 197, 255, 0.35); }

.tabs { display: flex; gap: 6px; padding: 4px 12px 8px; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.tab.is-active { color: var(--text); background: rgba(56, 189, 248, 0.12); border-color: rgba(56, 189, 248, 0.35); }
.badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--warn);
  color: #1a0d02;
  font-size: 11px;
}

.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.list { list-style: none; margin: 0; padding: 4px 0 16px; }

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "name  right"
    "meta  right";
  gap: 2px 10px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(148, 197, 255, 0.08);
  cursor: pointer;
}
.row:active { background: rgba(56, 189, 248, 0.1); }
.row-name { grid-area: name; font-weight: 620; }
.row-meta { grid-area: meta; color: var(--muted); font-size: 12.5px; }
.row-right { grid-area: right; align-self: center; text-align: right; font-size: 12.5px; color: var(--muted); }
.row.in-zone { background: rgba(249, 115, 22, 0.12); }
.zone-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--warn);
  color: #1a0d02;
  font-size: 11px;
  font-weight: 700;
  vertical-align: 1px;
}
.empty { display: block; padding: 22px 16px; color: var(--muted); text-align: center; font-size: 13.5px; }
.history-date {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line);
}
.history-dates {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.history-hint { color: var(--muted); font-size: 12.5px; }
.date-chip {
  padding: 4px 10px; border-radius: 999px; font: inherit; font-size: 12px;
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  cursor: pointer; white-space: nowrap;
}
.date-chip:hover { color: var(--text); border-color: rgba(251, 191, 36, 0.5); }
.date-chip.is-selected {
  background: rgba(251, 191, 36, 0.16); border-color: rgba(251, 191, 36, 0.6); color: #fbbf24;
  font-weight: 600;
}
.history-date input {
  color: var(--text); background: var(--panel-solid); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; font: inherit; color-scheme: dark;
}

/* A red cross where a boat went nowhere for a while -- the best available
   guess at where it found something. divIcon draws a white box by default. */
.loiter-icon { background: none; border: none; }
.track-stops { color: #ef4444; font-weight: 600; }

/* ---- zone picker ---- */
.zones-status { margin: 0; padding: 12px 14px; color: var(--muted); font-size: 13px; }
.zones-status.is-warning { color: #fbbf24; }

.zone-group { border-top: 1px solid var(--line); }
.zone-group > summary {
  padding: 11px 14px; cursor: pointer; font-weight: 600; font-size: 13.5px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  list-style: none;
}
.zone-group > summary::-webkit-details-marker { display: none; }
/* A disclosure triangle that rotates, since the native marker is hidden. */
.zone-group > summary::before {
  content: "▸"; color: var(--muted); font-size: 11px; margin-right: 8px;
  transition: transform 0.15s ease; display: inline-block;
}
.zone-group[open] > summary::before { transform: rotate(90deg); }
.zone-count { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: auto; }

.zone-row {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px;
  padding: 9px 14px 11px 34px; align-items: start; cursor: pointer;
}
.zone-row input { margin-top: 2px; accent-color: #fbbf24; width: 17px; height: 17px; }
.zone-name { font-size: 13.5px; font-weight: 600; }
.zone-desc { grid-column: 2; color: var(--muted); font-size: 12px; line-height: 1.4; }
.zone-row input:disabled ~ .zone-name { color: var(--muted); }
.zone-row.is-custom { grid-template-columns: 1fr auto; align-items: center; cursor: default; }

.zone-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-top: 1px solid var(--line);
}
.zone-quota { color: var(--muted); font-size: 12px; }
.zone-btn {
  padding: 7px 13px; border-radius: 9px; font: inherit; font-size: 13px;
  border: 1px solid rgba(251, 191, 36, 0.5); background: transparent;
  color: #fbbf24; cursor: pointer;
}
.zone-btn:disabled { opacity: 0.4; cursor: default; }
.zone-btn.is-primary { background: rgba(251, 191, 36, 0.18); font-weight: 600; }
.zone-remove {
  padding: 4px 9px; border-radius: 8px; font: inherit; font-size: 12px;
  border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer;
}
.zone-remove:hover { color: #ef4444; border-color: rgba(239, 68, 68, 0.5); }

/* Floats over the map: while drawing, the sheet is collapsed out of the way. */
.draw-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 1000; display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 12px;
  background: var(--panel-solid); border: 1px solid rgba(251, 191, 36, 0.45);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  max-width: calc(100vw - 32px); flex-wrap: wrap; justify-content: center;
}
#draw-hint { font-size: 12.5px; color: var(--muted); }

/* ---- map markers ---- */
.boat-icon { display: grid; place-items: center; }
.boat-icon svg { display: block; filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.6)); }
.boat-label {
  position: absolute;
  left: 50%;
  top: 22px;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 10.5px;
  font-weight: 700;
  color: #e8f1fb;
  text-shadow: 0 1px 3px #04101c, 0 0 6px #04101c;
  pointer-events: none;
}
.leaflet-popup-content-wrapper { background: var(--panel-solid); color: var(--text); border-radius: 12px; }
.leaflet-popup-tip { background: var(--panel-solid); }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; }
.popup-title { font-weight: 700; margin-bottom: 4px; }
.popup-meta { color: var(--muted); }

.leaflet-control-zoom { display: none; }
@media (min-width: 720px) {
  .leaflet-control-zoom { display: block; }
  .sheet { left: auto; right: 12px; bottom: 12px; width: 380px; border-radius: 16px; border: 1px solid var(--line); }
}

/* ---- chartplotter track panel ---- */
.panel-row { list-style: none; padding: 0; }
.track-panel {
  margin: 8px 12px 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(251, 191, 36, 0.10);
  border: 1px solid rgba(251, 191, 36, 0.4);
}
.track-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.track-id { min-width: 0; }
.track-title { font-weight: 700; font-size: 15px; line-height: 1.25; }
.track-sub { font-weight: 500; color: var(--muted); font-size: 12.5px; }

/* One word for the thing you actually want to know at a glance. */
.track-state {
  flex: none;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: rgba(148, 163, 184, 0.18);
  color: #94a3b8;
}
.track-state.is-running  { background: rgba(52, 211, 153, 0.18); color: #34d399; }
.track-state.is-cruising { background: rgba(56, 189, 248, 0.18); color: #38bdf8; }
.track-state.is-idling   { background: rgba(251, 191, 36, 0.18); color: #fbbf24; }

/* Fixed columns with the label above the number: four inline stats wrapped
   unpredictably at phone widths and read as one run-on string. */
.track-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 12px 0 8px;
}
.track-stat-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 3px;
}
.track-stat-value {
  font-size: 18px;
  font-weight: 700;
  color: #fbbf24;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.track-stat-value i {
  font-style: normal;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.track-since { color: var(--muted); font-size: 12px; }
.track-empty { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
.track-close {
  margin-top: 10px;
  padding: 7px 12px;
  border-radius: 9px;
  border: 1px solid rgba(251, 191, 36, 0.5);
  background: transparent;
  color: #fbbf24;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.row.is-selected { background: rgba(251, 191, 36, 0.12); box-shadow: inset 3px 0 0 #fbbf24; }
