:root {
  --bg: #0f1e2e;
  --panel: rgba(15, 30, 46, 0.55);
  --panel-border: rgba(160, 200, 235, 0.22);
  --text: #eaf2f8;
  --muted: #90a6ba;
  --accent: #4ea3ff;
  --moving: #37d67a;
  --staying: #f0a92b;
  --stale: #e05a5a;
  --track: #4ea3ff;
}

* { box-sizing: border-box; }
/* The `hidden` attribute must win over elements that set an explicit display
   (e.g. .ed-splitbar { display: flex }), which would otherwise reveal them. */
[hidden] { display: none !important; }

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

#map { position: absolute; inset: 0; }

.panel {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 5;
  width: 300px;
  max-width: calc(100vw - 32px);
  padding: 18px 18px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.30);
  /* Keep text legible over the translucent, blurred backdrop. */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.panel__header { display: flex; align-items: center; gap: 10px; }
.panel__header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0.5px;
}

.dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.05);
  transition: background 0.3s;
}
.dot.moving  { background: var(--moving); }
.dot.staying { background: var(--staying); }
.dot.stale   { background: var(--stale); }

.panel__status { margin: 14px 0 6px; }
.status__primary {
  font-size: 16px;
  font-weight: 600;
}
.status__secondary {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

.facts {
  margin: 14px 0 4px;
  padding: 12px 0;
  border-top: 1px solid var(--panel-border);
  border-bottom: 1px solid var(--panel-border);
  display: grid;
  gap: 8px;
}
.facts > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.facts dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; margin: 0; }
.facts dd { margin: 0; font-size: 13px; font-variant-numeric: tabular-nums; text-align: right; }

.ranges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}
.ranges button {
  flex: 1 1 auto;
  padding: 7px 8px;
  font-size: 12.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.ranges button:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.ranges button.active {
  color: #06121e;
  background: var(--accent);
  font-weight: 600;
}

.range-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  min-height: 14px;
}

/* Trip list */
.trips { margin-top: 14px; }
.trips__head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 8px;
}
.trips__title {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--muted);
}
.trips__edit {
  font-size: 12px; color: var(--accent); text-decoration: none;
}
.trips__edit:hover { text-decoration: underline; }
.trips__list {
  display: grid; gap: 5px;
  max-height: 220px; overflow-y: auto;
  /* room for the scrollbar so it doesn't cover text */
  margin-right: -4px; padding-right: 4px;
}
.trips__empty { font-size: 12.5px; color: var(--muted); }

/* Year / month / day drill-down navigator */
.tripnav { display: grid; gap: 5px; margin-bottom: 9px; }
.tripnav__row { display: flex; flex-wrap: wrap; gap: 5px; }
.tripnav__row--days { max-height: 66px; overflow-y: auto; }
.tnav {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s;
}
.tnav:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.tnav.active { color: #06121e; background: var(--accent); font-weight: 600; }
.tnav__n {
  font-size: 10.5px; line-height: 1;
  padding: 2px 5px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.12); color: var(--muted);
}
.tnav.active .tnav__n { background: rgba(6, 18, 30, 0.22); color: #06121e; }
.trip {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 8px 9px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  border-radius: 8px;
  transition: background 0.15s, border-color 0.15s;
}
.trip:hover { background: rgba(255, 255, 255, 0.08); }
.trip.active { border-color: var(--accent); background: rgba(78, 163, 255, 0.14); }
.trip__tick { display: flex; align-items: center; padding-top: 1px; cursor: pointer; }
.trip__tick input {
  width: 15px; height: 15px; margin: 0;
  accent-color: var(--accent); cursor: pointer;
}
.trip__body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 3px;
  text-align: left; padding: 0;
  color: inherit; background: none; border: none; cursor: pointer;
  font: inherit;
}
.trip__route { font-size: 13px; font-weight: 600; }
.trip__arr { color: var(--muted); font-weight: 400; }
.trip__dates {
  font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.trip__stats {
  margin-top: 3px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px 12px;
}
.tstat { display: flex; flex-direction: column; line-height: 1.2; }
.tstat__v { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tstat__k {
  font-size: 9.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.4px;
}

/* Stop ("trip point") labels on the map */
.stop-marker {
  display: flex; align-items: center; gap: 6px;
  pointer-events: none; /* never steal hover from the track */
  transform: translateX(8px); /* clear the anchor dot */
  white-space: nowrap;
}
.stop-marker__dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--staying);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.35);
  margin-left: -8px;
}
.stop-marker__label {
  font-size: 12px; font-weight: 600; color: #10202f;
  background: rgba(240, 230, 200, 0.92);
  padding: 1px 6px; border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 11px;
  color: var(--muted);
}
.legend__bar {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(
    to right,
    rgb(213, 62, 79) 0%,
    rgb(253, 160, 80) 25%,
    rgb(240, 224, 110) 50%,
    rgb(102, 194, 165) 75%,
    rgb(49, 130, 189) 100%
  );
}
.legend--motor { margin-top: 6px; }
/* A track sample flanked by the two black dashed "engine on" lines. */
.legend__motor {
  width: 26px; height: 11px; flex: none;
  background:
    repeating-linear-gradient(to right, #000 0 3px, transparent 3px 6px) top/100% 2px no-repeat,
    repeating-linear-gradient(to right, #000 0 3px, transparent 3px 6px) bottom/100% 2px no-repeat,
    var(--accent) center/100% 3px no-repeat;
}

/* Hover weather card (mirrors the status-card look) */
/* Popup must not capture the mouse: otherwise it sits under the cursor next to
   the point, steals hover, and the map flickers back to its grab cursor. */
.wx-popup { pointer-events: none; }
.wx-popup .mapboxgl-popup-content {
  padding: 0;
  background: transparent;
  box-shadow: none;
}
.wx-popup .mapboxgl-popup-tip { display: none; }

.wx {
  min-width: 380px;
  padding: 12px 12px 10px;
  color: var(--text);
  background: rgba(20, 32, 46, 0.86);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.4);
  font-family: inherit;
}
.wx__time { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.wx__cards { display: flex; gap: 8px; }
.wx__card {
  flex: 1;
  padding: 8px 10px;
  border-radius: 10px;
}
.wx__card--temp { background: rgba(240, 224, 110, 0.16); }
.wx__card--wind { background: rgba(102, 194, 165, 0.16); }
.wx__card--sog { background: rgba(78, 163, 255, 0.16); }
.wx__lbl { font-size: 11px; color: var(--muted); }
.wx__big { font-size: 17px; font-weight: 600; margin-top: 2px; white-space: nowrap; }
.wx__windrow { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.wx__windrow .wx__big { margin-top: 0; }
.wx__arrow {
  flex: none;
  color: rgb(102, 194, 165);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
  transition: transform 0.2s ease;
}
.wx__sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.wx__note { font-size: 10.5px; color: var(--muted); margin-top: 8px; font-style: italic; }

/* ------------------------------------------------------------------ */
/* /trips editor                                                        */
/* ------------------------------------------------------------------ */
.panel--editor {
  width: 360px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
}
.back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; margin-right: 2px;
  font-size: 22px; line-height: 1; text-decoration: none;
  color: var(--text);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
}
.back:hover { background: rgba(255, 255, 255, 0.12); }
.ed-intro { margin: 12px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.ed-intro strong { color: var(--text); font-weight: 600; }

.ed-controls { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.ed-field { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.ed-field__in { display: inline-flex; align-items: center; gap: 4px; color: var(--text); }
.ed-field input {
  width: 46px; padding: 5px 6px;
  color: var(--text); font: inherit; font-size: 13px; text-align: right;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border); border-radius: 7px;
}

.btn {
  padding: 7px 11px; font: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--text); background: rgba(255, 255, 255, 0.06);
  border: 1px solid transparent; border-radius: 8px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn--primary { color: #06121e; background: var(--accent); }
.btn--primary:hover { background: #6bb4ff; }
.btn--danger { color: var(--stale); }
.btn--danger:hover { background: rgba(224, 90, 90, 0.16); }
.btn--small { padding: 4px 9px; font-size: 11.5px; margin-left: auto; }
.btn--small.active { color: #06121e; background: var(--accent); }

.ed-status { margin-top: 10px; min-height: 15px; font-size: 12px; color: var(--muted); }

.ed-splitbar {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px; padding: 9px 10px;
  font-size: 12px; color: var(--text);
  background: rgba(78, 163, 255, 0.14);
  border: 1px solid var(--accent); border-radius: 9px;
}
.ed-splitbar .btn { margin-left: auto; padding: 4px 9px; }

.ed-list {
  margin-top: 12px; padding-top: 4px;
  overflow-y: auto; flex: 1;
  border-top: 1px solid var(--panel-border);
}
.ed-empty { font-size: 12.5px; color: var(--muted); padding: 12px 2px; line-height: 1.5; }

.ed-stop {
  padding: 9px 10px; margin-top: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border); border-radius: 9px;
  cursor: pointer; transition: border-color 0.15s;
}
.ed-stop.focus { border-color: var(--accent); background: rgba(78, 163, 255, 0.10); }
.ed-stop__row { display: flex; align-items: center; gap: 6px; }
.ed-stop__pin {
  flex: none; width: 9px; height: 9px; border-radius: 50%;
  background: var(--staying); border: 2px solid #fff;
}
.ed-stop__name {
  flex: 1; min-width: 0; padding: 5px 7px;
  color: var(--text); font: inherit; font-size: 13px; font-weight: 600;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent; border-radius: 7px;
}
.ed-stop__name:hover { border-color: var(--panel-border); }
.ed-stop__name:focus { outline: none; border-color: var(--accent); background: rgba(0, 0, 0, 0.25); }
.iconbtn {
  flex: none; width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent; border-radius: 7px; cursor: pointer;
}
.iconbtn:hover { color: var(--text); background: rgba(255, 255, 255, 0.12); }
.iconbtn[data-act="merge"]:hover { color: var(--stale); }
.ed-stop__meta {
  margin-top: 6px; font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.ed-tag {
  margin-left: 4px; padding: 0 5px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.3px;
  color: var(--accent); border: 1px solid var(--panel-border); border-radius: 5px;
}

.ed-trip { display: flex; gap: 10px; padding: 4px 0 4px 14px; }
.ed-trip__spine {
  flex: none; width: 2px; margin-left: 3px;
  background: linear-gradient(to bottom, transparent, var(--accent), transparent);
  border-radius: 2px;
}
.ed-trip__body { flex: 1; display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.ed-trip__meta { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Season break: gap between years, where the boat wintered ashore (no passage). */
.ed-break {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 0 4px 14px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); opacity: 0.7;
}
.ed-break::before, .ed-break::after {
  content: ""; flex: 1; height: 1px;
  background: repeating-linear-gradient(to right, var(--muted) 0 3px, transparent 3px 7px);
  opacity: 0.5;
}
/* Data gap (missing track for > a day) vs the seasonal winter break. */
.ed-break--gap { color: #9aa4ad; }

.stop-marker--edit { cursor: pointer; }
.stop-marker--edit .stop-marker__label:hover { background: rgba(255, 246, 220, 0.98); }

.banner {
  position: absolute;
  bottom: 16px; left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  font-size: 13px;
}
.banner.hidden { display: none; }

.boat-marker {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(78, 163, 255, 0.4), 0 2px 6px rgba(0,0,0,0.4);
}

@media (max-width: 520px) {
  .panel { top: 10px; left: 10px; right: 10px; width: auto; }
}
