/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif; background: #0f172a; color: #e2e8f0; }

/* ===== Header ===== */
.app-header {
    display: grid;
    grid-template-columns: minmax(220px, 320px) 1fr minmax(250px, 320px);
    align-items: center;
    padding: .55rem 1rem;
    min-height: 68px;
    margin: 4px 4px 0;
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.98), rgba(23, 34, 52, 0.98));
    border: 1px solid rgba(100, 116, 139, 0.26);
    border-radius: 10px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03), 0 10px 24px rgba(2, 6, 23, 0.16);
    gap: 1rem;
}
.app-header h1 {
    font-size: 1rem;
    font-weight: 600;
    color: #38bdf8;
    letter-spacing: .02em;
    flex: 1;
    text-align: center;
}
.header-panel {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-width: 0;
}
.header-panel--left {
    min-width: 0;
}
.header-panel--right {
    min-width: 0;
    justify-content: flex-end;
}
.header-field {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #94a3b8;
    white-space: nowrap;
}
.header-status { display: flex; align-items: center; gap: .5rem; font-size: .8rem; color: #94a3b8; white-space: nowrap; }
.tile-status-message--header {
    margin-top: 0;
    padding: .35rem .55rem;
    font-size: .72rem;
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.control-select--header {
    min-width: 180px;
    max-width: 220px;
    flex: 0 0 220px;
    padding: .42rem 2.2rem .42rem .8rem;
    border-radius: 999px;
    border-color: rgba(100, 116, 139, 0.46);
    background-color: rgba(15, 23, 42, 0.72);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
.spinner { width: 14px; height: 14px; border: 2px solid #475569; border-top-color: #38bdf8; border-radius: 50%; animation: spin .6s linear infinite; }
.hidden { display: none !important; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Layout ===== */
.app-layout { display: flex; height: calc(100vh - 76px); overflow: hidden; }

.hidden-navigation-controls {
    display: none;
}
.control-help {
    margin-top: .3rem;
    font-size: .68rem;
    line-height: 1.4;
    color: #64748b;
}
.control-select {
    width: 100%; padding: .35rem 2rem .35rem .5rem; font-size: .8rem;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: #1e293b;
    background-image:
        linear-gradient(45deg, transparent 50%, #94a3b8 50%),
        linear-gradient(135deg, #94a3b8 50%, transparent 50%);
    background-position:
        calc(100% - 15px) calc(50% - 2px),
        calc(100% - 9px) calc(50% - 2px);
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    color: #e2e8f0;
    border: 1px solid #334155;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.control-select:focus {
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14);
}
.control-select:hover:not(:disabled) {
    background-color: #243247;
    border-color: rgba(100, 116, 139, 0.82);
}
.control-select:disabled { opacity: .5; cursor: not-allowed; }
.control-select::-ms-expand { display: none; }
.btn-primary {
    width: 100%; padding: .5rem; margin-top: .5rem; font-size: .8rem; font-weight: 600;
    background: #0ea5e9; color: #fff; border: none; border-radius: 4px; cursor: pointer;
    transition: background .15s;
}
.btn-primary:hover:not(:disabled) { background: #0284c7; }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-small {
    padding: .3rem .7rem; font-size: .75rem; font-weight: 500;
    background: #475569; color: #e2e8f0; border: none; border-radius: 4px; cursor: pointer;
}
.btn-small:hover { background: #64748b; }
.btn-small:disabled {
    opacity: .45;
    cursor: not-allowed;
    background: #334155;
}
.tile-status-message {
    margin-top: .35rem;
    padding: .55rem .7rem;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.85);
    color: #e2e8f0;
    font-size: .78rem;
    line-height: 1.4;
    border: 1px solid rgba(56, 189, 248, 0.35);
    display: none;
}
.tile-status-message.is-error {
    border-color: rgba(248, 113, 113, 0.6);
    color: #fecaca;
}

/* ===== Main content ===== */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.filter-group {
    min-width: 0;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.95), rgba(15, 23, 42, 0.72));
    border: 1px solid rgba(71, 85, 105, 0.7);
    border-radius: 16px;
    padding: .95rem 1rem 1rem;
    box-shadow: 0 16px 30px rgba(2, 6, 23, 0.2);
}
.filter-card-summary {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem;
    margin-top: 0;
}
.filter-range-pill,
.filter-meta-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: .28rem .7rem;
    border-radius: 999px;
    font-size: .74rem;
}
.filter-range-pill {
    background: rgba(56, 189, 248, 0.15);
    color: #e0f2fe;
    border: 1px solid rgba(56, 189, 248, 0.25);
}
.filter-meta-pill {
    background: rgba(30, 41, 59, 0.85);
    color: #94a3b8;
    border: 1px solid rgba(71, 85, 105, 0.65);
}
.noui-slider-container { margin-top: .75rem; margin-bottom: .75rem; }
.filter-presets {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem;
}
.filter-presets-row {
    display: flex;
    align-items: center;
    gap: .45rem;
    flex-wrap: wrap;
}
.filter-preset-btn {
    border: 1px solid rgba(71, 85, 105, 0.7);
    background: rgba(30, 41, 59, 0.8);
    color: #cbd5e1;
    border-radius: 999px;
    font-size: .72rem;
    padding: .35rem .7rem;
    cursor: pointer;
}
.filter-preset-btn:hover {
    border-color: #38bdf8;
    color: #ffffff;
    background: rgba(14, 165, 233, 0.18);
}
.filter-preset-label {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    cursor: default;
    color: #e0f2fe;
    border-color: rgba(56, 189, 248, 0.32);
    background: rgba(14, 165, 233, 0.18);
    pointer-events: none;
}

/* noUiSlider theme overrides */
.noUi-target {
    background: linear-gradient(90deg, rgba(30, 41, 59, 0.85), rgba(51, 65, 85, 0.95));
    border: 1px solid rgba(71, 85, 105, 0.8);
    height: 10px;
    border-radius: 999px;
    box-shadow: inset 0 1px 3px rgba(2, 6, 23, 0.35);
}
.noUi-connect {
    background: linear-gradient(90deg, #0ea5e9 0%, #22d3ee 100%);
}
.noUi-handle {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #f8fafc;
    border: 3px solid #0ea5e9;
    top: -6px;
    right: -10px;
    box-shadow: 0 8px 18px rgba(14, 165, 233, 0.3);
    cursor: grab;
}
.noUi-handle::before, .noUi-handle::after { display: none; }

.inspector-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 1rem;
    background: rgba(15, 23, 42, 0.94);
    border-bottom: 1px solid #334155;
}
.inspector-copy {
    display: flex;
    flex-direction: column;
    gap: .2rem;
}
.inspector-kicker {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: #f59e0b;
}
.inspector-label {
    font-size: .82rem;
    color: #e2e8f0;
}

/* ===== Viz grid ===== */
.viz-grid {
    display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
    gap: 4px; padding: 4px; flex: 1; overflow: hidden;
}
.viz-panel {
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.98), rgba(23, 34, 52, 0.98));
    border: 1px solid rgba(100, 116, 139, 0.26);
    border-radius: 10px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03), 0 10px 24px rgba(2, 6, 23, 0.16);
    overflow: hidden;
    display: flex; flex-direction: column; position: relative;
}
.viz-title {
    padding: .4rem .7rem; font-size: .75rem; font-weight: 600;
    color: #94a3b8; background: rgba(15,23,42,.54); border-bottom: 1px solid rgba(100, 116, 139, 0.22);
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.viz-title-text { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.viz-actions { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.viz-control-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: .28rem .65rem;
    border-radius: 999px;
    background: rgba(30, 41, 59, 0.88);
    border: 1px solid rgba(71, 85, 105, 0.7);
    color: #e2e8f0;
    font-size: .72rem;
    white-space: nowrap;
}
.viz-control-chip--strategy {
    min-width: 70px;
    font-weight: 700;
    letter-spacing: .04em;
}
.viz-control-chip--strategy.is-dense {
    border-color: rgba(34, 197, 94, 0.45);
    color: #bbf7d0;
    background: rgba(20, 83, 45, 0.22);
}
.viz-control-chip--strategy.is-sparse {
    border-color: rgba(56, 189, 248, 0.45);
    color: #bae6fd;
    background: rgba(7, 89, 133, 0.24);
}
.tile-step-btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}
.tile-step-btn i {
    font-size: .8rem;
}
.export-btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}
.export-btn i {
    font-size: .78rem;
}
.viz-hint { font-weight: 400; font-size: .65rem; color: #475569; }
.viz-context { font-weight: 400; font-size: .68rem; color: #64748b; }
#map-container { flex: 1; min-height: 0; }
.chart-stage {
    flex: 1;
    min-height: 0;
    padding: .5rem;
    position: relative;
}
.chart-stage canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}
.depth-profile-layout {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: stretch;
    gap: .25rem;
    padding: .45rem .45rem .45rem .3rem;
}
.depth-profile-layout .chart-stage {
    padding: .15rem .15rem .15rem .25rem;
}
.panel-filter {
    margin: 0 .55rem .45rem;
    padding: .45rem .95rem .55rem;
    border-radius: 10px;
    box-shadow: none;
}
.panel-filter .filter-card-summary {
    gap: .35rem;
}
.panel-filter .filter-range-pill,
.panel-filter .filter-meta-pill {
    min-height: 24px;
    padding: .16rem .55rem;
    font-size: .68rem;
}
.panel-filter .noui-slider-container {
    margin-top: .45rem;
    margin-bottom: .45rem;
    margin-left: .2rem;
    margin-right: .2rem;
}
.panel-filter .noUi-target {
    height: 8px;
}
.panel-filter .noUi-handle {
    width: 18px;
    height: 18px;
    top: -6px;
    right: -9px;
}
.panel-filter .filter-presets {
    gap: .3rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
}
.panel-filter .filter-presets::-webkit-scrollbar {
    display: none;
}
.panel-filter .filter-preset-btn {
    font-size: .66rem;
    line-height: 1;
    padding: .22rem .5rem;
    white-space: nowrap;
}
.panel-filter--vertical {
    --depth-slider-track-width: 7px;
    --depth-slider-handle-size: 16px;
    width: 74px;
    min-width: 74px;
    margin: 0;
    padding: .4rem .22rem .35rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .28rem;
    border-radius: 12px;
}
.panel-filter--vertical .filter-card-summary {
    justify-content: center;
    width: 100%;
}
.panel-filter--vertical .filter-range-pill {
    text-align: center;
    justify-content: center;
    line-height: 1.3;
    width: 100%;
    min-height: 42px;
    padding: .22rem .25rem;
    font-size: .62rem;
    white-space: normal;
}
#depth-filter.noui-slider-container--vertical.noUi-target {
    flex: 1;
    width: var(--depth-slider-track-width);
    min-height: 220px;
    height: 100%;
    margin: .45rem 0 .55rem;
    padding: 0;
    align-self: center;
    border: none;
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.96), rgba(51, 65, 85, 0.92));
    box-shadow: inset 0 0 0 1px rgba(71, 85, 105, 0.55);
}
#depth-filter.noui-slider-container--vertical.noUi-target.noUi-vertical {
    width: var(--depth-slider-track-width);
}
#depth-filter.noui-slider-container--vertical.noUi-target .noUi-base,
#depth-filter.noui-slider-container--vertical.noUi-target .noUi-connects,
#depth-filter.noui-slider-container--vertical.noUi-target .noUi-connect {
    width: 100%;
}
#depth-filter.noui-slider-container--vertical.noUi-target .noUi-connect {
    background: linear-gradient(180deg, #0ea5e9 0%, #22d3ee 100%);
}
#depth-filter.noui-slider-container--vertical.noUi-target .noUi-handle {
    width: var(--depth-slider-handle-size);
    height: var(--depth-slider-handle-size);
    top: auto;
    right: calc((var(--depth-slider-track-width) - var(--depth-slider-handle-size)) / 2);
    bottom: calc(var(--depth-slider-handle-size) / -2);
}
.filter-presets--vertical {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    overflow: visible;
    padding-bottom: 0;
}
.filter-presets--vertical .filter-preset-btn {
    flex: 0 0 auto;
    text-align: center;
    min-width: 52px;
}
.viz-panel.is-loading { overflow: hidden; }
.viz-panel.is-loading::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.48);
    z-index: 4;
}
.viz-panel.is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(148, 163, 184, 0.12) 45%, transparent 100%);
    transform: translateX(-100%);
    animation: skeleton-wave 1.2s linear infinite;
    z-index: 5;
}
@keyframes skeleton-wave {
    to { transform: translateX(100%); }
}

/* ===== Empty state ===== */
.empty-state {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: #475569; text-align: center; gap: .5rem;
}
.empty-icon { font-size: 3rem; }
.empty-state h2 { font-size: 1.2rem; color: #64748b; }
.empty-state p { font-size: .85rem; max-width: 400px; }

/* ===== Leaflet bbox selection ===== */
.leaflet-bbox-selection { border: 2px dashed #38bdf8; background: rgba(56,189,248,.12); }
.map-hover-tooltip {
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid #334155;
    color: #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 8px 20px rgba(2, 6, 23, 0.35);
    padding: .35rem .45rem;
}
.map-hover-tooltip:before { border-top-color: rgba(15, 23, 42, 0.92); }
.leaflet-control-layers {
    background: rgba(15, 23, 42, 0.92);
    color: #e2e8f0;
    border: 1px solid #334155;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(2, 6, 23, 0.35);
}
.leaflet-control-layers label {
    color: #e2e8f0;
}
.leaflet-control-layers-expanded {
    padding: .5rem .65rem;
}
.leaflet-control-layers-toggle {
    filter: brightness(1.3) contrast(1.1);
}
.leaflet-top.leaflet-left .leaflet-control {
    margin-left: 10px;
}
.leaflet-control-zoom,
.leaflet-draw,
.reset-zoom-control {
    margin-top: 10px;
}
.reset-zoom-control__button {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: #000;
    border: none;
    border-radius: 0;
    cursor: pointer;
    box-shadow: none;
    appearance: none;
    font-size: 16px;
}
.reset-zoom-control__button:hover {
    background: #f4f4f4;
}
.reset-zoom-control__button:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: 2px;
}
.reset-zoom-control__button i {
    font-size: .95rem;
}
.leaflet-container .leaflet-overlay-pane svg,
.leaflet-container .leaflet-overlay-pane svg path,
.leaflet-container .leaflet-overlay-pane svg rect {
    pointer-events: auto;
}
.leaflet-container .leaflet-interactive {
    stroke: #38bdf8;
    stroke-opacity: 1;
    stroke-width: 2.5;
    fill: rgba(56, 189, 248, 0.16);
    fill-opacity: 1;
}
.leaflet-draw-guide-dash {
    stroke: #38bdf8;
    stroke-opacity: 0.95;
    stroke-width: 2;
}
.leaflet-overlay-pane .leaflet-draw-guides,
.leaflet-overlay-pane .leaflet-draw-guide,
.leaflet-overlay-pane .leaflet-draw-guide-dash,
.leaflet-overlay-pane .leaflet-draw-shape,
.leaflet-overlay-pane .leaflet-draw-polyline,
.leaflet-overlay-pane .leaflet-draw-polygon {
    stroke: #38bdf8 !important;
    stroke-opacity: 1 !important;
    stroke-width: 2.5 !important;
}
.leaflet-overlay-pane .leaflet-draw-shape {
    fill: rgba(56, 189, 248, 0.16) !important;
    fill-opacity: 1 !important;
}
.leaflet-draw-toolbar,
.leaflet-draw-actions {
    border: none;
    box-shadow: 0 12px 24px rgba(2, 6, 23, 0.32);
}
.leaflet-draw-toolbar a,
.leaflet-draw-actions a {
    width: 40px;
    height: 40px;
    line-height: 40px;
    background-color: rgba(15, 23, 42, 0.96);
    color: #e2e8f0;
    border: 1px solid #334155;
    border-bottom-color: #334155;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}
.leaflet-draw-toolbar a:hover,
.leaflet-draw-actions a:hover {
    background-color: #1e293b;
    border-color: #38bdf8;
}
.leaflet-draw-toolbar a:first-child {
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}
.leaflet-draw-toolbar a:last-child {
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
}
.leaflet-draw-actions {
    margin-left: 10px;
}
.leaflet-draw-actions li:first-child a {
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}
.leaflet-draw-actions li:last-child a {
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
}
.leaflet-draw-actions a {
    width: auto;
    min-width: 96px;
    padding: 0 14px;
    line-height: 38px;
    font-size: .78rem;
    font-weight: 600;
    text-decoration: none;
}
.reset-zoom-control__button {
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
}
.leaflet-draw-toolbar .leaflet-draw-draw-rectangle {
    background-position: 50% 50%;
}
.leaflet-draw-toolbar .leaflet-disabled {
    opacity: 0.45;
}
.leaflet-draw-tooltip {
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid #334155;
    border-radius: 8px;
    color: #e2e8f0;
    box-shadow: 0 10px 24px rgba(2, 6, 23, 0.35);
}
.leaflet-draw-tooltip:before {
    border-right-color: rgba(15, 23, 42, 0.95);
}
.leaflet-error-draw-tooltip {
    background: rgba(127, 29, 29, 0.96);
    border-color: rgba(248, 113, 113, 0.75);
}
.leaflet-error-draw-tooltip:before {
    border-right-color: rgba(127, 29, 29, 0.96);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0f172a; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ===== Color legend ===== */
.color-legend {
    position: absolute; bottom: 24px; right: 10px; z-index: 500;
    background: rgba(15,23,42,.85); border-radius: 4px; padding: 6px 8px;
    font-size: .65rem; color: #94a3b8; backdrop-filter: blur(4px);
    min-width: 172px;
}
.color-legend canvas { display: block; border-radius: 2px; margin-bottom: 3px; }
.legend-labels { display: flex; justify-content: space-between; }

@media (max-width: 1200px) {
    .filters-bar {
        grid-template-columns: repeat(2, minmax(220px, 1fr));
    }
}

@media (max-width: 800px) {
    .filters-bar {
        grid-template-columns: 1fr;
    }

    .viz-grid {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(4, minmax(220px, 1fr));
    }

    .viz-title {
        align-items: flex-start;
        flex-direction: column;
    }

    .inspector-bar {
        align-items: flex-start;
        flex-direction: column;
    }

    .panel-filter--vertical {
        width: 70px;
        min-width: 70px;
    }

    .panel-filter--vertical .filter-card-summary {
        justify-content: center;
    }

    .panel-filter--vertical .filter-range-pill {
        justify-content: center;
        text-align: center;
    }

    #depth-filter.noui-slider-container--vertical.noUi-target {
        min-height: 140px;
    }

    .filter-presets--vertical .filter-preset-btn {
        flex: 0 0 auto;
    }

    .panel-filter .filter-presets {
        flex-wrap: wrap;
        overflow-x: visible;
    }
}
