/* PHACT Web GUI — HUD Theme */

:root {
    --bg: #0a0e14;
    --panel-bg: #0d1117;
    --title: #00afff;
    --label: #808080;
    --dim: #585858;
    --good: #5fff00;
    --warn: #ffaf00;
    --alarm: #ff0000;
    --text: #c8d0d8;
    --border: #1a2030;
    --glow: rgba(0, 175, 255, 0.15);
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'SF Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
    min-height: 100vh;
}

/* Scanline overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.03) 2px,
        rgba(0, 0, 0, 0.03) 4px
    );
    z-index: 9999;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(0, 175, 255, 0.05) 0%, transparent 100%);
}

.header h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--title);
    text-transform: uppercase;
    letter-spacing: 3px;
    text-shadow: 0 0 20px rgba(0, 175, 255, 0.3);
}

/* LIVE badge */
.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    font-weight: 700;
    color: var(--alarm);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--alarm);
    animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 4px var(--alarm); }
    50% { opacity: 0.3; box-shadow: 0 0 8px var(--alarm); }
}

.live-badge.stale {
    color: var(--dim);
}

.live-badge.stale .live-dot {
    background: var(--dim);
    animation: none;
}

.header .status {
    font-size: 11px;
    color: var(--dim);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.header-clock {
    margin-left: auto;
    font-size: 11px;
    color: var(--label);
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
}

.footer-links {
    margin-top: 8px;
}
.footer-links a {
    color: var(--label);
    text-decoration: none;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    transition: all 0.2s;
}
.footer-links a:hover {
    color: var(--title);
    border-bottom-color: var(--title);
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}

.breadcrumb a {
    color: var(--title);
    text-decoration: none;
    cursor: pointer;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.breadcrumb a:hover {
    text-shadow: 0 0 8px rgba(0, 175, 255, 0.5);
}

.breadcrumb .sep {
    color: var(--dim);
}

.breadcrumb .current {
    color: var(--text);
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Views */
.view {
    display: none;
    padding: 24px;
}

.view.active {
    display: block;
}

/* Globe */
#globe-container {
    height: 420px;
    width: 100%;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
}

/* Constellation stats strip */
.constellation-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(90deg, rgba(0, 175, 255, 0.04) 0%, transparent 100%);
    font-size: 11px;
    color: var(--label);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.constellation-stats:empty {
    display: none;
}

.stat {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.stat-value {
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
}

/* Constellation table */
.fleet-table {
    width: 100%;
    border-collapse: collapse;
}

.fleet-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--title);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    border-bottom: 2px solid var(--title);
    background: linear-gradient(180deg, var(--glow) 0%, transparent 100%);
}

.fleet-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.fleet-table tr {
    cursor: pointer;
    transition: background 0.15s;
}

.fleet-table tbody tr:hover {
    background: var(--glow);
}

.fleet-table .mono {
    font-variant-numeric: tabular-nums;
}

/* Panel grid */
.panel-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.panel {
    position: relative;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.panel-header {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 700;
    color: var(--title);
    text-transform: uppercase;
    letter-spacing: 2px;
    background: linear-gradient(90deg, rgba(0, 175, 255, 0.12) 0%, transparent 100%);
    border-bottom: 1px solid var(--border);
}

.panel-body {
    padding: 12px;
}

.panel-full {
    grid-column: 1 / -1;
}

/* Key-value rows */
.kv-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0;
}

.kv-label {
    color: var(--label);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.kv-value {
    font-variant-numeric: tabular-nums;
}

/* Status indicators */
.good { color: var(--good); }
.warn { color: var(--warn); }
.alarm { color: var(--alarm); font-weight: 700; animation: pulse-alarm 1.5s ease-in-out infinite; }
.dim { color: var(--dim); }
.label-color { color: var(--label); }

@keyframes pulse-alarm {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Alarm glow on bar fills */
.bar-fill.alarm {
    animation: glow-alarm 1.5s ease-in-out infinite;
}

@keyframes glow-alarm {
    0%, 100% { box-shadow: 0 0 6px rgba(255, 0, 0, 0.4); }
    50% { box-shadow: 0 0 14px rgba(255, 0, 0, 0.8); }
}

/* Progress bars */
.bar-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bar {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    max-width: 100px;
}

.bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

.bar-fill.good { background: var(--good); box-shadow: 0 0 6px rgba(95, 255, 0, 0.4); }
.bar-fill.warn { background: var(--warn); box-shadow: 0 0 6px rgba(255, 175, 0, 0.4); }
.bar-fill.alarm { background: var(--alarm); box-shadow: 0 0 6px rgba(255, 0, 0, 0.4); }

/* Tables inside panels */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.data-table th {
    text-align: left;
    padding: 4px 8px;
    font-size: 10px;
    font-weight: 600;
    color: var(--label);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table .totals td {
    border-top: 2px solid var(--border);
    font-weight: 600;
    color: var(--label);
}

/* Heater/boolean indicators */
.indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.indicator.on { background: var(--warn); box-shadow: 0 0 6px rgba(255, 175, 0, 0.5); }
.indicator.off { background: var(--dim); }

/* Status badge */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.badge.ok { background: rgba(95, 255, 0, 0.15); color: var(--good); }
.badge.safe { background: rgba(255, 0, 0, 0.15); color: var(--alarm); }
.badge.eclipse { background: rgba(255, 175, 0, 0.15); color: var(--warn); }

/* Empty state */
.empty {
    text-align: center;
    padding: 60px 24px;
    color: var(--dim);
    font-size: 14px;
    letter-spacing: 1px;
}

.empty .icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

/* Severity badges for events */
.sev-info { color: var(--title); }
.sev-warn { color: var(--warn); }
.sev-alarm { color: var(--alarm); font-weight: 700; }

/* Service state badges */
.state-run { color: var(--good); }
.state-stop { color: var(--dim); }
.state-crash { color: var(--alarm); }

/* Source code overlay */
.source-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.source-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 80%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 40px rgba(0, 175, 255, 0.1);
}

.source-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 700;
    color: var(--title);
    text-transform: uppercase;
    letter-spacing: 2px;
    background: linear-gradient(90deg, rgba(0, 175, 255, 0.12) 0%, transparent 100%);
    border-bottom: 1px solid var(--border);
}

.source-close {
    background: none;
    border: none;
    color: var(--label);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.source-close:hover {
    color: var(--text);
}

/* Program metadata section */
.source-meta {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    line-height: 1.6;
    background: rgba(0, 175, 255, 0.04);
}

.source-meta:empty {
    display: none;
}

.source-meta-desc {
    color: var(--text);
    margin-bottom: 8px;
    font-size: 12px;
}

.source-meta-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
}

.source-meta-field {
    white-space: nowrap;
}

.source-meta-label {
    color: var(--label);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-right: 4px;
    font-size: 10px;
}

.source-meta-value {
    color: var(--text);
}

.source-meta-role-core {
    color: var(--alarm);
    font-weight: 700;
}

.source-meta-role-root {
    color: var(--warn);
    font-weight: 700;
}

.source-meta-role-user {
    color: var(--dim);
}

.source-meta-perms {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.source-meta-perm {
    background: rgba(0, 175, 255, 0.1);
    border: 1px solid rgba(0, 175, 255, 0.2);
    border-radius: 3px;
    padding: 1px 6px;
    font-size: 10px;
    color: var(--title);
}

.source-meta-hooks {
    margin-top: 6px;
    color: var(--dim);
    font-size: 10px;
}

.source-meta-hook {
    color: var(--good);
    margin-right: 8px;
}

.source-code {
    margin: 0;
    padding: 16px;
    overflow: auto;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text);
    white-space: pre;
    tab-size: 4;
}

/* QD syntax highlighting */
.qd-comment { color: var(--dim); font-style: italic; }
.qd-string { color: var(--warn); }
.qd-keyword { color: #c678dd; font-weight: 700; }
.qd-number { color: var(--good); }
.qd-call { color: var(--title); }
.qd-arrow { color: #c678dd; }
.qd-directive { color: var(--label); font-style: italic; }

/* Clickable service name */
.svc-link {
    color: var(--title);
    cursor: pointer;
    text-decoration: none;
}

.svc-link:hover {
    text-decoration: underline;
    text-shadow: 0 0 6px rgba(0, 175, 255, 0.4);
}

/* Footer */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 32px 24px;
    margin-top: 24px;
    background: linear-gradient(180deg, transparent 0%, rgba(0, 175, 255, 0.03) 100%);
}

.footer-content {
    max-width: 720px;
}

.footer-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--title);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 12px;
}

.site-footer p {
    font-size: 12px;
    color: var(--label);
    line-height: 1.7;
    margin-bottom: 8px;
}

.site-footer .footer-dim {
    color: var(--dim);
    font-size: 11px;
}

/* Sparklines */
.sparkline {
    vertical-align: middle;
    display: inline-block;
}

.sparkline-row {
    padding: 4px 0;
    text-align: center;
}

/* Satellite breathing animation */
@keyframes sat-breathe {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
}

/* Eclipse glow animation */
@keyframes eclipse-glow {
    0%, 100% { filter: drop-shadow(0 0 8px rgba(255,175,0,0.8)); transform: scale(1); }
    50% { filter: drop-shadow(0 0 14px rgba(255,175,0,0.5)); transform: scale(1.2); }
}

/* Health score */
.health-score {
    display: inline-flex;
    align-items: baseline;
    gap: 2px;
    font-size: 11px;
    color: var(--label);
    padding-left: 12px;
    border-left: 3px solid var(--title);
    margin-right: 12px;
}

.health-value {
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Satellite tooltip */
.sat-tooltip {
    position: fixed;
    z-index: 4000;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px 14px;
    font-size: 11px;
    pointer-events: none;
    box-shadow: 0 0 20px rgba(0,175,255,0.15);
    min-width: 160px;
}

.tip-name {
    color: var(--title);
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.tip-row {
    padding: 2px 0;
    color: var(--text);
}

/* Last update counter */
#last-update {
    font-size: 10px;
    color: var(--dim);
    letter-spacing: 1px;
}

/* Mercator map */
#mercator-map {
    width: 100%;
    height: 120px;
    display: block;
    border-bottom: 1px solid var(--border);
}

/* Orbital plane dividers */
.plane-divider td {
    padding: 4px 12px !important;
    border-bottom: 1px solid var(--border) !important;
    background: rgba(0,175,255,0.04);
}

.plane-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--title);
    text-transform: uppercase;
    letter-spacing: 2px;
    padding-left: 8px;
    border-left: 3px solid var(--title);
}

.plane-divider {
    cursor: default !important;
}

.plane-divider:hover {
    background: rgba(0,175,255,0.04) !important;
}

/* GPS Receiver panel */
.gps-panel {
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
}

.gps-panel:empty {
    display: none;
}

.gps-panel .panel-header {
    background: linear-gradient(90deg, rgba(95, 255, 0, 0.12) 0%, transparent 100%);
    color: var(--good);
}

.gps-panel .panel-body {
    display: flex;
    flex-wrap: wrap;
    gap: 0 24px;
}

.gps-panel .kv-row {
    min-width: 160px;
}

/* Terminal panel */
#panel-terminal-body {
    display: flex;
    flex-direction: column;
    height: 300px;
    padding: 0;
}

.terminal-output {
    flex: 1;
    overflow-y: auto;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    padding: 12px;
}

.terminal-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: 1px solid var(--border);
    padding: 8px 12px;
    flex-shrink: 0;
}

.terminal-prompt {
    color: var(--title);
    font-size: 12px;
    white-space: nowrap;
}

.terminal-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    caret-color: var(--title);
}

.terminal-input::placeholder {
    color: var(--dim);
}

.term-cmd { color: var(--good); }
.term-out { color: var(--dim); }
.term-err { color: var(--alarm); }
.term-prompt-echo { color: var(--title); }

/* HUD corner brackets (injected into every .panel via JS) */
.hud-c {
    position: absolute;
    width: 10px;
    height: 10px;
    border-color: var(--title);
    border-style: solid;
    opacity: 0.5;
    pointer-events: none;
}
.hud-c.tl { top: 0; left: 0; border-width: 1.5px 0 0 1.5px; }
.hud-c.tr { top: 0; right: 0; border-width: 1.5px 1.5px 0 0; }
.hud-c.bl { bottom: 0; left: 0; border-width: 0 0 1.5px 1.5px; }
.hud-c.br { bottom: 0; right: 0; border-width: 0 1.5px 1.5px 0; }

/* Panel glow by alert state */
.panel[data-alert="warn"] {
    border-color: rgba(255,175,0,0.5);
    box-shadow: 0 0 10px rgba(255,175,0,0.2), inset 0 0 20px rgba(255,175,0,0.03);
}
.panel[data-alert="alarm"] {
    border-color: rgba(255,0,0,0.6);
    box-shadow: 0 0 14px rgba(255,0,0,0.35), inset 0 0 20px rgba(255,0,0,0.05);
    animation: glow-alarm 1.5s ease-in-out infinite;
}



/* New log/event row arrival animation */
@keyframes row-arrive {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0); }
}
.data-table tr.new-row td {
    animation: row-arrive 0.3s ease-out forwards;
}

/* Responsive */
@media (max-width: 900px) {
    .panel-grid {
        grid-template-columns: 1fr;
    }
    .hide-narrow {
        display: none;
    }
    .constellation-right {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

.hide-always {
    display: none;
}

/* Narrow: stack globe, table, footer in column order */
@media (max-width: 1023px) {
    .constellation-layout {
        display: flex;
        flex-direction: column;
    }
    .constellation-left {
        display: contents;
    }
    .constellation-left .site-footer {
        order: 99;
    }
}

/* Wide-screen two-pane: globe beside fleet table */
@media (min-width: 1024px) {
    #view-constellation.view.active {
        overflow: hidden;
        height: calc(100vh - 57px);
        box-sizing: border-box;
    }
    .constellation-layout {
        display: flex;
        height: 100%;
    }
    .constellation-left {
        flex: 0 0 50%;
        max-width: 50%;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
    }
    .constellation-left #globe-container {
        flex: 1;
        height: auto;
        min-height: 300px;
    }
    .constellation-left #mercator-map {
        flex-shrink: 0;
    }
    .constellation-left .site-footer {
        flex-shrink: 0;
    }
    .constellation-right {
        flex: 1;
        overflow-x: auto;
        overflow-y: auto;
    }
}
