:root {
  --bg-0: #060a13;
  --bg-1: #0b1220;
  --bg-2: #111a2e;
  --bg-3: #18243d;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e6ecf5;
  --text-dim: #8ea0bd;
  --text-mute: #5e6c87;
  --accent: #38e1ff;
  --accent-2: #6c8cff;
  --warn: #ffb84d;
  --ok: #4ade80;
  --danger: #ff5d6c;
  --moving: #ff5d6c;
  --docked: #38a1ff;
  --speedboat: #b46bff;
  --fast: #4ade80;
  --route: #ffb84d;
  --trail: #38e1ff;
  --shadow-1: 0 2px 8px rgba(0,0,0,.35);
  --shadow-2: 0 10px 30px rgba(0,0,0,.45);
  --radius: 10px;
  --radius-lg: 14px;
  --topbar-h: 56px;
  --sidebar-w: 320px;
}

:root[data-theme="light"] {
  --bg-0: #eef3fb;
  --bg-1: #ffffff;
  --bg-2: #f4f7fd;
  --bg-3: #e6ecf6;
  --line: rgba(10, 25, 50, 0.08);
  --line-strong: rgba(10, 25, 50, 0.18);
  --text: #0b1220;
  --text-dim: #46587a;
  --text-mute: #6b7a93;
  --shadow-1: 0 2px 8px rgba(15,30,60,.08);
  --shadow-2: 0 10px 30px rgba(15,30,60,.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-0);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }
input, select, button { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ───────────── Top bar ───────────── */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  z-index: 1000;
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  background: linear-gradient(180deg, rgba(11,18,32,.92), rgba(11,18,32,.78));
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--line);
}
:root[data-theme="light"] #topbar {
  background: linear-gradient(180deg, rgba(255,255,255,.95), rgba(255,255,255,.82));
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #2cc6ff 0%, #5a7bff 60%, #8a5bff 100%);
  box-shadow: 0 6px 18px rgba(60,120,255,.35), inset 0 0 0 1px rgba(255,255,255,.18);
}
.brand .title h1 { font-size: 15px; line-height: 1.1; margin: 0; font-weight: 600; letter-spacing: .2px; }
.brand .subtitle { font-size: 11px; color: var(--text-dim); white-space: nowrap; }

.search {
  flex: 1; max-width: 460px;
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text-dim);
  transition: border-color .15s, background .15s;
}
.search:focus-within { border-color: var(--accent); background: var(--bg-3); }
.search input {
  flex: 1; background: transparent; border: 0; outline: none;
  color: var(--text); font-size: 13px;
}
.search input::placeholder { color: var(--text-mute); }
.search kbd {
  font-size: 10px; padding: 2px 6px; border-radius: 5px;
  background: var(--bg-3); border: 1px solid var(--line);
  color: var(--text-dim);
}

.status { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 12px; }
.status .pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(74,222,128,.6);
  animation: pulse 2s infinite;
}
.status.warn .pulse { background: var(--warn); animation: none; }
.status.error .pulse { background: var(--danger); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(74,222,128,.5); }
  70% { box-shadow: 0 0 0 8px rgba(74,222,128,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); }
}

.topbar-actions { display: flex; gap: 6px; margin-left: auto; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px;
  background: transparent; border: 1px solid transparent;
  display: grid; place-items: center; color: var(--text-dim);
  transition: background .15s, color .15s, border-color .15s, transform .15s;
}
.icon-btn:hover { background: var(--bg-2); color: var(--text); border-color: var(--line); }
.icon-btn:active { transform: scale(.95); }
.icon-btn.spinning svg { animation: spin 0.8s linear; }
@keyframes spin { to { transform: rotate(360deg); } }
.mobile-only { display: none; }

/* ───────────── Layout ───────────── */
#sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  z-index: 900;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 12px 20px;
  display: flex; flex-direction: column; gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-3) transparent;
}
#sidebar::-webkit-scrollbar { width: 8px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 4px; }

/* Schedules nav link — visible text link at the top of the sidebar */
.nav-link-schedules {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 13px; font-weight: 600;
  border-radius: 10px;
  text-decoration: none;
  transition: opacity .15s, transform .1s;
  flex: 0 0 auto;
}
.nav-link-schedules:hover { opacity: .9; }
.nav-link-schedules:active { transform: scale(.99); }
.nav-link-schedules svg { flex: 0 0 auto; }

/* About nav link — secondary text link below the schedules link */
.nav-link-about {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px;
  background: var(--bg-2);
  color: var(--text-dim); font-size: 12px; font-weight: 500;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-decoration: none;
  transition: background .15s, color .15s, transform .1s;
  flex: 0 0 auto;
}
.nav-link-about:hover { background: var(--bg-3); color: var(--text); }
.nav-link-about:active { transform: scale(.99); }
.nav-link-about svg { flex: 0 0 auto; }

#map-wrap {
  position: fixed;
  top: var(--topbar-h);
  left: var(--sidebar-w);
  right: 0;
  bottom: 0;
}
#map { width: 100%; height: 100%; background: #0a1325; }

#map-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
}
#map-overlay > * { pointer-events: auto; }

/* ───────────── Panels ───────────── */
.panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow-1);
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.panel-header h2 {
  margin: 0; font-size: 12px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-dim);
}
.panel-header .count {
  display: inline-block;
  font-size: 11px; font-weight: 600;
  background: var(--bg-3);
  color: var(--text);
  padding: 1px 7px;
  border-radius: 999px;
  margin-left: 6px;
  letter-spacing: 0;
  text-transform: none;
}
.link-btn {
  background: none; border: 0; color: var(--accent);
  font-size: 12px; padding: 2px 4px;
}
.link-btn:hover { text-decoration: underline; }

.field { display: block; margin-bottom: 10px; }
.field > span {
  display: block; font-size: 11px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 5px;
}
.field select, .field input[type="text"], .field input[type="search"] {
  width: 100%; height: 34px; padding: 0 10px;
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: 8px; color: var(--text);
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%238ea0bd' d='M6 8L0 0h12z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.field select option { background: var(--bg-1); color: var(--text); }

.range-row { display: flex; align-items: center; gap: 8px; }
.range-row input[type=range] {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 4px; background: var(--bg-3);
  border-radius: 999px; outline: none;
}
.range-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-1);
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--line-strong);
}
.range-val { font-size: 12px; color: var(--text-dim); min-width: 46px; text-align: right; }

/* Toggles */
.toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 4px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .track {
  position: relative; width: 32px; height: 18px;
  background: var(--bg-3); border-radius: 999px;
  transition: background .15s;
  flex: 0 0 auto;
}
.toggle .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; transition: transform .15s;
  box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(14px); }
.toggle:hover { color: var(--accent); }

.tiles { margin-top: 8px; }
.tiles .lbl {
  display: block; font-size: 11px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 5px;
}
.seg {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: 8px; padding: 3px;
  gap: 2px;
}
.seg button {
  background: transparent; border: 0; padding: 6px 4px;
  font-size: 12px; color: var(--text-dim);
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button.active {
  background: var(--bg-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.sort select {
  background: var(--bg-1);
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
}

/* Ferry list */
.ferry-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 8px;
  max-height: 50vh; overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-3) transparent;
}
.ferry-list::-webkit-scrollbar { width: 6px; }
.ferry-list::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 3px; }

.ferry-item {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  position: relative;
  overflow: hidden;
}
.ferry-item:hover { background: var(--bg-3); border-color: var(--line-strong); }
.ferry-item:active { transform: scale(.99); }
.ferry-item.selected { border-color: var(--accent); background: var(--bg-3); }

.ferry-card-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.ferry-item .badge {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; flex: 0 0 auto;
  font-size: 14px; font-weight: 600;
  color: #fff;
  background: var(--docked);
  box-shadow: 0 0 0 2px var(--bg-1);
}
.ferry-item.moving .badge { background: var(--moving); }
.ferry-item.speedboat .badge { background: var(--speedboat); }
.ferry-item.fast .badge { background: var(--fast); }
.ferry-card-titles {
  display: flex; flex-direction: column; gap: 2px;
  flex: 1; min-width: 0;
}
.ferry-item .name {
  font-size: 13px; font-weight: 600;
  line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.ferry-item .code {
  font-size: 10px; padding: 1px 7px;
  background: var(--bg-3); color: var(--text-dim);
  border-radius: 999px; flex: 0 0 auto; align-self: flex-start;
}
.ferry-item .leg {
  font-size: 12px; color: var(--text-dim);
  line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  margin-bottom: 10px;
}
.ferry-item .progress {
  height: 5px;
  background: var(--bg-3); border-radius: 999px; overflow: hidden;
  margin-bottom: 10px;
}
.ferry-item .progress > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  transition: width .6s ease;
}
.ferry-card-meta {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.meta-pill {
  font-size: 11px; font-weight: 500;
  padding: 3px 8px;
  background: var(--bg-2); color: var(--text-mute);
  border-radius: 999px;
  white-space: nowrap;
}

.empty { text-align: center; padding: 20px 10px; color: var(--text-dim); }
.empty-art { font-size: 32px; margin-bottom: 6px; opacity: .7; }
.empty .muted { color: var(--text-mute); font-size: 11px; }

/* ───────────── Map overlay widgets ───────────── */
#legend {
  position: absolute; right: 12px; bottom: 24px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 11px;
  color: var(--text-dim);
  box-shadow: var(--shadow-2);
  min-width: 150px;
  line-height: 1.7;
}
#legend .legend-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--text-mute);
  margin-bottom: 6px;
}
#legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
#legend .dot.moving { background: var(--moving); }
#legend .dot.docked { background: var(--docked); }
#legend .dot.speedboat { background: var(--speedboat); }
#legend .dot.fast { background: var(--fast); }
#legend .dot.cargo { background: var(--warn); }
#legend .line { display: inline-block; width: 18px; height: 0; margin-right: 6px; vertical-align: middle; }
#legend .line.route { border-top: 2px dashed var(--route); }
#legend .line.trail { border-top: 2px solid var(--trail); }
#legend .line.progress { border-top: 3px solid var(--accent-2); }
#legend .legend-sep { height: 1px; background: var(--line); margin: 6px 0; }
#legend .heat { display: inline-block; width: 14px; height: 14px; border-radius: 50%; margin-right: 6px; vertical-align: middle; filter: blur(0.5px); }
#legend .heat.flight { background: radial-gradient(circle, rgba(255,40,0,0.95) 0%, rgba(255,140,0,0.55) 60%, rgba(255,230,0,0) 100%); }
#legend .heat.event { background: radial-gradient(circle, rgba(180,80,220,0.85) 0%, rgba(130,80,220,0.45) 60%, rgba(80,80,220,0) 100%); }
#legend .heat.ferry { background: radial-gradient(circle, rgba(0,130,110,0.9) 0%, rgba(0,200,170,0.5) 60%, rgba(0,220,200,0) 100%); }

.heat-toggles { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.heat-toggles .lbl { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }

.heat-info-marker { background: transparent; border: none; }
.heat-info-dot {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff;
  border: 2px solid rgba(255,255,255,0.85);
  box-shadow: 0 1px 6px rgba(0,0,0,0.5);
  cursor: pointer;
}
.heat-info-dot.flight { background: rgba(255, 80, 0, 0.85); }
.heat-info-dot.event { background: rgba(150, 80, 220, 0.85); }
.heat-info-dot.ferry { background: rgba(0, 160, 135, 0.9); }

.heat-popup .leaflet-popup-content-wrapper { background: var(--bg-1); color: var(--text); border: 1px solid var(--line); border-radius: 10px; }
.heat-popup .leaflet-popup-tip { background: var(--bg-1); }
.heat-popup-body { font-size: 13px; line-height: 1.4; min-width: 200px; }
.heat-popup-section { padding: 4px 0; }
.heat-popup-section + .heat-popup-section { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 10px; }
.heat-popup-h { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.heat-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; }
.heat-dot.flight { background: #ff5000; }
.heat-dot.event { background: #9650dc; }
.heat-dot.ferry { background: #00a087; }
.heat-popup-sub { font-size: 11px; color: var(--text-dim); margin: 3px 0 2px; }
.heat-popup-desc { font-size: 12px; color: var(--text-dim); margin: 3px 0; }
.heat-badge { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 600; }
.heat-badge.intl { background: rgba(255,80,0,0.18); color: #ffae66; }
.heat-badge.dom { background: rgba(150,80,220,0.18); color: #c79ef0; }
.heat-badge.ferry { background: rgba(0,160,135,0.18); color: #6fd9c2; }
.heat-flight-list { list-style: none; padding: 6px 0 2px; margin: 0; }
.heat-flight-list li { padding: 4px 0; border-top: 1px dashed var(--line); }
.heat-flight-list li:first-child { border-top: none; }
.heat-flight-num { font-weight: 600; font-size: 12px; }
.heat-flight-meta { font-size: 11px; color: var(--text-dim); }
.heat-popup-tip { font-size: 11px; color: #ffae66; margin-top: 6px; font-style: italic; }
.heat-popup-note { font-size: 11px; color: #c79ef0; margin-top: 6px; font-style: italic; }
.heat-popup-section.ferry .heat-popup-tip { color: #6fd9c2; }

#clock {
  position: absolute; left: 12px; top: 12px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-2);
  z-index: 500;
}
#clock .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--text-mute); }
#clock #clock-time { font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: .5px; }

.info-card {
  position: absolute; left: 12px; bottom: 24px;
  width: 320px; max-width: calc(100vw - 24px);
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  overflow: hidden;
  z-index: 500;
  transition: transform .2s, opacity .2s;
}
.info-card.hidden { opacity: 0; pointer-events: none; transform: translateY(10px); }
.info-card .close {
  position: absolute; top: 6px; right: 8px;
  width: 26px; height: 26px;
  background: transparent; border: 0; color: var(--text-dim);
  font-size: 22px; line-height: 1;
  border-radius: 6px;
}
.info-card .close:hover { background: var(--bg-2); color: var(--text); }
.info-card .info-body { padding: 14px 14px 14px; }
.info-card h3 { margin: 0 0 4px; font-size: 15px; }
.info-card .code-line { font-size: 11px; color: var(--text-dim); margin-bottom: 10px; }
.info-card .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-top: 10px; }
.info-card .grid div { font-size: 12px; color: var(--text-dim); }
.info-card .grid div b { color: var(--text); font-weight: 600; display: block; font-size: 13px; margin-top: 2px; }
.info-card .progress {
  margin-top: 10px;
  background: var(--bg-3); height: 5px; border-radius: 999px; overflow: hidden;
}
.info-card .progress > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.info-card .bar-stops { display: flex; align-items: center; gap: 4px; margin-top: 12px; flex-wrap: wrap; }
.info-card .bar-stops .pip {
  flex: 1; min-width: 4px; height: 4px; border-radius: 2px;
  background: var(--bg-3);
}
.info-card .bar-stops .pip.passed { background: var(--accent); }
.info-card .bar-stops .pip.current { background: var(--warn); box-shadow: 0 0 0 3px rgba(255,184,77,.2); }
.info-card .bar-stops .labels { display: flex; justify-content: space-between; font-size: 10px; color: var(--text-mute); margin-top: 4px; width: 100%; }

/* Mobile FAB */
.mobile-fab {
  display: none;
  position: fixed; right: 14px; bottom: 14px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b1220;
  border: 0;
  align-items: center; justify-content: center;
  box-shadow: 0 10px 24px rgba(56,225,255,.4);
  z-index: 1100;
}
.mobile-fab span {
  position: absolute; top: -4px; right: -4px;
  min-width: 20px; height: 20px;
  border-radius: 999px;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700;
  display: grid; place-items: center;
  padding: 0 5px;
  border: 2px solid var(--bg-0);
}

/* Leaflet overrides */
.leaflet-container { font-family: inherit; background: var(--bg-0) !important; }
.leaflet-control-zoom {
  border: 1px solid var(--line) !important;
  background: var(--bg-1) !important;
  box-shadow: var(--shadow-2) !important;
}
.leaflet-control-zoom a {
  background: var(--bg-1) !important;
  color: var(--text) !important;
  border-bottom: 1px solid var(--line) !important;
}
.leaflet-control-zoom a:hover { background: var(--bg-2) !important; }
.leaflet-control-attribution {
  background: rgba(11,18,32,.6) !important;
  color: var(--text-dim) !important;
  font-size: 10px !important;
  padding: 2px 6px !important;
  border-radius: 4px 0 0 0;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-1) !important;
  color: var(--text) !important;
  box-shadow: var(--shadow-2) !important;
  border-radius: 10px !important;
  border: 1px solid var(--line);
}
.leaflet-popup-content { margin: 12px 14px !important; font-size: 12px; line-height: 1.5; }
.leaflet-popup-close-button { color: var(--text-dim) !important; }
.leaflet-popup-close-button:hover { color: var(--text) !important; }

.ferry-popup { min-width: 200px; }
.ferry-popup h4 { margin: 0 0 2px; font-size: 14px; }
.ferry-popup .sub { font-size: 11px; color: var(--text-dim); margin-bottom: 8px; }
.ferry-popup .row { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); padding: 2px 0; }
.ferry-popup .row b { color: var(--text); }
.ferry-popup .progress {
  margin-top: 8px; height: 4px;
  background: var(--bg-3); border-radius: 999px; overflow: hidden;
}
.ferry-popup .progress > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.ferry-popup .stops { display: flex; align-items: center; gap: 3px; margin-top: 8px; }
.ferry-popup .stops .pip { flex: 1; height: 3px; border-radius: 2px; background: var(--bg-3); }
.ferry-popup .stops .pip.passed { background: var(--accent); }
.ferry-popup .stops .pip.current { background: var(--warn); }

.ferry-icon {
  position: relative;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  transform-origin: center;
  will-change: transform;
}
.ferry-icon .vessel {
  width: 18px; height: 18px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; color: #fff;
  background: var(--docked);
  box-shadow: 0 0 0 2px rgba(255,255,255,.9), 0 2px 6px rgba(0,0,0,.4);
  transition: background .3s;
  opacity: 0.92;
}
.ferry-icon.moving .vessel { background: var(--moving); }
.ferry-icon.speedboat .vessel { background: var(--speedboat); }
.ferry-icon.speedboat.moving .vessel { background: var(--speedboat); }
.ferry-icon.fast .vessel { background: var(--fast); }
.ferry-icon.fast.moving .vessel { background: var(--fast); }
.ferry-icon.fast { width: 32px; height: 32px; }
.ferry-icon.fast .vessel { width: 20px; height: 20px; }
.ferry-icon.cargo .vessel { background: var(--warn); color: #2a1d05; }
.ferry-icon.cargo.moving .vessel { background: var(--warn); color: #2a1d05; }
.ferry-icon.moving::before {
  content: ""; position: absolute; inset: -6px;
  border-radius: 50%;
  border: 1.5px solid var(--moving);
  opacity: .55;
  animation: ringPulse 1.8s ease-out infinite;
}
.ferry-icon.moving::after {
  content: ""; position: absolute; inset: -10px;
  border-radius: 50%;
  border: 1.5px solid var(--moving);
  opacity: .25;
  animation: ringPulse 1.8s ease-out .6s infinite;
}
.ferry-icon.fast::before {
  border-color: var(--fast);
  animation: ringPulse 1.4s ease-out infinite;
}
.ferry-icon.fast::after {
  border-color: var(--fast);
  animation: ringPulse 1.4s ease-out .4s infinite;
}
@keyframes ringPulse {
  0% { transform: scale(.7); opacity: .6; }
  100% { transform: scale(1.4); opacity: 0; }
}

.leaflet-overlay-pane .leaflet-heatmap-layer {
  z-index: 0;
  pointer-events: none;
}
.leaflet-overlay-pane svg.leaflet-zoom-animated {
  position: relative;
  z-index: 1;
}

.ferry-trail {
  stroke: var(--trail);
  stroke-opacity: .9;
  stroke-width: 4;
  stroke-linecap: round;
  fill: none;
  filter: drop-shadow(0 0 4px rgba(56,225,255,.5));
}

.ferry-progress {
  stroke: var(--accent-2);
  stroke-opacity: .8;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  filter: drop-shadow(0 0 6px rgba(108,140,255,.45));
}

.stop-icon {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text); border: 2px solid var(--bg-1);
  box-shadow: 0 0 0 1px var(--line-strong);
}
.stop-icon.terminal {
  width: 10px; height: 10px;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(56,225,255,.3);
}

.atoll-label {
  background: transparent; border: 0;
  color: var(--text-dim);
  font-size: 10px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
  white-space: nowrap;
  pointer-events: none;
}
:root[data-theme="light"] .atoll-label {
  color: #1a2a4a;
  text-shadow: 0 1px 1px rgba(255,255,255,.9);
}

/* Cluster styling */
.marker-cluster { background: rgba(56,225,255,.15) !important; }
.marker-cluster div {
  background: rgba(56,225,255,.85) !important;
  color: #0b1220 !important;
  font-weight: 700 !important;
}

/* ───────────── Simulation panel ───────────── */
.sim-controls { display: flex; flex-direction: column; gap: 8px; }
.sim-row { display: flex; align-items: center; gap: 8px; }
.sim-btn {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--bg-1); border: 1px solid var(--line);
  display: grid; place-items: center;
  color: var(--text-dim); font-size: 14px;
  transition: background .15s, border-color .15s, color .15s;
  flex: 0 0 auto;
}
.sim-btn:hover { background: var(--bg-3); border-color: var(--accent); color: var(--text); }
.sim-btn.active { background: var(--accent); color: var(--bg-0); border-color: var(--accent); }
.sim-info {
  flex: 1; display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.sim-badge {
  font-size: 10px; font-weight: 600;
  color: var(--accent);
  background: rgba(56, 225, 255, .12);
  padding: 2px 8px; border-radius: 999px;
  letter-spacing: .02em;
  white-space: nowrap;
}
.sim-datetime {
  flex: 1; min-width: 0;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  padding: 6px 8px;
  transition: border-color .15s, background .15s;
}
.sim-datetime:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-2);
}
.sim-datetime::-webkit-calendar-picker-indicator {
  filter: var(--icon-filter, none);
  cursor: pointer;
}

/* ───────────── Responsive ───────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 100vw; }
  .brand .subtitle { display: none; }
  .search { display: none; }
  .mobile-only { display: grid; }

  #sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    width: 88vw; max-width: 360px;
    box-shadow: var(--shadow-2);
  }
  body.sidebar-open #sidebar { transform: translateX(0); }
  body.sidebar-open::after {
    content: ""; position: fixed; inset: var(--topbar-h) 0 0 0;
    background: rgba(0,0,0,.5); z-index: 800;
  }
  #map-wrap { left: 0; }

  .topbar-actions { gap: 4px; }
  .status { display: none; }

  #legend { font-size: 10px; padding: 8px 10px; right: 8px; bottom: 80px; }
  #clock { left: 8px; top: 8px; padding: 6px 10px; font-size: 12px; }
  .info-card { left: 8px; right: 8px; bottom: 80px; width: auto; }
  .mobile-fab { display: flex; }
  body.ferry-list-open .mobile-fab { display: none; }
}

@media (max-width: 480px) {
  .brand .title h1 { font-size: 13px; }
  #topbar { padding: 0 10px; gap: 8px; }
  .topbar-actions .icon-btn { width: 32px; height: 32px; }
  #legend { display: none; }
}

/* Leaflet attribution shrink on mobile */
@media (max-width: 600px) {
  .leaflet-control-attribution { font-size: 9px !important; }
}

/* ───────────── Schedules Page ───────────── */
body.schedules-page { overflow: auto; }

.schedules-quick-links {
  margin: 16px 0 8px;
  padding: 12px 16px;
  background: var(--bg-2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.schedules-quick-links .quick-link {
  color: var(--accent, #4c8eff);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}
.schedules-quick-links .quick-link:hover { text-decoration: underline; }
.schedules-quick-links .quick-hint {
  color: var(--text-mute);
  font-size: 12px;
}

#schedules-app {
  margin-top: var(--topbar-h);
  padding: 20px 24px;
  max-width: 1200px;
  min-height: calc(100vh - var(--topbar-h));
}

.schedules-header {
  margin-bottom: 20px;
}

.schedules-controls {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.schedules-controls .field {
  min-width: 260px;
  flex: 1;
  max-width: 400px;
  margin-bottom: 0;
}

.view-tabs {
  display: flex;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.view-tabs button {
  background: transparent;
  border: 0;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.view-tabs button:hover { color: var(--text); }
.view-tabs button.active {
  background: var(--bg-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.port-info {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.port-info .port-name {
  font-size: 18px;
  font-weight: 700;
}

.port-info .port-meta {
  font-size: 12px;
  color: var(--text-dim);
  padding: 3px 10px;
  background: var(--bg-2);
  border-radius: 999px;
}

.loading, .error {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

.error { color: var(--danger); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.empty-state .empty-art { font-size: 48px; margin-bottom: 12px; opacity: .7; }
.empty-state p { font-size: 15px; margin: 6px 0; }
.empty-state .muted { color: var(--text-mute); font-size: 12px; }

/* Schedule table base */
.schedule-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-1);
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.schedule-table th,
.schedule-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.schedule-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-2);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  z-index: 1;
}

.schedule-table tbody tr:hover { background: var(--bg-2); }
.schedule-table tbody tr:last-child td { border-bottom: 0; }

/* Daily table */
.daily-table .route-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 80px;
}

.daily-table .route-name-sm {
  font-size: 10px;
  color: var(--text-mute);
  white-space: normal;
  max-width: 200px;
  line-height: 1.3;
}

.daily-table .vessel-cell {
  font-size: 12px;
  color: var(--text-dim);
}

.sched-cell {
  text-align: center !important;
  font-size: 12px;
  min-width: 60px;
}

.sched-cell.has-sched {
  color: var(--accent);
  font-weight: 500;
}

.sched-cell .time {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.sched-cell .time-entry {
  display: flex;
  align-items: baseline;
  gap: 3px;
  line-height: 1.5;
}

.sched-cell .time-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 1px 4px;
  border-radius: 3px;
  line-height: 1.2;
}

.sched-cell .time-label.dep {
  background: rgba(59, 130, 246, .15);
  color: #60a5fa;
}

.sched-cell .time-label.arr {
  background: rgba(16, 185, 129, .15);
  color: #34d399;
}

.sched-cell .time-dir {
  font-size: 10px;
  color: var(--text-mute);
}

.sched-cell .time-more {
  font-size: 10px;
  color: var(--text-mute);
  margin-top: 2px;
}

.sched-cell .yes { color: var(--ok); }

.sched-cell.muted { color: var(--text-mute); font-size: 11px; }

/* Weekly table */
.weekly-table th {
  text-align: center;
}

.weekly-table .date-sub {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-mute);
  text-transform: none;
  letter-spacing: 0;
  margin-top: 2px;
}

.weekly-table th.today,
.monthly-table td.today {
  background: var(--bg-3);
  color: var(--accent);
}

.weekly-table .time-cell {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  min-width: 70px;
}

.weekly-table .sched-entry {
  font-size: 11px;
  line-height: 1.4;
  padding: 1px 0;
}

.weekly-table .sched-entry strong {
  color: var(--accent);
}

.weekly-table .sched-entry .time-label {
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 1px 3px;
  border-radius: 3px;
  margin-left: 2px;
}

.weekly-table .sched-entry .time-label.dep {
  background: rgba(59, 130, 246, .15);
  color: #60a5fa;
}

.weekly-table .sched-entry .time-label.arr {
  background: rgba(16, 185, 129, .15);
  color: #34d399;
}

.weekly-table .sched-entry .time-dir {
  font-size: 9px;
  color: var(--text-mute);
}

/* Monthly table */
.month-header {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
  text-align: center;
}

.monthly-table th {
  text-align: center;
  font-size: 11px;
}

.monthly-table td {
  text-align: center;
  vertical-align: top;
  padding: 6px 8px;
  min-width: 90px;
  height: 80px;
}

.monthly-table td.pad {
  background: transparent;
}

.monthly-table .day-num {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.monthly-table td.has-routes .day-num {
  color: var(--accent);
}

.monthly-table td.today .day-num {
  color: var(--accent);
  background: var(--accent);
  color: var(--bg-0);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  margin-bottom: 4px;
}

.monthly-table .day-routes {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
}

.monthly-table .day-route {
  font-size: 9px;
  padding: 1px 5px;
  background: var(--bg-2);
  border-radius: 4px;
  color: var(--text-dim);
  font-weight: 500;
}

.monthly-table .day-route.more {
  color: var(--text-mute);
  font-size: 8px;
  background: transparent;
}

.month-legend {
  margin-top: 20px;
  padding: 16px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.month-legend h3 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 8px;
}

.legend-item {
  font-size: 12px;
  color: var(--text-dim);
  padding: 6px 10px;
  background: var(--bg-2);
  border-radius: 8px;
}

.legend-item strong { color: var(--text); }
.legend-item .days { color: var(--accent); }

 /* Responsive schedules */
 @media (max-width: 768px) {
   #schedules-app { padding: 14px 12px; }
   .schedules-controls { flex-direction: column; align-items: stretch; }
   .schedules-controls .field { max-width: none; }
   .view-tabs button { padding: 8px 14px; font-size: 12px; }
   .monthly-table td { min-width: 60px; height: 60px; padding: 4px; }
   .daily-table th, .daily-table td { padding: 8px 6px; }
   .daily-table .route-name-sm { max-width: 120px; }
 }

/* ── Server-rendered master schedule pages ── */
body.schedule-page { overflow: auto; }

.schedule-master {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
  color: var(--text);
  background: var(--bg);
}

.schedule-master h2 {
  font-size: 22px;
  margin: 0 0 8px;
  color: var(--text);
}
.schedule-master h3 {
  font-size: 16px;
  margin: 28px 0 10px;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sched-breadcrumb {
  font-size: 13px;
  color: var(--text-mute);
  margin-bottom: 16px;
}
.sched-breadcrumb a {
  color: var(--accent, #4c8eff);
  text-decoration: none;
}
.sched-breadcrumb a:hover { text-decoration: underline; }

.sched-intro {
  color: var(--text-mute);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 24px;
}

.sched-operator-group {
  margin-bottom: 32px;
}
.sched-operator-group h2 .count {
  color: var(--text-mute);
  font-size: 14px;
  font-weight: 400;
}

.master-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.master-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg-2);
  color: var(--text-mute);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border, #1e2a3a);
}
.master-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border, #1e2a3a);
}
.master-table tbody tr:hover { background: var(--bg-2); }
.master-table a {
  color: var(--accent, #4c8eff);
  text-decoration: none;
}
.master-table a:hover { text-decoration: underline; }

.route-detail-header {
  margin-bottom: 24px;
}
.route-detail-header h2 { font-size: 24px; }
.route-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  font-size: 13px;
  color: var(--text-mute);
  margin-top: 8px;
}
.route-meta .meta-item strong { color: var(--text); }
.route-meta a {
  color: var(--accent, #4c8eff);
  text-decoration: none;
}
.route-meta a:hover { text-decoration: underline; }

.route-detail-table th, .route-detail-table td {
  padding: 10px 14px;
}
.route-detail-table a {
  color: var(--accent, #4c8eff);
  text-decoration: none;
}
.route-detail-table a:hover { text-decoration: underline; }

.day-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.day-pill {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}
.day-pill.active {
  background: var(--accent, #4c8eff);
  color: #fff;
}
.day-pill.inactive {
  background: var(--bg-2);
  color: var(--text-mute);
  opacity: 0.5;
}

.island-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}
.island-pill {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--bg-2);
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
  border: 1px solid var(--border, #1e2a3a);
}
.island-pill:hover {
  background: var(--accent, #4c8eff);
  color: #fff;
  border-color: var(--accent, #4c8eff);
}

.route-remarks {
  margin: 20px 0;
  padding: 14px 18px;
  background: var(--bg-2);
  border-left: 3px solid var(--accent, #4c8eff);
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.6;
}

.port-detail-table th, .port-detail-table td {
  padding: 10px 12px;
}
.port-detail-table a {
  color: var(--accent, #4c8eff);
  text-decoration: none;
}
.port-detail-table a:hover { text-decoration: underline; }

.back-link {
  margin-top: 32px;
  font-size: 14px;
}
.back-link a {
  color: var(--accent, #4c8eff);
  text-decoration: none;
}
.back-link a:hover { text-decoration: underline; }

.schedule-footer {
  text-align: center;
  padding: 24px;
  font-size: 13px;
  color: var(--text-mute);
  border-top: 1px solid var(--border, #1e2a3a);
}
.schedule-footer a {
  color: var(--accent, #4c8eff);
  text-decoration: none;
}
.schedule-footer a:hover { text-decoration: underline; }
.schedule-footer .muted { font-size: 11px; margin-top: 4px; }

@media (max-width: 768px) {
  .schedule-master { padding: 16px 12px 40px; }
  .master-table, .route-detail-table, .port-detail-table { font-size: 12px; }
  .master-table th, .master-table td,
  .route-detail-table th, .route-detail-table td,
  .port-detail-table th, .port-detail-table td { padding: 8px 6px; }
  .route-meta { flex-direction: column; gap: 4px; }
}

/* ───────────── About page ───────────── */
.about-content {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 20px 60px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
}
.about-section { margin-bottom: 28px; }
.about-section h2 {
  font-size: 20px;
  margin: 0 0 10px;
  color: var(--text);
}
.about-section p { margin: 0 0 12px; color: var(--text-dim); font-size: 15px; }
.about-section ul { margin: 0 0 12px; padding-left: 22px; color: var(--text-dim); font-size: 15px; }
.about-section li { margin-bottom: 6px; }
.about-section a { color: var(--accent, #4c8eff); text-decoration: none; }
.about-section a:hover { text-decoration: underline; }
@media (max-width: 768px) { .about-content { padding: 20px 14px 40px; } }
