:root {
    --bg-deep: #000000;
    --text-core: #ffffff;
    --text-dim: #8a8a8a;
    --text-body: #cccccc;
    --yellow-raw: #FBBF23;
    --yellow-glow: rgba(251, 191, 35, 0.4);
    --line: rgba(255,255,255, 0.1);
    --teal: #2DD4BF;

    --aqi-good: #2ECC40;
    --aqi-satisfactory: #A3E635;
    --aqi-moderate: #FBBF23;
    --aqi-poor: #F97316;
    --aqi-severe: #EF4444;
    --aqi-hazardous: #B91C1C;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-deep);
    color: var(--text-core);
    font-family: 'Space Grotesk', sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

*:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

.fog-overlay {
    position: fixed;
    top: -50%; left: -50%; right: -50%; bottom: -50%;
    background: radial-gradient(circle at center, var(--yellow-glow) 0%, transparent 40%);
    opacity: 0;
    pointer-events: none;
    z-index: 0;
    transition: opacity 1s ease, transform 10s linear;
}
.fog-overlay.level-high { opacity: 0.15; transform: scale(1.2); }
.fog-overlay.level-critical { opacity: 0.4; transform: scale(1.5); }

.cyber-frame {
    display: grid;
    grid-template-columns: 90px 1fr 420px;
    height: 100vh;
    border: 1px solid var(--line);
    position: relative;
    z-index: 10;
}

/* FIX #1 + #8: SIDEBAR */
.vertical-nav {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    border-right: 1px solid var(--line);
    padding: 1.2rem 0;
    background: rgba(0,0,0,0.5);
}

.brand-strip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    border-bottom: 1px solid var(--line);
    width: 100%;
    text-align: center;
    padding: 0.5rem 0 0.8rem;
}
.brand-logo {
    font-family: 'Anton', sans-serif;
    font-size: 1.4rem;
    color: var(--yellow-raw);
    letter-spacing: 2px;
    line-height: 1;
}
.brand-sub {
    font-size: 0.5rem;
    letter-spacing: 3px;
    color: var(--text-dim);
    margin-top: 2px;
}

.cities-label {
    font-size: 0.55rem;
    letter-spacing: 3px;
    color: var(--text-dim);
    margin-top: 0.8rem;
    text-align: center;
}

.city-selector {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    justify-content: center;
    width: 100%;
    padding: 0 0.4rem;
}

.city-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.65rem;
    letter-spacing: 1.5px;
    cursor: pointer;
    transition: color 0.25s, background 0.25s;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0.5rem 0.6rem;
    border-radius: 4px;
    width: 100%;
    text-align: left;
    border-left: 2px solid transparent;
}
.city-btn:hover {
    color: var(--text-core);
    background: rgba(255,255,255,0.04);
}
.city-btn.active {
    color: var(--yellow-raw);
    font-weight: 700;
    border-left-color: var(--yellow-raw);
    background: rgba(251,191,35,0.06);
}

.city-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--text-dim);
    flex-shrink: 0;
    transition: background 0.25s, border-color 0.25s;
}
.city-btn.active .city-dot {
    background: var(--yellow-raw);
    border-color: var(--yellow-raw);
}
.city-name { flex: 1; }

.admin-open {
    background: none;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 4px;
    color: var(--text-dim);
    font-family: 'Space Grotesk', sans-serif;
    cursor: pointer;
    margin-bottom: 0.5rem;
    transition: color 0.3s, border-color 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 0.5rem;
    font-size: 0.55rem;
    letter-spacing: 1px;
    opacity: 0.5;
}
.admin-open:hover {
    color: var(--text-core);
    border-color: rgba(255,255,255,0.25);
    opacity: 0.85;
}
.lock-icon { font-size: 0.8rem; }
.admin-label { letter-spacing: 2px; }

/* MAIN CANVAS */
.master-canvas {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 2rem 3rem;
    overflow: hidden;
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 20;
}

.header-city-block { display: flex; flex-direction: column; gap: 0.2rem; }
#city-title {
    font-size: 2.8rem;
    letter-spacing: -2px;
    font-weight: 700;
    line-height: 1;
}
.header-tagline {
    font-size: 0.7rem;
    letter-spacing: 2px;
    color: var(--text-dim);
}

/* FIX #2: VIEW TOGGLE */
.view-toggle-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    z-index: 20;
}
.toggle-context-label {
    font-size: 0.6rem;
    letter-spacing: 3px;
    color: var(--text-dim);
}
.view-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.toggle-label-side {
    font-size: 0.75rem;
    letter-spacing: 2px;
    color: var(--text-dim);
    transition: color 0.3s, font-weight 0.3s;
    user-select: none;
}
.toggle-label-side.active-side { color: var(--text-core); font-weight: 700; }

.toggle-track {
    width: 48px;
    height: 24px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 12px;
    cursor: pointer;
    position: relative;
    transition: background 0.3s, border-color 0.3s;
    flex-shrink: 0;
    padding: 0;
}
.toggle-track:hover { border-color: rgba(255,255,255,0.4); }
.toggle-track[aria-checked="true"] {
    background: rgba(45, 212, 191, 0.25);
    border-color: var(--teal);
}
.toggle-thumb {
    position: absolute;
    top: 3px; left: 3px;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--text-core);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}
.toggle-track[aria-checked="true"] .toggle-thumb {
    transform: translateX(24px);
    background: var(--teal);
}

.exec-timestamp {
    position: absolute;
    top: 5.5rem;
    right: 3rem;
    font-size: 0.65rem;
    letter-spacing: 2px;
    color: var(--text-dim);
    z-index: 20;
}
.exec-ts-label { color: var(--text-dim); margin-right: 4px; }

/* TYPOGRAPHY LAYER */
.typography-layer {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    z-index: 10;
    gap: 0.4rem;
}

.pm-massive {
    font-family: 'Anton', sans-serif;
    font-size: clamp(90px, 24vw, 360px);
    line-height: 0.85;
    color: var(--yellow-raw);
    transition: text-shadow 1s ease, color 1s ease;
}
.pm-massive.critical { text-shadow: 0 0 100px rgba(251, 191, 35, 0.7); }
.pm-massive.elevated { text-shadow: 0 0 30px rgba(251, 191, 35, 0.3); }

/* FIX #3: SEVERITY BADGE */
.severity-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.8rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 3px;
    margin-top: 0.3rem;
    transition: background 0.5s, color 0.5s;
    background: rgba(255,255,255,0.1);
    color: var(--text-dim);
}
.severity-badge.badge-good      { background: var(--aqi-good); color: #000; }
.severity-badge.badge-satisfactory { background: var(--aqi-satisfactory); color: #000; }
.severity-badge.badge-moderate  { background: var(--aqi-moderate); color: #000; }
.severity-badge.badge-poor      { background: var(--aqi-poor); color: #fff; }
.severity-badge.badge-severe    { background: var(--aqi-severe); color: #fff; }
.severity-badge.badge-hazardous { background: var(--aqi-hazardous); color: #fff; box-shadow: 0 0 20px rgba(185,28,28,0.6); }

.label-overlay {
    font-size: 1.1rem;
    letter-spacing: 10px;
    color: var(--text-body);
    position: relative;
    z-index: 2;
}

/* FIX #3: AQI SCALE BAR */
.aqi-scale-bar {
    margin-top: 0.8rem;
    width: clamp(180px, 30vw, 360px);
    pointer-events: auto;
}
.aqi-scale-track {
    display: flex;
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 4px;
}
.aqi-seg { flex: 1; transition: opacity 0.3s; }
.aqi-seg:hover { opacity: 0.8; }
.aqi-seg.good         { background: var(--aqi-good); }
.aqi-seg.satisfactory { background: var(--aqi-satisfactory); }
.aqi-seg.moderate     { background: var(--aqi-moderate); }
.aqi-seg.poor         { background: var(--aqi-poor); }
.aqi-seg.severe       { background: var(--aqi-severe); }
.aqi-seg.hazardous    { background: var(--aqi-hazardous); }

.aqi-scale-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.45rem;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 2px;
}

.aqi-marker-row {
    position: relative;
    height: 14px;
    width: 100%;
}
.aqi-marker {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    width: 10px; height: 10px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: #fff;
    transition: left 0.8s cubic-bezier(0.4,0,0.2,1), background 0.5s;
    box-shadow: 0 0 8px rgba(255,255,255,0.5);
}

/* RIGHT PANEL */
.data-panel {
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    padding: 2.5rem 2rem;
    overflow-y: auto;
    z-index: 20;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(10px);
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.data-panel::-webkit-scrollbar { width: 3px; }
.data-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.panel-title {
    font-size: 0.7rem;
    letter-spacing: 4px;
    color: var(--text-dim);
    margin-bottom: 1rem;
}

.line-divider {
    height: 1px;
    background: var(--line);
    margin-bottom: 1.5rem;
    width: 100%;
}

.editorial-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 3rem;
}

/* FIX #4: IMPACT VECTORS */
.editorial-item {
    position: relative;
    padding-left: 1rem;
    border-left: 2px solid transparent;
    transition: border-left-color 0.3s, transform 0.3s;
}
.editorial-item:hover {
    border-left-color: var(--yellow-raw);
    transform: translateX(4px);
}

.editorial-item h4 {
    font-size: 1rem;
    letter-spacing: -0.5px;
    margin-bottom: 0.3rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.severity-icon { font-size: 0.9rem; }

/* FIX #10: body text contrast */
.editorial-item p {
    font-size: 0.9rem;
    color: var(--text-body);
    line-height: 1.5;
}

.highlight-not-allowed    { color: #ef4444; }
.highlight-not-allowed-bg {
    background: #ef4444; color: var(--bg-deep) !important;
    padding: 0.2rem 0.6rem; font-weight: 700; display: inline-block; border-radius: 2px;
}
.highlight-advisable    { color: var(--yellow-raw); }
.highlight-advisable-bg {
    background: var(--yellow-raw); color: var(--bg-deep) !important;
    padding: 0.2rem 0.6rem; font-weight: 700; display: inline-block; border-radius: 2px;
}
.highlight-allowed    { color: #4ade80; }
.highlight-allowed-bg {
    background: #4ade80; color: var(--bg-deep) !important;
    padding: 0.2rem 0.6rem; font-weight: 700; display: inline-block; border-radius: 2px;
}

/* FIX #7: EXEC DIRECTIVES */
.directive-item {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    padding: 0.7rem 0.8rem;
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 4px;
    transition: border-color 0.3s;
    margin-bottom: 0.8rem;
}
.directive-item:hover { border-color: rgba(255,255,255,0.2); }

.priority-badge {
    flex-shrink: 0;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    margin-top: 2px;
}
.p1-badge { background: var(--aqi-hazardous); color: #fff; }
.p2-badge { background: var(--aqi-severe); color: #fff; }
.p3-badge { background: var(--aqi-moderate); color: #000; }

.directive-body { flex: 1; }
.directive-text { font-size: 0.85rem; color: var(--text-body); line-height: 1.4; }
.directive-meta { font-size: 0.65rem; color: var(--text-dim); margin-top: 0.2rem; letter-spacing: 1px; }

/* FIX #5: EXPANDABLE ALERT CARDS */
.alert-card {
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    overflow: hidden;
    transition: border-color 0.3s;
    margin-bottom: 0.8rem;
}
.alert-card.priority-urgent { border-left: 3px solid var(--aqi-severe); }
.alert-card.priority-high   { border-left: 3px solid var(--aqi-poor); }
.alert-card.priority-normal { border-left: 3px solid var(--aqi-moderate); }

.alert-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem 0.8rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}
.alert-card-header:hover { background: rgba(255,255,255,0.04); }

.alert-card-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--text-core);
}
.alert-urgency-badge {
    font-size: 0.6rem;
    font-weight: 700;
    padding: 0.1rem 0.35rem;
    border-radius: 2px;
    background: rgba(239,68,68,0.2);
    color: #ef4444;
    letter-spacing: 1px;
}

.alert-chevron {
    font-size: 0.7rem;
    color: var(--text-dim);
    transition: transform 0.3s;
}
.alert-card.expanded .alert-chevron { transform: rotate(180deg); }

.alert-card-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
}
.alert-card.expanded .alert-card-body { max-height: 200px; }
.alert-card-detail {
    padding: 0.6rem 0.8rem 0.8rem;
    font-size: 0.85rem;
    color: var(--text-body);
    line-height: 1.5;
    border-top: 1px solid rgba(255,255,255,0.06);
}

/* MODALS */
.cyber-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.92);
    backdrop-filter: blur(20px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s;
}
.cyber-modal.visible { opacity: 1; pointer-events: auto; }

.modal-content {
    border: 1px solid var(--yellow-raw);
    padding: 2.5rem;
    width: clamp(320px, 90vw, 560px);
    background: #0a0a0a;
    box-shadow: 0 0 50px var(--yellow-glow);
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.modal-header h2 {
    color: var(--yellow-raw);
    letter-spacing: 3px;
    font-size: 1.2rem;
}
.modal-subtitle {
    font-size: 0.78rem;
    color: var(--text-dim);
    letter-spacing: 1px;
    margin-bottom: 2rem;
    line-height: 1.4;
}
.close-btn {
    background: none; border: none;
    color: var(--text-core); font-size: 1.8rem; cursor: pointer;
    line-height: 1; padding: 0 0.3rem;
    transition: color 0.2s;
}
.close-btn:hover { color: var(--yellow-raw); }

/* FIX #9: INPUT VALIDATION */
.input-matrix { margin-top: 1rem; }
.input-line {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid var(--line);
    padding: 0.8rem 0;
    margin-bottom: 0.5rem;
    gap: 1rem;
}
.input-line label { letter-spacing: 2px; font-size: 0.85rem; padding-top: 0.4rem; }
.input-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.input-line input {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 3px;
    color: var(--yellow-raw);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.4rem;
    text-align: right;
    width: 90px;
    outline: none;
    padding: 0.1rem 0.3rem;
    transition: border-color 0.2s;
}
.input-line input:focus { border-color: rgba(251,191,35,0.4); }
.input-line input.invalid { border-color: #ef4444 !important; color: #ef4444; }
.validation-msg {
    font-size: 0.6rem;
    letter-spacing: 1px;
    color: #ef4444;
    min-height: 0.9rem;
}

.cyber-btn {
    width: 100%;
    margin-top: 2rem;
    padding: 1.2rem;
    background: var(--yellow-raw);
    color: var(--bg-deep);
    border: none;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    letter-spacing: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s, opacity 0.2s;
    border-radius: 2px;
}
.cyber-btn:hover:not(:disabled) { background: #ffffff; }
.cyber-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    background: var(--yellow-raw);
}

/* PIN MODAL */
.pin-modal-content { max-width: 380px; }
.pin-instructions { font-size: 0.8rem; color: var(--text-dim); letter-spacing: 1px; margin-bottom: 1.5rem; line-height: 1.4; }
.pin-input-row { display: flex; gap: 0.8rem; align-items: center; }
.pin-input-row input {
    flex: 1;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 3px;
    color: var(--yellow-raw);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    text-align: center;
    letter-spacing: 6px;
    padding: 0.5rem;
    outline: none;
    transition: border-color 0.2s;
}
.pin-input-row input:focus { border-color: rgba(251,191,35,0.5); }
.pin-submit-btn { width: auto; margin-top: 0; padding: 0.8rem 1.5rem; flex-shrink: 0; }
.pin-error { font-size: 0.7rem; color: #ef4444; letter-spacing: 1px; margin-top: 0.8rem; min-height: 1rem; }

/* CONFIRM MODAL */
.confirm-modal-content { max-width: 420px; border-color: var(--aqi-severe); box-shadow: 0 0 40px rgba(239,68,68,0.3); }
.confirm-modal-content h2 { color: var(--aqi-severe); font-size: 1.1rem; letter-spacing: 2px; margin-bottom: 1rem; }
.confirm-msg { font-size: 0.85rem; color: var(--text-body); line-height: 1.6; margin-bottom: 0.5rem; letter-spacing: 0.5px; }
.confirm-btns { display: flex; gap: 1rem; margin-top: 0; }
.confirm-yes { background: var(--aqi-severe); margin-top: 1.5rem; flex: 1; }
.confirm-yes:hover:not(:disabled) { background: var(--aqi-hazardous) !important; }
.confirm-no { background: transparent; border: 1px solid var(--line); color: var(--text-core); margin-top: 1.5rem; flex: 1; }
.confirm-no:hover { background: rgba(255,255,255,0.05) !important; }
