/* style.css – Cyberpunk APRS-style for Meshtastic Terminal */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;800&display=swap');

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

html, body {
    height: 100%;
    width: 100%;
    background: #000;
    color: #0ff;
    font-family: 'JetBrains Mono', monospace;
    overflow: hidden;
}

:root {
    --chrome-header-h: 56px;
    --chrome-tabs-h: 48px;
    --chrome-h: calc(var(--chrome-header-h) + var(--chrome-tabs-h));
    --chrome-z: 20000;
    --map-z: 1;
}

/* Shell */
#terminal {
    position: relative;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    overflow: hidden;
    background: #000;
}

h1, h2, h3 { color: #0ff; text-shadow: 0 0 10px #0ff; letter-spacing: 2px; }
a { color: #0f8; }

/* CRT Scanlines — keep BELOW chrome so they never mask tabs/header */
#crt {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}
#crt::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(transparent 50%, rgba(0,255,255,0.03) 50%);
    background-size: 100% 4px;
    pointer-events: none;
}
#crt::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0,255,255,0.015);
    pointer-events: none;
    animation: scan 8s linear infinite;
}
@keyframes scan { 0% { transform: translateY(-100%); } 100% { transform: translateY(100%); } }

@keyframes pulse-ring {
    0% { transform: scale(0.1); opacity: 1; }
    100% { transform: scale(4); opacity: 0; }
}
.ping-anim {
    background: #00ffaa;
    border-radius: 50%;
    animation: pulse-ring 1.5s cubic-bezier(0.215, 0.61, 0.355, 1);
}

/* Fixed chrome — cannot be scrolled away or covered by Leaflet */
#header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--chrome-header-h);
    background: #000;
    padding: 8px 15px;
    border-bottom: 2px solid #0ff;
    box-shadow: 0 0 20px #0ff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    z-index: var(--chrome-z);
    overflow: hidden;
}
#header h1 {
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.status-line {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    white-space: nowrap;
}
.status-line span { margin-right: 12px; color: #0f8; font-size: 0.9em; }
#server-status { color: #f00; }
.blink { animation: blink 1.5s steps(1) infinite; }
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:0.3; } }

#tab-bar {
    position: fixed;
    top: var(--chrome-header-h);
    left: 0;
    right: 0;
    height: var(--chrome-tabs-h);
    display: flex;
    align-items: center;
    background: #000;
    border-bottom: 2px solid #0ff;
    padding: 0 15px;
    gap: 4px;
    z-index: var(--chrome-z);
}
#tab-bar .tab {
    background: #000;
    color: #0ff;
    border: 1px solid #0ff;
    padding: 6px 18px;
    font-family: 'JetBrains Mono', monospace;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.9em;
    transition: all 0.2s;
}
#tab-bar .tab:hover {
    background: #033;
    box-shadow: 0 0 10px #0ff;
}
#tab-bar .tab.active {
    background: #0ff;
    color: #000;
    box-shadow: 0 0 15px #0ff;
}

/* Main workspace sits UNDER fixed chrome */
#main {
    position: fixed;
    top: var(--chrome-h);
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    overflow: hidden;
    z-index: 10;
    background: #000;
}

#panels {
    width: 440px;
    max-width: 40vw;
    display: flex;
    flex-direction: column;
    background: #000;
    border-right: 2px solid #0ff;
    box-shadow: 0 0 20px #0ff;
    flex-shrink: 0;
    overflow: hidden;
    min-height: 0;
    z-index: 20;
    position: relative;
}

#view-area {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    min-height: 0;
    min-width: 0;
    z-index: var(--map-z);
}

.view-panel {
    position: absolute;
    inset: 0;
    overflow: auto;
    display: none;
    min-height: 0;
    background: #000;
}

#map-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    min-height: 0;
    overflow: hidden;
    position: absolute;
    inset: 0;
    z-index: var(--map-z);
}

/* Leaflet must stay inside map box and below chrome */
#map {
    width: 100%;
    height: 100%;
    min-height: 0;
    z-index: var(--map-z) !important;
}
.leaflet-container {
    width: 100% !important;
    height: 100% !important;
    z-index: var(--map-z) !important;
    background: #000;
    font: inherit;
}
.leaflet-pane,
.leaflet-map-pane,
.leaflet-tile-pane,
.leaflet-overlay-pane,
.leaflet-shadow-pane,
.leaflet-marker-pane,
.leaflet-tooltip-pane,
.leaflet-popup-pane {
    z-index: auto;
}
.leaflet-top,
.leaflet-bottom {
    z-index: 50;
}
.leaflet-control {
    z-index: 50;
}

/* Left panels */
.panel {
    background: #000;
    padding: 0 12px 12px 12px;
    overflow: hidden;
    border-bottom: 2px solid #033;
    display: flex;
    flex-direction: column;
}
.panel h2 {
    font-size: 1em;
    margin: 8px 0;
    flex-shrink: 0;
}
.panel > .scroll,
.panel.scroll > .scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}
#activity-log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    font-size: 0.8em;
    white-space: pre-wrap;
}
#node-details {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    font-size: 0.85em;
}

table { color: #0ff; font-size: 0.85em; }
th { color: #0f8; text-align: left; border-bottom: 1px solid #033; padding: 2px 4px; }
td { padding: 2px 4px; border-bottom: 1px dashed #022; }
tr:hover { background: #022; cursor: pointer; }

.scroll {
    scrollbar-width: thin;
    scrollbar-color: #0ff #000;
}
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb { background: #0ff; box-shadow: 0 0 10px #0ff; }

/* Corner labels on map */
.corner-tr, .corner-tl {
    position: absolute;
    z-index: 60;
    color: #0ff;
    font-size: 0.75em;
    pointer-events: none;
    text-shadow: 0 0 8px #0ff;
}
.corner-tr { top: 8px; right: 10px; }
.corner-tl { bottom: 8px; left: 10px; }

/* ============================================================
   SIGINT DASHBOARD PANELS
   ============================================================ */
.intel-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 12px;
    height: 100%;
    min-height: 0;
    overflow: auto;
}
.intel-grid-focus {
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: minmax(160px, auto);
}
.intel-span-2 { grid-column: 1 / -1; }
.intel-card {
    background: #000;
    border: 1px solid #033;
    padding: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.intel-card h3 {
    font-size: 0.9em;
    margin-bottom: 8px;
    color: #0ff;
}
.card-sub {
    color: #0f8;
    font-size: 0.75em;
    font-weight: 400;
    margin-left: 8px;
}
.chart-wrap {
    flex: 1;
    min-height: 120px;
    position: relative;
    margin-bottom: 8px;
}
.chart-wrap.chart-tall { min-height: 200px; }
.chart-wrap canvas {
    position: absolute;
    inset: 0;
}

.tele-controls {
    padding: 12px;
    border-bottom: 1px solid #033;
    flex-shrink: 0;
}
.tele-label {
    color: #0ff;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9em;
}
.tele-label select {
    background: #000;
    color: #0ff;
    border: 1px solid #0ff;
    font-family: 'JetBrains Mono', monospace;
    padding: 4px 8px;
    margin-left: 8px;
}
.tele-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 12px;
    flex: 1;
    min-height: 0;
}
.tele-fleet-stats {
    margin-left: 16px;
    color: #0f8;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
}

#detections-feed .detection-entry {
    padding: 4px 0;
    border-bottom: 1px dashed #033;
    font-size: 0.85em;
}
.detections-full {
    flex: 1;
    min-height: 140px;
}
.det-time { color: #0f8; }
.det-from { color: #f80; }
.det-text { color: #0ff; }

#health-cards {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}
@media (max-width: 1100px) {
    #health-cards { grid-template-columns: repeat(3, 1fr); }
}
.health-card {
    background: #033;
    padding: 10px;
    border: 1px solid #0ff;
    text-align: center;
}
.health-label {
    font-size: 0.75em;
    color: #0f8;
    margin-bottom: 4px;
}
.health-value {
    font-size: 1.2em;
    color: #0ff;
    text-shadow: 0 0 8px #0ff;
}

#messages-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
}
#messages-table th, #messages-table td {
    padding: 2px 4px;
    text-align: left;
    border-bottom: 1px dashed #033;
}
#messages-container {
    flex: 1;
    min-height: 180px;
}

/* Graph panel — full remaining height under toolbar */
#graph-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    background: #000;
}
#telemetry-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}
.graph-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid #033;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8em;
    color: #0ff;
    flex-shrink: 0;
    background: #000;
    z-index: 2;
}
.graph-stats { color: #0f8; flex: 1; min-width: 180px; }
.graph-toggle { color: #0ff; display: inline-flex; align-items: center; gap: 6px; }
.graph-toggle input, .graph-toggle select {
    accent-color: #0ff;
    background: #000;
    color: #0ff;
    border: 1px solid #0ff;
    font-family: inherit;
}
.graph-body {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    overflow: hidden;
}
#graph-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: #000;
}

.intel-note {
    color: #0f8;
    font-size: 0.75em;
    margin: 8px 0 0;
    min-height: 1em;
}
#rf-links-table,
.rf-links-full {
    flex: 1;
    min-height: 160px;
}
#rf-links-table table { width: 100%; border-collapse: collapse; font-size: 0.85em; }
#rf-links-table th, #rf-links-table td {
    border-bottom: 1px dashed #033;
    padding: 3px 6px;
    text-align: left;
    color: #0ff;
}
.snr-good { color: #0f8; }
.snr-mid { color: #ff0; }
.snr-bad { color: #f66; }

.leaflet-popup-pane
{
    z-index: 6000 !important;
}
.leaflet-popup {
    z-index: 6001 !important;
}
#map-container
{
    /* Allow popups to render outside the view box; do NOT clip them */
    overflow: visible;
}
#map
{
    overflow: visible;
}

/* ============================================================
   MAP DRAWER (small screens)
   ============================================================ */

#map-drawer-toggle
{
    position: fixed;
    top: calc(var(--chrome-h) + 8px);
    left: 8px;
    z-index: 30;
    background: #000;
    color: #0ff;
    border: 1px solid #0ff;
    border-radius: 4px;
    padding: 6px 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    letter-spacing: 1px;
    cursor: pointer;
    display: none;
    box-shadow: 0 0 10px #0ff;
}
#map-drawer-toggle:hover
{
    background: #033;
}

/* Drawer panel container */
#panels
{
    position: absolute;
    left: 0;
    top: var(--chrome-h);
    bottom: 0;
    width: 320px;
    max-width: 88vw;
    background: #000;
    border-right: 2px solid #0ff;
    box-shadow: 0 0 20px #0ff;
    z-index: 25;
    transition: transform 0.22s ease;
}

/* Hide panels by default on small screens; show via transform */
@media (max-width: 992px)
{
    #map-drawer-toggle
    {
        display: block;
    }

    #panels
    {
        transform: translateX(-100%);
    }

    body.drawer-open #panels
    {
        transform: translateX(0);
    }

    body.drawer-open #map-drawer-toggle
    {
        left: 332px;
    }
}

/* Desktop keeps the normal side rail */
@media (min-width: 993px)
{
    #panels
    {
        position: relative;
        transform: none;
        width: 440px;
        max-width: 40vw;
        z-index: 20;
    }

    #map-drawer-toggle
    {
        display: none !important;
    }
}

@media (max-width: 900px) {
    #panels { width: 320px; max-width: 45vw; }
    .intel-grid, .intel-grid-focus { grid-template-columns: 1fr; }
    .intel-span-2 { grid-column: auto; }
    #health-cards { grid-template-columns: 1fr 1fr; }
    #header h1 { font-size: 0.95rem; }
}
