:root {
  color-scheme: dark;
  --ink: #e9f3f5;
  --muted: #88a1aa;
  --panel: rgba(7, 21, 29, 0.94);
  --panel-strong: #07151d;
  --line: rgba(174, 214, 220, 0.14);
  --accent: #42d5c5;
  --accent-strong: #20bbaa;
  --track: #ffb55e;
  --danger: #ff746d;
  --shadow: 0 18px 50px rgba(0, 8, 13, 0.32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body, .app-shell, .map-stage, #map { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; background: var(--panel-strong); color: var(--ink); }
button, input { font: inherit; }
button { color: inherit; }

#map { z-index: 0; background: #c8d8d9; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { background: rgba(244, 249, 249, 0.86) !important; color: #33484f; }
.leaflet-control-attribution a { color: #116a72; }
.leaflet-control-zoom { margin: 0 18px 66px 0 !important; border: 0 !important; box-shadow: var(--shadow) !important; }
.leaflet-control-zoom a { color: #16343b !important; border: 0 !important; }

.topbar {
  position: absolute; z-index: 500; top: 0; left: 0; right: 0; height: 78px;
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  pointer-events: none; background: linear-gradient(to bottom, rgba(2, 13, 20, 0.78), transparent);
}
.brand, .live-status { pointer-events: auto; }
.brand { display: flex; gap: 11px; align-items: center; color: var(--ink); text-decoration: none; }
.brand-mark { position: relative; width: 44px; height: 44px; overflow: hidden; border-radius: 13px; background: #063978; box-shadow: var(--shadow); }
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: cover; }
.brand strong, .brand small { display: block; }
.brand strong { font-family: Georgia, "Times New Roman", serif; font-size: 22px; letter-spacing: .015em; }
.brand small { margin-top: 1px; color: #b0c3c8; font-size: 10px; letter-spacing: .16em; text-transform: uppercase; }

.live-status { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); box-shadow: var(--shadow); color: #b7cbd0; font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #dba342; box-shadow: 0 0 0 4px rgba(219,163,66,.12); }
.live-status.connected .status-dot { background: var(--accent); box-shadow: 0 0 0 4px rgba(66,213,197,.13); }
.live-status.disconnected .status-dot { background: var(--danger); }

.control-panel {
  position: absolute; z-index: 600; top: 92px; left: 18px; width: min(390px, calc(100vw - 36px));
  max-height: calc(100vh - 126px); overflow: auto; border: 1px solid var(--line); border-radius: 18px;
  background: var(--panel); box-shadow: var(--shadow); backdrop-filter: blur(18px); scrollbar-width: thin;
}
.search-wrap { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); background: rgba(7, 21, 29, .98); }
.search-wrap svg { width: 19px; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.search-wrap input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 14px; }
.search-wrap input::placeholder { color: #79929b; }
kbd { border: 1px solid var(--line); border-radius: 5px; padding: 2px 7px; color: var(--muted); font-size: 11px; }
.filter-menu { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; margin-top: 7px; }
.filter-menu label { display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 6px; color: #b7cbd0; font-size: 11px; cursor: pointer; }
.filter-menu label:hover { background: rgba(66, 213, 197, .08); }
.filter-menu input { margin: 0; accent-color: var(--accent-strong); }
.flag-filter-menu { grid-template-columns: 1fr; max-height: 190px; overflow-y: auto; padding-right: 3px; }
.flag-filter-menu label { display: grid; grid-template-columns: auto 18px 1fr; }
.flag-filter-menu .flag-icon-small { width: 18px; height: 13px; }
.flag-filter-placeholder { width: 18px; color: var(--muted); text-align: center; }
.filter-empty { margin: 7px 6px 2px; color: var(--muted); font-size: 10px; }
.filter-actions { display: flex; justify-content: flex-end; gap: 5px; margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--line); }
.filter-actions button { padding: 4px 7px; border: 0; background: transparent; color: var(--accent); font-size: 10px; cursor: pointer; }

.map-toolbar { position: absolute; z-index: 610; top: 92px; right: 18px; display: grid; gap: 6px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); }
.map-tool { position: relative; width: 38px; height: 38px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 7px; background: #102730; cursor: pointer; }
.map-tool:hover, .map-tool.active { background: #17424c; }
.map-tool:disabled { opacity: .42; cursor: default; }
.map-tool svg { width: 21px; fill: none; stroke: #d4e4e7; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool-dot { position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border: 1px solid #102730; border-radius: 50%; background: var(--track); }
.filter-panel, .map-type-panel, .symbol-size-panel { position: absolute; z-index: 605; top: 92px; right: 70px; width: min(310px, calc(100vw - 94px)); max-height: calc(100vh - 126px); overflow: auto; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.filter-panel header, .map-type-panel header, .symbol-size-panel header { position: relative; display: flex; justify-content: space-between; align-items: start; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.filter-panel h2, .map-type-panel h2, .symbol-size-panel h2 { font-family: inherit; font-size: 18px; font-weight: 650; }
.filter-panel header .icon-button, .map-type-panel header .icon-button, .symbol-size-panel header .icon-button { top: -4px; right: -4px; }
.map-type-options { display: grid; gap: 7px; margin-top: 14px; }
.map-type-options label { display: flex; align-items: flex-start; gap: 9px; padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: #0a1c25; cursor: pointer; }
.map-type-options label:hover { border-color: rgba(66, 213, 197, .45); }
.map-type-options label:has(input:checked) { border-color: var(--accent-strong); background: rgba(66, 213, 197, .1); }
.map-type-options input { margin: 3px 0 0; accent-color: var(--accent-strong); }
.map-type-options span, .map-type-options strong, .map-type-options small { display: block; }
.map-type-options strong { color: var(--ink); font-size: 12px; }
.map-type-options small { margin-top: 3px; color: var(--muted); font-size: 10px; line-height: 1.35; }
.reset-filter { margin-top: 14px; padding: 8px 11px; border: 0; border-radius: 7px; background: var(--accent-strong); color: #021316; font-size: 11px; font-weight: 700; cursor: pointer; }
.filter-section { margin: 16px 0 0; padding: 12px 0 0; border: 0; border-top: 1px solid var(--line); }
.filter-section legend { width: 100%; padding: 0; color: var(--ink); font-size: 12px; font-weight: 700; }
.filter-section legend small { float: right; color: var(--muted); font-size: 9px; font-weight: 500; }
.filter-section > label { display: flex; align-items: center; gap: 7px; margin-top: 10px; color: #c3d3d7; font-size: 12px; }
.filter-section input { accent-color: var(--accent-strong); }
.filter-section label small { margin-left: auto; color: var(--muted); }

.welcome-panel, .vessel-details { position: relative; padding: 24px; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
h1, h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 500; line-height: 1.08; }
h1 { max-width: 280px; font-size: 32px; }
h2 { padding-right: 34px; font-size: 28px; }
.welcome-panel > p:not(.eyebrow) { margin: 12px 0 22px; color: #9bb0b6; font-size: 14px; line-height: 1.6; }
.metric-row { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); padding-top: 18px; }
.metric-row div + div { border-left: 1px solid var(--line); padding-left: 20px; }
.metric-row strong, .metric-row span { display: block; }
.metric-row strong { font-size: 21px; }
.metric-row span { margin-top: 2px; color: var(--muted); font-size: 11px; }

.search-results { border-bottom: 1px solid var(--line); padding: 6px; }
.search-result { width: 100%; display: flex; justify-content: space-between; gap: 12px; padding: 11px 12px; border: 0; border-radius: 10px; background: transparent; text-align: left; cursor: pointer; }
.search-result:hover, .search-result:focus-visible { outline: 0; background: rgba(66, 213, 197, .1); }
.search-result strong, .search-result span { display: block; }
.search-result strong { font-size: 13px; }
.search-result span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.search-result .search-metadata { display: flex; align-items: center; gap: 6px; }
.search-result .search-metadata span { margin-top: 0; }
.search-result em { align-self: center; color: var(--accent); font-size: 11px; font-style: normal; }
.no-results { margin: 0; padding: 16px; color: var(--muted); text-align: center; font-size: 13px; }

.icon-button { position: absolute; top: 17px; right: 17px; width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 50%; background: transparent; cursor: pointer; color: var(--muted); font-size: 21px; }
.icon-button:hover { color: var(--ink); border-color: rgba(174,214,220,.3); }
.identity-line { display: flex; gap: 7px; margin: 8px 0 20px; color: var(--muted); font-size: 12px; }
.mobile-sheet-toggle, .mobile-vessel-summary { display: none; }
.telemetry-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; overflow: hidden; margin: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--line); }
.telemetry-grid div { padding: 7px 11px; background: #0a1c25; }
.telemetry-grid dt { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.telemetry-grid dd { margin: 2px 0 0; font-size: 15px; }
.telemetry-grid .status-cell, .telemetry-grid .wide-cell { grid-column: 1 / -1; }
#detail-flag { display: flex; align-items: center; gap: 7px; }
.flag-icon { width: 24px; height: 18px; flex: none; object-fit: cover; border-radius: 2px; box-shadow: 0 0 0 1px rgba(255,255,255,.22); }
.flag-icon-small { width: 18px; height: 13px; }
.track-header { display: flex; align-items: end; justify-content: space-between; margin-top: 24px; }
.track-header p { margin: 0; }
#track-summary { color: var(--muted); font-size: 12px; }
.text-button { border: 0; background: transparent; color: var(--accent); cursor: pointer; font-size: 12px; }
.text-button:disabled { opacity: .35; cursor: default; }
.segmented-control { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; margin-top: 12px; padding: 3px; border-radius: 10px; background: #031017; }
.segmented-control button { padding: 7px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.segmented-control button.active { background: #12313a; color: var(--ink); }
.track-state { min-height: 18px; margin-top: 10px; color: var(--muted); font-size: 11px; }
.track-speed-key { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 7px; margin-top: 3px; color: var(--muted); font-size: 9px; }
.track-speed-key i { height: 4px; border-radius: 999px; background: linear-gradient(90deg, #78909c, #27b8bd 18%, #2daf72 38%, #d8bd3f 58%, #e58b2a 78%, #e05252); }
.leaflet-tooltip.track-position-tooltip { padding: 8px 10px; border: 1px solid rgba(174, 214, 220, .25); border-radius: 8px; background: #07151d; box-shadow: 0 7px 20px rgba(0, 8, 13, .3); color: var(--ink); }
.leaflet-tooltip-top.track-position-tooltip::before { border-top-color: #07151d; }
.track-position-tooltip strong, .track-position-tooltip span, .track-position-tooltip time { display: block; }
.track-position-tooltip strong { margin-bottom: 3px; color: var(--accent); font-size: 12px; }
.track-position-tooltip span, .track-position-tooltip time { color: #aec0c5; font-size: 10px; line-height: 1.45; }
.track-position-tooltip time { margin-top: 3px; color: var(--muted); }
.leaflet-tooltip.vessel-hover-tooltip { min-width: 150px; padding: 9px 11px; border: 1px solid rgba(174, 214, 220, .28); border-radius: 9px; background: #07151d; box-shadow: 0 8px 22px rgba(0, 8, 13, .38); color: var(--ink); }
.leaflet-tooltip-top.vessel-hover-tooltip::before { border-top-color: #07151d; }
.vessel-hover-tooltip strong, .vessel-hover-tooltip span { display: block; }
.vessel-hover-tooltip strong { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; color: var(--accent); font-size: 12px; }
.vessel-tooltip-flag { width: 24px; height: 18px; flex: none; object-fit: cover; border-radius: 2px; box-shadow: 0 0 0 1px rgba(255,255,255,.22); }
.vessel-hover-tooltip span { color: #aec0c5; font-size: 10px; line-height: 1.5; }
.vessel-hover-tooltip .vessel-tooltip-destination { margin-top: 3px; color: var(--muted); }
.speed-history { margin-top: 17px; padding-top: 16px; border-top: 1px solid var(--line); }
.speed-history-header p { margin: 0; }
#speed-summary { color: var(--muted); font-size: 11px; }
.speed-chart { height: 126px; margin-top: 9px; border-radius: 10px; background: #061820; overflow: hidden; }
.speed-chart svg { display: block; width: 100%; height: 100%; }
.speed-chart .grid-line { stroke: rgba(174, 214, 220, .12); stroke-width: 1; vector-effect: non-scaling-stroke; }
.speed-chart .axis-label { fill: var(--muted); font-size: 9px; }
.speed-chart .speed-area { fill: url(#speed-area-gradient); }
.speed-chart .speed-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.speed-chart .average-line { stroke: var(--track); stroke-width: 1; stroke-dasharray: 4 4; opacity: .8; vector-effect: non-scaling-stroke; }
.speed-chart-empty { height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 11px; }

.map-legend { position: absolute; z-index: 500; right: 18px; bottom: 18px; max-width: 390px; display: flex; flex-wrap: wrap; gap: 8px 14px; padding: 9px 12px; border-radius: 9px; background: var(--panel); box-shadow: var(--shadow); color: #aec0c5; font-size: 10px; }
.map-legend span { display: flex; align-items: center; gap: 6px; }
.legend-vessel { width: 9px; height: 9px; border: 1px solid rgba(255,255,255,.9); border-radius: 2px; background: var(--marker-color); }
.legend-track { width: 18px; border-top: 2px solid var(--track); }

.vessel-marker { width: 23px; height: 23px; display: grid; place-items: center; filter: drop-shadow(0 2px 3px rgba(0, 15, 20, .45)); transition: transform .25s ease; }
.vessel-marker svg { width: 23px; height: 23px; fill: var(--marker-color, #78909c); stroke: white; stroke-width: 1.3; }
.vessel-marker.selected svg { stroke: var(--track); stroke-width: 2.7; filter: drop-shadow(0 0 3px rgba(255,181,94,.9)); }
.vessel-marker.stationary svg { stroke-width: 1.8; }
.vessel-marker.stale { opacity: .45; filter: grayscale(.45) drop-shadow(0 2px 3px rgba(0, 15, 20, .35)); }
.type-cargo, .legend-vessel.type-cargo { --marker-color: #268bd2; }
.type-tanker, .legend-vessel.type-tanker { --marker-color: #e05252; }
.type-passenger, .legend-vessel.type-passenger { --marker-color: #9b6de3; }
.type-fishing, .legend-vessel.type-fishing { --marker-color: #2daf72; }
.type-tug, .legend-vessel.type-tug { --marker-color: #e58b2a; }
.type-pleasure, .legend-vessel.type-pleasure { --marker-color: #27b8bd; }
.type-other, .legend-vessel.type-other { --marker-color: #78909c; }
.leaflet-div-icon { border: 0; background: transparent; }

@media (max-width: 640px) {
  .topbar { height: 68px; padding: 0 14px; }
  .brand-mark { width: 38px; height: 38px; }
  .brand small { display: none; }
  .control-panel {
    top: auto; bottom: 0; left: 0; width: 100%; max-height: calc(82px + env(safe-area-inset-bottom));
    overflow: hidden; padding-bottom: env(safe-area-inset-bottom); border-width: 1px 0 0;
    border-radius: 20px 20px 0 0; transition: max-height .24s ease;
    box-shadow: 0 -16px 44px rgba(0, 8, 13, .34);
  }
  .control-panel.search-expanded { max-height: min(58dvh, 500px); overflow-y: auto; }
  .control-panel:not(.has-vessel-details) .search-wrap { padding-top: 29px; }
  .control-panel.has-vessel-details {
    top: auto; bottom: 0; left: 0; width: 100%; max-height: min(31dvh, 238px); overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom); border-width: 1px 0 0; border-radius: 20px 20px 0 0;
    transition: max-height .24s ease; box-shadow: 0 -16px 44px rgba(0, 8, 13, .34);
  }
  .control-panel.has-vessel-details .mobile-search-sheet-toggle { display: none; }
  .control-panel.has-vessel-details:has(.mobile-expanded) { max-height: min(82dvh, 720px); overflow-y: auto; }
  .control-panel.has-vessel-details .search-wrap { display: none; }
  .map-toolbar { top: auto; right: 10px; bottom: 18px; }
  .control-panel ~ .map-toolbar { bottom: calc(var(--mobile-panel-height, 82px) + 12px); }
  .map-stage .leaflet-control-zoom { display: block; margin-bottom: calc(var(--mobile-panel-height, 82px) + 12px) !important; }
  .control-panel.has-vessel-details:has(.mobile-expanded) ~ .map-toolbar { display: none; }
  .map-stage:has(.control-panel.has-vessel-details .mobile-expanded) .leaflet-control-zoom { display: none; }
  .filter-panel, .map-type-panel, .symbol-size-panel { top: 76px; right: 58px; max-height: calc(100vh - 94px); }
  .welcome-panel, .vessel-details { padding: 18px; }
  .control-panel.has-vessel-details .vessel-details { padding: 43px 18px 17px; }
  .mobile-sheet-toggle {
    position: absolute; z-index: 3; top: 0; left: 50%; width: 132px; height: 36px; display: flex;
    align-items: center; justify-content: center; gap: 7px; padding: 9px 4px 4px; border: 0;
    background: transparent; color: var(--muted); transform: translateX(-50%); cursor: pointer;
    appearance: none; -webkit-appearance: none; font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
  }
  .mobile-sheet-handle { position: absolute; top: 7px; left: 50%; width: 38px; height: 4px; border-radius: 999px; background: #557078; transform: translateX(-50%); }
  .mobile-sheet-toggle svg { width: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; transition: transform .2s ease; }
  .mobile-expanded .mobile-sheet-toggle svg,
  .search-expanded .mobile-search-sheet-toggle svg { transform: rotate(180deg); }
  .control-panel.has-vessel-details .icon-button { top: 35px; right: 15px; }
  .mobile-vessel-summary { display: grid; grid-template-columns: 28px 64px minmax(0, 1fr); align-items: center; gap: 10px; margin-top: 13px; padding-top: 11px; border-top: 1px solid var(--line); }
  .mobile-vessel-summary > span { min-width: 0; }
  .mobile-vessel-summary small, .mobile-vessel-summary strong { display: block; }
  .mobile-vessel-summary small { color: var(--muted); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
  .mobile-vessel-summary strong { margin-top: 2px; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-summary-flag { display: grid; place-items: center; color: var(--muted); }
  .mobile-expanded .mobile-vessel-summary { display: none; }
  .control-panel.has-vessel-details:not(:has(.mobile-expanded)) .identity-line { margin-bottom: 0; }
  .control-panel.has-vessel-details:not(:has(.mobile-expanded)) .telemetry-grid,
  .control-panel.has-vessel-details:not(:has(.mobile-expanded)) .track-header,
  .control-panel.has-vessel-details:not(:has(.mobile-expanded)) .segmented-control,
  .control-panel.has-vessel-details:not(:has(.mobile-expanded)) .track-state,
  .control-panel.has-vessel-details:not(:has(.mobile-expanded)) .track-speed-key,
  .control-panel.has-vessel-details:not(:has(.mobile-expanded)) .speed-history { display: none; }
  .welcome-panel h1 { font-size: 27px; }
  .map-legend { display: none; }
  .leaflet-control-zoom { margin-bottom: 18px !important; }
}

@media (max-width: 640px) and (prefers-reduced-motion: reduce) {
  .control-panel, .mobile-sheet-toggle svg { transition: none; }
}

@media (max-width: 640px) and (max-height: 480px) {
  .control-panel.has-vessel-details { max-height: min(42dvh, 170px); }
  .control-panel.has-vessel-details .vessel-details { padding-bottom: 11px; }
  .control-panel.has-vessel-details:not(:has(.mobile-expanded)) .eyebrow,
  .control-panel.has-vessel-details:not(:has(.mobile-expanded)) .identity-line { display: none; }
}
