:root {
    --bg: #080a0f;
    --surface: rgba(19, 22, 29, 0.92);
    --surface-strong: rgba(25, 29, 37, 0.98);
    --surface-soft: rgba(255, 255, 255, 0.045);
    --line: rgba(255, 255, 255, 0.12);
    --line-strong: rgba(255, 255, 255, 0.18);
    --text: #f4f7fb;
    --muted: #9ba6b5;
    --blue: #42c7ff;
    --green: #41d69d;
    --amber: #f2b84b;
    --orange: #ff8a4c;
    --red: #ff5f73;
    --violet: #9b8cff;
    --cold: #7aa7ff;
    --shadow: 0 22px 50px rgba(0, 0, 0, 0.38);
    --radius: 8px;
    --font-ui: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

:root[data-theme="light"] {
    --bg: #f5f7fb;
    --surface: rgba(255, 255, 255, 0.90);
    --surface-strong: rgba(255, 255, 255, 0.98);
    --surface-soft: rgba(15, 23, 42, 0.045);
    --line: rgba(15, 23, 42, 0.12);
    --line-strong: rgba(15, 23, 42, 0.18);
    --text: #111827;
    --muted: #64748b;
    --blue: #0284c7;
    --green: #059669;
    --amber: #b7791f;
    --orange: #ea580c;
    --red: #e11d48;
    --violet: #6d5dfc;
    --cold: #2563eb;
    --shadow: 0 22px 50px rgba(15, 23, 42, 0.10);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    font-family: var(--font-ui);
    background:
        linear-gradient(180deg, rgba(66, 199, 255, 0.10), transparent 34rem),
        linear-gradient(135deg, #080a0f 0%, #10121a 48%, #080a0f 100%);
}

:root[data-theme="light"] body {
    background:
        linear-gradient(180deg, rgba(2, 132, 199, 0.12), transparent 34rem),
        linear-gradient(135deg, #f8fafc 0%, #eef4fb 52%, #f5f7fb 100%);
}

body.is-fetching {
    cursor: progress;
}

a {
    color: inherit;
}

button,
input {
    font: inherit;
}

.app-shell {
    width: min(1600px, calc(100% - 28px));
    margin: 0 auto;
    padding: 20px 0 42px;
}

.hero-panel,
.panel,
.metric-card,
.empty-state,
.loading-panel {
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.hero-panel {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 18px;
    padding: 18px;
    border-radius: var(--radius);
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 280px;
}

.brand-mark {
    display: grid;
    place-items: center;
    flex: 0 0 58px;
    width: 58px;
    height: 58px;
    border-radius: var(--radius);
    border: 1px solid rgba(66, 199, 255, 0.34);
    background: linear-gradient(145deg, rgba(66, 199, 255, 0.20), rgba(65, 214, 157, 0.10));
    color: var(--blue);
    font-size: 1.35rem;
}

.eyebrow {
    color: var(--blue);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    margin-top: 3px;
    font-size: clamp(1.5rem, 2.8vw, 2.35rem);
    line-height: 1.02;
    letter-spacing: 0;
}

.hero-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 9px;
    color: var(--muted);
    font-size: 0.92rem;
}

.hero-meta strong {
    color: var(--text);
    font-weight: 700;
}

.hero-meta--warning {
    color: #ffd2a8;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--green);
    box-shadow: 0 0 0 5px rgba(65, 214, 157, 0.14);
}

.live-dot--warning {
    background: var(--orange);
    box-shadow: 0 0 0 5px rgba(255, 138, 76, 0.14);
}

.quick-filters {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.theme-actions {
    display: flex;
    align-items: center;
}

.theme-toggle {
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.segmented,
.date-form {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius);
    padding: 5px;
}

.segment,
.date-form button {
    min-height: 36px;
    border: 0;
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 10px;
    cursor: pointer;
    background: transparent;
    transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.segment:hover,
.date-form button:hover,
.segment.is-active {
    color: var(--text);
    background: rgba(66, 199, 255, 0.14);
}

.date-form label {
    display: grid;
    gap: 2px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.date-form input {
    width: 136px;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    background: rgba(0, 0, 0, 0.22);
    padding: 0 9px;
    color-scheme: dark;
}

:root[data-theme="light"] .date-form input {
    background: rgba(255, 255, 255, 0.70);
    color-scheme: light;
}

.date-form button {
    border: 1px solid rgba(66, 199, 255, 0.34);
    background: rgba(66, 199, 255, 0.10);
    color: var(--text);
}

.content-grid {
    display: grid;
    gap: 16px;
    margin-top: 16px;
}

.loading-panel {
    display: grid;
    place-items: center;
    gap: 12px;
    min-height: 360px;
    padding: 42px 18px;
    border-radius: var(--radius);
    text-align: center;
}

.loading-panel p {
    color: var(--muted);
}

.loading-spinner {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 3px solid var(--line);
    border-top-color: var(--blue);
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

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

.metric-card {
    min-height: 152px;
    padding: 16px;
    border-radius: var(--radius);
    overflow: hidden;
}

.metric-card--freezing {
    border-color: rgba(65, 214, 157, 0.34);
}

.metric-card--risk {
    border-color: rgba(255, 138, 76, 0.38);
}

.metric-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.metric-head i {
    color: var(--blue);
}

.metric-value {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-top: 18px;
    font-family: var(--font-mono);
    font-size: clamp(1.9rem, 3vw, 2.55rem);
    font-weight: 800;
    line-height: 1;
}

.metric-value small {
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 700;
}

.metric-card p {
    margin-top: 12px;
    color: var(--muted);
    font-size: 0.86rem;
}

.panel {
    border-radius: var(--radius);
    padding: 16px;
}

.panel--wide {
    width: 100%;
}

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

.panel-head--compact {
    margin-bottom: 10px;
}

.panel-head h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    line-height: 1.25;
    letter-spacing: 0;
}

.panel-head h2 i {
    color: var(--blue);
    font-size: 0.92rem;
}

.panel-head p {
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.84rem;
}

.legend-inline {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    font-size: 0.78rem;
}

.legend-inline span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 26px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.035);
}

.legend-inline i {
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: currentColor;
}

.legend-zero {
    color: var(--blue);
}

.legend-warm {
    color: var(--red);
}

.legend-green {
    color: var(--green);
}

.legend-cold {
    color: var(--cold);
}

.chart-frame {
    position: relative;
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius);
    background: rgba(4, 6, 10, 0.45);
    padding: 12px;
}

:root[data-theme="light"] .chart-frame {
    background: rgba(255, 255, 255, 0.74);
}

.chart-frame--trend {
    height: 310px;
}

.chart-frame--profile {
    height: 560px;
}

.chart-frame canvas {
    width: 100% !important;
    height: 100% !important;
}

.chart-fallback {
    display: none;
    position: absolute;
    inset: 12px;
    place-items: center;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 6px;
}

.chart-frame.is-unavailable canvas {
    display: none;
}

.chart-frame.is-unavailable .chart-fallback {
    display: grid;
}

.analysis-layout {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(360px, 1fr);
    gap: 16px;
}

.levels-panel {
    padding-bottom: 0;
    overflow: hidden;
}

.levels-table {
    margin-inline: -16px;
    border-top: 1px solid var(--line);
}

.levels-row {
    display: grid;
    grid-template-columns: 1.2fr 0.75fr 0.75fr 1fr;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 8px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    font-size: 0.88rem;
}

.levels-row--head {
    min-height: 38px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.035);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.level-name {
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: var(--blue);
    font-weight: 800;
}

.level-name small {
    color: var(--muted);
    font-weight: 500;
}

.wind-cell {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 7px;
}

.wind-arrow {
    color: var(--muted);
    transform: rotate(var(--wind-rotation));
}

.convective-note {
    margin: 0 -16px;
    padding: 14px 16px 16px;
    background: rgba(255, 255, 255, 0.035);
}

.convective-note span {
    display: block;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.convective-note p {
    margin-top: 7px;
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.45;
}

.synop-viewer {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(0, 0, 0, 0.32);
}

.synop-viewer img {
    display: block;
    width: 100%;
    max-height: min(64vh, 720px);
    object-fit: contain;
    background: #05070b;
}

.synop-viewer div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    color: var(--muted);
    font-size: 0.86rem;
}

.synop-viewer strong {
    color: var(--text);
}

.synop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.synop-card {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 9px;
    align-items: center;
    min-height: 72px;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    background: rgba(255, 255, 255, 0.035);
    text-align: left;
    cursor: pointer;
}

.synop-card i {
    color: var(--blue);
}

.synop-card small {
    grid-column: 2;
    color: var(--muted);
}

.synop-card.is-active,
.synop-card:hover {
    border-color: rgba(66, 199, 255, 0.45);
    background: rgba(66, 199, 255, 0.10);
}

.history-panel {
    padding-bottom: 0;
    overflow: hidden;
}

.filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--muted);
    background: rgba(255, 255, 255, 0.035);
    font-size: 0.84rem;
    white-space: nowrap;
}

.filter-toggle input {
    accent-color: var(--blue);
}

.table-scroll {
    margin: 0 -16px;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
    font-size: 0.9rem;
}

th,
td {
    padding: 11px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    text-align: left;
}

th {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: var(--surface-strong);
}

tbody tr {
    transition: background 0.14s ease;
}

tbody tr:hover,
tbody tr.is-active {
    background: rgba(66, 199, 255, 0.08);
}

td a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.run-pill,
.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0 7px;
    font-size: 0.72rem;
    font-weight: 800;
}

.run-pill {
    color: #cfe9ff;
    background: rgba(66, 199, 255, 0.12);
}

.status-success {
    color: #baf7d9;
    border-color: rgba(65, 214, 157, 0.34);
    background: rgba(65, 214, 157, 0.12);
}

:root[data-theme="light"] .status-success {
    color: #047857;
    border-color: rgba(5, 150, 105, 0.28);
    background: rgba(5, 150, 105, 0.10);
}

.status-info {
    color: #cfe6ff;
    border-color: rgba(122, 167, 255, 0.34);
    background: rgba(122, 167, 255, 0.12);
}

:root[data-theme="light"] .status-info {
    color: #1d4ed8;
    border-color: rgba(37, 99, 235, 0.25);
    background: rgba(37, 99, 235, 0.08);
}

.status-warning {
    color: #ffe2a4;
    border-color: rgba(242, 184, 75, 0.34);
    background: rgba(242, 184, 75, 0.12);
}

:root[data-theme="light"] .status-warning {
    color: #92400e;
    border-color: rgba(180, 83, 9, 0.25);
    background: rgba(245, 158, 11, 0.12);
}

.status-danger {
    color: #ffc8a9;
    border-color: rgba(255, 138, 76, 0.34);
    background: rgba(255, 138, 76, 0.12);
}

:root[data-theme="light"] .status-danger {
    color: #c2410c;
    border-color: rgba(234, 88, 12, 0.25);
    background: rgba(234, 88, 12, 0.10);
}

.status-critical {
    color: #ffc9d1;
    border-color: rgba(255, 95, 115, 0.40);
    background: rgba(255, 95, 115, 0.14);
}

:root[data-theme="light"] .status-critical {
    color: #be123c;
    border-color: rgba(225, 29, 72, 0.25);
    background: rgba(225, 29, 72, 0.10);
}

.status-neutral {
    color: var(--muted);
    border-color: var(--line);
    background: rgba(255, 255, 255, 0.045);
}

.mono {
    font-family: var(--font-mono);
}

.text-warm {
    color: var(--red);
}

.text-cold {
    color: var(--cold);
}

.text-green,
.text-success {
    color: var(--green);
}

.text-warning {
    color: var(--amber);
}

.text-danger,
.text-critical {
    color: var(--orange);
}

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

.empty-state {
    display: grid;
    place-items: center;
    gap: 12px;
    min-height: 360px;
    margin-top: 16px;
    padding: 42px 18px;
    border-radius: var(--radius);
    text-align: center;
}

.empty-state i {
    color: var(--orange);
    font-size: 2.2rem;
}

.empty-state h2 {
    font-size: 1.35rem;
}

.empty-state p {
    max-width: 620px;
    color: var(--muted);
    line-height: 1.5;
}

.debug-box {
    width: min(100%, 760px);
    margin: 8px 0 0;
    padding: 12px;
    overflow-x: auto;
    border: 1px solid rgba(255, 138, 76, 0.34);
    border-radius: var(--radius);
    color: #ffd2a8;
    background: rgba(255, 138, 76, 0.08);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.45;
    text-align: left;
    white-space: pre-wrap;
}

@media (max-width: 1180px) {
    .hero-panel,
    .analysis-layout {
        grid-template-columns: 1fr;
    }

    .hero-panel {
        flex-direction: column;
    }

    .quick-filters {
        justify-content: flex-start;
    }

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

    .analysis-layout {
        display: grid;
    }
}

@media (max-width: 720px) {
    .app-shell {
        width: min(100% - 18px, 1600px);
        padding-top: 10px;
    }

    .hero-panel,
    .panel,
    .metric-card {
        padding: 12px;
    }

    .brand-block {
        align-items: flex-start;
    }

    .brand-mark {
        flex-basis: 46px;
        width: 46px;
        height: 46px;
    }

    .quick-filters,
    .segmented,
    .date-form {
        width: 100%;
    }

    .segmented {
        justify-content: space-between;
    }

    .segment {
        flex: 1;
    }

    .date-form {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .date-form input {
        width: 100%;
    }

    .date-form button {
        grid-column: 1 / -1;
    }

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

    .panel-head {
        flex-direction: column;
    }

    .chart-frame--trend {
        height: 290px;
    }

    .chart-frame--profile {
        height: 520px;
    }

    .levels-row {
        grid-template-columns: 1fr 0.7fr 0.7fr 0.9fr;
        gap: 7px;
        font-size: 0.78rem;
    }
}
