:root {
    --bg: #09111d;
    --bg-deep: #050b14;
    --panel: rgba(11, 23, 39, 0.9);
    --panel-strong: #101f33;
    --panel-soft: #12263f;
    --border: rgba(114, 160, 212, 0.22);
    --border-strong: rgba(145, 191, 245, 0.34);
    --text: #ebf5ff;
    --muted: #92a8c6;
    --muted-strong: #b9c8dc;
    --accent: #4cd6a7;
    --accent-strong: #6df1bf;
    --warning: #f7b955;
    --danger: #ff7b72;
    --cool: #6cd4ff;
    --shadow: 0 28px 60px rgba(0, 0, 0, 0.35);
    --radius: 18px;
    --radius-sm: 12px;
    --focus: 0 0 0 3px rgba(108, 212, 255, 0.28);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    line-height: 1.5;
    font-family:
        "Segoe UI",
        "Helvetica Neue",
        Arial,
        sans-serif;
    background:
        radial-gradient(circle at top left, rgba(42, 94, 127, 0.3), transparent 28%),
        radial-gradient(circle at top right, rgba(60, 154, 128, 0.15), transparent 22%),
        linear-gradient(180deg, #07101c 0%, #09111d 45%, #060c13 100%);
}

a {
    color: inherit;
}

button,
input,
select {
    font: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.chip:focus-visible,
.button:focus-visible,
.species-card:focus-within,
.record-item:focus-within {
    outline: none;
    box-shadow: var(--focus);
}

.container {
    width: min(1400px, calc(100% - 32px));
    margin: 0 auto;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 9999;
    backdrop-filter: blur(16px);
    background: rgba(8, 15, 27, 0.88);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.brand img {
    width: 42px;
    height: 42px;
}

.brand strong {
    display: block;
    font-size: 1.1rem;
    letter-spacing: 0.02em;
}

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

.header-controls,
.toolbar,
.toolbar-inline,
.chip-row,
.metric-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.header-controls {
    align-items: end;
    justify-content: flex-end;
}

.control-stack {
    display: grid;
    gap: 5px;
}

.dashboard {
    padding: 24px 0 40px;
}

.section-gap {
    margin-top: 18px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 18px;
}

.span-3,
.span-4,
.span-5,
.span-6,
.span-7 {
    grid-column: span 12;
}

.panel {
    background:
        linear-gradient(180deg, rgba(17, 31, 51, 0.92), rgba(8, 18, 30, 0.96)),
        var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    position: relative;
    overflow: hidden;
}

.panel::before {
    content: "";
    position: absolute;
    inset: 0 auto auto 0;
    width: 180px;
    height: 1px;
    background: linear-gradient(90deg, rgba(108, 212, 255, 0.5), transparent);
}

.panel.compact {
    padding: 16px;
}

.section-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.section-head h1,
.section-head h2,
.status-panel-head h3 {
    margin: 0;
    font-weight: 650;
    line-height: 1.15;
}

.section-head h1 {
    font-size: clamp(1.65rem, 2.5vw, 2.25rem);
}

.section-head h2 {
    font-size: 1.35rem;
}

.input,
.button,
.chip {
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    background: rgba(10, 18, 30, 0.88);
}

.input {
    min-height: 40px;
    padding: 0 14px;
}

.input-compact {
    min-width: 150px;
}

.search-wide {
    flex: 1 1 260px;
}

.button,
.chip {
    min-height: 38px;
    padding: 0 14px;
    cursor: pointer;
    transition:
        border-color 120ms ease,
        background 120ms ease,
        transform 120ms ease;
}

.button:hover,
.chip:hover {
    border-color: var(--border-strong);
}

.button-subtle {
    background: rgba(9, 17, 29, 0.8);
}

.chip.is-active,
.button.is-active {
    background: linear-gradient(135deg, rgba(76, 214, 167, 0.2), rgba(108, 212, 255, 0.22));
    border-color: rgba(109, 241, 191, 0.34);
}

.source-line,
.summary-line,
.count-label {
    font-size: 0.84rem;
    color: var(--muted);
}

.map-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.75fr) minmax(320px, 0.9fr);
    gap: 16px;
}

.map-stage {
    position: relative;
    min-height: 560px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    background:
        radial-gradient(circle at 20% 20%, rgba(37, 94, 128, 0.35), transparent 22%),
        radial-gradient(circle at 80% 10%, rgba(51, 130, 88, 0.14), transparent 18%),
        #09111b;
}

.map-surface {
    width: 100%;
    height: 100%;
    min-height: 560px;
}

.leaflet-container {
    background: transparent;
    font-family: inherit;
}

.map-stage .leaflet-tile {
    filter: grayscale(0.75) saturate(0.6) brightness(0.75);
}

.map-stage.is-satellite .leaflet-tile {
    filter: none;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    background: #0c1522;
    color: var(--text);
    border: 1px solid var(--border);
}

.map-overlay {
    position: absolute;
    z-index: 500;
    display: grid;
    gap: 10px;
    max-width: min(260px, calc(100% - 24px));
    padding: 12px;
    border-radius: 16px;
    border: 1px solid rgba(145, 191, 245, 0.2);
    background: rgba(7, 13, 22, 0.84);
    backdrop-filter: blur(12px);
}

.map-stage.overlays-hidden .map-overlay {
    display: none;
}

.map-overlay.is-collapsed {
    gap: 0;
}

.map-overlay.is-collapsed .map-overlay-body {
    display: none;
}

.map-overlay-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.map-overlay.top-left {
    left: 12px;
    top: 12px;
}

.map-overlay.top-right {
    right: 12px;
    top: 12px;
}

.map-overlay.bottom-left {
    left: 12px;
    bottom: 12px;
}

.overlay-title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--muted);
}

.overlay-toggle {
    min-height: 28px;
    padding: 0 10px;
    border: 1px solid rgba(145, 191, 245, 0.2);
    border-radius: 999px;
    color: var(--muted-strong);
    background: rgba(10, 18, 30, 0.8);
    cursor: pointer;
}

.overlay-toggle:hover {
    border-color: var(--border-strong);
}

.map-overlay-body {
    display: grid;
    gap: 10px;
}

.legend-stack,
.map-summary-card,
.direction-list,
.stack-list,
.metric-stack,
.feed-list,
.subscore-list {
    display: grid;
    gap: 10px;
}

.legend-item,
.metric-item,
.stack-item,
.direction-item,
.feed-item,
.record-item,
.species-card,
.vital-card,
.impact-card,
.subscore-item {
    border: 1px solid rgba(145, 191, 245, 0.16);
    border-radius: 16px;
    background: rgba(12, 24, 38, 0.82);
}

.legend-item,
.stack-item,
.direction-item,
.metric-item {
    padding: 10px 12px;
}

.direction-item strong,
.stack-item strong,
.feed-item h3,
.record-item h4,
.species-card h3,
.vital-card h3,
.impact-card h3 {
    display: block;
    margin-bottom: 4px;
}

.side-rail {
    display: grid;
    gap: 16px;
}

.pulse-hero {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 18px;
    align-items: center;
}

.pulse-dial {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: conic-gradient(var(--accent) 0deg, rgba(255, 255, 255, 0.08) 0deg);
    box-shadow: inset 0 0 30px rgba(108, 212, 255, 0.12);
}

.pulse-core {
    width: 132px;
    height: 132px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    text-align: center;
    background:
        radial-gradient(circle at top, rgba(76, 214, 167, 0.08), transparent 45%),
        #09111d;
    border: 1px solid var(--border);
}

.pulse-score {
    font-size: 2.4rem;
    font-weight: 700;
    line-height: 1;
}

.pulse-label {
    font-size: 0.86rem;
    color: var(--muted-strong);
}

.lede {
    margin: 0 0 10px;
    color: var(--muted-strong);
}

.quality-pill,
.status-pill,
.signal-pill,
.count-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
    border: 1px solid rgba(145, 191, 245, 0.2);
    padding: 6px 10px;
    font-size: 0.8rem;
    color: var(--muted-strong);
    background: rgba(8, 15, 27, 0.85);
}

.count-badge {
    min-width: 28px;
    justify-content: center;
    color: var(--text);
}

.quality-pill::before,
.status-pill::before,
.signal-pill::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--cool);
}

.quality-high::before,
.status-improving::before {
    background: var(--accent);
}

.quality-medium::before,
.status-unstable::before {
    background: var(--warning);
}

.quality-low::before,
.status-critical::before,
.status-under-stress::before {
    background: var(--danger);
}

.vitals-grid,
.impact-grid,
.species-grid,
.status-grid {
    display: grid;
    gap: 16px;
}

.vitals-grid {
    grid-template-columns: repeat(12, minmax(0, 1fr));
}

.vital-card,
.impact-card {
    grid-column: span 12;
    padding: 16px;
    display: grid;
    gap: 12px;
}

.vital-header,
.impact-header,
.record-head,
.species-card-head,
.feed-head,
.status-panel-head,
.pager {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 10px;
}

.signal-row,
.micro-metrics,
.species-meta,
.record-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.signal-value {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.signal-value strong {
    font-size: 1.5rem;
    margin: 0;
}

.sparkline {
    width: 100%;
    height: 56px;
}

.sparkline-path {
    fill: none;
    stroke: var(--cool);
    stroke-width: 2.25;
}

.sparkline-fill {
    fill: url(#spark-fill);
    opacity: 0.18;
}

.sparkline-guide {
    stroke: rgba(146, 168, 198, 0.25);
    stroke-width: 1;
}

.impact-map {
    height: 170px;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid rgba(145, 191, 245, 0.16);
}

.metric-stack {
    height: 100%;
}

.metric-item strong {
    font-size: 1.55rem;
    font-weight: 700;
}

.record-list,
.feed-list,
.subscore-list {
    min-height: 80px;
}

.feed-item,
.record-item,
.species-card,
.subscore-item {
    padding: 14px;
}

.feed-item p,
.record-item p,
.species-card p {
    margin: 0;
    color: var(--muted-strong);
}

.species-card {
    display: grid;
    gap: 12px;
}

.species-card button,
.feed-item button,
.impact-card button,
.vital-card button {
    justify-self: start;
}

.species-grid {
    grid-template-columns: repeat(12, minmax(0, 1fr));
}

.status-grid {
    grid-template-columns: repeat(12, minmax(0, 1fr));
}

.status-panel {
    grid-column: span 12;
    display: grid;
    gap: 12px;
}

.status-panel-head {
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(145, 191, 245, 0.12);
}

.pager {
    align-items: center;
}

.empty-state {
    padding: 16px;
    border: 1px dashed rgba(145, 191, 245, 0.24);
    border-radius: 14px;
    color: var(--muted);
    text-align: center;
}

.site-footer {
    margin-top: 28px;
    padding: 22px 16px 30px;
    text-align: center;
    font-size: 0.84rem;
    color: var(--muted);
    border-top: 1px solid var(--border);
}

.detail-drawer {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 100;
}

.detail-drawer.is-open {
    display: block;
}

.drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(3, 7, 12, 0.6);
}

.drawer-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: min(520px, 100%);
    height: 100%;
    background:
        linear-gradient(180deg, rgba(15, 27, 43, 0.98), rgba(8, 15, 27, 1)),
        #08101a;
    border-left: 1px solid var(--border);
    box-shadow: -28px 0 60px rgba(0, 0, 0, 0.32);
    padding: 18px;
    overflow-y: auto;
}

.drawer-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.drawer-body {
    display: grid;
    gap: 14px;
}

.drawer-section {
    display: grid;
    gap: 8px;
    padding: 14px;
    border-radius: 16px;
    border: 1px solid rgba(145, 191, 245, 0.16);
    background: rgba(10, 18, 30, 0.82);
}

.drawer-section h3,
.drawer-section h4 {
    margin: 0;
}

.drawer-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tone-positive {
    color: var(--accent-strong);
}

.tone-warning {
    color: var(--warning);
}

.tone-negative {
    color: var(--danger);
}

.tone-muted {
    color: var(--muted);
}

@media (min-width: 780px) {
    .span-3 {
        grid-column: span 3;
    }

    .span-4 {
        grid-column: span 4;
    }

    .span-5 {
        grid-column: span 5;
    }

    .span-6 {
        grid-column: span 6;
    }

    .span-7 {
        grid-column: span 7;
    }

    .vital-card {
        grid-column: span 6;
    }

    .impact-card,
    .species-card {
        grid-column: span 4;
    }

    .status-panel {
        grid-column: span 6;
    }
}

@media (max-width: 1100px) {
    .map-layout {
        grid-template-columns: 1fr;
    }

    .side-rail {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 820px) {
    .header-inner,
    .pulse-hero,
    .section-head,
    .status-panel-head,
    .feed-head,
    .species-card-head,
    .record-head {
        grid-template-columns: 1fr;
        display: grid;
    }

    .pulse-hero {
        justify-items: start;
    }

    .pulse-dial {
        width: 154px;
        height: 154px;
    }

    .pulse-core {
        width: 112px;
        height: 112px;
    }

    .side-rail {
        grid-template-columns: 1fr;
    }

    .drawer-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .container {
        width: min(100% - 20px, 1400px);
    }

    .dashboard {
        padding-top: 16px;
    }

    .panel,
    .drawer-panel {
        padding: 16px;
    }

    .map-stage,
    .map-surface {
        min-height: 440px;
    }

    .map-overlay {
        max-width: calc(100% - 20px);
    }

    .map-overlay.top-right {
        top: auto;
        bottom: 12px;
        right: 12px;
    }

    .map-overlay.bottom-left {
        left: 12px;
        right: 12px;
        bottom: 12px;
    }

    .input,
    .button,
    .chip {
        width: 100%;
    }

    .toolbar-inline .input {
        width: auto;
    }
}
