:root {
    --bg: #05070d;
    --bg-side: #060911;
    --bg-panel: #0a0f1a;
    --bg-card: #0d1421;
    --bg-elevated: #141d2e;
    --border: #1c2537;
    --text: #e6eaf1;
    --text-muted: #6b7893;
    --accent: #22d3ee;
    --accent-hover: #06b6d4;
    --accent-soft: rgba(34, 211, 238, 0.10);
    --ok: #34d399;
    --warn: #fb923c;
    --danger: #f87171;
    --violet: #a78bfa;
}

* { box-sizing: border-box; }

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

#shell {
    display: flex;
    height: 100vh;
}

/* ---------------- Sidebar ---------------- */
#sidenav {
    width: 240px;
    background: var(--bg-side);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.15s ease;
}

#sidenav.collapsed {
    width: 68px;
}

#sidenav.collapsed .brand-text,
#sidenav.collapsed .nav-label,
#sidenav.collapsed .nav-badge {
    display: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    flex-shrink: 0;
}

.brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-icon svg { width: 18px; height: 18px; }

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.brand-mark {
    font-size: 0.68rem;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.brand-sub {
    font-size: 0.92rem;
    font-weight: 700;
}

.side-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px;
    flex: 1;
}

.side-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    position: relative;
}

.side-nav a:hover {
    background: var(--bg-elevated);
    color: var(--text);
}

.side-nav a.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: flex;
}

.nav-icon svg { width: 100%; height: 100%; }

.nav-label { flex: 1; }

.nav-badge {
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 6px;
}

#collapse-btn {
    margin: 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 6px;
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#collapse-btn svg { width: 16px; height: 16px; }

/* ---------------- Main column ---------------- */
#main-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 14px;
}

.status-title {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.status-eyebrow {
    font-size: 0.66rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.09em;
}

.status-heading {
    font-size: 1.05rem;
    font-weight: 700;
}

.topbar-readouts {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.plain-readout {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.2;
}

.readout-label {
    font-size: 0.62rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.readout-value {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.88rem;
    font-weight: 600;
}

.readout-value.accent { color: var(--accent); }

.pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-card);
}

.pill svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.pill-ok svg, .pill-ok .pill-value { color: var(--ok); }

.pill-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.pill-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pill-value {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.icon-btn {
    position: relative;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn svg { width: 16px; height: 16px; }

.icon-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--danger);
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #03141a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* ---------------- Page content ---------------- */
#page-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.page-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 24px;
}

.page-header { padding: 0 0 16px; flex-shrink: 0; }
.full-bleed .page-header { padding: 16px 16px 10px; }

.page-eyebrow {
    display: block;
    font-size: 0.7rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 4px;
}

.page-header h1 { margin: 0 0 6px; font-size: 1.4rem; }

.page-description {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.86rem;
    max-width: 640px;
}

#app.full-bleed {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* ---------------- Dashboard card grid ---------------- */
.dcard-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    align-items: start;
}

.dcard-grid .span-2 { grid-column: span 2; }

@media (max-width: 1100px) {
    .dcard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dcard-grid .span-2 { grid-column: span 2; }
}
@media (max-width: 640px) {
    .dcard-grid { grid-template-columns: 1fr; }
    .dcard-grid .span-2 { grid-column: span 1; }
}

.dcard {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
}

.dcard-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.card-badge {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid rgba(34,211,238,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.dcard-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.dcard-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.dcard-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.dcard-tab {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
}

.dcard-tab.active {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: rgba(34,211,238,0.35);
}

/* Metric rows with sparkline (Environmental Overview style) */
.metric-row {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.metric-row:last-child { border-bottom: none; }

.metric-row-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.metric-value {
    font-size: 1.25rem;
    font-weight: 700;
}

.metric-unit {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 3px;
}

.sparkline-mini { display: block; width: 100%; height: 32px; margin-top: 6px; }

/* Layer checklist */
.layer-check-list { display: flex; flex-direction: column; gap: 2px; }

.layer-check {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 4px;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border);
}

.layer-check:last-child { border-bottom: none; }

.layer-check input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.layer-check .layer-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layer-check svg {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Stat strip (bottom row of the big command-center card) */
.stat-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.stat-strip .stat-label {
    font-size: 0.62rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: block;
    margin-bottom: 3px;
}

.stat-strip .stat-value {
    font-size: 0.95rem;
    font-weight: 700;
}

/* Mini live map preview (Dashboard card 1) */
.map-preview {
    height: 260px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.map-preview-cta {
    display: inline-block;
    margin-top: 10px;
    font-size: 0.78rem;
    color: var(--accent);
    text-decoration: none;
}

.map-preview-cta:hover { color: var(--accent-hover); }

/* Legend chip row */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 10px; }

.chip {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.chip-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ---------------- Coming-soon ---------------- */
.coming-soon { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.coming-soon-icon { font-size: 2rem; color: var(--accent); margin-bottom: 12px; }
.coming-soon h2 { color: var(--text); font-size: 1.1rem; margin: 0 0 8px; }

/* ---------------- Ocean Map page (toolbar / map / sidebar) ---------------- */
#toolbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 10px 16px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.toolbar-group { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.toolbar-group label { color: var(--text-muted); }

.toolbar-group select,
.toolbar-group input[type="date"] {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 8px;
    font-size: 0.85rem;
    color-scheme: dark;
}

.legend { margin-left: auto; }

.legend img {
    height: 26px;
    background: #0f172a;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px;
}

#body { flex: 1; display: flex; min-height: 0; }
#map { flex: 1; background: var(--bg); }

/* Dark-theme filter for the base OpenStreetMap layer only (keyless,
   since CARTO's own dark tiles now require an API key). Leaflet's
   `className` option scopes this to just that layer's <img> tiles —
   the Copernicus overlay on top is unaffected. */
.leaflet-tile.basemap-dark {
    filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9) saturate(0.7);
}

#sidebar {
    width: 420px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    background: var(--bg-panel);
    z-index: 5;
}

.tab-btn {
    flex: 1;
    padding: 12px 8px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.panel { display: none; padding: 16px; }
.panel.active { display: block; }

.hint { color: var(--text-muted); font-size: 0.85rem; line-height: 1.4; }

.variable-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 16px;
}

.variable-card h3 {
    font-size: 0.9rem;
    margin: 0 0 2px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.variable-card .unit-tag {
    font-size: 0.7rem;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 1px 6px;
    border-radius: 999px;
}

.chart-sub-heading {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 14px 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Small summary stat boxes (used on Alerts and other list pages) */
.kpi-row {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 18px;
    min-width: 140px;
}

.kpi-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.kpi-value {
    display: block;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
}

.status-ok { color: var(--ok) !important; }

.now-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    margin: 4px 0 6px;
}

.primary-btn {
    margin-top: 10px;
    background: var(--accent);
    color: #03141a;
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
}

.primary-btn:hover { background: var(--accent-hover); }

.primary-btn:disabled { background: #26324a; color: var(--text-muted); cursor: not-allowed; }

.save-status { margin-top: 6px; font-size: 0.78rem; color: var(--text-muted); }

#saved-list { list-style: none; padding: 0; margin: 12px 0 0; }

#saved-list li {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    background: var(--bg-card);
    font-size: 0.85rem;
    transition: border-color 0.15s;
}

#saved-list li:hover { border-color: var(--accent); }
#saved-list li .loc-coords { font-weight: 600; color: var(--text); }
#saved-list li .loc-meta { color: var(--text-muted); font-size: 0.75rem; margin-top: 2px; }

.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--bg-elevated); color: var(--text); }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-muted); }

/* ---------------- Weather strip (below the map) ---------------- */
#weather-strip {
    flex-shrink: 0;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    padding: 10px 16px 14px;
}

.weather-strip-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 8px;
}

.weather-tiles {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.weather-tile {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    min-width: 108px;
    flex-shrink: 0;
}

.weather-tile .wt-label {
    display: block;
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
    white-space: nowrap;
}

.weather-tile .wt-value {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

.weather-tile .wt-value .wt-unit {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 2px;
}

.weather-tile.wt-marine .wt-value { color: var(--accent); }
.weather-tile.wt-wind .wt-value { color: var(--warn); }

/* ---------------- Nav cards (unused now but kept for compat) ---------------- */
.nav-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px;
    text-decoration: none;
    color: var(--text);
}
.nav-card h3 { margin: 0 0 6px; font-size: 1rem; color: var(--accent); }
.nav-card p { margin: 0; font-size: 0.82rem; color: var(--text-muted); line-height: 1.4; }
