/* ═══════════════════════════════════════════════════════════════════════
   MeshDash C2 — styles.css (C2 Dark Theme)
   Comprehensive dark-theme stylesheet for the index dashboard.
   Works with md-header.js (62px fixed top) and md-footer-widget.js (36px fixed bottom).
   ═══════════════════════════════════════════════════════════════════════ */

/* ── CSS Variables (C2 Palette) ─────────────────────────────────────── */
:root {
    /* Surface */
    --bg-primary:       #020912;   /* deepest background */
    --bg-secondary:     #060e1c;   /* sidebar, topbar */
    --card-background:  #0a1628;   /* cards */
    --card-bg-hover:    #0d1c34;   /* hover state */

    /* Borders & Dividers */
    --border-color:     #1c3050;   /* bd2 */
    --divider-color:    #152030;   /* bd */

    /* Text */
    --text-primary:     #bdd4f0;   /* txt */
    --text-secondary:   #c5d7eb;   /* txt2 */
    --text-muted:       #83acd7;   /* txt3 */

    /* Accent */
    --primary-color:    #00c8f5;   /* acc */
    --primary-dim:      rgba(0,200,245,0.05);
    --primary-glow:     rgba(0,200,245,0.13);

    /* Signal quality (used for SNR, RSSI, etc.) */
    --signal-excellent: #00f090;   /* ok */
    --signal-good:      #b060ff;   /* pur */
    --signal-fair:      #ffa800;   /* warn */
    --signal-poor:      #ff3050;   /* err */

    /* Battery */
    --battery-full:     #00f090;
    --battery-good:     #b060ff;
    --battery-fair:     #ffa800;
    --battery-low:      #ff3050;

    /* Misc */
    --highlight-color:  #00c8f5;
    --error-color:      #ff3050;
    --warning-color:    #ffa800;
    --info-color:       #00c8f5;
    --purple:           #b060ff;
    --orange:           #ff7030;

    /* Spacing — header 62px + spacer ~82px, footer 36px */
    --header-height:    62px;
    --footer-height:    36px;

    /* Radius */
    --radius-sm:  4px;
    --radius-md:  8px;
    --radius-lg: 12px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-med:  0.25s ease;

    /* Fonts */
    --font-mono: 'Share Tech Mono', 'SFMono-Regular', Consolas, monospace;
    --font-sans: 'Exo 2', 'Segoe UI', system-ui, sans-serif;
}

/* ── Reset & Base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.55;
    min-height: 100vh;
    overflow-x: hidden;
    padding-bottom: calc(var(--footer-height) + 12px);
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
}

/* Scanline overlay (C2 signature) */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 9990;
    pointer-events: none;
    background: repeating-linear-gradient(0deg, transparent 0, transparent 2px, rgba(0,0,0,.055) 2px, rgba(0,0,0,.055) 4px);
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color var(--transition-fast);
}
a:hover { color: #33e8ff; } /* lighter accent */

code, pre {
    font-family: var(--font-mono);
    font-size: 0.88em;
}
code {
    background: rgba(255,255,255,0.04);
    padding: 1px 5px;
    border-radius: 3px;
    color: var(--primary-color);
    word-break: break-all;
}
pre {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px;
    overflow-x: auto;
    max-height: 300px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
pre code { background: none; padding: 0; }

img { max-width: 100%; height: auto; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #263d5e; border-radius: 2px; } /* bd3 */
::-webkit-scrollbar-thumb:hover { background: #83acd7; }

/* Selection */
::selection { background: var(--primary-dim); color: var(--text-primary); }

/* ── Dashboard Container ───────────────────────────────────────────── */
.dashboard {
    max-width: 1680px;
    margin: 0 auto;
    padding: 0 1rem 2rem;
}

/* ── Page Header (inside .dashboard) ───────────────────────────────── */
.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px 0 10px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 12px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.header-left h1 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.header-left h1 i { color: var(--primary-color); }
.header-left h1 .highlight,
.highlight { color: var(--primary-color); }
.highlight-text { color: var(--primary-color); font-weight: 600; }

/* Status dot in page header */
.status-container {
    display: flex;
    align-items: center;
    gap: 6px;
}
.status-indicator {
    width: 8px; height: 8px; border-radius: 50%;
    background: #3a3a4a;
    transition: background 0.4s, box-shadow 0.4s;
    flex-shrink: 0;
}
.status-indicator.connected    { background: var(--signal-excellent); box-shadow: 0 0 8px var(--primary-glow); }
.status-indicator.reconnecting { background: var(--warning-color);   box-shadow: 0 0 6px rgba(255,168,0,0.5); animation: pulse-warn 0.9s infinite alternate; }
.status-indicator.disconnected { background: var(--error-color);     box-shadow: 0 0 6px rgba(255,48,80,0.4); }
.status-indicator.error        { background: var(--error-color);     box-shadow: 0 0 6px rgba(255,48,80,0.4); }
.status-indicator.initializing { background: #3a3a4a; }
.status-text { font-size: 0.78rem; color: var(--text-secondary); }

@keyframes pulse-warn {
    0%   { opacity: 0.5; transform: scale(0.85); }
    100% { opacity: 1;   transform: scale(1.15); }
}

/* Header right */
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 0.82rem;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}
.header-controls button,
.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.btn-icon:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }

/* Average display */
#api-average-display {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.average-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
.average-item strong { color: var(--text-primary); }
.average-item strong i { margin-right: 3px; }
.average-item-clickable { cursor: pointer; padding: 3px 6px; border-radius: var(--radius-sm); transition: background var(--transition-fast); }
.average-item-clickable:hover { background: rgba(255,255,255,0.05); }
.average-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: none;
    align-items: center;
    gap: 4px;
}

/* Signal dot (inline) */
.signal-dot {
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    margin-left: 3px;
    vertical-align: middle;
}
.signal-dot.excellent { background: var(--signal-excellent); }
.signal-dot.good      { background: var(--signal-good); }
.signal-dot.fair      { background: var(--signal-fair); }
.signal-dot.poor      { background: var(--signal-poor); }
.signal-dot.unknown   { background: #3a3a4a; }

/* Local node info block */
#local-node-info {
    font-size: 0.82rem;
    color: var(--text-secondary);
    max-width: 100%;
    overflow: hidden;
}
#local-node-info i { color: var(--primary-color); margin-right: 4px; }
#local-node-info .node-id { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); }
.node-id-small {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
    background: rgba(255,255,255,0.03);
    padding: 1px 5px;
    border-radius: 3px;
}

/* Badges (C2 pill style) */
.badge-success {
    display: inline-block;
    background: rgba(0,240,144,0.1);
    color: var(--signal-excellent);
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid rgba(0,240,144,0.3);
}
.badge-neutral {
    display: inline-block;
    background: rgba(90,128,168,0.1);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.75rem;
    border: 1px solid var(--border-color);
}
.badge-warning {
    background: rgba(255,168,0,0.1);
    color: var(--warning-color);
    border: 1px solid rgba(255,168,0,0.3);
}
.badge-error {
    background: rgba(255,48,80,0.1);
    color: var(--error-color);
    border: 1px solid rgba(255,48,80,0.3);
}

/* ── Info Bar (stats strip) ────────────────────────────────────────── */
.info-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 14px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}
.info-item {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.info-item i { color: var(--text-muted); font-size: 0.75rem; }
.info-item strong { color: var(--text-secondary); font-weight: 600; }
.info-item .val {
    color: var(--text-primary);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    min-width: 16px;
}

/* ── Cards (C2 style) ──────────────────────────────────────────────── */
.card {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color var(--transition-fast);
}
.card:hover { border-color: #263d5e; } /* bd3 */

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 16px; /* match C2 .ch */
    background: var(--bg-primary); /* darker header */
    border-bottom: 1px solid var(--divider-color);
}
.card-header h2 {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}
.card-header h2 i { color: var(--primary-color); font-size: 0.85rem; }

.card-header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* ── Card Content Wrapper (Scroll Container) ───────────────────────── */
/* This is the window we look through for scrollable areas. */
.card-content {
    flex: 1;              /* Take all remaining space in the card */
    min-height: 0;        /* Critical fix for nested flex scrolling */
    overflow-y: auto;     /* Add scrollbar HERE */
    overflow-x: hidden;
    padding: 14px;        /* Spacing belongs to the wrapper */
    position: relative;
    
    /* Scrollbar Polish */
    scrollbar-width: thin;
    scrollbar-color: #263d5e transparent;
}

/* ── Main Grid ─────────────────────────────────────────────────────── */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

/* ── Sort Buttons ──────────────────────────────────────────────────── */
#node-sort-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}
#node-sort-buttons label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 2px;
}
.sort-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.72rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all var(--transition-fast);
    white-space: nowrap;
}
.sort-btn:hover { background: #0d1c34; color: var(--text-primary); border-color: #263d5e; }
.sort-btn.active {
    background: rgba(0,200,245,0.1);
    color: var(--primary-color);
    border-color: rgba(0,200,245,0.3);
    font-weight: 600;
}
.sort-btn i { font-size: 0.68rem; }

/* ── Search ────────────────────────────────────────────────────────── */
.search-container { position: relative; }
#node-search,
input[type="search"] {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    width: 160px;
    outline: none;
    transition: border-color var(--transition-fast), background var(--transition-fast);
    font-family: var(--font-sans);
}
#node-search:focus,
input[type="search"]:focus {
    border-color: var(--primary-color);
    background: rgba(0,200,245,0.03);
    box-shadow: 0 0 0 2px rgba(0,200,245,0.08);
}
#node-search::placeholder { color: var(--text-muted); }

/* ── Nodes Grid ────────────────────────────────────────────────────── */
#nodes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
    align-content: start;
    height: auto !important; 
    max-height: none !important;
    overflow: visible !important;
    padding: 0 !important; /* Prevent double padding */
    margin: 0 !important;
    flex: none !important;
}

/* ── Node Card (C2 style) ──────────────────────────────────────────── */
.node-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    cursor: pointer;
    transition: all var(--transition-med);
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
}
.node-card:hover {
    border-color: rgba(0,200,245,0.25);
    background: var(--card-bg-hover);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    transform: translateY(-1px);
}

/* Node header */
.node-header {
    display: flex;
    align-items: center;
    gap: 10px;
}
.node-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(0,200,245,0.15), rgba(0,200,245,0.05));
    border: 1px solid rgba(0,200,245,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--primary-color);
    flex-shrink: 0;
    letter-spacing: 0.5px;
    font-family: var(--font-mono);
}
.node-info { min-width: 0; flex: 1; }
.node-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.node-id {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Node core stats grid */
.node-core-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(85px, 1fr));
    gap: 6px;
}
.stat-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 6px;
    background: rgba(0,0,0,0.15);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.stat-item.full-width { grid-column: 1 / -1; }
.stat-label {
    font-size: 0.62rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
    font-family: var(--font-mono);
}
.stat-value {
    font-size: 0.78rem;
    color: var(--text-primary);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Node secondary info */
.node-secondary-info {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding-top: 6px;
    border-top: 1px solid var(--divider-color);
}
.node-secondary-info strong { color: var(--text-muted); font-weight: 600; }

/* Node map placeholder */
.node-map-container {
    width: 100%;
    height: 120px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: #080810;
    position: relative;
    margin-top: auto;   /* ← add this line */
}
.map-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    gap: 6px;
}
.map-placeholder i { font-size: 1rem; }
.static-map-placeholder { position: relative; }
.map-placeholder-text {
    position: absolute;
    top: 5px; left: 5px;
    font-size: 0.65rem;
    color: rgba(200,200,200,0.6);
    background: rgba(0,0,0,0.5);
    padding: 1px 4px;
    border-radius: 2px;
    z-index: 401;
}
.node-map-container iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

/* ── Signal Bars ───────────────────────────────────────────────────── */
.signal-bars {
    display: inline-flex;
    align-items: flex-end;
    gap: 1.5px;
    height: 16px;
    vertical-align: middle;
}
.signal-bar {
    width: 4px;
    border-radius: 1px;
    background: #2a2a3a;
    transition: background var(--transition-fast);
}
.signal-bars.excellent .signal-bar.active { background: var(--signal-excellent); }
.signal-bars.good      .signal-bar.active { background: var(--signal-good); }
.signal-bars.fair      .signal-bar.active { background: var(--signal-fair); }
.signal-bars.poor      .signal-bar.active { background: var(--signal-poor); }

/* ── Battery Indicator ─────────────────────────────────────────────── */
.battery-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
}
.battery-icon { font-size: 0.85rem; }
.battery-icon.full { color: var(--battery-full); }
.battery-icon.good { color: var(--battery-good); }
.battery-icon.fair { color: var(--battery-fair); }
.battery-icon.low  { color: var(--battery-low); }

/* ── N/A and Placeholders ──────────────────────────────────────────── */
.na { color: var(--text-muted); font-style: italic; font-size: 0.85em; }

.loading-state,
.loading-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 30px 16px;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    grid-column: 1 / -1;
}
.loading-state i,
.loading-placeholder i {
    font-size: 1.4rem;
    color: var(--primary-color);
}

.error-placeholder {
    color: var(--error-color);
    text-align: center;
    padding: 16px;
    font-size: 0.82rem;
}

.placeholder-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px 16px;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.placeholder-message i { font-size: 1.6rem; color: #2a2a3a; }

/* ── Message Feed (C2 style) ───────────────────────────────────────── */
.message-feed {
    overflow-y: auto;
    height: 500px;
    padding: 0;
    display: flex;
    flex-direction: column;
}
.styled-feed { padding: 10px; }

.message-item {
    display: flex;
    gap: 10px;
    padding: 8px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.025);
    transition: background var(--transition-fast);
    animation: fadeSlideIn 0.2s ease;
    width: 100%;
    max-width: 100% !important;
    margin-bottom: 4px;
}
.message-item:hover { background: rgba(255,255,255,0.02); }

/* Remove any chat bubble styling that might affect the feed */
.message-item.current-user {
    align-self: flex-start;
    flex-direction: row;
}
.message-item.current-user .message-content {
    background: var(--card-background);
    border-color: var(--border-color);
    border-radius: 0 12px 12px 12px;
}
.message-item.current-user .sender-name {
    color: var(--text-primary);
}

@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.message-icon {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.78rem;
    background: rgba(255,255,255,0.04);
    color: var(--text-muted);
}
/* Message type colour classes (C2 pill colors) */
.message-icon.message    { background: rgba(0,240,144,0.1);   color: var(--signal-excellent); }
.message-icon.position   { background: rgba(0,200,245,0.1);   color: var(--primary-color); }
.message-icon.telemetry  { background: rgba(176,96,255,0.1); color: var(--purple); }
.message-icon.user-info  { background: rgba(255,168,0,0.1);   color: var(--warning-color); }
.message-icon.admin      { background: rgba(255,48,80,0.1);   color: var(--error-color); }
.message-icon.routing    { background: rgba(90,128,168,0.1);  color: var(--text-secondary); }
.message-icon.system     { background: rgba(90,128,168,0.05); color: var(--text-muted); }
.message-icon.encrypted  { background: rgba(255,48,80,0.08);  color: var(--error-color); }
.message-icon.decrypted  { background: rgba(0,240,144,0.08);  color: var(--signal-excellent); }
.message-icon.waypoint   { background: rgba(255,112,48,0.1);  color: var(--orange); }
.message-icon.unknown    { background: rgba(255,255,255,0.03); color: var(--text-muted); }

.message-content { flex: 1; min-width: 0; }
.message-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}
.message-sender { font-weight: 600; font-size: 0.82rem; color: var(--text-primary); }
.message-time   { font-size: 0.68rem; color: var(--text-muted); white-space: nowrap; }
.message-text   { font-size: 0.78rem; color: var(--text-secondary); word-break: break-word; line-height: 1.4; width: 100%; }

.message-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--divider-color);
    width: 100%;
}
.message-meta-item {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    gap: 3px;
}

/* Ensure signal bars and RSSI stay together */
.signal-bars + span {
    margin-left: 0.2rem;
    display: inline;
}

/* Message type indicator pill (C2 style) */
.msg-type-indicator {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    background: rgba(255,255,255,0.04);
    color: var(--text-muted);
    border: 1px solid transparent;
}
.msg-type-indicator.message   { background: rgba(0,240,144,0.1);   color: var(--signal-excellent); border-color: rgba(0,240,144,0.3); }
.msg-type-indicator.position  { background: rgba(0,200,245,0.1);   color: var(--primary-color);    border-color: rgba(0,200,245,0.3); }
.msg-type-indicator.telemetry { background: rgba(176,96,255,0.1); color: var(--purple);           border-color: rgba(176,96,255,0.3); }
.msg-type-indicator.user-info { background: rgba(255,168,0,0.1);   color: var(--warning-color);   border-color: rgba(255,168,0,0.3); }
.msg-type-indicator.encrypted { background: rgba(255,48,80,0.08);  color: var(--error-color);     border-color: rgba(255,48,80,0.2); }
.msg-type-indicator.decrypted { background: rgba(0,240,144,0.08);  color: var(--signal-excellent); border-color: rgba(0,240,144,0.2); }
.msg-type-indicator.routing   { background: rgba(90,128,168,0.1);  color: var(--text-secondary);  border-color: rgba(90,128,168,0.2); }
.msg-type-indicator.waypoint  { background: rgba(255,112,48,0.1);  color: var(--orange);          border-color: rgba(255,112,48,0.3); }

/* Packet controls */
.packet-controls { display: flex; align-items: center; gap: 8px; }
.packet-counter {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}
.packet-counter i { font-size: 0.65rem; }

/* ── Pagination ────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 12px 0 4px;
}
#pageInfo {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* ── Buttons (C2 style) ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition-fast);
    white-space: nowrap;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-color: var(--border-color);
    font-family: var(--font-sans);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.btn:hover:not(:disabled) {
    background: #0d1c34;
    color: var(--text-primary);
    border-color: #263d5e;
}

.btn-primary {
    background: rgba(0,200,245,0.1);
    color: var(--primary-color);
    border-color: rgba(0,200,245,0.3);
}
.btn-primary:hover:not(:disabled) {
    background: rgba(0,200,245,0.2);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-success {
    background: rgba(0,240,144,0.1);
    color: var(--signal-excellent);
    border-color: rgba(0,240,144,0.3);
}
.btn-success:hover {
    background: rgba(0,240,144,0.2);
    border-color: var(--signal-excellent);
    color: var(--signal-excellent);
}

.btn-warning {
    background: rgba(255,168,0,0.1);
    color: var(--warning-color);
    border-color: rgba(255,168,0,0.3);
}
.btn-warning:hover {
    background: rgba(255,168,0,0.2);
    border-color: var(--warning-color);
    color: var(--warning-color);
}

.btn-danger {
    background: rgba(255,48,80,0.1);
    color: var(--error-color);
    border-color: rgba(255,48,80,0.3);
}
.btn-danger:hover {
    background: rgba(255,48,80,0.2);
    border-color: var(--error-color);
    color: var(--error-color);
}

.btn-secondary {
    background: rgba(255,255,255,0.04);
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.btn-secondary:hover:not(:disabled) {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
}

.btn-small { padding: 4px 10px; font-size: 0.72rem; }

/* ── Modal (C2 style) ──────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 50000;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
    padding: 20px;
}
.modal.active { display: flex; }

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 64px rgba(0,0,0,0.7);
}
.modal-content.wide-modal { max-width: 1060px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background: rgba(0,0,0,0.2);
}
.modal-header h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.modal-header h2 i { color: var(--primary-color); }
.header-title-group { display: flex; flex-direction: column; gap: 2px; }

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    line-height: 1;
}
.close-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }

.modal-body {
    overflow-y: auto;
    padding: 16px 18px;
    flex: 1;
}

/* ── Modal Tabs ────────────────────────────────────────────────────── */
.modal-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0;
    overflow-x: auto;
    flex-wrap: nowrap;
}
.modal-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    transition: all var(--transition-fast);
}
.modal-tab:hover { color: var(--text-primary); }
.modal-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: 600;
}

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

/* ── Overview Dashboard (inside modal) ─────────────────────────────── */
.overview-dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
}

/* ── Tables (C2 style) ─────────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}
thead th {
    background: var(--bg-primary);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.5px;
    padding: 7px 10px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 2;
    font-family: var(--font-mono);
}
tbody td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--divider-color);
    color: var(--text-secondary);
    white-space: nowrap;
}
tbody tr:hover td { background: var(--bg-secondary); }

/* Config table (node detail) */
.config-table-container { margin-top: 12px; grid-column: 1 / -1; }
.config-table-container h4 {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--divider-color);
}
.config-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.76rem;
}
.config-table td {
    padding: 4px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.02);
}
.config-table td:first-child {
    color: var(--text-muted);
    font-weight: 500;
    width: 45%;
    white-space: nowrap;
}
.config-table td:last-child {
    color: var(--text-secondary);
    word-break: break-all;
}
.config-block { grid-column: 1 / -1; }

/* ── Map Container (modal) ─────────────────────────────────────────── */
.map-container {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: #080810;
}
.full-height-map { height: 450px; }
#node-detail-map { width: 100%; height: 100%; }
#map-loading-error {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(10,10,16,0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.82rem;
    z-index: 500;
}
#map-loading-error i { font-size: 1.4rem; }

/* Leaflet overrides (C2 dark) */
.leaflet-container { background: #080810 !important; }
.custom-wp-icon { background: none !important; border: none !important; }

/* ── Averages Chart Modal ──────────────────────────────────────────── */
#modal-chart-container {
    position: relative;
    height: 350px;
    width: 100%;
}
#modal-chart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px;
    color: var(--text-muted);
    font-size: 0.82rem;
}
#modal-chart-loading i { font-size: 1.2rem; color: var(--primary-color); }

/* ── Packet Log Items (modal feed) ─────────────────────────────────── */
.packet-log-item {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.025);
    transition: background var(--transition-fast);
}
.packet-log-item:hover { background: rgba(255,255,255,0.02); }

.packet-log-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 3px;
}
.packet-log-type {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--primary-color);
    letter-spacing: 0.3px;
}
.packet-log-time { font-size: 0.68rem; color: var(--text-muted); }
.packet-log-content { font-size: 0.78rem; color: var(--text-secondary); word-break: break-word; line-height: 1.4; }
.packet-log-meta {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.5;
}

/* ── DM Input ──────────────────────────────────────────────────────── */
.dm-input-container input[type="text"] {
    flex-grow: 1;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--card-background);
    color: var(--text-primary);
    font-size: 0.82rem;
    outline: none;
    transition: border-color var(--transition-fast);
}
.dm-input-container input[type="text"]:focus { border-color: var(--primary-color); }

/* ── Debug Panel (C2) ──────────────────────────────────────────────── */
.debug-panel {
    display: none;
    position: fixed;
    bottom: 40px;
    right: 16px;
    width: 480px;
    max-height: 360px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    z-index: 60000;
    flex-direction: column;
    overflow: hidden;
}
.debug-panel.active { display: flex; }

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(0,0,0,0.3);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.debug-header h3 {
    font-size: 0.82rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}
.debug-header h3 i { color: var(--primary-color); }
.debug-buttons { display: flex; gap: 4px; }

.debug-content {
    overflow-y: auto;
    flex: 1;
    padding: 8px;
}
#debug-output {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
}

/* ── Loading / Spinner ─────────────────────────────────────────────── */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 30px;
    color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════════════
   FIXED SCROLL LAYOUT (The "Wrapper" Method)
   Solves overlapping/squashed cards by scrolling the .card-content wrapper
   instead of the grid itself.
   ═══════════════════════════════════════════════════════════════════════ */

/* 1. Define the Fixed Dashboard Height */
@media (min-width: 992px) {
    .main-grid {
        /* 100vh minus header (~70px) & margins */
        height: calc(100vh - 140px);
        overflow: hidden; /* Stop the main page scrolling */
        align-items: stretch;
    }

    .card {
        height: 100%;
        display: flex;
        flex-direction: column;
        overflow: hidden; /* Contains the children */
    }

    /* Card content scrolling is defined in .card-content above */
}

/* 2. The Lists/Grids inside just grow naturally */
#existing-tasks-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: auto !important; 
    max-height: none !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    flex: none !important;
}

/* 3. Mobile Fallback (Standard Scroll) */
@media (max-width: 991px) {
    .main-grid { height: auto; }
    .card-content { 
        max-height: 500px; /* Force a scroll height on mobile */
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   SENSORS / IoT MONITOR PAGE — Form Wizard, Block Cards, Task Scheduling
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Form Wizard ───────────────────────────────────────────────────── */
.form-wizard {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.wizard-step {
    display: none;
    flex-direction: column;
    gap: 16px;
    animation: wizardFadeIn 0.25s ease;
}
.wizard-step.active { display: flex; }

@keyframes wizardFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.wizard-step h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    margin: 0;
}

/* ── Form Groups & Controls ────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.2px;
}

.form-control {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    font-family: var(--font-sans);
    outline: none;
    width: 100%;
    transition: border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}
.form-control:focus {
    border-color: var(--primary-color);
    background: rgba(0,200,245,0.03);
    box-shadow: 0 0 0 2px rgba(0,200,245,0.08);
}
.form-control::placeholder { color: var(--text-muted); }

/* Select styling */
select.form-control {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%235a80a8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    cursor: pointer;
}

/* Input with inline button */
.input-with-button {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.input-with-button .form-control { flex: 1; }
.input-with-button .btn { flex-shrink: 0; white-space: nowrap; }

/* Helper text below inputs */
.helper-text {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Additional info / tips block */
.additional-info-text {
    margin-top: 10px;
    padding: 12px 14px;
    background: rgba(0,200,245,0.03);
    border: 1px solid rgba(0,200,245,0.08);
    border-radius: var(--radius-md);
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.55;
}
.additional-info-text p { margin-bottom: 6px; }
.additional-info-text p:last-child { margin-bottom: 0; }
.additional-info-text ul {
    margin: 6px 0;
    padding-left: 20px;
}
.additional-info-text li {
    margin-bottom: 4px;
    list-style-type: disc;
    color: var(--text-secondary);
}
.additional-info-text li::marker { color: var(--primary-color); }

/* ── Buttons (sensor page variants) ────────────────────────────────── */
.btn.primary {
    background: rgba(0,200,245,0.1);
    color: var(--primary-color);
    border: 1px solid rgba(0,200,245,0.3);
}
.btn.primary:hover:not(:disabled) { background: rgba(0,200,245,0.2); border-color: var(--primary-color); }

.btn.secondary {
    background: rgba(255,255,255,0.04);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.btn.secondary:hover:not(:disabled) { background: rgba(255,255,255,0.08); color: var(--text-primary); }

/* Button row (back / submit alignment) */
.button-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--divider-color);
    margin-top: 6px;
}

/* ── Error & Success Messages ──────────────────────────────────────── */
.error-message {
    background: rgba(255,48,80,0.08);
    border: 1px solid rgba(255,48,80,0.2);
    color: var(--error-color);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    line-height: 1.45;
    display: flex;
    align-items: flex-start;
    gap: 6px;
}
.error-message i { flex-shrink: 0; margin-top: 2px; }

.success-message {
    background: rgba(0,240,144,0.06);
    border: 1px solid rgba(0,240,144,0.18);
    color: var(--signal-excellent);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    line-height: 1.45;
    display: flex;
    align-items: flex-start;
    gap: 6px;
}
.success-message i { flex-shrink: 0; margin-top: 2px; }

/* ── Loading indicator (inline) ────────────────────────────────────── */
#loading-blocks {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    color: var(--text-muted);
    font-size: 0.82rem;
}
#loading-blocks i { color: var(--primary-color); }

/* ── Block Cards (Step 2) ──────────────────────────────────────────── */
.blocks-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 480px;
    overflow-y: auto;
    padding-right: 4px;
}

.block-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    cursor: pointer;
    transition: all var(--transition-med);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.block-card:hover {
    border-color: rgba(0,200,245,0.2);
    background: var(--card-bg-hover);
}
.block-card.selected {
    border-color: var(--primary-color);
    background: rgba(0,200,245,0.04);
    box-shadow: 0 0 0 1px var(--primary-color), 0 0 12px rgba(0,200,245,0.08);
}

.block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.block-type {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--primary-color);
    background: rgba(0,200,245,0.1);
    padding: 2px 8px;
    border-radius: 3px;
}
.block-type i { font-size: 0.65rem; }
.block-id {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.block-content {
    font-size: 0.82rem;
    color: var(--text-primary);
    line-height: 1.45;
    word-break: break-word;
    padding: 6px 0;
    border-top: 1px solid rgba(255,255,255,0.03);
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.block-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    font-size: 0.68rem;
    color: var(--text-muted);
}
.block-meta-item { display: flex; align-items: center; gap: 3px; }
.block-meta-item strong { color: var(--text-secondary); font-weight: 600; }

.block-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 4px;
}
.block-actions .btn {
    font-size: 0.72rem;
    padding: 4px 12px;
}

.no-blocks {
    text-align: center;
    color: var(--text-muted);
    padding: 30px 16px;
    font-size: 0.85rem;
}

/* ── Selected Content Preview (Step 3) ─────────────────────────────── */
.selected-content-preview {
    background: rgba(0,200,245,0.03);
    border: 1px solid rgba(0,200,245,0.12);
    border-radius: var(--radius-md);
    padding: 12px 14px;
}
.selected-content-preview h4 {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.content-preview {
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-family: var(--font-mono);
    font-size: 0.88rem;
    color: var(--primary-color);
    word-break: break-word;
    line-height: 1.45;
    max-height: 120px;
    overflow-y: auto;
}

/* ── Instructions Panel ────────────────────────────────────────────── */
.instructions {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.6;
}
.instructions h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
}
.instructions h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 16px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.instructions p {
    margin-bottom: 8px;
}
.instructions ul {
    margin: 8px 0 12px;
    padding-left: 20px;
}
.instructions li {
    margin-bottom: 5px;
    list-style-type: disc;
}
.instructions li::marker { color: var(--primary-color); }
.instructions li strong { color: var(--text-primary); }

/* ── Form Actions (modal footers) ──────────────────────────────────── */
.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--divider-color);
    margin-top: 10px;
}

/* ── Task Summary Card ─────────────────────────────────────────────── */
.task-summary {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.5;
}
.task-summary p {
    margin-bottom: 3px;
}
.task-summary p:last-child { margin-bottom: 0; }
.task-summary strong { color: var(--text-primary); }

/* ── Schedule Options (radio group) ────────────────────────────────── */
.schedule-options {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    padding: 6px 0;
}
.schedule-options label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color var(--transition-fast);
}
.schedule-options label:hover { color: var(--text-primary); }

/* Radio button styling */
.schedule-options input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    width: 14px; height: 14px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    flex-shrink: 0;
}
.schedule-options input[type="radio"]:checked {
    border-color: var(--primary-color);
    background: var(--primary-color);
    box-shadow: inset 0 0 0 2.5px var(--bg-secondary);
}

/* Schedule inputs */
.schedule-inputs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.schedule-inputs .form-group.hidden { display: none; }

/* Inline layout for weekly (day + time side by side) */
#schedule-input-weekly {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}
#schedule-input-weekly.hidden { display: none; }
#schedule-input-weekly label { white-space: nowrap; }
#schedule-input-weekly .form-control { max-width: 180px; }

/* ── Cron Preview ──────────────────────────────────────────────────── */
.cron-preview {
    margin-top: 10px;
    padding: 10px 12px;
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-muted);
}
.cron-preview pre {
    margin-top: 4px;
    background: transparent;
    border: none;
    padding: 0;
    font-size: 0.92rem;
    color: var(--primary-color);
    max-height: none;
    overflow: visible;
}
.cron-preview code {
    background: none;
    padding: 0;
    font-size: inherit;
    color: inherit;
}
.cron-preview .na { color: var(--text-muted); font-style: italic; font-size: 0.82rem; }

/* ── Hidden utility ────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════════════════
   TASK SCHEDULER PAGE — Task List Items, Type Toggles, Modal Controls
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Task List Items ───────────────────────────────────────────────── */
#existing-tasks-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 600px;
    overflow-y: auto;
    padding-right: 4px;
}

.task-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: all var(--transition-fast);
    position: relative;
}

.task-item:hover {
    border-color: rgba(0,200,245,0.3);
    background: var(--card-bg-hover);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transform: translateY(-1px);
}

.task-item div {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.task-item div strong {
    color: var(--text-primary);
    font-weight: 600;
    min-width: 70px;
    display: inline-block;
}

.task-item code {
    font-size: 0.75rem;
    color: var(--purple);
    background: rgba(176,96,255,0.08);
}

/* Live Preview inside task card */
.live-preview-value {
    font-family: var(--font-mono);
    font-size: 0.85em;
    color: var(--primary-color);
    background: rgba(0,200,245,0.08);
    padding: 1px 6px;
    border-radius: 3px;
    word-break: break-all;
}

/* Task Action Buttons (Edit/Delete) */
.task-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.04);
}

.task-actions .btn {
    font-size: 0.72rem;
    padding: 4px 10px;
}

/* Delete Button Specifics */
.btn.delete {
    background: rgba(255,48,80,0.06);
    color: var(--error-color);
    border-color: rgba(255,48,80,0.2);
}
.btn.delete:hover {
    background: rgba(255,48,80,0.15);
    border-color: var(--error-color);
    color: #fff;
}

/* ── Task Type Toggle (Segmented Control) ──────────────────────────── */
.task-type-toggle {
    display: flex;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 2px;
}

.task-type-toggle input[type="radio"] {
    display: none; /* Hide standard radio */
}

.task-type-toggle label {
    flex: 1;
    text-align: center;
    padding: 7px 12px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 2px;
    transition: all var(--transition-fast);
    user-select: none;
}

.task-type-toggle label:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.03);
}

.task-type-toggle input[type="radio"]:checked + label {
    background: rgba(0,200,245,0.1);
    color: var(--primary-color);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* ── Sensor Preview Area (Modal) ───────────────────────────────────── */
#sensor-preview-area {
    margin-top: 8px;
    background: #080810;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px;
    min-height: 42px;
    display: flex;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

#sensor-preview-area strong {
    color: var(--text-secondary);
    margin-right: 8px;
}

#sensor-preview-area pre {
    margin: 0;
    font-family: var(--font-mono);
    color: var(--primary-color);
    white-space: pre-wrap;
    background: none;
    border: none;
    padding: 0;
}

/* ── DateTime Input Dark Mode Fix ──────────────────────────────────── */
input[type="datetime-local"],
input[type="time"],
input[type="date"] {
    color-scheme: dark;
}

input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
    filter: invert(1) opacity(0.6);
    cursor: pointer;
}
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover,
input[type="time"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

/* ═══════════════════════════════════════════════════════════════════════
   AUTO-REPLY RULES PAGE — Rule Cards, Status Toggles, Placeholders
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Rule List Item ────────────────────────────────────────────────── */
#existing-rules-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* Ensure it works with the fixed-scroll layout applied earlier */
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

.rule-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all var(--transition-fast);
}

.rule-item:hover {
    border-color: rgba(0,200,245,0.3);
    background: var(--card-bg-hover);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transform: translateY(-1px);
}

/* Rule Header (Trigger & Toggle) */
.rule-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    padding-bottom: 8px;
}

.rule-title {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 600;
    display: flex;
    align-items: center;
}

.rule-title code {
    margin-left: 6px;
    font-size: 0.85em;
    color: var(--primary-color);
    background: rgba(0,200,245,0.08);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Status Toggle (Enabled/Disabled chip) */
.rule-status-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
    border: 1px solid transparent;
}

.rule-status-toggle.enabled {
    background: rgba(0,240,144,0.1);
    color: var(--signal-excellent);
    border-color: rgba(0,240,144,0.2);
}
.rule-status-toggle.enabled:hover {
    background: rgba(0,240,144,0.2);
}

.rule-status-toggle.disabled {
    background: rgba(90,128,168,0.1);
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.rule-status-toggle.disabled:hover {
    background: rgba(90,128,168,0.15);
    color: var(--text-primary);
}

/* Rule Content (Response Text) */
.rule-content {
    background: rgba(0,0,0,0.2);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-left: 2px solid var(--border-color);
}

.rule-content strong {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    margin-right: 6px;
}

/* Rule Meta (Cooldown etc) */
.rule-meta {
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.rule-meta-item i { margin-right: 4px; }

/* Rule Actions */
.rule-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 4px;
}

/* ── Placeholder System (Modal) ────────────────────────────────────── */
.placeholder-group {
    margin-bottom: 16px;
}

.placeholder-category {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.placeholder-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.placeholder-pill {
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    padding: 4px 10px;
    border-radius: 14px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.placeholder-pill:hover {
    background: rgba(0,200,245,0.1);
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

/* Placeholder Table (in help modal) */
.placeholder-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-bottom: 20px;
}
.placeholder-table th {
    text-align: left;
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
}
.placeholder-table td {
    padding: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    color: var(--text-secondary);
}
.placeholder-table code {
    color: var(--primary-color);
    background: rgba(255,255,255,0.03);
    padding: 2px 5px;
    border-radius: 3px;
}

/* ── Form Layout ───────────────────────────────────────────────────── */
/* Grid for the 2-column form */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* Helper Text */
.helper-text {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
    font-style: italic;
}

/* ═══════════════════════════════════════════════════════════════════════
   MESHTASTIC CHAT PAGE — Sidebar, Chat Bubbles, Input Area, Node Popover
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Sidebar Layout ────────────────────────────────────────────────── */
#sidebar {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 0; /* Override default card-content padding */
}

/* Sidebar Stats Strip */
.sidebar-stats {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0,0,0,0.2);
    padding: 8px 0;
}
.sidebar-stat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-right: 1px solid rgba(255,255,255,0.03);
}
.sidebar-stat:last-child { border-right: none; }
.sidebar-stat .sv { font-weight: 700; font-size: 0.9rem; color: var(--text-primary); }
.sidebar-stat .sl { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* Sidebar Search */
.sidebar-search {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}
#sidebar-filter {
    width: 100%;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8rem;
    outline: none;
}
#sidebar-filter:focus { border-color: var(--primary-color); }

/* Section Labels */
.sidebar-section-label {
    padding: 8px 14px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    background: rgba(255,255,255,0.02);
    letter-spacing: 0.5px;
    display: flex;
    justify-content: space-between;
}
.sidebar-section-label .count { background: rgba(255,255,255,0.05); padding: 0 5px; border-radius: 3px; }

/* ── Channel Items ─────────────────────────────────────────────────── */
.channel-item {
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    border-left: 3px solid transparent;
    border-bottom: 1px solid rgba(255,255,255,0.02);
    transition: all var(--transition-fast);
}
.channel-item:hover { background: var(--card-bg-hover); }
.channel-item.active {
    background: rgba(0,200,245,0.05);
    border-left-color: var(--primary-color);
}

.channel-info { display: flex; align-items: center; gap: 10px; overflow: hidden; }
.channel-hash { 
    color: var(--text-muted); 
    font-size: 1.1rem; 
    font-weight: 300; 
    width: 18px; 
    text-align: center; 
}
.channel-item.active .channel-hash { color: var(--primary-color); }

.channel-name-text { font-size: 0.88rem; font-weight: 500; color: var(--text-secondary); white-space: nowrap; }
.channel-item.active .channel-name-text { color: var(--text-primary); font-weight: 600; }

.channel-role-badge { 
    font-size: 0.6rem; padding: 1px 4px; border-radius: 3px; background: rgba(255,255,255,0.1); color: var(--text-muted); margin-left: 4px; 
}
.channel-role-badge.primary { background: rgba(0,200,245,0.15); color: var(--primary-color); }

.channel-meta-icons { font-size: 0.65rem; color: var(--text-muted); margin-top: 2px; }

.unread-badge {
    background: var(--error-color);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    display: none;
}
.unread-badge.visible { display: inline-block; }

/* ── Node Items (Sidebar) ──────────────────────────────────────────── */
.node-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.015);
    transition: background var(--transition-fast);
}
.node-item:hover { background: var(--card-bg-hover); }

.node-avatar-sm {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; 
    align-items: center; 
    justify-content: center;
    font-size: 0.75rem; 
    font-weight: 700; 
    color: rgba(255,255,255,0.9);
    flex-shrink: 0;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.node-details { flex: 1; min-width: 0; }
.node-details .node-name { font-size: 0.82rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.node-details .node-sub { font-size: 0.68rem; color: var(--text-muted); }

.node-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.signal-val { font-size: 0.65rem; font-weight: 600; font-family: var(--font-mono); }
.signal-good { color: var(--signal-excellent); } 
.signal-ok { color: var(--signal-fair); } 
.signal-bad { color: var(--signal-poor); }

.online-dot { width: 6px; height: 6px; border-radius: 50%; background: #3a3a4a; margin-top: 2px; }
.online-dot.recent { background: var(--primary-color); box-shadow: 0 0 4px var(--primary-glow); }

/* ── Chat Card Layout ──────────────────────────────────────────────── */
#chat-card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#chat-card .card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0; /* Reset for full width input */
    position: relative;
    overflow: hidden;
}

#message-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scroll-behavior: auto; /* JS handles smooth scrolling */
}

/* Scroll FAB */
.scroll-fab {
    position: absolute;
    bottom: 90px; right: 20px;
    width: 36px; height: 36px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--primary-color);
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    cursor: pointer;
    opacity: 0; pointer-events: none;
    transition: all var(--transition-med);
    z-index: 10;
}
.scroll-fab.visible { opacity: 1; pointer-events: auto; }
.scroll-fab:hover { background: var(--card-bg-hover); transform: translateY(-2px); }

/* ── Messages (C2 bubble style) ────────────────────────────────────── */
/* Note: General .message-item styles are defined in the main message feed section.
   These are overrides for the chat page's specific bubble look. */

/* Ensure chat-specific messages use the bubble style */
#message-container .message-item {
    max-width: 85%;
    margin-bottom: 10px;
}
#message-container .message-item.current-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

#message-container .message-item .node-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.7rem; font-weight: 700; color: #fff;
    cursor: pointer;
    margin-top: 2px;
}

#message-container .message-content {
    background: #0d1c34; /* bg3 */
    padding: 8px 12px;
    border-radius: 0 12px 12px 12px;
    position: relative;
    min-width: 140px;
    border: 1px solid rgba(255,255,255,0.03);
}

#message-container .message-item.current-user .message-content {
    background: rgba(0,200,245,0.1);
    border-color: rgba(0,200,245,0.15);
    border-radius: 12px 0 12px 12px;
}

#message-container .sender-name { font-weight: 600; color: var(--text-primary); cursor: pointer; }
#message-container .sender-name:hover { text-decoration: underline; }
#message-container .message-item.current-user .sender-name { color: var(--primary-color); }

#message-container .hw-badge { 
    font-size: 0.6rem; background: rgba(255,255,255,0.05); 
    padding: 0 4px; border-radius: 3px; color: var(--text-muted); 
}

#message-container .message-text {
    font-size: 0.9rem;
    color: #e0e0e8;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}
#message-container .message-text a { text-decoration: underline; }

#message-container .message-meta {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid rgba(255,255,255,0.03);
    font-size: 0.65rem;
    color: var(--text-muted);
}
#message-container .message-meta-item { display: flex; align-items: center; gap: 3px; }
#message-container .meta-icon { font-size: 0.6rem; opacity: 0.7; }

/* System & Date Messages */
.system-message {
    align-self: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: rgba(255,255,255,0.03);
    padding: 4px 12px;
    border-radius: 12px;
    margin: 10px 0;
}
.date-separator {
    display: flex; align-items: center; justify-content: center;
    margin: 15px 0;
    position: relative;
}
.date-separator::before {
    content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--border-color); z-index: 1;
}
.date-separator span {
    background: var(--card-background);
    padding: 0 10px;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    z-index: 2;
}

/* ── Chat Input Area ───────────────────────────────────────────────── */
.chat-input-area {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 12px 16px;
    flex-shrink: 0;
}

.input-row { display: flex; gap: 10px; align-items: flex-start; }

.input-wrapper { position: relative; flex: 1; }
#message-input {
    width: 100%;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 45px 10px 14px;
    border-radius: 20px;
    outline: none;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}
#message-input:focus:not(:disabled) { border-color: var(--primary-color); background: rgba(0,0,0,0.3); }
#message-input:disabled { opacity: 0.6; cursor: not-allowed; }

#char-count {
    position: absolute;
    right: 12px; top: 50%; transform: translateY(-50%);
    font-size: 0.7rem; color: var(--text-muted);
    pointer-events: none;
}
#char-count.warning { color: var(--warning-color); }
#char-count.danger { color: var(--error-color); }

#send-button {
    width: 40px; height: 38px;
    border-radius: 50%;
    padding: 0;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.input-hints {
    display: flex; justify-content: space-between;
    font-size: 0.7rem; color: var(--text-muted);
    margin-top: 6px; padding: 0 4px;
}
.input-hints strong { color: var(--text-secondary); }

/* ── Node Popover ──────────────────────────────────────────────────── */
.popover-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(2px);
    z-index: 2000;
    display: none; align-items: center; justify-content: center;
}
.popover-overlay.active { display: flex; animation: fadeIn 0.2s; }

.popover {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 320px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    overflow: hidden;
    animation: popUp 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes popUp { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.popover-head {
    background: rgba(255,255,255,0.03);
    padding: 16px;
    display: flex; align-items: center; gap: 12px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}
.popover-av {
    width: 48px; height: 48px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; font-weight: 700; color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.popover-id-block { overflow: hidden; }
.popover-longname { font-weight: 600; font-size: 1rem; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.popover-nodeid { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); }
.popover-x {
    position: absolute; top: 10px; right: 10px;
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 5px;
}
.popover-x:hover { color: var(--text-primary); }

.popover-body { padding: 12px; max-height: 60vh; overflow-y: auto; }

.popover-sec { margin-bottom: 12px; }
.popover-sec:last-child { margin-bottom: 0; }
.popover-sec-title {
    font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--primary-color); font-weight: 700; margin-bottom: 6px;
    border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 2px;
}
.popover-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.pf-l { font-size: 0.7rem; color: var(--text-muted); }
.pf-v { font-size: 0.75rem; color: var(--text-primary); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ═══════════════════════════════════════════════════════════════════════
   DIRECT MESSAGES PAGE — Contact List, DM Bubbles, Status Icons
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Sidebar Contact List ──────────────────────────────────────────── */
#node-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Note: .node-item styles are shared with Chat sidebar; they are consolidated here. */
#node-list .node-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.02);
    transition: all var(--transition-fast);
    position: relative;
}
#node-list .node-item.active {
    background: rgba(0,200,245,0.08);
    border-left: 3px solid var(--primary-color);
    padding-left: 13px; /* Compensate for border to keep alignment */
}

/* Avatar Circle */
#node-list .node-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.9rem; font-weight: 700; color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    flex-shrink: 0;
}

/* Contact Info Text */
#node-list .node-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
#node-list .node-name { 
    font-size: 0.9rem; font-weight: 600; color: var(--text-primary); 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 
}
#node-list .node-meta { font-size: 0.7rem; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }

/* Status Dot (Online/Offline) */
#node-list .online-dot { width: 8px; height: 8px; border-radius: 50%; background: #3a3a4a; }
#node-list .online-dot.online { background: var(--signal-excellent); box-shadow: 0 0 6px var(--primary-glow); }

/* Unread Badge */
#node-list .unread-badge {
    background: var(--error-color);
    color: white;
    font-size: 0.7rem; font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    display: none;
}
#node-list .unread-badge.visible { display: block; }

/* ── Chat Area Layout ──────────────────────────────────────────────── */
#message-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-image: radial-gradient(rgba(255,255,255,0.02) 1px, transparent 1px);
    background-size: 20px 20px;
}

.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; color: var(--text-muted); text-align: center; opacity: 0.6;
}
.empty-state i { font-size: 3rem; margin-bottom: 1rem; color: var(--border-color); }

/* ── Message Bubbles (C2 style) ────────────────────────────────────── */
.msg-row {
    display: flex;
    width: 100%;
}

.msg-row.incoming { justify-content: flex-start; }
.msg-row.outgoing { justify-content: flex-end; }

.msg-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 16px;
    position: relative;
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Incoming Style */
.msg-row.incoming .msg-bubble {
    background: #0d1c34;
    border: 1px solid rgba(255,255,255,0.05);
    border-bottom-left-radius: 2px;
    color: var(--text-primary);
}

/* Outgoing Style */
.msg-row.outgoing .msg-bubble {
    background: rgba(0,200,245,0.15);
    border: 1px solid rgba(0,200,245,0.25);
    border-bottom-right-radius: 2px;
    color: var(--text-primary);
}

.msg-text a { color: var(--primary-color); text-decoration: underline; }

/* Meta Data (Time & Status) inside bubble */
.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 4px;
    font-size: 0.65rem;
    color: rgba(255,255,255,0.5);
    user-select: none;
}

/* ── Message Status Icons ──────────────────────────────────────────── */
.status-icon { font-size: 0.7rem; }

.status-pending { color: var(--text-muted); opacity: 0.7; }
.status-sent    { color: var(--text-secondary); }
.status-acked   { color: var(--primary-color); }
.status-error   { color: var(--error-color); }

/* ── Input Area ────────────────────────────────────────────────────── */
.chat-input-area {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 16px;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 8px 8px 8px 16px;
    transition: border-color var(--transition-fast);
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 1px rgba(0,200,245,0.1);
}

textarea#msg-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    resize: none;
    max-height: 120px;
    padding: 8px 0;
    outline: none;
}

textarea#msg-input::placeholder { color: var(--text-muted); }

#send-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    padding: 0;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    margin-bottom: 2px; /* Align with bottom of textarea text */
}

/* ── Raw Modal Code ────────────────────────────────────────────────── */
#raw-content {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--primary-color);
    background: rgba(0,0,0,0.3);
    padding: 12px;
    border-radius: var(--radius-sm);
    white-space: pre-wrap;
    word-break: break-all;
}

/* ═══════════════════════════════════════════════════════════════════════
   SYSTEM SETTINGS PAGE — Config Grid, Toggles, Input Groups, Sticky Footer
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Settings Grid Layout ──────────────────────────────────────────── */
#settingsForm {
    /* Padding at bottom to ensure content isn't hidden behind sticky footer */
    padding-bottom: 80px; 
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 20px;
    align-items: start;
}

.settings-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.settings-header {
    background: rgba(0,0,0,0.2);
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.settings-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.settings-header h3 i { color: var(--primary-color); }

.settings-header p {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
    margin: 0;
}

.settings-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Form Enhancements ─────────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.help-text {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.4;
}
.help-text code {
    background: rgba(255,255,255,0.06);
    padding: 2px 4px;
    border-radius: 3px;
    color: var(--text-primary);
}

/* Input Group (for password eye toggle) */
.input-group {
    display: flex;
    width: 100%;
}
.input-group .form-control {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: 0;
    flex: 1;
}
.input-group-btn {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border-color);
    border-left: 0;
    color: var(--text-muted);
    padding: 0 12px;
    border-top-right-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}
.input-group-btn:hover {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
}

/* ── Toggle Switches (C2 iOS Style) ────────────────────────────────── */
.toggle-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    padding: 4px 0;
}

.toggle-label-group {
    flex: 1;
}
.toggle-label-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
}

/* The Switch Container */
.switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }

/* The Slider */
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #2a2a3a;
    transition: .3s;
    border-radius: 24px;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(18px);
}

/* ── Sticky Footer (Solved) ────────────────────────────────────────── */
.sticky-footer {
    position: sticky;
    /* Use bottom: 0 so it sticks to the viewport until the footer appears */
    bottom: 0; 
    left: 0; 
    right: 0;
    
    /* Solid background prevents the footer text from bleeding through */
    background: var(--card-bg, #0b111a); 
    background: rgba(11, 17, 26, 0.95); 
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    
    border-top: 1px solid var(--border-color);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between; /* Keeps Restart left and Save right */
    align-items: center;
    gap: 15px;
    
    /* High z-index but lower than most system modals */
    z-index: 900; 
    box-shadow: 0 -10px 30px rgba(0,0,0,0.5);
    
    /* Adds separation from the content above it */
    margin-top: 3rem; 
}

/* Fix for mobile viewports to ensure it doesn't overlap the bottom of the screen */
@media (max-width: 768px) {
    .sticky-footer {
        padding: 20px;
        flex-direction: column-reverse;
        gap: 10px;
    }
    .sticky-footer div {
        width: 100%;
        display: flex;
        gap: 10px;
    }
    .sticky-footer button {
        flex: 1;
    }
}

.restart-banner {
    flex: 1;
    background: rgba(255,168,0,0.1);
    border: 1px solid rgba(255,168,0,0.3);
    color: var(--warning-color);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    visibility: hidden;
}

.restart-banner.visible {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
}

.btn-save {
    background: rgba(0,200,245,0.1);
    color: var(--primary-color);
    border: 1px solid rgba(0,200,245,0.3);
    padding: 8px 20px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all var(--transition-fast);
}
.btn-save:hover { background: rgba(0,200,245,0.2); border-color: var(--primary-color); }
.btn-save:disabled { opacity: 0.7; cursor: wait; }

/* ── Modal & Progress (Restart) ────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(5px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    animation: fadeIn 0.2s;
}

.modal-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 450px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    gap: 15px;
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-icon { margin-bottom: 5px; }
.modal-title { font-size: 1.4rem; font-weight: 700; color: var(--text-primary); }
.modal-message { color: var(--text-secondary); font-size: 0.95rem; }
.modal-warning { 
    background: rgba(255,48,80,0.1); 
    color: var(--error-color); 
    padding: 10px; 
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

/* Progress Bar */
.modal-progress {
    height: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    overflow: hidden;
    margin: 10px 0;
}
.modal-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--warning-color);
    transition: width 0.3s linear, background-color 0.3s;
}

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}
.status-badge-warning { background: rgba(255,168,0,0.15); color: var(--warning-color); }

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
}

.modal-btn {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    border: none;
    font-size: 0.9rem;
    display: flex; align-items: center; gap: 8px;
    transition: transform 0.1s;
}
.modal-btn:active { transform: scale(0.96); }

.modal-btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.modal-btn-outline:hover { border-color: var(--text-primary); color: var(--text-primary); }

.modal-btn-primary { background: var(--error-color); color: #000; }
.modal-btn-primary:hover { background: #ff4a6a; }

.modal-btn-success { background: var(--signal-excellent); color: #000; }
.modal-btn-success:hover { background: #2affb0; }

/* ═══════════════════════════════════════════════════════════════════════
   MESHTASTIC MAP PAGE — Leaflet Overrides, Map Controls, Legend, Popups
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Map Container Layout ──────────────────────────────────────────── */
/* Ensure map fills the remaining card space */
#map {
    flex: 1;
    width: 100%;
    min-height: 500px; /* Fallback height */
    z-index: 1;
    background: #020912; /* Dark background before tiles load */
}

/* ── Map Top Controls Toolbar ──────────────────────────────────────── */
.map-controls-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
}

.map-style-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}
.map-style-selector select {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    outline: none;
    cursor: pointer;
}

.filter-options {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}
.filter-options label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    user-select: none;
}
.filter-options input[type="checkbox"] {
    accent-color: var(--primary-color);
}

.map-action-buttons {
    display: flex;
    gap: 8px;
    margin-left: auto; /* Push to right */
}

/* ── Leaflet Dark Mode Overrides ───────────────────────────────────── */
/* Container & Tiles */
.leaflet-container {
    font-family: var(--font-sans) !important;
    background: #111 !important;
}

/* Popups */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 20px rgba(0,0,0,0.6) !important;
    border-radius: var(--radius-md) !important;
}

.leaflet-popup-content {
    margin: 12px 14px !important;
    line-height: 1.5;
}

/* Close button */
.leaflet-container a.leaflet-popup-close-button {
    color: var(--text-muted) !important;
    padding: 8px !important; 
    width: 24px !important; height: 24px !important;
    font: 16px/14px Tahoma, Verdana, sans-serif !important;
}
.leaflet-container a.leaflet-popup-close-button:hover {
    color: var(--primary-color) !important;
}

/* Zoom Controls */
.leaflet-bar {
    border: none !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4) !important;
}
.leaflet-bar a {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-bottom: 1px solid var(--border-color) !important;
}
.leaflet-bar a:hover {
    background-color: var(--card-bg-hover) !important;
    color: var(--primary-color) !important;
}
.leaflet-bar a:last-child {
    border-bottom: none !important;
}

/* ── Custom Popup Content ──────────────────────────────────────────── */
.node-popup h3 {
    margin: 0 0 8px 0;
    font-size: 0.95rem;
    color: var(--primary-color);
    border-bottom: 1px solid var(--divider-color);
    padding-bottom: 4px;
}

.node-popup table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    margin-bottom: 10px;
}
.node-popup td {
    padding: 2px 0;
    vertical-align: top;
}
.node-popup td:first-child {
    color: var(--text-muted);
    padding-right: 12px;
    white-space: nowrap;
}
.node-popup td:last-child {
    color: var(--text-primary);
    text-align: right;
    font-family: var(--font-mono);
}

/* Popup Message Form */
.popup-message-form {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--divider-color);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.popup-message-form label { font-size: 0.75rem; color: var(--text-secondary); }
.popup-message-form input {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    outline: none;
}
.popup-message-form button {
    background: var(--primary-color);
    color: #000;
    border: none;
    border-radius: var(--radius-sm);
    padding: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
}
.popup-message-form button:hover { background: #33e8ff; }
.popup-message-form button:disabled { opacity: 0.6; cursor: not-allowed; }

.popup-message-feedback { font-size: 0.7rem; min-height: 1rem; }
.popup-message-feedback.success { color: var(--primary-color); }
.popup-message-feedback.error { color: var(--error-color); }

/* Signal dots in popup */
.signal-indicator { display: inline-block; padding: 1px 4px; border-radius: 3px; background: rgba(255,255,255,0.05); }
.signal-excellent { color: var(--signal-excellent); }
.signal-good { color: var(--signal-good); }
.signal-fair { color: var(--signal-fair); }
.signal-poor { color: var(--signal-poor); }

/* ── Floating Legend ───────────────────────────────────────────────── */
.legend {
    background: rgba(10,22,40,0.95); /* bg2 high opacity */
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px;
    width: 260px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    transition: width 0.2s, padding 0.2s;
}

/* Minimized State */
.legend.minimized {
    width: auto;
    padding: 6px;
    gap: 0;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.legend-header h4 { margin: 0; font-size: 0.85rem; color: var(--text-primary); }
.btn-minimize {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 2px 6px;
}
.btn-minimize:hover { color: var(--text-primary); }

.legend.minimized .legend-header h4 { display: none; }

/* Search in Legend */
.legend-search-container input {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.75rem;
    outline: none;
}
.legend-search-container input:focus { border-color: var(--primary-color); }

/* Legend List */
.legend-content {
    max-height: 350px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 4px;
}
.legend-content h5 {
    margin: 8px 0 4px;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.legend-item {
    display: flex;
    align-items: center;
    font-size: 0.78rem;
    color: var(--text-secondary);
    padding: 3px 4px;
    border-radius: 4px;
}
.legend-item.clickable { cursor: pointer; transition: background 0.1s; }
.legend-item.clickable:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }

.legend-color {
    width: 10px; height: 10px; border-radius: 50%;
    margin-right: 8px;
    box-shadow: 0 0 4px rgba(0,0,0,0.5);
    flex-shrink: 0;
}

/* Hidden by search filter */
.hidden-by-search { display: none !important; }

/* ═══════════════════════════════════════════════════════════════════════
   SSE DEBUGGER PAGE — Scoped to #debugger-container
   ═══════════════════════════════════════════════════════════════════════ */

/* Override body and dashboard ONLY when the debugger is on the page */
body:has(#debugger-container) {
    overflow: hidden; 
}

.dashboard:has(#debugger-container) {
    height: calc(100vh - var(--header-height) - 10px); 
    padding-bottom: 0;
    display: flex;
    flex-direction: column;
}

/* === Debugger Container Layout === */
#debugger-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--font-mono);
    font-size: 0.88rem;
    color: var(--text-primary);
    background: var(--bg-secondary);
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

/* ── Top Bar ── */
#debugger-container #topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    flex-wrap: wrap;
}

#debugger-container #topbar h1 {
    font-size: 0.95rem;
    color: var(--primary-color);
    font-weight: 700;
    white-space: nowrap;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

#debugger-container .tb-sep { width: 1px; height: 20px; background: var(--divider-color); }

#debugger-container #conn-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--error-color); flex-shrink: 0;
    transition: background 0.4s, box-shadow 0.4s;
}
#debugger-container #conn-dot.on { background: var(--signal-excellent); box-shadow: 0 0 8px var(--primary-glow); }
#debugger-container #conn-dot.wait { background: var(--warning-color); animation: dbg-pulse-warn 0.9s infinite alternate; }

@keyframes dbg-pulse-warn {
    0%   { opacity: 0.5; transform: scale(0.85); }
    100% { opacity: 1;   transform: scale(1.15); }
}

#debugger-container #conn-label { font-size: 0.75rem; color: var(--text-secondary); }

#debugger-container #pkt-count {
    font-size: 0.78rem; color: var(--text-muted); margin-left: auto;
}
#debugger-container #pkt-count span { color: var(--primary-color); font-weight: 700; font-variant-numeric: tabular-nums; }

/* Filter bar */
#debugger-container .filter-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#debugger-container .filter-group label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 600; }

#debugger-container #filter-input, 
#debugger-container #event-filter {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    padding: 5px 10px;
    outline: none;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}
#debugger-container #filter-input { width: 200px; }
#debugger-container #filter-input:focus, 
#debugger-container #event-filter:focus { 
    border-color: var(--primary-color); 
    background: rgba(0,200,245,0.03); 
}
#debugger-container #filter-input::placeholder { color: var(--text-muted); }
#debugger-container #event-filter option { background: var(--bg-secondary); }

#debugger-container .tb-btn {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    padding: 5px 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
#debugger-container .tb-btn:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }
#debugger-container .tb-btn.danger:hover { border-color: var(--error-color); color: var(--error-color); background: rgba(255,48,80,0.08); }
#debugger-container .tb-btn.active { background: rgba(0,200,245,0.1); border-color: var(--primary-color); color: var(--primary-color); font-weight: 600; }
#debugger-container #pause-btn.paused { background: rgba(255,168,0,0.1); border-color: var(--warning-color); color: var(--warning-color); }

/* ── Layout: sidebar + main ── */
#debugger-container #layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar: event type counts ── */
#debugger-container #sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 12px 0;
    display: flex;
    flex-direction: column;
}

#debugger-container .sb-header {
    padding: 0 14px 10px;
    border-bottom: 1px solid var(--divider-color);
    flex-shrink: 0;
}

#debugger-container .sb-title {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 10px;
    font-weight: 600;
}

#debugger-container .sb-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 0.7rem;
}

#debugger-container .sb-stat {
    background: rgba(0,0,0,0.15);
    padding: 8px;
    border-radius: var(--radius-sm);
    border-left: 2px solid var(--text-muted);
}

#debugger-container .sb-stat-label { color: var(--text-secondary); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.4px; }
#debugger-container .sb-stat-value { color: var(--primary-color); font-weight: 700; font-size: 0.8rem; margin-top: 2px; }

#debugger-container #sb-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

#debugger-container .sb-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
    border-bottom: 1px solid rgba(255,255,255,0.015);
}
#debugger-container .sb-row:hover { background: var(--card-bg-hover); }
#debugger-container .sb-row.active-filter {
    border-left-color: var(--primary-color);
    background: rgba(0,200,245,0.05);
}

#debugger-container .sb-row-content { flex: 1; }
#debugger-container .sb-name { font-size: 0.75rem; color: var(--text-secondary); font-weight: 500; }
#debugger-container .sb-rate { font-size: 0.65rem; color: var(--text-muted); margin-top: 2px; }

#debugger-container .sb-count {
    font-size: 0.7rem; font-weight: 700; font-variant-numeric: tabular-nums;
    background: rgba(255,255,255,0.05); border-radius: 10px;
    padding: 2px 8px; color: var(--text-muted);
    min-width: 36px; text-align: right;
}
#debugger-container .sb-count.has { background: rgba(0,200,245,0.1); color: var(--primary-color); }

/* ── Main stream area ── */
#debugger-container #main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Stream ── */
#debugger-container #stream {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}
#debugger-container #stream::-webkit-scrollbar { width: 6px; }
#debugger-container #stream::-webkit-scrollbar-track { background: transparent; }
#debugger-container #stream::-webkit-scrollbar-thumb { background: #263d5e; border-radius: 3px; }
#debugger-container #stream::-webkit-scrollbar-thumb:hover { background: #83acd7; }

#debugger-container .evt {
    display: flex;
    border-bottom: 1px solid rgba(255,255,255,0.025);
    transition: background var(--transition-fast);
}
#debugger-container .evt:hover { background: rgba(255,255,255,0.02); }
#debugger-container .evt.duplicate { opacity: 0.5; }
#debugger-container .evt.duplicate::after { content: " [DUP]"; color: var(--error-color); font-size: 0.7rem; padding-top: 8px; }

#debugger-container .evt-gutter { width: 6px; flex-shrink: 0; }

#debugger-container .evt-meta {
    flex-shrink: 0;
    width: 260px;
    padding: 10px 14px;
    border-right: 1px solid var(--border-color);
    background: var(--bg-secondary);
}
#debugger-container .evt-time { font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 4px; }
#debugger-container .evt-time .ms { color: var(--text-muted); }
#debugger-container .evt-type {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 3px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
#debugger-container .evt-seq { font-size: 0.65rem; color: var(--text-muted); margin-top: 4px; font-family: var(--font-mono); }

#debugger-container .evt-body {
    flex: 1;
    padding: 10px 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

#debugger-container .evt-summary {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-sans);
}
#debugger-container .evt-summary:hover { color: var(--text-primary); }
#debugger-container .evt-summary .chevron { font-size: 0.65rem; color: var(--text-muted); transition: transform var(--transition-fast); }
#debugger-container .evt-summary.open .chevron { transform: rotate(90deg); color: var(--primary-color); }

#debugger-container .evt-metadata {
    display: flex;
    gap: 16px;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 6px;
    flex-wrap: wrap;
}

#debugger-container .evt-metadata-item { display: flex; gap: 4px; }
#debugger-container .evt-metadata-label { color: var(--text-secondary); }
#debugger-container .evt-metadata-value { color: var(--primary-color); font-weight: 600; }

#debugger-container .evt-json {
    display: none;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-top: 8px;
    overflow-x: auto;
    font-size: 0.78rem;
    line-height: 1.5;
    white-space: pre;
    max-height: 400px;
    overflow-y: auto;
    color: var(--text-secondary);
}
#debugger-container .evt-json.show { display: block; }
#debugger-container .evt-json::-webkit-scrollbar { width: 6px; height: 6px; }
#debugger-container .evt-json::-webkit-scrollbar-thumb { background: #263d5e; border-radius: 3px; }

/* JSON syntax highlighting */
#debugger-container .j-key   { color: var(--info-color); }
#debugger-container .j-str   { color: var(--primary-color); }
#debugger-container .j-num   { color: var(--warning-color); }
#debugger-container .j-bool  { color: #fd79a8; }
#debugger-container .j-null  { color: var(--text-muted); }
#debugger-container .j-punc  { color: var(--text-secondary); }

/* Event type colours */
#debugger-container .et-packet            { background: rgba(0,200,245,0.1); color: var(--primary-color); }
#debugger-container .et-node_update       { background: rgba(176,96,255,0.12); color: var(--purple); }
#debugger-container .et-nodes             { background: rgba(176,96,255,0.12); color: var(--purple); }
#debugger-container .et-connection_status { background: rgba(255,112,48,0.12); color: var(--orange); }
#debugger-container .et-local_node_info   { background: rgba(0,240,144,0.12); color: var(--signal-excellent); }
#debugger-container .et-stats             { background: rgba(0,200,245,0.1); color: var(--primary-color); }
#debugger-container .et-sync_status       { background: rgba(176,96,255,0.12); color: var(--purple); }
#debugger-container .et-system_update     { background: rgba(255,112,48,0.12); color: var(--orange); }
#debugger-container .et-activity          { background: rgba(100,200,100,0.12); color: #64c864; }
#debugger-container .et-error             { background: rgba(255,48,80,0.15); color: var(--error-color); }
#debugger-container .et-other             { background: rgba(90,128,168,0.1); color: var(--text-secondary); }

/* Gutter colours */
#debugger-container .eg-packet            { background: var(--primary-color); }
#debugger-container .eg-node_update       { background: var(--purple); }
#debugger-container .eg-nodes             { background: var(--purple); }
#debugger-container .eg-connection_status { background: var(--orange); }
#debugger-container .eg-local_node_info   { background: var(--signal-excellent); }
#debugger-container .eg-stats             { background: var(--primary-color); }
#debugger-container .eg-sync_status       { background: var(--purple); }
#debugger-container .eg-system_update     { background: var(--orange); }
#debugger-container .eg-activity          { background: #64c864; }
#debugger-container .eg-error             { background: var(--error-color); }
#debugger-container .eg-other             { background: var(--text-muted); }

/* ── Bottom detail pane ── */
#debugger-container #detail-pane {
    height: 0;
    flex-shrink: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    overflow: hidden;
    transition: height 0.2s cubic-bezier(0.175, 0.885, 0.32, 1);
    display: flex;
    flex-direction: column;
}
#debugger-container #detail-pane.open { height: 320px; }
#debugger-container #detail-hdr {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background: rgba(0,0,0,0.2);
}
#debugger-container #detail-title { font-size: 0.85rem; color: var(--text-primary); font-weight: 600; flex: 1; }

#debugger-container #detail-close {
    background: none; border: none; color: var(--text-muted);
    font-size: 1.2rem; cursor: pointer; padding: 4px;
    border-radius: var(--radius-sm); line-height: 1;
    transition: all var(--transition-fast);
}
#debugger-container #detail-close:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }

#debugger-container #detail-body {
    flex: 1; overflow: auto; padding: 14px 16px;
    font-size: 0.8rem; line-height: 1.6;
    white-space: pre; color: var(--text-secondary);
}

/* ── Status bar ── */
#debugger-container #statusbar {
    display: flex; align-items: center; gap: 16px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    font-size: 0.72rem;
    color: var(--text-muted);
    flex-shrink: 0;
    flex-wrap: wrap;
}
#debugger-container #statusbar span { display: flex; align-items: center; gap: 5px; }
#debugger-container #statusbar .val { color: var(--text-secondary); font-weight: 700; font-family: var(--font-mono); }

#debugger-container .evt-raw { font-size: 0.75rem; color: var(--text-muted); }
#debugger-container .hl { background: rgba(255,168,0,0.2); color: var(--warning-color); border-radius: 2px; padding: 0 3px; }

/* Analytics Panel */
#debugger-container #analytics-panel {
    height: 0;
    flex-shrink: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    overflow: hidden;
    transition: height 0.2s cubic-bezier(0.175, 0.885, 0.32, 1);
    display: flex;
    flex-direction: column;
}

#debugger-container #analytics-panel.open { height: 220px; }

#debugger-container #analytics-hdr {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background: rgba(0,0,0,0.2);
    cursor: pointer;
}

#debugger-container #analytics-close {
    background: none; border: none; color: var(--text-muted);
    font-size: 1.1rem; cursor: pointer; padding: 4px;
    border-radius: var(--radius-sm); margin-left: auto;
    transition: all var(--transition-fast); line-height: 1;
}
#debugger-container #analytics-close:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }

#debugger-container #analytics-body {
    flex: 1;
    overflow: auto;
    padding: 14px 16px;
    font-size: 0.78rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 14px;
    align-content: start;
}

#debugger-container .analytics-card {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px;
}

#debugger-container .analytics-title {
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
    font-weight: 600;
}

#debugger-container .analytics-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#debugger-container .analytics-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.75rem;
}

#debugger-container .analytics-label { color: var(--text-secondary); }
#debugger-container .analytics-value { color: var(--primary-color); font-weight: 700; font-family: var(--font-mono); }

#debugger-container .stack-item {
    background: rgba(0,200,245,0.1);
    padding: 4px 8px;
    border-left: 2px solid var(--primary-color);
    margin: 3px 0;
    font-size: 0.72rem;
    color: var(--text-primary);
}

#debugger-container .stack-count {
    color: var(--warning-color);
    font-weight: 700;
    margin-left: 6px;
}

/* ═══════════════════════════════════════════════════════════════════════
   RESPONSIVE — Consolidated Mobile/Tablet Overrides
   ═══════════════════════════════════════════════════════════════════════ */

/* Large tablets and below */
@media (max-width: 1200px) {
    .header-right { font-size: 0.78rem; }
    #api-average-display { gap: 6px; }
}

/* Tablets */
@media (max-width: 992px) {
    .main-grid {
        grid-template-columns: 1fr;
    }
    .message-feed {
        height: 500px !important;
        max-height: 500px !important;
    }
    .modal-content.wide-modal { max-width: 95vw; }
    .overview-dashboard { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

    /* Sensor/Block page */
    .blocks-container { max-height: 380px; }
}

@media (max-width: 860px) {
    .dashboard { padding: 0 0.6rem 2rem; }

    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 10px 0;
    }
    .header-right { width: 100%; overflow-x: auto; }

    #nodes-grid {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: 10px;
    }

    .card-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .card-header-controls { width: 100%; }
    #node-sort-buttons { flex-wrap: wrap; }

    #modal-chart-container { height: 260px; }
    .full-height-map { height: 320px; }

    /* Chat page mobile stacking */
    .main-grid { 
        flex-direction: column; 
        height: auto !important; 
        overflow: visible !important;
    }
    .card { height: auto !important; overflow: visible !important; }
    
    #sidebar { 
        max-height: 300px; 
        margin-bottom: 10px; 
        order: 2; /* Move sidebar below chat on mobile if preferred, or keep on top */
    }
    #sidebar-list { overflow-y: auto; }
    
    #chat-card {
        height: 80vh !important; /* Fixed height for chat on mobile */
        order: 1;
    }
    #message-container { height: 100%; overflow-y: auto; }
    
    .message-item { max-width: 95%; }
    .scroll-fab { bottom: 80px; }
}

/* Small mobile */
@media (max-width: 600px) {
    html { font-size: 13px; }

    .header-left h1 { font-size: 1rem; }

    #nodes-grid {
        grid-template-columns: 1fr;
    }
    .node-core-stats {
        grid-template-columns: repeat(3, 1fr);
    }

    .info-bar {
        gap: 4px 10px;
        font-size: 0.72rem;
        padding: 6px 8px;
    }

    #node-search { width: 120px; }

    .modal { padding: 8px; }
    .modal-content { max-height: 95vh; }
    .modal-content.wide-modal { max-width: 100%; }
    .modal-body { padding: 10px 12px; }
    .modal-tabs { gap: 0; }
    .modal-tab { padding: 6px 8px; font-size: 0.72rem; }

    .overview-dashboard { grid-template-columns: 1fr 1fr; }

    #modal-chart-container { height: 200px; }
    .full-height-map { height: 260px; }

    .debug-panel { width: calc(100vw - 24px); right: 12px; bottom: 44px; }

    .message-item { padding: 6px 10px; gap: 8px; }
    .message-icon { width: 28px; height: 28px; font-size: 0.7rem; }

    /* Sensor/IoT page */
    .input-with-button {
        flex-direction: column;
    }
    .input-with-button .btn { width: 100%; justify-content: center; }

    .schedule-options { flex-direction: column; gap: 8px; }

    #schedule-input-weekly {
        flex-direction: column;
        align-items: stretch;
    }
    #schedule-input-weekly .form-control { max-width: 100%; }

    .block-header { flex-direction: column; align-items: flex-start; gap: 4px; }

    .button-row { flex-direction: column; }
    .button-row .btn { width: 100%; justify-content: center; }

    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; justify-content: center; }

    .blocks-container { max-height: 320px; }

    /* Task page */
    .task-item {
        padding: 10px;
    }
    .task-actions {
        justify-content: stretch;
    }
    .task-actions .btn {
        flex: 1;
        justify-content: center;
    }
    #schedule-input-weekly {
        flex-direction: column;
        align-items: stretch;
    }
    #schedule-input-weekly label {
        margin-left: 0 !important;
        margin-top: 8px;
    }

    /* Auto-reply page */
    .rule-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
    .rule-status {
        align-self: flex-start;
    }

    /* Map page */
    .map-controls-container {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .map-action-buttons {
        margin-left: 0;
        justify-content: space-between;
    }
    .map-action-buttons .btn { flex: 1; justify-content: center; }
    
    .legend {
        width: 200px;
        max-height: 40vh;
    }
    .leaflet-bottom.leaflet-right { margin-bottom: 20px; }
}

@media (max-width: 400px) {
    .node-core-stats { grid-template-columns: 1fr 1fr; }
    .overview-dashboard { grid-template-columns: 1fr; }
}

/* Responsive form grid */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    .placeholder-table {
        font-size: 0.75rem;
    }
    .placeholder-table td, .placeholder-table th {
        padding: 6px 4px;
    }
    
    /* Settings page */
    .settings-grid {
        grid-template-columns: 1fr;
    }
    .sticky-footer {
        flex-direction: column;
        align-items: stretch;
    }
    .restart-banner {
        text-align: center;
        justify-content: center;
        order: -1; /* Banner on top of buttons */
    }
    .btn-save { justify-content: center; }
    
    /* DMs page */
    .msg-bubble { max-width: 85%; }
    #message-container { padding: 12px; }
    .input-wrapper { border-radius: 20px; }
}