html, body { margin: 0; padding: 0; height: 100%; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { display: flex; }

/* ===== Material-3-inspired persistent drawer (320px) ===== */
:root {
  --md-surface:        #fdfcff;
  --md-surface-2:      #f1f2f8;
  --md-surface-3:      #e6e8ef;
  --md-primary:        #1d5dba;
  --md-primary-on:     #ffffff;
  --md-primary-tint:   #e2eafd;
  --md-text:           #1a1c1e;
  --md-text-mute:      #5a5f6a;
  --md-outline:        #c2c7d0;
  --md-warning:        #c84a3e;
  --drawer-w: 320px;
}

#drawer {
  width: var(--drawer-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--md-surface);
  color: var(--md-text);
  box-shadow: 1px 0 4px rgba(0, 0, 0, 0.08);
  z-index: 10;
  font-size: 14px;
}

#drawer-header {
  padding: 14px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--md-surface-3);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand-mark { font-size: 22px; }
.brand-name { font-size: 18px; letter-spacing: 0.2px; }
.user-chip { font-size: 13px; }
.user-chip a { color: var(--md-primary); text-decoration: none; }
.user-chip a:hover { text-decoration: underline; }

/* Tabs */
#drawer-tabs {
  display: flex;
  border-bottom: 1px solid var(--md-surface-3);
  background: var(--md-surface);
  flex-shrink: 0;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 10px 6px;
  font: inherit;
  font-size: 13px;
  color: var(--md-text-mute);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: background-color 120ms, color 120ms;
}
.tab:hover { background: var(--md-surface-2); }
.tab[aria-selected="true"] {
  color: var(--md-primary);
  border-bottom-color: var(--md-primary);
  font-weight: 600;
}
.tab[hidden] { display: none; }

/* List area (top half) */
.drawer-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 4px 0;
  min-height: 120px;
}
.drawer-list .row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.drawer-list .row:hover { background: var(--md-surface-2); }
.drawer-list .row.selected {
  background: var(--md-primary-tint);
  border-left-color: var(--md-primary);
}
.drawer-list .row .swatch {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--md-primary);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
  flex-shrink: 0;
}
.drawer-list .row .body { min-width: 0; flex: 1; }
.drawer-list .row .name { font-weight: 500; }
.drawer-list .row .meta { font-size: 12px; color: var(--md-text-mute); }
.drawer-list .row .star {
  background: none; border: 0; cursor: pointer;
  color: var(--md-text-mute); font-size: 16px; padding: 2px 4px;
}
.drawer-list .row .star.on { color: #e9a823; }
.drawer-list .empty { padding: 12px 14px; color: var(--md-text-mute); }

/* Selection card (bottom half) */
.selection-card {
  border-top: 1px solid var(--md-surface-3);
  background: var(--md-surface-2);
  padding: 10px 14px 12px;
  flex: 0 0 auto;
  max-height: 40vh;
  overflow-y: auto;
}
.selection-card.empty { background: var(--md-surface); }
.selection-card__header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.selection-card__header strong { font-size: 12px; color: var(--md-text-mute); text-transform: uppercase; letter-spacing: 0.5px; }
.selection-card__header button {
  border: 0; background: transparent; cursor: pointer; color: var(--md-text-mute);
  font-size: 14px; padding: 2px 6px; border-radius: 4px;
}
.selection-card__header button:hover { background: var(--md-surface-3); }
.selection-card h2 { font-size: 16px; margin: 4px 0 2px; }
.selection-card .kv { display: grid; grid-template-columns: 1fr; gap: 2px; margin: 6px 0; }
.selection-card .kv span { font-size: 13px; color: var(--md-text-mute); }
.selection-card .kv strong { font-size: 13px; color: var(--md-text); font-weight: 500; }
.selection-card .actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.selection-card .actions button,
.selection-card .actions a {
  font: inherit; font-size: 12px;
  padding: 4px 10px; border-radius: 16px;
  border: 1px solid var(--md-outline); background: var(--md-surface);
  color: var(--md-text); cursor: pointer; text-decoration: none;
}
.selection-card .actions button:hover,
.selection-card .actions a:hover { background: var(--md-surface-2); }
.selection-card .actions .primary {
  background: var(--md-primary); border-color: var(--md-primary); color: var(--md-primary-on);
}

#drawer-footer {
  padding: 8px 14px; border-top: 1px solid var(--md-surface-3);
  font-size: 12px; color: var(--md-text-mute);
}
#drawer-footer a { color: var(--md-primary); text-decoration: none; }

/* ===== Map area ===== */
#map-wrap { position: relative; flex: 1 1 auto; height: 100vh; }
#map { position: absolute; inset: 0; }

/* Minimal HUD — only ever shows ONE thing: selection OR most-recent followed update. */
.hud {
  position: absolute;
  top: 12px; right: 12px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  max-width: 280px;
  pointer-events: none;
  font-size: 13px;
}
.hud-title { font-weight: 600; }
.hud-sub { color: var(--md-text-mute); font-size: 12px; margin-top: 2px; }

/* Leaflet layer control — position below HUD and match its style */
.leaflet-top.leaflet-right {
  top: 60px;
}
.leaflet-control-layers {
  background: rgba(255, 255, 255, 0.92) !important;
  backdrop-filter: blur(4px);
  border-radius: 10px !important;
  border: none !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12) !important;
  font-family: inherit;
  font-size: 13px;
}
.leaflet-control-layers-toggle {
  background-color: rgba(255, 255, 255, 0.92) !important;
  border-radius: 10px !important;
  width: 36px !important;
  height: 36px !important;
}
.leaflet-control-layers-expanded {
  padding: 8px 12px !important;
}
.leaflet-control-layers label {
  font-size: 13px;
}

/* Markers */
.ship-marker {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  text-shadow: 0 0 3px white, 0 0 3px white;
}
.ship-marker.selected {
  filter: drop-shadow(0 0 4px var(--md-primary)) drop-shadow(0 0 2px var(--md-primary));
}

.muted { color: var(--md-text-mute); }
.small { font-size: 12px; }

/* Compact mobile fallback */
@media (max-width: 640px) {
  body { flex-direction: column; }
  #drawer { width: 100%; height: 45vh; box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
  #map-wrap { height: 55vh; }
  .selection-card { max-height: 28vh; }
}

/* Toast notifications */
#toast-host {
  position: fixed;
  bottom: 16px; right: 16px;
  z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  color: #fff;
  background: var(--md-warning, #c84a3e);
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
  animation: toast-in 200ms ease-out;
  transition: opacity 400ms;
}
.toast.fade { opacity: 0; }
.toast-error { background: var(--md-warning, #c84a3e); }
.toast-info { background: var(--md-primary, #1d5dba); }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Voyage rows */
.drawer-list .row.active-voyage { background: var(--md-primary-tint); }
.badge-active { color: #2e8b57; font-size: 10px; }
.voyage-actions { display: flex; gap: 2px; align-items: center; flex-shrink: 0; }
.voyage-btn {
  background: none; border: 0; cursor: pointer; padding: 2px 4px;
  font-size: 13px; border-radius: 4px; opacity: 0.6;
}
.voyage-btn:hover { opacity: 1; background: var(--md-surface-3); }
.voyage-btn.danger:hover { background: #fde2e0; }


/* Tide station markers */
.tide-marker { background: transparent; border: none; }
.tide-marker .tide-dot {
  width: 18px; height: 18px; line-height: 18px;
  text-align: center; font-size: 14px;
  background: rgba(0, 100, 200, 0.85); color: #fff;
  border-radius: 50%; border: 1px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  cursor: pointer;
}

/* Live AIS markers (read-only ingest feed) */
.ais-marker { background: transparent; border: none; }
.ais-marker .ais-arrow {
  display: block;
  width: 0; height: 0;
  margin: 2px auto;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 12px solid rgba(40, 40, 40, 0.85);
  transform-origin: 50% 70%;
  filter: drop-shadow(0 0 1px #fff);
  cursor: pointer;
}

/* AIS watch button inside popup */
.ais-watch-btn {
  margin-top: 6px;
  padding: 3px 10px;
  font-size: 12px;
  border: 1px solid var(--md-primary);
  border-radius: 4px;
  background: var(--md-primary-tint);
  color: var(--md-primary);
  cursor: pointer;
  font-weight: 500;
}
.ais-watch-btn:hover { background: var(--md-primary); color: #fff; }

/* AIS vessel annotation editor (alias + notes) */
.ais-annotation {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid var(--md-outline);
  border-radius: 6px;
  background: var(--md-surface-2);
}
.annotation-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--md-text-muted, #888);
  margin: 6px 0 3px;
}
.annotation-label:first-child { margin-top: 0; }
.annotation-label .hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: #c0883a;
}
.annotation-alias,
.annotation-notes {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--md-outline);
  border-radius: 4px;
  font-size: 13px;
  background: var(--md-surface);
  color: var(--md-text);
  outline: none;
  font-family: inherit;
  resize: vertical;
}
.annotation-alias:focus,
.annotation-notes:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 2px var(--md-primary-tint);
}
.annotation-save { margin-top: 8px; }
.annotation-cancel {
  margin-top: 8px;
  margin-left: 6px;
  font-size: 13px;
}
.annotation-status {
  margin-left: 8px;
  font-size: 12px;
  color: #2e7d32;
}
.annotation-notes-view {
  margin: 8px 0;
  padding: 8px 10px;
  border-left: 3px solid var(--md-primary);
  background: var(--md-surface-2);
  border-radius: 0 4px 4px 0;
  font-size: 13px;
  white-space: pre-wrap;
  color: var(--md-text);
}

/* Track time-window slider */
.track-control {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid var(--md-outline);
  border-radius: 6px;
  background: var(--md-surface-2);
}
.track-slider {
  width: 100%;
  margin: 4px 0 2px;
  accent-color: var(--md-primary);
}
.track-slider-ends {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--md-text-muted, #888);
  margin-bottom: 8px;
}
.track-window-label { color: var(--md-primary); font-weight: 600; }

/* Watching tab search field */
.watch-search-wrap {
  padding: 8px 12px;
  position: sticky;
  top: 0;
  background: var(--md-surface);
  z-index: 1;
}
.watch-search {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  border: 1px solid var(--md-outline);
  border-radius: 6px;
  font-size: 13px;
  background: var(--md-surface-2);
  color: var(--md-text);
  outline: none;
  transition: border-color 0.15s;
}
.watch-search:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 2px var(--md-primary-tint);
}
.watch-section-label {
  padding: 6px 12px 2px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--md-text-mute);
}
#watch-search-results .search-result {
  border-left: 3px solid #3498db;
}
