/* REF016 Live */

:root {
    /* Backgrounds — deep navy */
    --bg-primary: #070910;
    --bg-secondary: #0d1019;
    --bg-card: #131722;
    --bg-hover: #191e2c;
    --bg-input: #0d1019;

    /* Borders & depth */
    --border: #1c2236;
    --border-focus: #2c3650;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --shadow: 0 3px 12px rgba(0,0,0,0.35);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);

    /* Text */
    --text-primary: #f0f2f7;
    --text-secondary: #c8cdd8;
    --text-muted: #8894ab;

    /* Accent — Muted Cyan */
    --accent: #7ab5c2;
    --accent-hover: #96c8d3;
    --accent-dim: rgba(122,181,194,0.1);
    --accent-strong: rgba(122,181,194,0.2);

    /* Semantic */
    --green: #34d399;
    --green-dim: rgba(52,211,153,0.1);
    --orange: #f59e0b;
    --orange-dim: rgba(245,158,11,0.1);
    --red: #ef4444;
    --red-dim: rgba(239,68,68,0.1);

    /* Module colors */
    --module-a: #7ab5c2;
    --module-b: #34d399;
    --module-c: #f59e0b;
    --module-d: #a78bfa;
    --module-e: #f472b6;

    /* On-air */
    --onair-bg: #dc2626;
    --onair-text: #fff;
    --onair-end-bg: #3b4257;
    --onair-end-text: #c8cdd8;

    /* Signal badges */
    --sig-excellent-bg: #052e16;
    --sig-excellent-text: #4ade80;
    --sig-good-bg: #0a3321;
    --sig-good-text: #86efac;
    --sig-fair-bg: #451a03;
    --sig-fair-text: #fbbf24;
    --sig-poor-bg: #450a0a;
    --sig-poor-text: #f87171;

    /* Status badges */
    --badge-pending-bg: rgba(122,181,194,0.1);
    --badge-pending-text: #7ab5c2;
    --badge-active-bg: rgba(59,130,246,0.12);
    --badge-active-text: #93c5fd;
    --badge-done-bg: rgba(34,197,94,0.12);
    --badge-done-text: #86efac;
    --badge-error-bg: rgba(239,68,68,0.12);
    --badge-error-text: #fca5a5;
    --badge-transcribe-bg: rgba(249,115,22,0.12);
    --badge-transcribe-text: #fdba74;
    --badge-transcribe-done-bg: rgba(16,185,129,0.12);
    --badge-transcribe-done-text: #6ee7b7;

    /* Live status */
    --live-connected-bg: #052e16;
    --live-connected-text: #4ade80;
    --live-disconnected-bg: #450a0a;
    --live-disconnected-text: #f87171;

    /* Transcript */
    --tx-text: #8894ab;
    --tx-stat: #5c6580;
    --onair-detail: #8894ab;
    --onair-label: #5c6580;

    /* Header */
    --header-bg: linear-gradient(180deg, #111520 0%, #0a0d14 100%);
    --header-border: rgba(122,181,194,0.15);
    --header-shadow: 0 1px 0 rgba(122,181,194,0.08), 0 4px 20px rgba(0,0,0,0.5);
    --tab-active-bg: rgba(122,181,194,0.08);

    /* Layout */
    --radius: 10px;
    --radius-sm: 6px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
    --transition: 0.2s ease;
}

[data-theme="light"] {
    --bg-primary: #e4e8f0;
    --bg-secondary: #f2f4f8;
    --bg-card: #ffffff;
    --bg-hover: #eceef4;
    --bg-input: #eceef4;

    --border: #c4c9d6;
    --border-focus: #a0a8ba;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow: 0 3px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.14);

    --text-primary: #0a0a0a;
    --text-secondary: #1f2937;
    --text-muted: #6b7280;

    /* Accent — Muted Cyan */
    --accent: #2d8093;
    --accent-hover: #1a6b7d;
    --accent-dim: rgba(45,128,147,0.06);
    --accent-strong: rgba(45,128,147,0.12);

    --green: #059669;
    --green-dim: rgba(5,150,105,0.08);
    --orange: #d97706;
    --orange-dim: rgba(217,119,6,0.08);
    --red: #dc2626;
    --red-dim: rgba(220,38,38,0.08);

    --module-a: #2d8093;
    --module-b: #059669;
    --module-c: #d97706;
    --module-d: #7c3aed;
    --module-e: #db2777;

    --onair-end-bg: #9ca3af;
    --onair-end-text: #fff;

    --sig-excellent-bg: #d1fae5;
    --sig-excellent-text: #065f46;
    --sig-good-bg: #d1fae5;
    --sig-good-text: #065f46;
    --sig-fair-bg: #fef3c7;
    --sig-fair-text: #78350f;
    --sig-poor-bg: #fee2e2;
    --sig-poor-text: #991b1b;

    --badge-pending-bg: rgba(107,114,128,0.1);
    --badge-pending-text: #6b7280;
    --badge-active-bg: rgba(45,128,147,0.1);
    --badge-active-text: #1a6b7d;
    --badge-done-bg: rgba(5,150,105,0.1);
    --badge-done-text: #047857;
    --badge-error-bg: rgba(220,38,38,0.08);
    --badge-error-text: #b91c1c;
    --badge-transcribe-bg: rgba(234,88,12,0.08);
    --badge-transcribe-text: #9a3412;
    --badge-transcribe-done-bg: rgba(5,150,105,0.08);
    --badge-transcribe-done-text: #047857;

    --live-connected-bg: #d1fae5;
    --live-connected-text: #065f46;
    --live-disconnected-bg: #fee2e2;
    --live-disconnected-text: #991b1b;

    --tx-text: #4b5563;
    --tx-stat: #6b7280;
    --onair-detail: #4b5563;
    --onair-label: #9ca3af;

    --header-bg: linear-gradient(180deg, #ffffff 0%, #f0f2f7 100%);
    --header-border: #c4c9d6;
    --header-shadow: 0 2px 8px rgba(0,0,0,0.06);
    --tab-active-bg: rgba(45,128,147,0.06);
}

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

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Header ──────────────────────────────── */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    box-shadow: var(--header-shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left h1 {
    font-size: 18px;
    font-weight: 600;
}

.ref-id {
    color: var(--accent);
    font-family: var(--font-mono);
    font-weight: 700;
    letter-spacing: 1px;
}

.subtitle {
    color: var(--text-secondary);
    font-weight: 400;
}

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

.stat-value {
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ws-status {
    font-size: 14px;
    color: var(--red);
    transition: color var(--transition);
}

.ws-status.connected {
    color: var(--green);
}

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-focus);
}

/* ── Navigation ──────────────────────────── */

nav#tabs {
    display: flex;
    gap: 2px;
    padding: 0 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 10px 20px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
}

.tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: var(--tab-active-bg);
}

/* Live indicator dot on tab */
.tab .live-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--red);
    margin-left: 6px;
    vertical-align: middle;
    animation: live-pulse 1.5s ease-in-out infinite;
}

@keyframes live-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Header live mini card */
.header-live-card {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
    background: var(--red-dim);
    border: 1px solid rgba(239,68,68,0.2);
}

.header-live-card.visible { display: flex; }

.header-live-card:hover { background: rgba(239,68,68,0.15); }

.header-live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--red);
    animation: live-pulse 1.5s ease-in-out infinite;
}

.header-live-label {
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--red);
}

.header-live-call {
    font-weight: 600;
    color: var(--text-primary);
}

.header-live-mod {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-weight: 600;
}

.header-live-idle {
    color: var(--text-muted);
    font-style: italic;
}

/* ── Tab Content ─────────────────────────── */

.tab-content {
    display: none;
    padding: 20px 24px;
    max-width: 1400px;
    margin: 0 auto;
}

.tab-content.active {
    display: block;
}

/* ── Dashboard Grid ──────────────────────── */

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 20px;
    align-items: start;
}

#modules-sidebar {
    position: sticky;
    top: 80px;
}

/* ── Module Cards ────────────────────────── */

#modules {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.module-card.module-empty .module-body {
    display: none;
}

.module-card.module-empty {
    opacity: 0.5;
}

.module-card.module-highlight {
    border-color: var(--accent);
    box-shadow: 0 0 16px var(--accent-dim), var(--shadow);
    transform: scale(1.02);
}

.module-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.module-card:hover {
    border-color: var(--border-focus);
    box-shadow: var(--shadow);
}

.module-card.active {
    border-color: var(--green);
    box-shadow: 0 0 20px var(--green-dim), var(--shadow);
}

.module-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.module-letter {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 18px;
}

.module-card[data-module="A"] .module-letter { color: var(--module-a); }
.module-card[data-module="B"] .module-letter { color: var(--module-b); }
.module-card[data-module="C"] .module-letter { color: var(--module-c); }
.module-card[data-module="D"] .module-letter { color: var(--module-d); }
.module-card[data-module="E"] .module-letter { color: var(--module-e); }

.module-status {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg-primary);
}

.module-card.active .module-status {
    color: var(--green);
    background: var(--green-dim);
}

.module-body {
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    min-height: 48px;
}

.mod-gateways {
    margin-bottom: 6px;
}

.mod-gw-tag {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-mono);
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid var(--accent-strong);
    letter-spacing: 0.3px;
}

.mod-users {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.3;
    margin-bottom: 4px;
}

.mod-last-tx {
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.7;
}

/* ── Section Headers ─────────────────────── */

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.section-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 14px;
}

.filter-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    width: 200px;
    transition: all var(--transition);
}

.filter-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ── Tables ──────────────────────────────── */

.table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
}

thead th:hover {
    color: var(--text-secondary);
}

tbody td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--bg-hover);
}

td.callsign {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent);
}

td.muted {
    color: var(--text-muted);
    font-size: 12px;
}
td.loc-rotate {
    transition: opacity 0.4s ease;
}
td.loc-rotate.loc-msg {
    font-style: italic;
    color: var(--text-secondary);
}

td .tx-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    margin-right: 6px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ── Callsign Flags & DPRS ──────────────── */

.flag {
    display: inline-block;
    vertical-align: middle;
}

.flag-img {
    vertical-align: middle;
    border-radius: 1px;
}

.dprs-link {
    color: var(--text-muted);
    margin-left: 4px;
    vertical-align: middle;
    opacity: 0.4;
    transition: opacity 0.15s, color 0.15s;
}

.dprs-link:hover {
    opacity: 1;
    color: var(--accent);
}

.dprs-icon {
    vertical-align: -1px;
}

/* ── Section Controls ──────────────────────── */

/* ── Linked Gateways ────────────────────── */

#gateways-section {
    margin-top: 20px;
}

#gateways-section h2 {
    margin-bottom: 12px;
}

.gateways-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.gw-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 13px;
    transition: all var(--transition);
    cursor: default;
}

.gw-item:hover {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-sm);
}

.gw-module-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.gw-call {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent);
}

.gw-remote {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.7;
}

.gw-local {
    font-size: 11px;
    color: var(--text-muted);
}

.gw-duration {
    font-size: 11px;
    color: var(--text-muted);
}

.gw-flag {
    display: inline-flex;
    align-items: center;
}

/* ── Module Collapsible Body ───────────── */

.mod-body-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.mod-body-list li {
    padding: 2px 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.mod-show-more {
    font-size: 11px;
    color: var(--accent);
    cursor: pointer;
    padding: 4px 0 0;
    border: none;
    background: none;
    font-family: var(--font);
}

.mod-show-more:hover {
    text-decoration: underline;
}

/* TX indicator in module card — Discord/TeamSpeak style */
.mod-user-tx {
    color: var(--green) !important;
    font-weight: 700;
}

.tx-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    margin-right: 4px;
    vertical-align: middle;
    animation: tx-pulse 1s ease-in-out infinite;
}

@keyframes tx-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.mod-tx-standalone {
    padding: 2px 0;
    font-size: 12px;
    margin-bottom: 4px;
}

.section-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.module-filter {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all var(--transition);
}

.module-filter:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.lh-toggle {
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.lh-toggle input {
    margin-right: 4px;
    vertical-align: middle;
}

/* ── Callsign Lookup ─────────────────────── */

.lookup-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.lookup-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 16px;
    font-family: var(--font-mono);
    text-transform: uppercase;
    width: 240px;
    transition: all var(--transition);
}

.lookup-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow);
}

.lookup-result {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: none;
    box-shadow: var(--shadow-sm);
}

.lookup-result.visible {
    display: block;
}

.lookup-field {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.lookup-field:last-child {
    border-bottom: none;
}

.lookup-label {
    color: var(--text-muted);
    font-size: 13px;
}

.lookup-value {
    font-family: var(--font-mono);
    font-weight: 600;
}

.lookup-value.online {
    color: var(--green);
}

.lookup-value.offline {
    color: var(--text-muted);
}

/* ── Stats ───────────────────────────────── */

.stats-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
}

.stats-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.stats-card canvas {
    width: 100% !important;
    height: 200px !important;
}

.stats-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
}

.stats-bar-label {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    min-width: 80px;
}

.stats-bar-fill {
    height: 6px;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.5s ease;
}

.stats-bar-count {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    min-width: 30px;
    text-align: right;
}

.stats-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.stats-card-header h3 { margin: 0; }

/* Pills strip */
.stats-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 8px;
}
.stats-pill {
    flex: 1;
    min-width: 100px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    text-align: center;
}
.stats-pill-value {
    display: block;
    font-family: var(--font-mono);
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
}
.stats-pill-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* Toggle buttons */
.stats-toggle {
    display: flex;
    gap: 2px;
    background: var(--bg-secondary);
    border-radius: 5px;
    padding: 2px;
}
.stats-toggle-btn {
    padding: 4px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
    color: var(--text-muted);
    transition: background 0.2s, color 0.2s;
}
.stats-toggle-btn.active {
    background: var(--accent);
    color: #000;
}

/* Module bars */
.stats-module-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.stats-module-bar:last-child { border-bottom: none; }
.stats-module-letter {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 700;
    min-width: 24px;
    text-align: center;
}
.stats-module-fill {
    height: 10px;
    border-radius: 5px;
    transition: width 0.5s ease;
}
.stats-module-count {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 40px;
    text-align: right;
}

/* Active callsigns with module border */
.stats-bar-module {
    border-left: 3px solid var(--text-muted);
    padding-left: 8px;
}

/* Records grid */
.stats-record-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.stats-record-tile {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}
.stats-record-value {
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}
.stats-record-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.stats-record-detail {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Signal quality bar */
.stats-signal-bar {
    display: flex;
    height: 20px;
    border-radius: 10px;
    overflow: hidden;
    margin: 12px 0;
}
.stats-signal-seg { transition: width 0.5s ease; }
.stats-signal-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 8px;
    font-size: 0.8rem;
}
.stats-signal-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}
.stats-signal-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* Callsign links */
.callsign-link {
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}
.callsign-link:hover {
    text-decoration: underline;
}

/* Activity bar track */
.stats-bar-track {
    flex: 1;
    background: var(--bg-primary);
    border-radius: 3px;
    height: 6px;
}

/* Repeater table */
.stats-rpt-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.stats-rpt-table th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
}
.stats-rpt-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}
.stats-rpt-table tr:last-child td { border-bottom: none; }
.stats-rpt-call {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent);
}
.stats-rpt-chevron {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.2s;
    display: inline-block;
}
.stats-rpt-row.expanded .stats-rpt-chevron {
    transform: rotate(90deg);
}
.stats-rpt-users-row td {
    padding: 0 8px 8px !important;
    border-bottom: 1px solid var(--border) !important;
}
.stats-rpt-users {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    padding: 4px 0;
}
.stats-rpt-user {
    font-size: 0.8rem;
    font-family: var(--font-mono);
}
.stats-rpt-user-tx {
    color: var(--text-muted);
    font-size: 0.7rem;
}

/* Donut chart */
.stats-donut-wrap {
    display: flex;
    align-items: center;
    gap: 20px;
}
.stats-donut-legend {
    font-size: 0.85rem;
}
.stats-donut-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}
.stats-donut-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}
.stats-donut-label { color: var(--text-secondary); }
.stats-donut-count {
    font-family: var(--font-mono);
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-left: auto;
}

/* ── Audio Transmissions (legacy) ────────── */

.audio-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    transition: border-color var(--transition);
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
}

.audio-item:hover {
    border-color: var(--border-focus);
}

.audio-meta {
    flex: 0 0 auto;
    min-width: 180px;
}

.audio-call {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 15px;
    color: var(--accent);
}

.audio-info {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.play-btn {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    background: transparent;
    color: var(--accent);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all var(--transition);
}

.play-btn:hover {
    background: var(--accent);
    color: var(--bg-card);
    box-shadow: 0 0 12px var(--accent-dim);
}

.audio-transcript {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
    font-style: italic;
    padding: 4px 10px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    min-height: 28px;
    line-height: 1.4;
}

.audio-transcript:empty::after {
    content: "No transcription";
    color: var(--text-muted);
}

.waveform {
    flex: 1;
    height: 32px;
    min-width: 100px;
    max-width: 240px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* ── Packet Monitor ──────────────────────── */

.pkt-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

.pkt-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}

.pkt-stats-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.pkt-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.pkt-stat-label {
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pkt-stat-value {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 18px;
    color: var(--text-primary);
}

.pkt-stat-unit {
    font-size: 11px;
    color: var(--text-muted);
}

.pkt-table-wrap {
    max-height: 500px;
    overflow-y: auto;
}

#pkt-table td {
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 4px 10px;
    white-space: nowrap;
}

#pkt-table td.pkt-type-header { color: var(--green); font-weight: 700; }
#pkt-table td.pkt-type-voice { color: var(--accent); }
#pkt-table td.pkt-type-control { color: var(--orange); }
#pkt-table td.pkt-type-keepalive { color: var(--text-muted); }
#pkt-table td.pkt-type-unknown { color: var(--red); }

.pkt-hex {
    color: var(--text-muted);
    font-size: 11px;
}

/* ── Footer ──────────────────────────────── */

footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 12px 24px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: 40px;
}

.footer-stats {
    display: flex;
    gap: 16px;
    align-items: center;
    font-size: 12px;
}

.footer-stats .stat-label {
    font-size: 10px;
    margin-right: 4px;
}

.footer-stats .stat-value {
    font-size: 12px;
}

footer a {
    color: var(--accent);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* ── Scrollbar ───────────────────────────── */

::-webkit-scrollbar { width: 14px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 7px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Firefox */
* { scrollbar-width: auto; scrollbar-color: var(--border) var(--bg-secondary); }

/* ── Responsive ──────────────────────────── */

@media (max-width: 960px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    #modules-sidebar { position: static; order: -1; }
    #modules { flex-direction: row; flex-wrap: wrap; gap: 10px; }
    #modules .module-card { flex: 1 1 140px; min-width: 120px; }
    .module-card.module-empty { display: block; }
    .stats-grid { grid-template-columns: 1fr; }
    .stats-record-grid { grid-template-columns: repeat(2, 1fr); }
    .stats-donut-wrap { flex-direction: column; }
    header { padding: 10px 16px; }
    .tab-content { padding: 16px; }
    nav#tabs { padding: 0 16px; overflow-x: auto; }
    .lh-card-top { gap: 6px; }
}

@media (max-width: 600px) {
    #modules .module-card { flex: 1 1 100px; }
    .table-wrap { overflow-x: auto; }
    table { min-width: 600px; }
    .lh-audio-row { flex-wrap: wrap; }
    .section-controls { flex-wrap: wrap; }
}

/* ── Last Heard — inline audio rows ──────── */

.lh-audio-expand td {
    background: var(--bg-primary);
}

.lh-audio-expand:hover td {
    background: var(--bg-primary);
}

.lh-audio-cell {
    padding: 6px 14px !important;
}

.lh-audio-inline {
    display: flex;
    align-items: center;
    gap: 10px;
}

.lh-audio-inline .play-btn {
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    font-size: 12px;
    border-width: 1.5px;
}

.lh-audio-inline .waveform {
    flex: 0 1 200px;
    height: 28px;
}

.lh-dur {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.lh-transcript-inline {
    flex: 1;
    font-size: 13px;
    color: var(--tx-text);
    font-style: italic;
    line-height: 1.4;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Listen Live ─────────────────────────── */

.listen-icon {
    vertical-align: -3px;
    margin-right: 8px;
    color: var(--accent);
}

.live-modules {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 16px;
}

.live-modules-label {
    color: var(--text-muted);
    font-size: 13px;
    margin-right: 4px;
}

.live-mod-btn {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    transition: all 0.15s;
}
.live-mod-btn:hover { background: var(--bg-hover); border-color: var(--border-focus); }
.live-mod-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
}

.live-stop-btn {
    margin-left: 8px;
}

.live-status-bar {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 16px;
    font-size: 13px;
}

.live-buffer-label {
    color: var(--text-muted);
}

.live-status {
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
}
.live-status.connected { background: var(--live-connected-bg); color: var(--live-connected-text); }
.live-status.disconnected { background: var(--live-disconnected-bg); color: var(--live-disconnected-text); }

.live-transcript-section {
    margin-top: 16px;
}

/* On-air box */
.onair-box {
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
    box-shadow: var(--shadow-sm);
}
.onair-box.onair-ended { opacity: 0.85; }
.onair-header { margin-bottom: 6px; }
.onair-badge {
    display: inline-block;
    background: var(--onair-bg);
    color: var(--onair-text);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    animation: onair-pulse 1.2s ease-in-out infinite;
}
.onair-badge-end {
    display: inline-block;
    background: var(--onair-end-bg);
    color: var(--onair-end-text);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.onair-call { font-size: 15px; }
.onair-module { color: var(--text-muted); font-size: 13px; }
.onair-dur { color: var(--text-muted); font-size: 12px; font-family: var(--font-mono); }
.onair-details {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--onair-detail);
}
.onair-field { white-space: nowrap; }
.onair-label { color: var(--onair-label); font-size: 10px; font-weight: 600; letter-spacing: 0.3px; margin-right: 3px; }
@keyframes onair-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Signal quality badges */
.sig-badge {
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.sig-excellent { background: var(--sig-excellent-bg); color: var(--sig-excellent-text); }
.sig-good { background: var(--sig-good-bg); color: var(--sig-good-text); }
.sig-fair { background: var(--sig-fair-bg); color: var(--sig-fair-text); }
.sig-poor { background: var(--sig-poor-bg); color: var(--sig-poor-text); }
.sig-loss { color: var(--sig-poor-text); font-weight: 600; }

/* Transcript log */
.live-transcripts {
    font-size: 13px;
    line-height: 1.6;
    max-height: 400px;
    overflow-y: auto;
}
.live-tx-entry {
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}
.live-tx-entry:last-child { border-bottom: none; }
.live-tx-time {
    color: var(--text-muted);
    font-size: 12px;
    font-family: var(--font-mono);
}
.tx-via { color: var(--text-muted); font-size: 12px; }
.tx-stat {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--tx-stat);
    margin-left: 4px;
}
.tx-archive {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 999px;
    margin-left: 8px;
    font-weight: 600;
}
.tx-archive-pending { background: var(--badge-pending-bg); color: var(--badge-pending-text); }
.tx-archive-running { background: var(--badge-active-bg); color: var(--badge-active-text); }
.tx-archive-done { background: var(--badge-done-bg); color: var(--badge-done-text); }
.tx-archive-error { background: var(--badge-error-bg); color: var(--badge-error-text); }
.tx-transcribe {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 999px;
    margin-left: 8px;
    font-weight: 600;
}
.tx-transcribe-running { background: var(--badge-transcribe-bg); color: var(--badge-transcribe-text); }
.tx-transcribe-done { background: var(--badge-transcribe-done-bg); color: var(--badge-transcribe-done-text); }
.tx-transcribe-empty { background: var(--badge-pending-bg); color: var(--badge-pending-text); }
.tx-transcribe-error { background: var(--badge-error-bg); color: var(--badge-error-text); }
.tx-text { color: var(--tx-text); font-size: 12px; }

/* Real-time Last Heard indicators */
.rt-live {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: var(--red);
    color: #fff;
    animation: rt-pulse 1.2s ease-in-out infinite;
}
@keyframes rt-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
.rt-pending {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    border-top-color: transparent;
    animation: rt-spin 0.8s linear infinite;
    vertical-align: middle;
}
@keyframes rt-spin {
    to { transform: rotate(360deg); }
}
.lh-row-live {
    background: var(--red-dim) !important;
    border-left: 2px solid var(--red);
}
.lh-show-more-btn {
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 6px 20px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
}
.lh-show-more-btn:hover { background: var(--border); color: var(--text-primary); }
