:root {
    --bg: #efe6d3;
    --surface: #fffaf1;
    --surface-muted: #fff4e3;
    --ink: #2f1d16;
    --muted: #7d675c;
    --line: #e7d4bd;
    --forest: #85421c;
    --forest-dark: #4f230d;
    --ember: #cf3f22;
    --amber: #e39d2d;
    --blue: #2d7dd2;
    --violet: #7455c7;
    --shadow: 0 18px 45px rgba(74, 35, 13, 0.14);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(227, 157, 45, 0.18), transparent 28%),
        radial-gradient(circle at bottom right, rgba(214, 66, 31, 0.12), transparent 22%),
        var(--bg);
    font-family: "Segoe UI", Arial, sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select {
    font: inherit;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: 64px 1fr;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 0 24px;
    color: #fff;
    background: linear-gradient(90deg, #4c2610 0%, #7c3118 55%, #9a4318 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-mark {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    padding: 3px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.96);
    overflow: hidden;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.brand-title {
    display: block;
    font-size: 16px;
    font-weight: 800;
    line-height: 1.05;
    margin: 0;
}

.brand-subtitle {
    display: block;
    margin: 2px 0 0;
    color: rgba(246, 251, 243, 0.7);
    font-size: 0.85rem;
}

.system-status {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #d8eadf;
    font-size: 13px;
    white-space: nowrap;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: #9ca3af;
}

.status-dot.online {
    background: #5ee28a;
    box-shadow: 0 0 0 5px rgba(94, 226, 138, 0.12);
}

.status-dot.offline {
    background: #ef765f;
    box-shadow: 0 0 0 5px rgba(239, 118, 95, 0.13);
}

.workspace {
    height: calc(100vh - 64px);
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr) 320px;
    overflow: hidden;
}

.workspace.fire-only {
    grid-template-columns: 320px minmax(0, 1fr);
}

.workspace.wildlife-only {
    grid-template-columns: 340px minmax(0, 1fr) 340px;
}

.panel {
    min-width: 0;
    overflow: auto;
    padding: 14px;
    background: var(--surface);
    border-right: 1px solid var(--line);
}

.right-panel {
    border-right: 0;
    border-left: 1px solid var(--line);
}

.panel-header {
    margin-bottom: 14px;
}

.eyebrow {
    margin: 0 0 6px;
    color: #a14520;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 8px;
    font-size: 24px;
    line-height: 1.1;
}

h2 {
    margin-bottom: 12px;
    font-size: 17px;
}

h3 {
    margin-bottom: 8px;
    font-size: 15px;
}

.muted {
    color: var(--muted);
}

.section {
    margin-bottom: 14px;
}

.metric-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.metric {
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-muted);
}

.metric-label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.metric-value {
    display: block;
    font-size: 22px;
    font-weight: 850;
}

.metric-note {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.snapshot-note {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.5);
}

.snapshot-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.control-group {
    display: grid;
    gap: 9px;
}

.layer-toggle,
.camera-row,
.route-stop,
.alert-card,
.risk-row {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-muted);
}

.layer-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 11px;
}

.layer-meta {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}

.swatch {
    width: 13px;
    height: 13px;
    flex: 0 0 auto;
    border-radius: 4px;
    background: var(--forest);
}

.swatch.base {
    background: linear-gradient(135deg, #27543a 0%, #7fa36c 100%);
}

.swatch.heat {
    background: var(--ember);
}

.swatch.grid {
    background: var(--amber);
}

.swatch.prediction {
    background: var(--forest);
}

.swatch.border {
    background: #6f5a50;
}

.swatch.patrol {
    background: var(--blue);
}

.swatch.wildlife {
    background: var(--violet);
}

.toggle {
    position: relative;
    width: 42px;
    height: 24px;
    flex: 0 0 auto;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle span {
    position: absolute;
    inset: 0;
    cursor: pointer;
    border-radius: 999px;
    background: #cbd7cf;
    transition: 0.2s;
}

.toggle span::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: 0.2s;
}

.toggle input:checked + span {
    background: var(--forest);
}

.toggle input:checked + span::before {
    transform: translateX(18px);
}

.range-control {
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-muted);
}

.range-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    font-weight: 800;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--forest);
}

.map-stage {
    position: relative;
    min-width: 0;
}

#map {
    width: 100%;
    height: 100%;
    background: #f2ddc4;
}

.map-toolbar {
    position: absolute;
    z-index: 900;
    top: 16px;
    left: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    pointer-events: none;
}

.toolbar-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    border: 1px solid rgba(79, 35, 13, 0.12);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
    pointer-events: auto;
}

.search-input {
    width: min(340px, 45vw);
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--ink);
}

.button-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 34px;
    padding: 7px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    cursor: pointer;
    font-weight: 800;
}

.btn.primary {
    color: #fff;
    border-color: #9a4318;
    background: linear-gradient(135deg, #9a4318, #d6421f);
}

.btn.danger {
    color: #fff;
    border-color: var(--ember);
    background: var(--ember);
}

.btn:hover {
    filter: brightness(0.97);
}

.alert-list,
.route-list,
.risk-list,
.camera-list {
    display: grid;
    gap: 10px;
}

.alert-card {
    padding: 12px;
    border-left: 5px solid var(--forest);
}

.alert-card.high,
.risk-row.high {
    border-left-color: var(--ember);
}

.alert-card.medium,
.risk-row.medium {
    border-left-color: var(--amber);
}

.alert-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 5px;
    font-weight: 850;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 23px;
    padding: 3px 8px;
    border-radius: 999px;
    color: var(--forest-dark);
    background: #d9f4df;
    font-size: 12px;
    font-weight: 850;
}

.badge.high {
    color: #7a1f12;
    background: #fde0d9;
}

.badge.medium {
    color: #6f4706;
    background: #fdecc4;
}

.badge.blue {
    color: #173e8a;
    background: #dbe8ff;
}

.risk-row,
.route-stop,
.camera-row {
    padding: 10px 11px;
}

.video-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    margin-bottom: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #14231a;
}

.video-frame img {
    display: none;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-frame.active img {
    display: block;
}

.video-placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 18px;
    color: #d8eadf;
    text-align: center;
    font-weight: 800;
}

.video-frame.active .video-placeholder {
    display: none;
}

.risk-row {
    border-left: 5px solid var(--forest);
}

.row-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px;
    font-weight: 850;
}

.progress {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #dde7e1;
}

.progress span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--forest);
}

.progress span.medium {
    background: var(--amber);
}

.progress span.high {
    background: var(--ember);
}

.legend {
    position: absolute;
    z-index: 900;
    right: 16px;
    bottom: 16px;
    width: 240px;
    padding: 11px 12px;
    border: 1px solid rgba(79, 35, 13, 0.12);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    color: var(--muted);
    font-size: 13px;
}

.empty-state {
    padding: 16px;
    border: 1px dashed #b8c7bd;
    border-radius: 14px;
    color: var(--muted);
    background: #fbfdfb;
}

@media (max-width: 1120px) {
    .workspace,
    .workspace.wildlife-only {
        grid-template-columns: 320px minmax(0, 1fr);
    }

    .right-panel {
        display: none;
    }
}

@media (max-width: 820px) {
    .app-shell {
        grid-template-rows: auto 1fr;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
        padding: 14px;
        gap: 12px;
    }


    .system-status {
        display: none;
    }

    .workspace,
    .workspace.fire-only,
    .workspace.wildlife-only {
        height: auto;
        min-height: calc(100vh - 128px);
        grid-template-columns: 1fr;
        grid-template-rows: 62vh auto;
    }

    .map-stage {
        order: 1;
        min-height: 62vh;
    }

    .panel,
    .right-panel {
        order: 2;
        display: block;
        border: 0;
        border-bottom: 1px solid var(--line);
    }

    .map-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar-card {
        width: 100%;
    }

    .search-input {
        width: 100%;
    }
}
