/* ===== RIGHT CONTENT ===== */
.content-panel {
    flex: 1;
    border: 1px solid var(--phosphor-dim);
    background:
        linear-gradient(180deg, rgba(32,194,14,0.04), transparent 18%),
        var(--panel-bg-deep);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow:
        inset 0 0 50px rgba(32, 194, 14, 0.035),
        0 0 22px rgba(0, 0, 0, 0.35);
    contain: layout paint style;
}

.content-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 8px 15px;
    border-bottom: 1px solid var(--phosphor-dim);
    font-size: var(--font-size-tiny);
    background: rgba(0, 15, 0, 0.4);
    flex-shrink: 0;
}

.toolbar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    min-width: 0;
}

.page-indicator { color: var(--amber); text-shadow: 0 0 5px var(--amber-dim); }

.database-slot-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.database-slot-button {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    border: 1px solid currentColor;
    background: rgba(0, 0, 0, 0.52);
    color: var(--red);
    display: grid;
    place-items: center;
    font-family: var(--terminal-font);
    font-size: 19px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    text-shadow: 0 0 6px currentColor;
    touch-action: manipulation;
}

.database-slot-button.loaded {
    color: var(--phosphor);
}

.database-slot-button:focus-visible {
    outline: 2px solid var(--amber);
    outline-offset: 3px;
}

.database-slot-button:hover {
    background: rgba(32, 194, 14, 0.09);
}

.content-viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-height: 0;
    contain: layout paint style;
}

.content-area {
    position: absolute;
    inset: 0;
    padding: 10px 15px;
    font-size: var(--font-size-base);
    line-height: 1.22;
    overflow: hidden;
    transform: translateZ(0);
    contain: layout paint style;
}

.output {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(57, 255, 20, 0.55) rgba(0, 18, 0, 0.35);
    contain: content;
}

.output::-webkit-scrollbar {
    width: 8px;
}

.output::-webkit-scrollbar-track {
    background: rgba(0, 18, 0, 0.35);
}

.output::-webkit-scrollbar-thumb {
    background: rgba(57, 255, 20, 0.45);
}

.output-line {
    min-height: 1.22em;
}

/* Embedded images in database entries (Base64 data URLs). Sit flush with the
   surrounding lines but stay constrained so they don't blow out the terminal
   column. The amber border keeps them aesthetically aligned with the rest of
   the UI. */
.entry-image-embed {
    display: block;
    max-width: 100%;
    max-height: 280px;
    height: auto;
    width: auto;
    margin: 6px 0 6px 14px;
    border: 1px solid var(--amber-line, rgba(255, 173, 0, 0.42));
    border-radius: 2px;
    background: rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 6px rgba(255, 173, 0, 0.15);
}

.output-line.entry-image-line {
    /* Don't apply the typewriter background tint to image-only lines */
    text-shadow: none;
}

.cli-command-line {
    color: var(--amber);
    text-shadow: 0 0 4px rgba(255, 173, 0, 0.45);
}

.terminal-typewriter-line {
    position: relative;
    text-shadow: 0 0 3px rgba(57, 255, 20, 0.42);
}

.terminal-typewriter-active::after {
    content: "\00a0";
    width: 0.58ch;
    height: 1.05em;
    margin-left: 0.16ch;
    display: inline-block;
    vertical-align: -0.14em;
    background: var(--phosphor);
    box-shadow: 0 0 5px rgba(57, 255, 20, 0.55);
    animation: terminalCursorBlink 0.75s steps(2, end) infinite;
}

body.terminal-typing .terminal-typewriter-line {
    text-shadow: 0 0 2px rgba(57, 255, 20, 0.42);
}

body.terminal-typing .terminal-typewriter-active::after {
    box-shadow: 0 0 4px rgba(57, 255, 20, 0.55);
}

@keyframes terminalCursorBlink {
    0%, 48% { opacity: 1; }
    49%, 100% { opacity: 0; }
}

.glow { text-shadow: 0 0 2px rgba(57, 255, 20, 0.5); }

/* ===== INPUT AREA ===== */
.input-area {
    border-top: 1px solid var(--phosphor-dim);
    padding: 10px 15px;
    display: flex;
    align-items: center;
    background: rgba(0, 12, 0, 0.4);
    flex-shrink: 0;
}

.prompt {
    color: var(--amber);
    margin-right: 10px;
    text-shadow: 0 0 4px var(--amber-dim);
}

#commandInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--phosphor);
    font-family: var(--terminal-font);
    font-size: var(--font-size-base);
    outline: none;
    text-shadow: 0 0 1px var(--phosphor);
    caret-color: var(--phosphor);
}

#commandInput:focus-visible {
    outline: 1px solid var(--cyan);
    outline-offset: 4px;
}

.cursor-block {
    width: 10px;
    height: 1.2em;
    background: var(--phosphor);
    animation: cursorBlink 1s step-end infinite;
    box-shadow: 0 0 4px var(--phosphor);
}
@keyframes cursorBlink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }

/* ===== TEXT STYLES ===== */
.t-amber { color: var(--amber); text-shadow: 0 0 2px rgba(255, 173, 0, 0.32); }
.t-red { color: var(--red); text-shadow: 0 0 2px rgba(255,51,51,0.32); }
.t-cyan { color: var(--cyan); text-shadow: 0 0 2px rgba(0,212,170,0.32); }
.t-magenta { color: var(--magenta); text-shadow: 0 0 2px rgba(255,0,255,0.32); }
.t-dim { opacity: 0.5; }
.t-bright { color: var(--phosphor-glow); text-shadow: 0 0 3px rgba(57, 255, 20, 0.42); }

/* ===== PASSWORD DIALOG ===== */
.dialog-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 200;
    justify-content: center;
    align-items: center;
}
.dialog-overlay.active { display: flex; }

.dialog-box {
    border: 2px solid var(--amber);
    background: rgba(5, 15, 5, 0.98);
    padding: 30px 40px;
    max-width: 450px;
    text-align: center;
    box-shadow: 0 0 50px rgba(255, 176, 0, 0.2);
    contain: layout paint style;
}

.dialog-box h2 {
    color: var(--amber);
    font-size: var(--font-size-title);
    margin-bottom: 20px;
    letter-spacing: 2px;
}

.dialog-box p {
    margin-bottom: 20px;
    color: #888;
}

.dialog-box input {
    width: 100%;
    background: rgba(0, 20, 0, 0.8);
    border: 1px solid var(--phosphor-dim);
    color: var(--phosphor);
    font-family: var(--terminal-font);
    font-size: var(--font-size-base);
    padding: 12px 15px;
    text-align: center;
    outline: none;
    margin-bottom: 10px;
}

.dialog-box input:focus {
    border-color: var(--phosphor);
    box-shadow: 0 0 10px var(--phosphor-dim);
}

.dialog-error {
    color: var(--red);
    font-size: var(--font-size-small);
    margin-bottom: 15px;
    display: none;
}
.dialog-error.visible { display: block; }

.dialog-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

.dialog-btn {
    padding: 10px 25px;
    border: 1px solid var(--phosphor-dim);
    background: rgba(0, 30, 0, 0.8);
    color: var(--phosphor);
    font-family: var(--terminal-font);
    font-size: var(--font-size-base);
    cursor: pointer;
    touch-action: manipulation;
    transition:
        background-color 0.18s var(--ui-ease),
        border-color 0.18s var(--ui-ease),
        color 0.18s var(--ui-ease),
        box-shadow 0.18s var(--ui-ease);
}

.dialog-btn:hover {
    background: rgba(0, 50, 0, 0.8);
    border-color: var(--phosphor);
    box-shadow: 0 0 10px var(--phosphor-dim);
}

.dialog-btn.primary {
    background: var(--phosphor-dim);
    color: var(--phosphor-glow);
}

.dialog-btn.cancel {
    border-color: #444;
    color: #666;
}

.dialog-btn:focus-visible,
.diagnostic-close:focus-visible,
.facility-close:focus-visible,
.boot-skip:focus-visible {
    outline: 2px solid var(--amber);
    outline-offset: 3px;
}

/* ===== DATABASE SELECTOR ===== */
.database-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 235;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background:
        radial-gradient(circle at 50% 20%, rgba(255, 176, 0, 0.08), transparent 34%),
        rgba(0, 0, 0, 0.88);
}

.database-modal-panel {
    width: min(720px, 100%);
    max-height: calc(var(--viewport-height) - 36px);
    border: 1px solid var(--amber);
    background:
        linear-gradient(90deg, rgba(255, 176, 0, 0.04), transparent 28%),
        rgba(3, 12, 5, 0.98);
    box-shadow:
        inset 0 0 40px rgba(32, 194, 14, 0.06),
        0 0 42px rgba(255, 176, 0, 0.13);
    overflow: hidden;
}

.database-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255, 176, 0, 0.35);
    background: rgba(0, 16, 0, 0.48);
}

.database-modal-title {
    color: var(--amber);
    font-size: var(--font-size-title);
    letter-spacing: 2px;
}

.database-modal-close,
.database-modal-action {
    border: 1px solid rgba(255, 176, 0, 0.5);
    background: rgba(20, 12, 0, 0.78);
    color: var(--amber);
    font-family: var(--terminal-font);
    font-size: var(--font-size-small);
    padding: 8px 11px;
    min-height: 38px;
    cursor: pointer;
    touch-action: manipulation;
}

.database-modal-close:focus-visible,
.database-modal-action:focus-visible,
.database-choice:focus-visible,
.database-password-input:focus-visible {
    outline: 2px solid var(--amber);
    outline-offset: 3px;
}

.database-modal-body {
    padding: 14px;
    overflow: auto;
    max-height: calc(var(--viewport-height) - 120px);
}

.database-modal-copy {
    color: var(--phosphor);
    font-size: var(--font-size-small);
    margin-bottom: 12px;
}

.database-list {
    display: grid;
    gap: 8px;
}

.database-choice {
    appearance: none;
    width: 100%;
    border: 1px solid rgba(32, 194, 14, 0.28);
    background:
        linear-gradient(90deg, rgba(32, 194, 14, 0.08), transparent),
        rgba(0, 10, 0, 0.66);
    color: var(--phosphor);
    font-family: var(--terminal-font);
    text-align: left;
    padding: 10px 12px;
    cursor: pointer;
}

.database-choice:hover {
    border-color: var(--cyan);
    background-color: rgba(0, 30, 20, 0.72);
}

.database-choice.disabled,
.database-choice:disabled {
    border-color: rgba(120, 120, 120, 0.28);
    background:
        linear-gradient(90deg, rgba(120, 120, 120, 0.08), transparent),
        rgba(10, 12, 10, 0.66);
    color: #666;
    cursor: not-allowed;
    opacity: 0.58;
}

.database-choice.disabled:hover,
.database-choice:disabled:hover {
    border-color: rgba(120, 120, 120, 0.28);
    background-color: rgba(10, 12, 10, 0.66);
}

.database-choice.disabled .database-choice-name,
.database-choice:disabled .database-choice-name,
.database-choice.disabled .database-choice-description,
.database-choice:disabled .database-choice-description {
    color: #666;
}

.database-choice-external {
    margin-top: 10px;
    border-color: rgba(255, 176, 0, 0.48);
    background:
        linear-gradient(90deg, rgba(255, 176, 0, 0.1), transparent),
        rgba(20, 12, 0, 0.66);
}

.database-choice-external .database-choice-name {
    color: var(--amber);
}

.database-choice-name,
.database-choice-description {
    display: block;
}

.database-choice-name {
    color: var(--cyan);
    font-size: var(--font-size-base);
    margin-bottom: 4px;
}

.database-choice-description {
    color: #777;
    font-size: var(--font-size-small);
}

.database-password-input {
    width: 100%;
    border: 1px solid var(--phosphor-dim);
    background: rgba(0, 20, 0, 0.8);
    color: var(--phosphor);
    font-family: var(--terminal-font);
    font-size: var(--font-size-base);
    padding: 11px 12px;
    margin-bottom: 10px;
}

.database-password-error {
    color: var(--red);
    min-height: 1.3em;
    font-size: var(--font-size-small);
    margin-bottom: 10px;
}

.database-decrypt-box {
    border: 1px solid rgba(32, 194, 14, 0.35);
    background:
        linear-gradient(90deg, rgba(32, 194, 14, 0.08), transparent 38%),
        rgba(0, 14, 4, 0.78);
    color: var(--phosphor);
    font-family: var(--terminal-font);
    font-size: var(--font-size-small);
    line-height: 1.45;
    min-height: 186px;
    margin-bottom: 12px;
    padding: 12px;
    white-space: pre-wrap;
    overflow: hidden;
}

.database-modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.database-modal-action.secondary {
    border-color: rgba(32, 194, 14, 0.35);
    color: var(--phosphor);
    background: rgba(0, 24, 0, 0.72);
}

.database-modal-action:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.database-slot-details {
    border: 1px solid rgba(32, 194, 14, 0.3);
    background: rgba(0, 14, 4, 0.72);
    color: var(--phosphor);
    font-family: var(--terminal-font);
    font-size: var(--font-size-small);
    line-height: 1.5;
    padding: 12px;
    margin-bottom: 12px;
    white-space: pre-wrap;
}

/* ===== DIAGNOSTIC DASHBOARD ===== */
.diagnostic-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 220;
    background:
        radial-gradient(circle at 50% 18%, rgba(32, 194, 14, 0.08), transparent 34%),
        rgba(0, 0, 0, 0.9);
    align-items: center;
    justify-content: center;
    padding: 18px;
}

.diagnostic-overlay.active { display: flex; }

.diagnostic-panel {
    width: min(1480px, 100%);
    height: min(900px, calc(var(--viewport-height) - 36px));
    max-height: calc(var(--viewport-height) - 36px);
    border: 1px solid var(--amber);
    background:
        linear-gradient(90deg, rgba(255, 176, 0, 0.045), transparent 26%),
        linear-gradient(180deg, rgba(32, 194, 14, 0.055), rgba(0, 0, 0, 0.08)),
        rgba(3, 12, 5, 0.98);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow:
        inset 0 0 44px rgba(32, 194, 14, 0.07),
        0 0 44px rgba(255, 176, 0, 0.12);
    contain: layout paint style;
}

.diagnostic-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255, 176, 0, 0.38);
    background: rgba(0, 18, 0, 0.48);
}

.diagnostic-title {
    color: var(--amber);
    letter-spacing: 2px;
    font-size: var(--font-size-title);
    min-width: 0;
}

.diagnostic-meta {
    color: var(--cyan);
    font-size: var(--font-size-tiny);
    opacity: 0.82;
    white-space: nowrap;
}

.diagnostic-close {
    border: 1px solid rgba(255, 176, 0, 0.5);
    background: rgba(20, 12, 0, 0.8);
    color: var(--amber);
    font-family: var(--terminal-font);
    font-size: var(--font-size-small);
    padding: 7px 10px;
    min-height: 36px;
    cursor: pointer;
    touch-action: manipulation;
}

.diagnostic-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(126px, 1fr)) minmax(158px, 1.18fr);
    gap: 8px;
    padding: 10px;
    min-height: 0;
    overflow: auto;
}

.diagnostic-dashboard-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-rows: minmax(150px, 1fr) minmax(150px, 1fr) minmax(150px, 1fr) minmax(138px, 0.9fr);
    grid-template-areas:
        "scope scope radar radar react react"
        "tomo tomo tomo tomo fabric fabric"
        "tomo tomo tomo tomo log log"
        "bio bio water water gauge uplink";
    gap: 7px;
}

.diagnostic-card {
    border: 1px solid rgba(32, 194, 14, 0.26);
    background:
        linear-gradient(180deg, rgba(32, 194, 14, 0.055), transparent 55%),
        rgba(0, 10, 0, 0.68);
    padding: 9px 10px;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    contain: layout paint style;
}

.diagnostic-card-feature {
    border-color: rgba(0, 255, 213, 0.34);
    box-shadow: inset 0 0 22px rgba(0, 255, 213, 0.035);
}

#diagGeneratorCard { grid-area: scope; }
#diagLifeCard { grid-area: bio; }
#diagOutpostCard { grid-area: radar; }
#diagNetworkCard { grid-area: water; }
#diagAlarmCard { grid-area: tomo; }
#diagPowerCard { grid-area: react; }
#diagSecurityCard { grid-area: fabric; }
#diagEventsCard { grid-area: log; }
#diagIntegrityCard { grid-area: gauge; }
#diagUplinkCard { grid-area: uplink; }

.diagnostic-card.wide {
    grid-column: 1 / -1;
}

.diagnostic-card.warn {
    border-color: rgba(255, 176, 0, 0.42);
}

.diagnostic-card.alert {
    border-color: rgba(255, 51, 51, 0.42);
}

.diagnostic-card.booting {
    border-color: rgba(255, 176, 0, 0.34);
    background:
        linear-gradient(180deg, rgba(255, 176, 0, 0.06), transparent 58%),
        rgba(0, 10, 0, 0.72);
    box-shadow: inset 0 0 18px rgba(255, 176, 0, 0.035);
}

.diagnostic-card.arming {
    border-color: rgba(0, 255, 213, 0.42);
    box-shadow:
        inset 0 0 20px rgba(0, 255, 213, 0.045),
        0 0 0 1px rgba(0, 255, 213, 0.045);
}

.diagnostic-card.online {
    animation: diagnostic-card-online 420ms ease-out 1;
}

.diagnostic-card.booting .diagnostic-readout,
.diagnostic-card.arming .diagnostic-readout {
    opacity: 0.88;
    filter: saturate(0.9);
}

@keyframes diagnostic-card-online {
    0% {
        box-shadow: inset 0 0 28px rgba(57, 255, 20, 0.16), 0 0 0 1px rgba(57, 255, 20, 0.22);
    }
    100% {
        box-shadow: inset 0 0 0 rgba(57, 255, 20, 0), 0 0 0 1px rgba(57, 255, 20, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .diagnostic-card.online {
        animation: none;
    }
}

.diagnostic-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: var(--amber);
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(32, 194, 14, 0.16);
    padding-bottom: 4px;
    margin-bottom: 6px;
    font-size: var(--font-size-small);
}

.diagnostic-label span:last-child {
    color: var(--cyan);
    opacity: 0.85;
    white-space: nowrap;
}

.diagnostic-vitals-controls {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
    color: var(--cyan);
    opacity: 0.94;
    white-space: nowrap;
}

.diagnostic-cycle-btn {
    border: 1px solid rgba(0, 255, 213, 0.34);
    background: rgba(0, 16, 12, 0.78);
    color: var(--cyan);
    font: inherit;
    font-size: 10px;
    line-height: 1;
    padding: 3px 6px;
    min-height: 22px;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.diagnostic-cycle-btn:hover,
.diagnostic-cycle-btn:focus-visible {
    border-color: rgba(255, 173, 0, 0.6);
    background: rgba(255, 173, 0, 0.12);
    color: var(--amber);
    outline: none;
}

.diagnostic-readout {
    margin: 0;
    color: var(--phosphor);
    font-family: var(--terminal-font);
    font-size: var(--font-size-small);
    line-height: 1.22;
    white-space: pre;
    overflow: hidden;
    min-height: 6.1em;
    flex: 1 1 auto;
}

.telemetry-widget {
    position: relative;
    display: block;
    min-height: 0;
    white-space: pre;
    background:
        radial-gradient(circle at 50% 50%, rgba(57, 255, 20, 0.055), transparent 66%),
        rgba(0, 8, 2, 0.38);
}

.telemetry-widget-wide {
    min-height: 160px;
}

.telemetry-widget-large {
    height: 100%;
    min-height: 0;
}

.telemetry-svg {
    display: block;
    width: 100%;
    height: 100%;
    min-height: inherit;
    overflow: hidden;
    font-family: var(--terminal-font);
}

.telemetry-trace {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.25;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
    filter: drop-shadow(0 0 2px currentColor);
}

.telemetry-trace-thin {
    stroke-width: 0.7;
}

.telemetry-trace-bold {
    stroke-width: 1.8;
}

.telemetry-ekg-trace {
    stroke-linecap: round;
    stroke-linejoin: round;
}

.telemetry-monitor-trace {
    stroke-linecap: round;
    stroke-linejoin: round;
    shape-rendering: geometricPrecision;
}

.telemetry-fill {
    fill: currentColor;
    stroke: none;
    opacity: 0.1;
}

.telemetry-hot-fill {
    fill: currentColor;
    stroke: none;
    opacity: 0.16;
}

.telemetry-guide {
    stroke: currentColor;
    fill: none;
    vector-effect: non-scaling-stroke;
    opacity: 0.16;
}

.telemetry-fill-guide {
    fill: currentColor;
    opacity: 0.055;
}

.telemetry-map-zone {
    fill: currentColor;
    stroke: currentColor;
    stroke-width: 0.65;
    stroke-dasharray: 4 3;
    vector-effect: non-scaling-stroke;
}

.telemetry-map-label-bg {
    fill: rgba(0, 8, 0, 0.82);
    stroke: currentColor;
    stroke-width: 0.6;
    vector-effect: non-scaling-stroke;
}

.telemetry-glyph {
    fill: currentColor;
    font-family: var(--terminal-font);
    font-size: 10px;
    dominant-baseline: middle;
    text-anchor: middle;
    white-space: pre;
    text-shadow: 0 0 3px currentColor;
}

.telemetry-label {
    fill: currentColor;
    font-family: var(--terminal-font);
    font-size: 9px;
    dominant-baseline: middle;
    text-anchor: start;
    opacity: 0.82;
}

.telemetry-map-label-strong {
    font-weight: 800;
    letter-spacing: 0.05em;
    paint-order: stroke;
    stroke: rgba(0, 0, 0, 0.88);
    stroke-width: 2px;
    text-shadow: 0 0 4px currentColor;
}

.telemetry-no-glow,
.browser-firefox .telemetry-trace,
.browser-firefox .telemetry-glyph,
.render-low .telemetry-trace,
.render-low .telemetry-glyph,
.render-reduced .telemetry-trace,
.render-reduced .telemetry-glyph,
.safe-mode .telemetry-trace,
.safe-mode .telemetry-glyph {
    filter: none;
    text-shadow: none;
}

.browser-firefox .telemetry-map-label-strong,
.render-low .telemetry-map-label-strong,
.render-reduced .telemetry-map-label-strong,
.safe-mode .telemetry-map-label-strong {
    text-shadow: none;
}

.safe-mode-indicator {
    color: var(--amber);
    border-color: rgba(255, 173, 0, 0.42);
}

.telemetry-cyan { color: var(--cyan); }
.telemetry-green { color: var(--phosphor); }
.telemetry-amber { color: var(--amber); }
.telemetry-red { color: var(--red); }
.telemetry-yellow { color: #ffff00; }
.telemetry-magenta { color: #ff55ff; }
.telemetry-orange { color: #ff4d00; }
.telemetry-white { color: rgba(245, 255, 245, 0.96); }
.telemetry-dim { color: rgba(57, 255, 20, 0.42); }

.diagnostic-card.wide .diagnostic-readout {
    min-height: 8.55em;
}

.diagnostic-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-top: 1px solid rgba(32, 194, 14, 0.2);
    padding: 9px 12px;
    color: var(--amber);
    font-size: var(--font-size-small);
    background: rgba(0, 14, 0, 0.42);
    min-height: 40px;
}

@media (max-width: 760px) {
    .diagnostic-overlay { padding: 10px; }
    .diagnostic-panel {
        height: calc(var(--viewport-height) - 20px);
        max-height: calc(var(--viewport-height) - 20px);
    }
    .diagnostic-header { align-items: flex-start; flex-wrap: wrap; }
    .diagnostic-grid {
        grid-template-columns: 1fr;
        grid-template-rows: none;
        grid-template-areas: none;
        align-content: start;
    }
    #diagGeneratorCard,
    #diagLifeCard,
    #diagOutpostCard,
    #diagNetworkCard,
    #diagAlarmCard,
    #diagPowerCard,
    #diagSecurityCard,
    #diagEventsCard,
    #diagIntegrityCard,
    #diagUplinkCard { grid-area: auto; }
    .diagnostic-card.wide { grid-column: auto; }
    .diagnostic-card { min-height: 118px; }
    .diagnostic-readout { font-size: 10px; min-height: 6.1em; }
    .diagnostic-card.wide .diagnostic-readout { min-height: 8.55em; }
}

@media (min-width: 761px) and (max-width: 1160px) {
    .diagnostic-dashboard-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        grid-template-rows: repeat(6, minmax(144px, 1fr));
        grid-template-areas:
            "scope scope radar radar"
            "tomo tomo tomo tomo"
            "tomo tomo tomo tomo"
            "react react fabric fabric"
            "log log gauge uplink"
            "bio bio water water";
    }
}

/* ===== FACILITY STATUS ===== */
.facility-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 225;
    background:
        radial-gradient(circle at 46% 28%, rgba(57, 255, 20, 0.055), transparent 34%),
        rgba(0, 0, 0, 0.91);
    align-items: center;
    justify-content: center;
    padding: 0;
}

.facility-overlay.active { display: flex; }

body.terminal-map-active {
    overflow: hidden !important;
    background: #000 !important;
}

body.terminal-map-active > :not(#facilityOverlay):not(script) {
    display: none !important;
}

body.terminal-map-active #facilityOverlay {
    display: flex !important;
}

body.terminal-map-active .facility-overlay,
body.terminal-map-active .facility-map-panel,
body.terminal-map-active .facility-map-shell {
    background: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
}

body.terminal-map-active .facility-map-panel {
    transform: none !important;
    opacity: 1 !important;
    will-change: auto !important;
}

body.terminal-map-active .facility-map-panel .facility-close {
    backdrop-filter: none !important;
    box-shadow: none !important;
}

.facility-panel {
    width: min(1320px, 100%);
    height: min(820px, calc(var(--viewport-height) - 36px));
    border: 1px solid rgba(57, 255, 20, 0.48);
    background:
        linear-gradient(90deg, rgba(57, 255, 20, 0.045), transparent 30%),
        linear-gradient(180deg, rgba(32, 194, 14, 0.055), rgba(0, 0, 0, 0.18)),
        rgba(2, 10, 6, 0.98);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow:
        inset 0 0 44px rgba(57, 255, 20, 0.055),
        0 0 42px rgba(57, 255, 20, 0.08);
    contain: layout paint style;
}

.facility-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(57, 255, 20, 0.28);
    background: rgba(0, 18, 5, 0.56);
}

.facility-title {
    color: var(--phosphor);
    letter-spacing: 2px;
    font-size: var(--font-size-title);
}

.facility-meta {
    color: var(--amber);
    font-size: var(--font-size-tiny);
    opacity: 0.86;
    white-space: nowrap;
}

.facility-close {
    border: 1px solid rgba(57, 255, 20, 0.42);
    background: rgba(0, 20, 8, 0.78);
    color: var(--phosphor);
    font-family: var(--terminal-font);
    font-size: var(--font-size-small);
    padding: 7px 10px;
    min-height: 36px;
    cursor: pointer;
    touch-action: manipulation;
}

.facility-layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(340px, 0.72fr);
    gap: 10px;
    padding: 10px;
}

.facility-map-wrap {
    position: relative;
    min-height: 0;
    border: 1px solid rgba(57, 255, 20, 0.28);
    background:
        radial-gradient(circle at 50% 50%, rgba(57, 255, 20, 0.06), transparent 58%),
        repeating-linear-gradient(0deg, rgba(32, 194, 14, 0.04), rgba(32, 194, 14, 0.04) 1px, transparent 1px, transparent 18px),
        repeating-linear-gradient(90deg, rgba(32, 194, 14, 0.03), rgba(32, 194, 14, 0.03) 1px, transparent 1px, transparent 18px),
        rgba(0, 7, 3, 0.78);
    overflow: hidden;
    contain: layout paint style;
}

.facility-atmosphere-canvas {
    position: absolute;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
    opacity: 0.55;
}

#facilityCanvas {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100%;
    min-height: 100%;
}

#facilityCanvas .telemetry-svg {
    min-height: 100%;
}

.facility-map-hud {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 8px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--amber);
    font-size: var(--font-size-tiny);
    pointer-events: none;
    opacity: 0.82;
    z-index: 2;
}

.facility-sidebar {
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.facility-card {
    border: 1px solid rgba(32, 194, 14, 0.26);
    background:
        linear-gradient(180deg, rgba(57, 255, 20, 0.045), transparent 55%),
        rgba(0, 10, 4, 0.76);
    padding: 8px 9px;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(57, 255, 20, 0.055);
    contain: layout paint style;
}

.facility-card-title {
    color: var(--amber);
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(57, 255, 20, 0.16);
    padding-bottom: 3px;
    margin-bottom: 5px;
    font-size: clamp(9px, 0.7vw, 11px);
}

.facility-readout {
    margin: 0;
    color: var(--phosphor);
    font-family: var(--terminal-font);
    font-size: clamp(9px, 0.66vw, 11px);
    line-height: 1.16;
    white-space: pre;
    overflow: hidden;
}

.facility-telemetry-strip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-top: 1px solid rgba(57, 255, 20, 0.18);
    padding: 7px 12px;
    min-height: 31px;
    color: var(--amber);
    background: rgba(0, 14, 5, 0.38);
    font-family: var(--terminal-font);
    font-size: clamp(9px, 0.7vw, 11px);
    letter-spacing: 0.04em;
    white-space: nowrap;
    overflow: hidden;
}

.facility-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-top: 1px solid rgba(57, 255, 20, 0.2);
    padding: 8px 12px;
    color: var(--phosphor);
    font-size: var(--font-size-small);
    background: rgba(0, 14, 5, 0.44);
    min-height: 38px;
}

.facility-zone-shape {
    fill: currentColor;
    stroke: currentColor;
    stroke-width: 0.8;
    vector-effect: non-scaling-stroke;
}

.facility-command-center-alert {
    color: var(--red);
}

.facility-map-panel {
    width: 100vw;
    height: var(--viewport-height);
    max-width: none;
    border: 0;
    background:
        radial-gradient(circle at 50% 38%, rgba(255, 138, 42, 0.06), transparent 42%),
        linear-gradient(180deg, rgba(30, 12, 3, 0.66), rgba(0, 0, 0, 0.92)),
        #020202;
    box-shadow: none;
}

.facility-map-panel .facility-header {
    position: absolute;
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    z-index: 6;
    padding: 0;
    border: 0;
    background: transparent;
}

.facility-map-panel .facility-header > div,
.facility-map-panel .facility-footer {
    display: none;
}

.facility-map-panel .facility-close {
    min-height: 42px;
    padding: 9px 13px;
    border-color: rgba(255, 154, 60, 0.72);
    color: var(--amber-soft);
    background: rgba(5, 2, 0, 0.72);
    box-shadow:
        inset 0 0 16px rgba(255, 154, 60, 0.12),
        0 0 18px rgba(255, 104, 32, 0.16);
    backdrop-filter: blur(3px);
}

.facility-map-shell {
    position: relative;
    flex: 1;
    min-height: 0;
    border: 0;
    overflow: hidden;
    background:
        repeating-linear-gradient(0deg, rgba(255, 154, 60, 0.025), rgba(255, 154, 60, 0.025) 1px, transparent 1px, transparent 5px),
        radial-gradient(circle at 50% 44%, rgba(255, 154, 60, 0.07), transparent 48%),
        #020202;
}

.facility-map-frame-wrap,
.facility-map-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.facility-map-frame {
    border: 0;
    display: block;
    background: #020202;
}

.facility-map-loader {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
    text-align: center;
    color: var(--amber);
    background:
        radial-gradient(circle at center, rgba(255, 154, 60, 0.08), transparent 30%),
        #000;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.facility-map-loader[hidden],
.facility-map-frame-wrap[hidden] {
    display: none;
}

.facility-loader-logo {
    color: var(--phosphor);
    font-size: clamp(18px, 3.6vw, 46px);
    letter-spacing: 0.18em;
    text-shadow: 0 0 16px rgba(57, 255, 20, 0.32);
}

.facility-loader-title {
    color: var(--cyan);
    font-size: clamp(11px, 1.1vw, 16px);
}

.facility-loader-bar {
    width: min(520px, 72vw);
    height: 11px;
    border: 1px solid rgba(255, 154, 60, 0.54);
    background: rgba(0, 0, 0, 0.72);
    padding: 2px;
    box-shadow: inset 0 0 14px rgba(255, 154, 60, 0.1);
}

.facility-loader-bar span {
    display: block;
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--amber), var(--red));
    box-shadow: 0 0 12px rgba(255, 154, 60, 0.36);
    transition: width 180ms linear;
}

.facility-loader-text {
    min-height: 1.4em;
    color: var(--amber-soft);
    font-size: var(--font-size-small);
}

.facility-map-loader[data-tone="error"] .facility-loader-text,
.facility-map-loader[data-tone="error"] .facility-loader-title {
    color: var(--red);
}

.facility-map-loader[data-tone="warn"] .facility-loader-text,
.facility-map-loader[data-tone="warn"] .facility-loader-title {
    color: var(--amber);
}

.facility-legacy-readouts {
    display: none;
}

@media (max-width: 820px) {
    .facility-overlay { padding: 10px; }
    .facility-panel {
        height: calc(var(--viewport-height) - 20px);
    }
    .facility-header { align-items: flex-start; flex-wrap: wrap; }
    .facility-layout {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(300px, 52vh) auto;
        overflow: auto;
    }
    .facility-sidebar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: none;
    }
    .facility-readout {
        font-size: 10px;
    }
    .facility-telemetry-strip {
        overflow-x: auto;
        scrollbar-width: thin;
    }

    .facility-map-panel {
        width: 100vw;
    }
}

@media (max-width: 560px) {
    .facility-sidebar {
        grid-template-columns: 1fr;
    }

    .facility-map-hud,
    .facility-footer {
        flex-wrap: wrap;
    }
}

/* Full-page tool transfer and diagnostic screen shell. */
.tool-transfer-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: grid;
    place-items: center;
    background: #000;
    color: var(--amber);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
}

.tool-transfer-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.tool-transfer-panel {
    width: min(520px, calc(100vw - 40px));
    border: 1px solid rgba(255, 176, 0, 0.58);
    background: rgba(7, 6, 2, 0.92);
    padding: 26px;
    box-shadow: 0 0 28px rgba(255, 176, 0, 0.14), inset 0 0 24px rgba(255, 176, 0, 0.06);
}

.tool-transfer-brand {
    color: var(--cyan);
    font-size: var(--font-size-small);
    letter-spacing: 0.14em;
    margin-bottom: 16px;
}

.tool-transfer-text {
    color: var(--amber);
    font-size: var(--font-size-base);
}

.tool-transfer-subtext {
    color: var(--green-dim);
    font-size: var(--font-size-small);
}

.tool-transfer-bar {
    height: 9px;
    margin: 18px 0 12px;
    border: 1px solid rgba(57, 255, 20, 0.38);
    background: rgba(57, 255, 20, 0.08);
    overflow: hidden;
}

.tool-transfer-bar span {
    display: block;
    width: 100%;
    height: 100%;
    transform-origin: left center;
    background: linear-gradient(90deg, var(--green), var(--cyan), var(--amber));
    animation: tool-transfer-fill 560ms ease forwards;
}

@keyframes tool-transfer-fill {
    from { transform: scaleX(0.08); }
    to { transform: scaleX(1); }
}

.diagnostic-screen-page {
    min-height: 100vh;
    overflow: hidden;
    background: #020403;
}

.diagnostic-screen-page .diagnostic-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    padding: clamp(8px, 1.2vw, 16px);
    background: radial-gradient(circle at 50% 38%, rgba(32, 194, 14, 0.08), transparent 56%), #020403;
}

.diagnostic-screen-page .diagnostic-panel {
    width: 100%;
    max-width: none;
    height: calc(var(--viewport-height, 100vh) - clamp(16px, 2.4vw, 32px));
}

@media (prefers-reduced-motion: reduce) {
    .tool-transfer-overlay,
    .tool-transfer-bar span {
        transition: none;
        animation: none;
    }
}

