* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: #0a1628;
    color: #c8d6e5;
    overflow: hidden;
    height: 100vh;
}

/* Ensure popups render above competitor label tooltips and wind/tidal canvases */
.leaflet-popup-pane {
    z-index: 802 !important;
}

.leaflet-tooltip-pane {
    z-index: 801 !important;
}

/* Leaflet zoom & layer controls — dark nautical theme */
.leaflet-bar {
    border: 1px solid rgba(100, 150, 200, 0.2) !important;
    border-radius: 6px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
    overflow: hidden;
}

.leaflet-bar a {
    background: rgba(10, 22, 40, 0.92) !important;
    color: #c8d6e5 !important;
    border-bottom: 1px solid rgba(100, 150, 200, 0.15) !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
}

.leaflet-bar a:last-child {
    border-bottom: none !important;
}

.leaflet-bar a:hover {
    background: rgba(100, 150, 200, 0.15) !important;
    color: #e2e8f0 !important;
}

.leaflet-control-layers {
    background: rgba(10, 22, 40, 0.92) !important;
    border: 1px solid rgba(100, 150, 200, 0.2) !important;
    border-radius: 6px !important;
    color: #c8d6e5 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

.leaflet-control-layers-toggle {
    background-color: rgba(10, 22, 40, 0.92) !important;
    width: 36px !important;
    height: 36px !important;
}

.leaflet-control-layers-separator {
    border-top-color: rgba(100, 150, 200, 0.15) !important;
}

/* Forecast quick buttons — hidden on desktop */
#forecast-quick-btns {
    display: none;
}

/* Map fills its view container */
#map {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
}

/* Status bar at bottom */
#status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 6px 16px;
    background: rgba(10, 22, 40, 0.92);
    backdrop-filter: blur(8px);
    border-top: 1px solid rgba(100, 150, 200, 0.15);
    font-size: 12px;
    color: #7a8fa6;
}

#status-bar span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.offline-dl-age {
    color: #4a6a8a;
    font-size: 10px;
}

.app-build {
    color: #2a4a6a;
    font-size: 9px;
    opacity: 0.6;
    font-family: monospace;
}

.dl-indicators {
    display: flex;
    align-items: center;
    gap: 4px;
}

.dl-badge {
    font-size: 9px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 10px;
    background: rgba(100, 150, 200, 0.12);
    color: #3a4f63;
    transition: background 0.3s, color 0.3s;
}

.dl-badge.done {
    background: rgba(39, 174, 96, 0.22);
    color: #27ae60;
}

@keyframes dl-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.dl-badge.loading {
    background: rgba(241, 196, 15, 0.2);
    color: #b8960a;
    animation: dl-pulse 1.2s ease-in-out infinite;
}

.status-connected::before,
.status-disconnected::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.status-connected::before {
    background: #27ae60;
    box-shadow: 0 0 6px #27ae60;
}

.status-disconnected::before {
    background: #e74c3c;
    box-shadow: 0 0 6px #e74c3c;
}

/* Shared toggle button base */
#layers-tray button {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    height: 28px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid rgba(100, 100, 100, 0.3);
    background: rgba(100, 100, 100, 0.2);
    color: #7a8fa6;
    white-space: nowrap;
}

/* NOW button — blue */
.timeline-now-btn {
    background: rgba(60, 160, 220, 0.2) !important;
    border-color: rgba(60, 160, 220, 0.3) !important;
    color: #5dade2 !important;
}
.timeline-now-btn:hover {
    background: rgba(60, 160, 220, 0.3) !important;
}

/* Calendar button — magenta/pink */
.timeline-cal-btn {
    background: rgba(232, 90, 180, 0.2) !important;
    border-color: rgba(232, 90, 180, 0.3) !important;
    color: #e85ab4 !important;
    font-size: 14px !important;
}
.timeline-cal-btn:hover {
    background: rgba(232, 90, 180, 0.3) !important;
}

/* Download button — green */
.timeline-dl-btn {
    background: rgba(46, 204, 113, 0.2) !important;
    border-color: rgba(46, 204, 113, 0.3) !important;
    color: #2ecc71 !important;
    font-size: 14px !important;
}
.timeline-dl-btn:hover {
    background: rgba(46, 204, 113, 0.3) !important;
}
.timeline-dl-btn.downloading {
    color: #f39c12 !important;
    animation: pulse-dl 1s infinite;
}

/* Flow toggle — blue */
#flow-toggle {
    background: rgba(60, 160, 220, 0.2);
    border-color: rgba(60, 160, 220, 0.3);
    color: #5dade2;
}

#flow-toggle:hover {
    background: rgba(60, 160, 220, 0.3);
}

#flow-toggle.flow-off {
    background: rgba(100, 100, 100, 0.2);
    border-color: rgba(100, 100, 100, 0.3);
    color: #7a8fa6;
}

/* Wind toggle — purple */
#wind-toggle {
    background: rgba(170, 70, 190, 0.2);
    border-color: rgba(170, 70, 190, 0.3);
    color: #bb8fce;
}

#wind-toggle:hover {
    background: rgba(170, 70, 190, 0.3);
}

#wind-toggle.wind-off {
    background: rgba(100, 100, 100, 0.2);
    border-color: rgba(100, 100, 100, 0.3);
    color: #7a8fa6;
}

/* Tide toggle — cyan */
#tide-toggle {
    background: rgba(0, 212, 255, 0.2);
    border-color: rgba(0, 212, 255, 0.3);
    color: #00d4ff;
}

#tide-toggle:hover {
    background: rgba(0, 212, 255, 0.3);
}

#tide-toggle.tide-off {
    background: rgba(100, 100, 100, 0.2);
    border-color: rgba(100, 100, 100, 0.3);
    color: #7a8fa6;
}

/* Side panel */
#panel {
    position: fixed;
    top: 40px;
    right: 0;
    width: 340px;
    height: calc(100vh - 114px);
    z-index: 1000;
    background: rgba(10, 22, 40, 0.94);
    backdrop-filter: blur(12px);
    border-left: 1px solid rgba(100, 150, 200, 0.12);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

#panel.collapsed {
    transform: translateX(340px);
}

#panel-toggle {
    position: fixed;
    right: 340px;
    top: 52px;
    z-index: 1001;
    background: rgba(10, 22, 40, 0.92);
    border: 1px solid rgba(100, 150, 200, 0.2);
    border-right: none;
    border-radius: 4px 0 0 4px;
    color: #7a8fa6;
    font-size: 18px;
    cursor: pointer;
    padding: 8px 5px;
    transition: right 0.3s ease, background 0.2s;
}

#panel-toggle:hover {
    background: rgba(100, 150, 200, 0.15);
    color: #e2e8f0;
}

/* When panel is collapsed, move toggle to screen edge */
body.panel-collapsed #panel-toggle {
    right: 0;
}

#panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid rgba(100, 150, 200, 0.1);
}

#panel-header h2 {
    font-size: 15px;
    font-weight: 600;
    color: #e2e8f0;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Vessel search */
#vessel-search-wrap {
    padding: 8px 12px 4px;
}

#vessel-search {
    width: 100%;
    background: rgba(100, 150, 200, 0.08);
    border: 1px solid rgba(100, 150, 200, 0.15);
    border-radius: 5px;
    padding: 6px 10px;
    font-size: 12px;
    color: #e2e8f0;
    outline: none;
    transition: border-color 0.2s;
}

#vessel-search::placeholder {
    color: #4a6a8a;
}

#vessel-search:focus {
    border-color: rgba(100, 150, 200, 0.4);
    background: rgba(100, 150, 200, 0.12);
}

#vessel-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* Vessel card */
.vessel-card {
    padding: 10px 12px;
    margin-bottom: 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    border-left: 3px solid transparent;
}

.vessel-card:hover {
    background: rgba(100, 150, 200, 0.08);
}

.vessel-card.own-vessel {
    border-left-color: #f39c12;
    background: rgba(243, 156, 18, 0.06);
}

.vessel-card.stale {
    opacity: 0.45;
}

.vessel-name {
    font-size: 13px;
    font-weight: 600;
    color: #e2e8f0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.vessel-type-badge {
    font-size: 9px;
    font-weight: 500;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Vessel visibility toggle */
.vessel-toggle {
    margin-left: auto;
    background: none;
    border: 1px solid rgba(100, 150, 200, 0.2);
    color: #5dade2;
    font-size: 14px;
    line-height: 1;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.vessel-toggle:hover {
    background: rgba(100, 150, 200, 0.15);
    border-color: rgba(100, 150, 200, 0.4);
}

.vessel-toggle.toggled-off {
    color: #4a5568;
    border-color: rgba(100, 100, 100, 0.2);
}

.vessel-card.vessel-hidden {
    opacity: 0.5;
}

.vessel-card.vessel-hidden .vessel-name,
.vessel-card.vessel-hidden .vessel-meta {
    text-decoration: line-through;
    text-decoration-color: rgba(100, 150, 200, 0.3);
}

.vessel-meta {
    display: flex;
    gap: 14px;
    margin-top: 4px;
    font-size: 11px;
    color: #5a7a9a;
}

.vessel-meta span {
    display: flex;
    align-items: center;
    gap: 3px;
}

.vessel-cpa {
    margin-top: 3px;
    font-size: 10px;
    color: #5a7a9a;
}

/* CPA/TCPA warning colors */
.cpa-warn {
    color: #f39c12 !important;
    font-weight: 600;
}

.cpa-danger {
    color: #e74c3c !important;
    font-weight: 700;
    text-transform: uppercase;
    animation: cpa-blink 1s ease-in-out infinite;
}

@keyframes cpa-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Type badge colors */
.type-sailing { background: rgba(52, 152, 219, 0.2); color: #5dade2; }
.type-cargo { background: rgba(46, 204, 113, 0.2); color: #58d68d; }
.type-tanker { background: rgba(231, 76, 60, 0.2); color: #ec7063; }
.type-passenger { background: rgba(155, 89, 182, 0.2); color: #bb8fce; }
.type-fishing { background: rgba(241, 196, 15, 0.2); color: #f4d03f; }
.type-other { background: rgba(149, 165, 166, 0.2); color: #aab7b8; }
.type-unknown { background: rgba(149, 165, 166, 0.15); color: #85929e; }

/* Current flow legend */
#flow-legend {
    position: fixed;
    bottom: 90px;
    left: 12px;
    z-index: 1000;
    background: rgba(10, 22, 40, 0.88);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(100, 150, 200, 0.15);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 10px;
    color: #7a8fa6;
    width: 210px;
    display: none;
}

#flow-legend.visible {
    display: block;
}

.flow-legend-title {
    font-size: 10px;
    color: #a0b0c0;
    margin-bottom: 4px;
    font-weight: 600;
}

.flow-legend-bar {
    width: 100%;
    height: 10px;
    border-radius: 3px;
    margin-bottom: 3px;
}

.flow-legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: #5a7a9a;
    width: 100%;
}

.flow-legend-source {
    margin-top: 5px;
    font-size: 9px;
    color: #4a6a8a;
    border-top: 1px solid rgba(100, 150, 200, 0.1);
    padding-top: 4px;
}

.flow-legend-confidence {
    font-size: 9px;
    margin-top: 3px;
    line-height: 1.3;
}

/* Wind speed legend */
#wind-legend {
    position: fixed;
    bottom: 174px;
    left: 12px;
    z-index: 1000;
    background: rgba(10, 22, 40, 0.88);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(170, 70, 190, 0.2);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 10px;
    color: #7a8fa6;
    width: 210px;
    display: none;
}

#wind-legend.visible {
    display: block;
}

.wind-legend-title {
    font-size: 10px;
    color: #bb8fce;
    margin-bottom: 4px;
    font-weight: 600;
}

#wind-color-toggle {
    display: inline-flex;
    gap: 4px;
    margin-left: 4px;
    vertical-align: middle;
}

#wind-color-toggle .color-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    cursor: pointer;
    opacity: 0.4;
    border: 1px solid transparent;
}

#wind-color-toggle .color-dot.active {
    opacity: 1;
    border-color: #fff;
}

#wind-color-toggle .color-dot.green { background: #78c81e; }
#wind-color-toggle .color-dot.purple { background: #aa46be; }

#wind-color-toggle .color-dot:hover {
    opacity: 0.8;
}

.wind-legend-bar {
    width: 100%;
    height: 10px;
    border-radius: 3px;
    margin-bottom: 3px;
}

.wind-legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: #5a7a9a;
    width: 100%;
}

.wind-legend-source {
    margin-top: 5px;
    font-size: 9px;
    color: #4a6a8a;
    border-top: 1px solid rgba(170, 70, 190, 0.1);
    padding-top: 4px;
}

/* Wind station icons */
.wind-station-icon {
    background: none !important;
    border: none !important;
}

.tide-station-icon {
    background: none !important;
    border: none !important;
}

/* Own vessel icon — no background box */
.own-vessel-icon {
    background: none !important;
    border: none !important;
}

/* Vessel popup styling */
.vessel-popup {
    z-index: 10000 !important;
}

.vessel-popup .leaflet-popup-content-wrapper {
    background: rgba(10, 22, 40, 0.95);
    color: #c8d6e5;
    border-radius: 8px;
    border: 1px solid rgba(100, 150, 200, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.vessel-popup .leaflet-popup-tip {
    background: rgba(10, 22, 40, 0.95);
    border: 1px solid rgba(100, 150, 200, 0.2);
}

.popup-content {
    font-size: 12px;
    min-width: 220px;
}

.popup-chart {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(100, 150, 200, 0.12);
}

.popup-chart-label {
    font-size: 10px;
    color: #5a7a9a;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 4px;
}

.popup-chart-loading,
.popup-chart-empty {
    font-size: 10px;
    color: #4a6a8a;
    font-style: italic;
    padding: 8px 0;
}

/* Current arrow icons */
.current-icon {
    background: none !important;
    border: none !important;
}

.popup-content h3 {
    font-size: 14px;
    color: #e2e8f0;
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(100, 150, 200, 0.15);
}

.popup-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.popup-label {
    color: #5a7a9a;
}

.popup-value {
    color: #c8d6e5;
    font-weight: 500;
}

/* Scrollbar */
#vessel-list::-webkit-scrollbar {
    width: 4px;
}

#vessel-list::-webkit-scrollbar-thumb {
    background: rgba(100, 150, 200, 0.2);
    border-radius: 2px;
}

/* Forecast banner */
.forecast-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    background: rgba(243, 156, 18, 0.15);
    backdrop-filter: blur(4px);
    border-bottom: 1px solid rgba(243, 156, 18, 0.3);
    color: #f39c12;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-align: center;
    padding: 5px 16px;
    overflow: hidden;
}

.forecast-banner.hidden {
    display: none;
}

.forecast-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: #f39c12;
    transition: width 0.3s ease;
    width: 0;
}

/* ---- Timeline Strip (Windy-style) ---- */
#timeline-strip {
    position: fixed;
    bottom: 32px;
    left: 0;
    right: 0;
    z-index: 1000;
    height: 40px;
    background: rgba(10, 22, 40, 0.95);
    backdrop-filter: blur(8px);
    border-top: 1px solid rgba(100, 150, 200, 0.12);
    display: flex;
    align-items: stretch;
}

/* On desktop, button row wrapper is invisible — buttons flow inline */
.timeline-btn-row {
    display: contents;
}

#timeline-scroll {
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
#timeline-scroll::-webkit-scrollbar { display: none; }

#timeline-track {
    display: flex;
    height: 100%;
    min-width: max-content;
}

/* Day group */
.timeline-day-group {
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(100, 150, 200, 0.1);
}

.timeline-day-label {
    font-size: 10px;
    font-weight: 600;
    color: #7a8fa6;
    text-align: center;
    padding: 2px 0;
    letter-spacing: 0.3px;
    white-space: nowrap;
    border-bottom: 1px solid rgba(100, 150, 200, 0.08);
}

.timeline-hours-row {
    display: flex;
    flex: 1;
    align-items: center;
}

.timeline-hour {
    min-width: 48px;
    text-align: center;
    font-size: 10px;
    color: #4a6a8a;
    cursor: pointer;
    padding: 4px 2px;
    border-radius: 3px;
    transition: all 0.15s;
    user-select: none;
    position: relative;
}

.timeline-hour:hover {
    background: rgba(100, 150, 200, 0.12);
    color: #c8d6e5;
}

.timeline-hour.now {
    color: #5dade2;
    font-weight: 700;
}

.timeline-hour.now::after {
    content: '';
    position: absolute;
    bottom: 1px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #5dade2;
}

.timeline-hour.selected {
    background: rgba(243, 156, 18, 0.25);
    color: #f39c12;
    font-weight: 700;
    border: 1px solid rgba(243, 156, 18, 0.4);
}

/* GO button */
.timeline-go {
    background: #f39c12;
    color: #0a1628;
    border: none;
    font-size: 12px;
    font-weight: 700;
    padding: 0 14px;
    cursor: pointer;
    letter-spacing: 0.5px;
    transition: all 0.2s;
    white-space: nowrap;
}
.timeline-go:hover { background: #e67e22; }
.timeline-go.hidden { display: none; }

/* NOW / Calendar / Download buttons are in #layers-tray — styled via shared rule + overrides above */

@keyframes pulse-dl {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Forecast mode status bar highlight */
#status-bar.forecast-mode {
    border-top-color: rgba(243, 156, 18, 0.4);
}

/* Vessels toggle button */
#vessels-toggle {
    background: rgba(243, 156, 18, 0.2);
    border-color: rgba(243, 156, 18, 0.3);
    color: #f39c12;
}

#vessels-toggle:hover {
    background: rgba(243, 156, 18, 0.3);
}

#vessels-toggle.vessels-off {
    background: rgba(100, 100, 100, 0.2);
    border-color: rgba(100, 100, 100, 0.3);
    color: #7a8fa6;
}

/* Mobile vessel list */
.mobile-vessel-list {
    position: fixed;
    bottom: 102px;
    left: 0;
    right: 0;
    z-index: 1004;
    max-height: calc(3 * 58px);
    overflow-y: auto;
    background: rgba(10, 22, 40, 0.95);
    backdrop-filter: blur(8px);
    border-top: 1px solid rgba(100, 150, 200, 0.15);
    scrollbar-width: thin;
}

.mobile-vessel-list.hidden {
    display: none;
}

.mobile-vessel-list .vessel-card {
    padding: 8px 12px;
    margin: 0;
    border-radius: 0;
    border-bottom: 1px solid rgba(100, 150, 200, 0.08);
}

/* Layers tray: on desktop, sits in the status bar area (right side) */
#layers-tray {
    position: fixed;
    bottom: 72px; /* 32px status + 40px timeline */
    right: 16px;
    z-index: 1001;
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 4px 10px;
    background: rgba(10, 22, 40, 0.85);
    backdrop-filter: blur(8px);
    border-radius: 6px;
    border: 1px solid rgba(100, 150, 200, 0.12);
}

/* Layers button: hidden on desktop */
#layers-btn {
    display: none;
}

/* Date/time picker panel */
.time-picker-panel {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1002;
    background: rgba(10, 22, 40, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(243, 156, 18, 0.25);
    border-radius: 8px;
    padding: 14px 16px;
    min-width: 260px;
}

.time-picker-panel.hidden {
    display: none;
}

.time-picker-title {
    font-size: 11px;
    font-weight: 600;
    color: #f39c12;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.time-picker-inputs {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.time-picker-inputs input {
    background: rgba(100, 150, 200, 0.1);
    border: 1px solid rgba(100, 150, 200, 0.2);
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 12px;
    color: #e2e8f0;
    outline: none;
    color-scheme: dark;
}

.time-picker-inputs input:focus {
    border-color: rgba(243, 156, 18, 0.4);
}

.time-picker-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.time-picker-btn {
    flex: 1;
    padding: 5px 12px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.time-picker-btn.go {
    background: rgba(243, 156, 18, 0.2);
    border-color: rgba(243, 156, 18, 0.4);
    color: #f39c12;
}

.time-picker-btn.go:hover {
    background: rgba(243, 156, 18, 0.3);
}

.time-picker-btn.cancel {
    background: rgba(100, 100, 100, 0.2);
    border-color: rgba(100, 100, 100, 0.3);
    color: #7a8fa6;
}

.time-picker-btn.cancel:hover {
    background: rgba(100, 100, 100, 0.3);
}

.time-picker-note {
    font-size: 9px;
    color: #4a6a8a;
    text-align: center;
}

/* Route planner panel */
.route-panel {
    position: fixed;
    bottom: 90px;
    right: 12px;
    width: 210px;
    background: rgba(10, 22, 40, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(100, 150, 200, 0.15);
    border-radius: 10px;
    padding: 10px 12px;
    z-index: 1001;
    font-size: 11px;
    color: #c8d6e5;
}

.route-panel.hidden { display: none; }

.route-panel-title {
    font-size: 12px;
    font-weight: 600;
    color: #27ae60;
    margin-bottom: 6px;
}

.route-status {
    color: #a0b0c0;
    margin-bottom: 6px;
}

.route-settings { margin-bottom: 6px; }

.route-perf-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    color: #a0b0c0;
}

.route-perf-label input[type="range"] {
    width: 80px;
    accent-color: #27ae60;
}

.route-result {
    border-top: 1px solid rgba(100, 150, 200, 0.15);
    padding-top: 6px;
    margin-top: 4px;
}

.route-result.hidden { display: none; }

.route-result div {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.route-clear-btn {
    margin-top: 8px;
    width: 100%;
    padding: 4px;
    background: rgba(231, 76, 60, 0.2);
    border: 1px solid rgba(231, 76, 60, 0.4);
    border-radius: 4px;
    color: #e74c3c;
    font-size: 10px;
    cursor: pointer;
}

.route-clear-btn.hidden { display: none; }

.route-details-btn {
    margin-top: 6px;
    width: 100%;
    padding: 4px;
    background: rgba(100, 150, 200, 0.15);
    border: 1px solid rgba(100, 150, 200, 0.3);
    border-radius: 4px;
    color: #a0b0c0;
    font-size: 10px;
    cursor: pointer;
}

.route-details-modal {
    position: fixed;
    bottom: 90px;
    right: 230px;
    width: 340px;
    max-height: 400px;
    background: rgba(10, 22, 40, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(100, 150, 200, 0.2);
    border-radius: 10px;
    z-index: 1002;
    font-size: 11px;
    color: #c8d6e5;
    display: flex;
    flex-direction: column;
}
.route-details-modal.hidden { display: none; }

.route-details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(100, 150, 200, 0.15);
    font-weight: 600;
    font-size: 12px;
}
.route-details-header button {
    background: none;
    border: none;
    color: #a0b0c0;
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
}

.route-details-body {
    overflow-y: auto;
    padding: 4px 0;
}

.route-details-body table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10px;
    font-variant-numeric: tabular-nums;
}
.route-details-body th {
    position: sticky;
    top: 0;
    background: rgba(10, 22, 40, 0.98);
    padding: 4px 6px;
    text-align: right;
    color: #a0b0c0;
    font-weight: 500;
    border-bottom: 1px solid rgba(100, 150, 200, 0.2);
}
.route-details-body th:first-child { text-align: left; }
.route-details-body td {
    padding: 3px 6px;
    text-align: right;
    border-bottom: 1px solid rgba(100, 150, 200, 0.06);
}
.route-details-body td:first-child { text-align: left; color: #f39c12; }

@media (max-width: 768px) {
    .route-details-modal {
        right: 8px;
        left: 8px;
        bottom: 140px;
        width: auto;
        max-height: 50vh;
    }
}

#route-toggle {
    background: rgba(39, 174, 96, 0.15);
    border-color: rgba(39, 174, 96, 0.4);
    color: #27ae60;
}

#route-toggle.route-off {
    background: rgba(100, 100, 100, 0.15);
    border-color: rgba(100, 100, 100, 0.3);
    color: #666;
}

#labels-toggle.labels-off {
    background: rgba(100, 100, 100, 0.15);
    border-color: rgba(100, 100, 100, 0.3);
    color: #666;
}

.route-time-label { background: none !important; border: none !important; }

.route-tooltip {
    background: rgba(10, 22, 40, 0.85) !important;
    border: 1px solid rgba(100, 150, 200, 0.3) !important;
    color: #c8d6e5 !important;
    font-size: 10px !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
}

.leaflet-container.route-mode { cursor: crosshair !important; }
.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1002;
    background: rgba(231, 76, 60, 0.18);
    backdrop-filter: blur(4px);
    border-bottom: 1px solid rgba(231, 76, 60, 0.35);
    color: #e74c3c;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-align: center;
    padding: 5px 16px;
}

.offline-banner.hidden {
    display: none;
}

#offline-cache-age {
    font-weight: 400;
    opacity: 0.8;
    margin-left: 6px;
}

/* Offline download progress panel */
.offline-dl-panel {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1002;
    background: rgba(10, 22, 40, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(46, 204, 113, 0.3);
    border-radius: 8px;
    padding: 14px 18px;
    min-width: 260px;
    text-align: center;
}

.offline-dl-panel.hidden {
    display: none;
}

.offline-dl-title {
    font-size: 11px;
    font-weight: 600;
    color: #2ecc71;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.offline-dl-bar-track {
    width: 100%;
    height: 6px;
    background: rgba(100, 150, 200, 0.15);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 6px;
}

.offline-dl-bar-fill {
    height: 100%;
    width: 0%;
    background: #2ecc71;
    border-radius: 3px;
    transition: width 0.2s ease;
}

.offline-dl-status {
    font-size: 10px;
    color: #7a8fa6;
}

.offline-dl-last {
    font-size: 9px;
    color: #4a6a8a;
    margin-top: 4px;
}

/* ============================================================
   Responsive — mobile portrait (MUST be last to override base)
   ============================================================ */
@media (max-width: 600px) {
    /* === Hide the scrollable timeline on mobile === */
    #timeline-strip {
        display: none !important;
    }

    /* === Status bar: narrow bottom row === */
    #status-bar {
        height: 32px;
        flex-wrap: nowrap;
        justify-content: flex-start;
        align-items: center;
        padding: 0 10px;
        gap: 8px;
        z-index: 1001;
    }

    /* Connection status: show dot + "AIS" label on mobile */
    #connection-status {
        font-size: 0; /* hide "Connected"/"Disconnected" text */
        width: auto;
        height: auto;
        min-width: unset;
        border-radius: 0;
        padding: 0;
        background: transparent !important;
        box-shadow: none !important;
        gap: 4px;
        display: flex;
        align-items: center;
    }
    #connection-status::before { display: inline-block !important; }
    #connection-status::after {
        content: 'AIS';
        font-size: 10px;
        color: #7a8fa6;
    }
    /* When needs-key class is set, show full tap-to-connect prompt */
    #connection-status.needs-key {
        font-size: 10px;
        border-radius: 3px;
        padding: 2px 6px;
        background: #e74c3c !important;
        color: #fff;
        box-shadow: none !important;
    }
    #connection-status.needs-key::after { display: none; }

    #vessel-count { font-size: 11px; }
    #message-count { display: none; }

    /* === Layers button: visible on mobile, in status bar === */
    #layers-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-left: auto;
        background: rgba(100, 150, 200, 0.1);
        border: 1px solid rgba(100, 150, 200, 0.2);
        border-radius: 4px;
        color: #7a8fa6;
        cursor: pointer;
        transition: all 0.2s;
        /* Large by default (collapsed state) */
        min-width: 48px;
        min-height: 28px;
        font-size: 20px;
    }
    #layers-btn:active { background: rgba(100, 150, 200, 0.25); }

    /* When controls are open, make the button smaller */
    body.mobile-controls-open #layers-btn {
        min-width: 36px;
        min-height: 24px;
        font-size: 16px;
    }

    /* === Layers tray: 2 rows on mobile === */
    #layers-tray {
        position: fixed;
        bottom: 92px; /* 32px status + 60px forecast */
        left: 0;
        right: 0;
        z-index: 1003;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px;
        padding: 8px 10px;
        background: rgba(10, 22, 40, 0.95);
        backdrop-filter: blur(8px);
        border-top: 1px solid rgba(100, 150, 200, 0.15);
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    #layers-tray.hidden {
        transform: translateY(100%);
        opacity: 0;
        pointer-events: none;
    }

    #layers-tray button {
        font-size: 12px;
        padding: 6px 10px;
        height: 44px;
        flex: 1;
        text-align: center;
    }

    /* Download button: full-width top row */
    #layers-tray .timeline-dl-btn {
        flex: 0 0 100%;
    }

    /* Hide desktop NOW/calendar on mobile (mobile has its own forecast buttons) */
    #layers-tray .timeline-now-btn,
    #layers-tray .timeline-cal-btn {
        display: none;
    }

    /* === Forecast quick buttons: Row 2, above status bar === */
    #forecast-quick-btns {
        display: flex;
        position: fixed;
        bottom: 32px; /* above status bar */
        left: 0;
        right: 0;
        z-index: 1002;
        background: rgba(10, 22, 40, 0.95);
        backdrop-filter: blur(8px);
        border-top: 1px solid rgba(100, 150, 200, 0.15);
        justify-content: center;
        gap: 6px;
        padding: 8px 10px;
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    #forecast-quick-btns.hidden {
        transform: translateY(100%);
        opacity: 0;
        pointer-events: none;
    }

    .fcst-quick-btn {
        flex: 1;
        height: 44px;
        background: rgba(100, 100, 100, 0.2);
        border: 1px solid rgba(100, 100, 100, 0.3);
        border-radius: 3px;
        color: #7a8fa6;
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
        text-align: center;
    }

    .fcst-quick-btn:last-child {
        border-right: none;
    }

    .fcst-quick-btn:active {
        background: rgba(46, 204, 113, 0.3);
    }

    .fcst-now-btn.active {
        background: rgba(46, 204, 113, 0.2);
        border-color: rgba(46, 204, 113, 0.3);
        color: #2ecc71;
    }

    .fcst-hour-btn.active {
        background: rgba(232, 90, 180, 0.2);
        border-color: rgba(232, 90, 180, 0.3);
        color: #e85ab4;
    }

    .fcst-set-btn {
        font-size: 10px;
        letter-spacing: 0.3px;
    }

    .fcst-set-btn.active {
        background: rgba(232, 90, 180, 0.2);
        border-color: rgba(232, 90, 180, 0.3);
        color: #e85ab4;
    }

    /* === Hide Leaflet zoom controls on mobile (pinch to zoom) === */
    .leaflet-control-zoom {
        display: none !important;
    }

    /* === Leaflet layer switcher: offset for iPhone safe area === */
    .leaflet-top.leaflet-left {
        top: 44px !important;
        left: 44px !important;
    }

    /* === Hide panel toggle on mobile (use Vessels button instead) === */
    #panel-toggle {
        display: none !important;
    }

    /* === Panel: slides up from above the 3-row bar === */
    #panel {
        width: 100%;
        height: 30vh;
        top: auto;
        bottom: 120px; /* 32 + 44 + 44 */
        border-left: none;
        border-top: 1px solid rgba(100, 150, 200, 0.12);
    }

    #panel.collapsed {
        transform: translateY(100vh);
    }

    .vessel-toggle {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    /* === Legends: reposition above 3-row bar (32+44+44=120) === */
    #flow-legend { bottom: 126px; }
    #wind-legend { bottom: 210px; }

    /* When controls collapsed, move legends down */
    body:not(.mobile-controls-open) #flow-legend { bottom: 38px; }
    body:not(.mobile-controls-open) #wind-legend { bottom: 122px; }

    /* === Mobile vessel list === */
    .mobile-vessel-list {
        bottom: 206px; /* 92px forecast+status + ~110px 2-row tray + 4px gap */
    }

    body:not(.mobile-controls-open) .mobile-vessel-list {
        bottom: 32px;
    }

    /* === Leaflet controls: larger touch targets === */
    .leaflet-bar a {
        width: 44px !important;
        height: 44px !important;
        line-height: 44px !important;
        font-size: 20px !important;
    }

    /* === Time picker and offline download panels === */
    .time-picker-panel {
        bottom: 126px;
    }
    .offline-dl-panel {
        bottom: 126px;
    }
    body:not(.mobile-controls-open) .time-picker-panel {
        bottom: 38px;
    }
    body:not(.mobile-controls-open) .offline-dl-panel {
        bottom: 38px;
    }
}

/* === Sailing Dashboard === */

#tab-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    z-index: 1002;
    display: flex;
    align-items: center;
    background: rgba(10, 22, 40, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(100, 150, 200, 0.15);
    padding: 0 8px;
    gap: 4px;
}

.tab-btn {
    padding: 6px 16px;
    background: none;
    border: none;
    color: #8395a7;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    min-height: 40px;
}

.tab-btn.active {
    color: #3498db;
    border-bottom-color: #3498db;
}

.tab-btn:hover {
    color: #c8d6e5;
}

.nmea-status {
    margin-left: auto;
    font-size: 11px;
    color: #8395a7;
    padding: 0 8px;
}

.nmea-status.connected {
    color: #2ecc71;
}

.nmea-status.replaying {
    color: #f39c12;
}

.view-container {
    position: absolute;
    top: 40px;
    left: 0;
    right: 0;
    bottom: 0;
}

#charts-view {
    display: flex;
    flex-direction: column;
    background: #0a1628;
    overflow-y: auto;
}

#nmea-source-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(100, 150, 200, 0.1);
    flex-wrap: wrap;
    min-height: 36px;
}

.nmea-source-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

#nmea-ws-url {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(100, 150, 200, 0.2);
    color: #c8d6e5;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    width: 220px;
}

#nmea-connect-btn,
.nmea-file-label {
    background: rgba(52, 152, 219, 0.2);
    border: 1px solid rgba(52, 152, 219, 0.4);
    color: #3498db;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

#nmea-connect-btn:hover,
.nmea-file-label:hover {
    background: rgba(52, 152, 219, 0.3);
}

#nmea-connect-btn.connected {
    background: rgba(46, 204, 113, 0.2);
    border-color: rgba(46, 204, 113, 0.4);
    color: #2ecc71;
}

.nmea-file-label input[type="file"] {
    display: none;
}

.nmea-divider {
    color: #576574;
    font-size: 11px;
}

.nmea-replay-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nmea-replay-controls.hidden {
    display: none;
}

.replay-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(100, 150, 200, 0.2);
    color: #c8d6e5;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    min-width: 32px;
}

#replay-speed {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(100, 150, 200, 0.2);
    color: #c8d6e5;
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 12px;
}

#replay-progress {
    font-size: 11px;
    color: #8395a7;
    font-variant-numeric: tabular-nums;
}

#instrument-panel {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 10px 12px;
}

.instrument-gauge {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(100, 150, 200, 0.12);
    border-radius: 8px;
    padding: 10px 8px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.gauge-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #8395a7;
}

.gauge-value {
    font-size: 28px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #ecf0f1;
    line-height: 1.1;
}

.gauge-unit {
    font-size: 10px;
    color: #576574;
}

.gauge-value.twa-irons { color: #e74c3c; }
.gauge-value.twa-close { color: #f39c12; }
.gauge-value.twa-optimal { color: #2ecc71; }

#chart-controls {
    display: flex;
    gap: 4px;
    padding: 4px 12px;
}

.chart-window-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(100, 150, 200, 0.15);
    color: #8395a7;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
}

.chart-window-btn.active {
    background: rgba(52, 152, 219, 0.2);
    border-color: rgba(52, 152, 219, 0.4);
    color: #3498db;
}

#chart-area {
    flex: 1;
    min-height: 200px;
    padding: 4px 12px 12px;
    position: relative;
}

#sailing-chart {
    width: 100% !important;
    height: 100% !important;
}

/* Competitor labels */
.competitor-tooltip {
    background: rgba(10, 22, 40, 0.9) !important;
    border: 1px solid rgba(100, 150, 200, 0.2) !important;
    color: #c8d6e5 !important;
    padding: 4px 8px !important;
    border-radius: 4px !important;
    font-size: 11px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4) !important;
    cursor: pointer !important;
}

.competitor-tooltip::before {
    display: none !important;
}

.comp-name {
    font-weight: 600;
    font-size: 10px;
    color: #8395a7;
    margin-bottom: 2px;
}

.comp-stats {
    display: flex;
    gap: 8px;
    font-variant-numeric: tabular-nums;
    font-size: 11px;
}

@media (max-width: 600px) {
    #instrument-panel {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
        padding: 8px;
    }

    .gauge-value {
        font-size: 22px;
    }

    #nmea-source-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .nmea-source-controls {
        flex-direction: column;
    }

    #nmea-ws-url {
        width: 100%;
    }

    #chart-area {
        min-height: 180px;
    }

    .tab-btn {
        flex: 1;
        text-align: center;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    #instrument-panel {
        grid-template-columns: repeat(4, 1fr);
        gap: 4px;
        padding: 4px 8px;
    }

    .gauge-value {
        font-size: 20px;
    }

    .instrument-gauge {
        padding: 6px 4px;
    }
}
