/* ── Dark/light theme tokens (added). Same --g3-* family and values as
   the (currently parked) themed graphics-control sheets - identical
   duplicate definitions are harmless and keep the HUD ecosystem on one
   palette when that work lands. RGB-triplet technique: dark renders
   byte-identical; light swaps triplets. Series/status colors in the JS
   config layer are data-plane and unchanged. ── */
.dark-theme {
    --g3-accent-rgb: 56, 189, 248;
    --g3-accent: #38bdf8;
    --g3-accent-bright: #67e8f9;
    --g3-glass-rgb: 2, 8, 20;
    --g3-deep-rgb: 15, 23, 42;
    --g3-ok-rgb: 6, 214, 160;
    --g3-ok: #06d6a0;
    --g3-alarm-rgb: 248, 113, 113;
    --g3-alarm: #f87171;
    --g3-dim-rgb: 148, 163, 184;
    --g3-dim: #94a3b8;
    --g3-fg-rgb: 226, 232, 240;
    --g3-fg: #e2e8f0;
    --g3-fg-mid: #cbd5e1;
    --g3-bright-rgb: 248, 250, 252;
    --g3-warn-rgb: 251, 191, 36;
    --g3-warn: #fbbf24;
    --g3-sel-rgb: 168, 64, 77;
    --g3-sel: #A8404D;
}

.light-theme {
    --g3-accent-rgb: 2, 132, 199;
    --g3-accent: #0284c7;
    --g3-accent-bright: #0369a1;
    --g3-glass-rgb: 255, 255, 255;
    --g3-deep-rgb: 228, 233, 241;
    --g3-ok-rgb: 13, 148, 136;
    --g3-ok: #0d9488;
    --g3-alarm-rgb: 214, 48, 48;
    --g3-alarm: #d63030;
    --g3-dim-rgb: 86, 103, 130;
    --g3-dim: #566782;
    --g3-fg-rgb: 19, 33, 59;
    --g3-fg: #13213B;
    --g3-fg-mid: #2c3e57;
    --g3-bright-rgb: 19, 33, 59;
    --g3-warn-rgb: 180, 83, 9;
    --g3-warn: #b45309;
    --g3-sel-rgb: 168, 64, 77;
    --g3-sel: #A8404D;
}

/**
 * TWX Panel - Stylesheet
 * Standalone CSS for TWX Panel Runtime Library
 * 
 * Usage:
 *   <link rel="stylesheet" href="twx-panel.css">
 *   <script src="twx-panel.js"></script>
 */

/* ══════════════════════════════════════════════════════════════════════════ */
/* Fonts Import */
/* ══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;700&display=swap');

/* ══════════════════════════════════════════════════════════════════════════ */
/* Panel Wrapper */
/* ══════════════════════════════════════════════════════════════════════════ */

.twx-panel-wrapper {
    position: absolute;
    transition: transform 0.4s ease;
    font-family: 'DM Sans', sans-serif;
    font-size: 11px;
    line-height: 1.3;
    color: rgba(var(--g3-dim-rgb), 0.6);
    box-sizing: border-box;
}

    .twx-panel-wrapper *,
    .twx-panel-wrapper *::before,
    .twx-panel-wrapper *::after {
        box-sizing: border-box;
    }

/* ══════════════════════════════════════════════════════════════════════════ */
/* Panel Structure */
/* ══════════════════════════════════════════════════════════════════════════ */

.twx-panel-inner {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

.twx-gradient-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

/* ══════════════════════════════════════════════════════════════════════════ */
/* Header */
/* ══════════════════════════════════════════════════════════════════════════ */

.twx-header {
    display: flex;
    align-items: center;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

    .twx-header:active {
        cursor: grabbing;
    }

.twx-header-dot {
    border-radius: 50%;
    flex-shrink: 0;
}

.twx-header-title {
    font-weight: 700;
    color: rgba(var(--g3-bright-rgb), 0.88);
    letter-spacing: 0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.twx-header-button {
    flex-shrink: 0;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.15s;
}

    .twx-header-button:hover {
        opacity: 1;
    }

/* ══════════════════════════════════════════════════════════════════════════ */
/* Body */
/* ══════════════════════════════════════════════════════════════════════════ */

.twx-body {
    flex: 1;
    position: relative;
    z-index: 1;
    overflow: hidden;
}

.twx-resize-handle {
    position: absolute;
    bottom: 2px;
    right: 2px;
    opacity: 0.2;
    cursor: nwse-resize;
}

/* ══════════════════════════════════════════════════════════════════════════ */
/* Layout */
/* ══════════════════════════════════════════════════════════════════════════ */

.twx-dragging {
    z-index: 10000 !important;

}

.twx-rows {
    display: flex;
    flex-direction: column;
}

.twx-columns {
    display: flex;
}

.twx-column-child {
    min-width: 0;
    overflow: hidden;
}

/* ══════════════════════════════════════════════════════════════════════════ */
/* Hover Effects */
/* ══════════════════════════════════════════════════════════════════════════ */

.twx-hover-glow:hover {
    filter: brightness(1.3);
    box-shadow: 0 0 8px currentColor;
}

.twx-hover-lift:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.twx-hover-brighten:hover {
    filter: brightness(1.4);
}
/* ══════════════════════════════════════════════════════════════
   TWX Panel — Scrollbar
   ══════════════════════════════════════════════════════════════ */

[data-twx-body] {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--g3-accent-rgb), 0.25) transparent;
}

    [data-twx-body]::-webkit-scrollbar {
        width: 5px;
    }

    [data-twx-body]::-webkit-scrollbar-track {
        background: transparent;
    }

    [data-twx-body]::-webkit-scrollbar-thumb {
        background: rgba(var(--g3-accent-rgb), 0.2);
        border-radius: 4px;
    }

        [data-twx-body]::-webkit-scrollbar-thumb:hover {
            background: rgba(var(--g3-accent-rgb), 0.4);
        }

/* ══════════════════════════════════════════════════════════════
   TWX Panel — Variable Explorer
   ══════════════════════════════════════════════════════════════ */

.twx-ve-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 6px;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.15s;
}

    .twx-ve-item:hover {
        background: rgba(var(--g3-accent-rgb), 0.06);
    }

.twx-ve-cb {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 1.5px solid rgba(100, 116, 139, 0.35);
    border-radius: 3px;
    background: transparent;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: all 0.15s;
}

    .twx-ve-cb:checked {
        background: var(--ve-color, var(--g3-ok));
        border-color: var(--ve-color, var(--g3-ok));
    }

        .twx-ve-cb:checked::after {
            content: '✓';
            position: absolute;
            top: -1px;
            left: 2px;
            font-size: 11px;
            color: #fff;
            font-weight: 700;
        }

.twx-ve-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.twx-ve-name {
    font-size: 13px;
    color: rgba(var(--g3-fg-rgb), 0.85);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.twx-ve-path {
    font-size: 9px;
    color: rgba(var(--g3-dim-rgb), 0.45);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.twx-ve-search {
    width: 100%;
    padding: 5px 8px 5px 26px;
    border: 1px solid rgba(var(--g3-accent-rgb), 0.1);
    border-radius: 5px;
    background: rgba(var(--g3-deep-rgb), 0.5);
    color: var(--g3-fg);
    font-size: 12px;
    font-family: 'DM Sans', sans-serif;
    outline: none;
    transition: border-color 0.15s;
}

    .twx-ve-search:focus {
        border-color: rgba(var(--g3-accent-rgb), 0.3);
    }

    .twx-ve-search::placeholder {
        color: rgba(var(--g3-dim-rgb), 0.3);
    }

.twx-ve-btn {
    padding: 6px 12px;
    border-radius: 5px;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-family: 'DM Sans', sans-serif;
}

    .twx-ve-btn:hover {
        filter: brightness(1.2);
        transform: translateY(-1px);
    }

    .twx-ve-btn:active {
        transform: translateY(0);
    }

.twx-ve-chevron {
    transition: transform 0.25s ease;
}

.twx-ve-collapsed .twx-ve-chevron {
    transform: rotate(-90deg);
}

/* ══════════════════════════════════════════════════════════════
   TWX Panel — Trend Popup Animation
   ══════════════════════════════════════════════════════════════ */

@keyframes twx-popup-in {
    from {
        opacity: 0;
        transform: scale(0.92) translateY(8px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.twx-trend-popup {
    animation: twx-popup-in 0.25s ease-out;
}
/* ══════════════════════════════════════════════════════════════
   TWX Panel Manager
   ══════════════════════════════════════════════════════════════ */

.twx-pm-list::-webkit-scrollbar {
    width: 3px;
}

.twx-pm-list::-webkit-scrollbar-track {
    background: transparent;
}

.twx-pm-list::-webkit-scrollbar-thumb {
    background: rgba(var(--g3-accent-rgb),0.2);
    border-radius: 2px;
}

.twx-pm-row {
    transition: background .15s;
}

    .twx-pm-row:hover {
        background: rgba(var(--g3-accent-rgb),0.06) !important;
    }

.twx-pm-tog {
    width: 28px;
    height: 15px;
    border-radius: 8px;
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .2s;
}

.twx-pm-tog-knob {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #fff;
    position: absolute;
    top: 2px;
    transition: left .2s;
}

@keyframes twx-pm-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(var(--g3-accent-rgb),0.4);
    }

    50% {
        box-shadow: 0 0 0 6px rgba(var(--g3-accent-rgb),0);
    }
}

/* ══════════════════════════════════════════════════════════════════════════
   Unified #listCard Sidebar  (Cards + Panels in one flat list)
   ══════════════════════════════════════════════════════════════════════════ */

/* ── search row ─────────────────────────────────────────────────────────── */
.list-toolbar {
    padding: 6px 8px 0;
}

    .list-toolbar #unifiedSearchBox {
        display: block;
        width: 100%;
        box-sizing: border-box;
        background: rgba(var(--g3-glass-rgb),0.6);
        border: 1px solid rgba(var(--g3-accent-rgb),0.25);
        border-radius: 4px;
        color: var(--g3-fg-mid);
        font-size: 11px;
        padding: 5px 10px;
        outline: none;
    }

        .list-toolbar #unifiedSearchBox::placeholder {
            color: rgba(var(--g3-dim-rgb),0.45);
        }

        .list-toolbar #unifiedSearchBox:focus {
            border-color: rgba(var(--g3-accent-rgb),0.55);
            background: rgba(var(--g3-glass-rgb),0.8);
        }

/* ── action buttons row ─────────────────────────────────────────────────── */
.list-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 8px 6px;
    border-bottom: 1px solid rgba(var(--g3-accent-rgb),0.12);
}

    .list-actions button {
        -webkit-appearance: none;
        appearance: none;
        flex: 1;
        width: auto; /* cancel cards.css #btnResetCards { width:100% } */
        margin: 0; /* cancel cards.css top margin */
        background: rgba(var(--g3-deep-rgb), 0.7);
        border: 1px solid rgba(var(--g3-accent-rgb), 0.15);
        border-radius: 4px;
        color: rgba(var(--g3-dim-rgb), 0.65);
        font-size: 10px;
        font-family: 'DM Sans', sans-serif;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        padding: 5px 4px;
        cursor: pointer;
        transition: background 0.15s, color 0.15s, border-color 0.15s;
        white-space: nowrap;
    }

        .list-actions button:hover {
            background: rgba(var(--g3-accent-rgb), 0.1);
            color: var(--g3-accent);
            border-color: rgba(var(--g3-accent-rgb), 0.35);
        }

/* ── the list itself ────────────────────────────────────────────────────── */
#listCard {
    list-style: none;
    margin: 0;
    padding: 4px 0;
    overflow-y: auto;
    max-height: calc(100vh - 140px);
}

/* ── each row ───────────────────────────────────────────────────────────── */
.twx-list-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px 5px 8px;
    border-bottom: 1px solid rgba(var(--g3-accent-rgb),0.06);
    transition: background 0.12s;
}

    .twx-list-item:hover {
        background: var(--state-hover-bg, rgba(var(--g3-accent-rgb),0.06)); /* theme hover token per Dinesh */
    }

/* coloured dot — cards get cyan, panels get a softer teal */
.twx-list-dot {
    flex-shrink: 0;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--g3-accent);
    opacity: 0.7;
}

[data-panel-id] .twx-list-dot {
    background: var(--g3-accent-bright);
}

/* label */
.twx-list-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    color: var(--g3-fg-mid);
    letter-spacing: 0.02em;
}

/* hidden items get dimmed label */
.twx-list-item[data-status="hide"] .twx-list-label {
    opacity: 0.4;
    font-style: italic;
}

/* ── focus (◎) button ───────────────────────────────────────────────────── */
.twx-list-focus {
    -webkit-appearance: none;
    appearance: none;
    flex-shrink: 0;
    align-self: center;
    background: none;
    border: none;
    color: rgba(var(--g3-accent-rgb),0.45);
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    margin: 0;
    cursor: pointer;
    transition: color 0.15s;
}

    .twx-list-focus:hover {
        color: var(--g3-accent);
    }

/* ── toggle switch ──────────────────────────────────────────────────────── */
.twx-list-toggle {
    flex-shrink: 0;
    align-self: center; /* force true vertical centre in flex row */
    position: relative;
    display: block; /* block avoids inline baseline offset */
    width: 30px;
    height: 16px;
    cursor: pointer;
    margin: 0;
}

    .twx-list-toggle input {
        opacity: 0;
        width: 0;
        height: 0;
        position: absolute;
    }

.twx-list-knob {
    position: absolute;
    inset: 0;
    background: rgba(var(--g3-accent-rgb),0.12);
    border: 1px solid rgba(var(--g3-accent-rgb),0.25);
    border-radius: 16px;
    transition: background 0.2s, border-color 0.2s;
}

    .twx-list-knob::after {
        content: '';
        position: absolute;
        left: 2px;
        top: 50%;
        transform: translateY(-50%);
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background: rgba(var(--g3-dim-rgb),0.5);
        transition: left 0.2s, background 0.2s;
    }

.twx-list-toggle input:checked + .twx-list-knob {
    background: rgba(var(--g3-accent-rgb),0.22);
    border-color: rgba(var(--g3-accent-rgb),0.55);
}

    .twx-list-toggle input:checked + .twx-list-knob::after {
        left: 16px;
        background: var(--g3-accent);
    }

/* ── LIGHT MODE CARD-WINDOW ARMOR (Dinesh's light review). The window
   chrome (backgrounds, borders, shadows) is written INLINE by
   twx-panel.js - currently the pre-theme JS, so the inline values are
   dark-tuned and composite milky over the light 3D canvas. Light-scoped
   !important overrides beat non-important inline styles. When the JS
   theme pass lands, these remain harmless (same family values). ── */
.light-theme .twx-panel-wrapper {
    color: var(--g3-fg);
}

.light-theme .twx-panel-inner {
    /* opaque (compositing lesson): translucent over the 3D canvas goes
       milky in the blank areas; .97 reads as a solid light surface */
    background: rgba(var(--g3-glass-rgb), 0.97) !important;
    border: 1px solid rgba(var(--g3-accent-rgb), 0.3) !important;
}

.light-theme .twx-header {
    background: rgba(var(--g3-deep-rgb), 0.85) !important;
}

    .light-theme .twx-header,
    .light-theme .twx-header span,
    .light-theme .twx-header label {
        color: var(--g3-fg) !important; /* header titles arrive inline-
            colored (accent teal) from the JS; fg for readability */
    }

.light-theme .twx-list-item {
    background: rgba(var(--g3-glass-rgb), 0.92) !important;
    border: 1px solid rgba(var(--g3-accent-rgb), 0.22) !important;
}

/* config-white inline text trap for the twx tree (same as cards.css:
   4,022 default rangeMapping whites; only WHITE is matched - alarm
   reds/ambers from populated mappings pass through) */
.light-theme .twx-panel-wrapper [style*="color:#ffffff" i],
.light-theme .twx-panel-wrapper [style*="color: #ffffff" i],
.light-theme .twx-panel-wrapper [style*="color:rgb(255, 255, 255)"],
.light-theme .twx-panel-wrapper [style*="color: rgb(255, 255, 255)"] {
    color: var(--g3-fg) !important;
}

/* ── LIGHT READABILITY: panels + charts (extension of the cards pass).
   Panel body text arrives INLINE from the pre-theme JS in three
   families: dim rgba(148,163,184,*), sky #38bdf8, and - the light-mode
   killer - DARK-THEME FG colors (#e2e8f0 / #cbd5e1 / rgb equivalents)
   which are pale-grey-on-white in day mode. Value traps for each;
   semantic warn/alarm inline colors pass through. ── */
.light-theme .twx-ve-path {
    color: var(--g3-dim);
}

.light-theme .twx-panel-wrapper [style*="color:rgba(148,163,184" i],
.light-theme .twx-panel-wrapper [style*="color: rgba(148, 163, 184"] {
    color: var(--g3-dim) !important; /* floor-label tone (Dinesh) */
}

.light-theme .twx-panel-wrapper [style*="color:#38bdf8" i],
.light-theme .twx-panel-wrapper [style*="color: #38bdf8" i] {
    color: var(--g3-accent) !important;
}

.light-theme .twx-panel-wrapper [style*="color:#e2e8f0" i],
.light-theme .twx-panel-wrapper [style*="color: #e2e8f0" i],
.light-theme .twx-panel-wrapper [style*="color:#cbd5e1" i],
.light-theme .twx-panel-wrapper [style*="color: #cbd5e1" i],
.light-theme .twx-panel-wrapper [style*="color: rgb(226, 232, 240)"],
.light-theme .twx-panel-wrapper [style*="color: rgb(203, 213, 225)"],
.light-theme .twx-panel-wrapper [style*="color:rgba(248,250,252" i],
.light-theme .twx-panel-wrapper [style*="color: rgba(248, 250, 252"] {
    color: var(--g3-dim) !important; /* dark-theme fg written inline;
        light target = floor-label tone (Dinesh) */
}

/* ── CHARTS in light: Highcharts + ApexCharts are SVG (CSS-reachable;
   fill beats presentation attrs, !important beats inline). ECharts is
   CANVAS - CSS cannot touch it; it stays dark-styled until the JS
   theme pass (twxChartPalette) is re-applied. Scoped to both trees. ── */
.light-theme .twx-panel-wrapper .highcharts-axis-labels text,
.light-theme .card .highcharts-axis-labels text,
.light-theme .twx-panel-wrapper .highcharts-legend-item text,
.light-theme .card .highcharts-legend-item text {
    fill: var(--g3-dim) !important;
}

.light-theme .twx-panel-wrapper .highcharts-title,
.light-theme .card .highcharts-title,
.light-theme .twx-panel-wrapper .highcharts-subtitle,
.light-theme .card .highcharts-subtitle {
    fill: var(--g3-fg) !important;
}

.light-theme .twx-panel-wrapper .highcharts-grid-line,
.light-theme .card .highcharts-grid-line {
    stroke: rgba(var(--g3-fg-rgb), 0.08) !important;
}

.light-theme .twx-panel-wrapper .apexcharts-text,
.light-theme .card .apexcharts-text {
    fill: var(--g3-dim) !important; /* floor-label tone */
}

.light-theme .twx-panel-wrapper .apexcharts-legend-text,
.light-theme .card .apexcharts-legend-text {
    color: var(--g3-dim) !important; /* Apex legend is HTML, not SVG */
}

.light-theme .twx-panel-wrapper .apexcharts-gridline,
.light-theme .card .apexcharts-gridline {
    stroke: rgba(var(--g3-fg-rgb), 0.08) !important;
}
