/* ═══════════════════════════════════════════════════════════════════════════════
   MunHub 5.0 — Muon Detector Hub
   Cosmic / Lunar themed scientific dashboard — fully responsive
   Deep space backgrounds, moonlight silver text, star gold accents
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
    --bg-primary:   #0c1220;
    --bg-secondary: #141d2e;
    --bg-tertiary:  #1c2740;
    --border-color: #283350;
    --text-primary: #e0e6f0;
    --text-secondary: #7a8599;
    --accent-primary: #f0c040;
    --accent-secondary: #40c4aa;
    --success: #40c4aa;
    --warning: #d4a020;
    --danger:  #e05050;
    --info:    #5090e0;
    --topbar-h: 54px;
    --stats-h: 36px;
}

[data-theme="light"] {
    --bg-primary:   #f0f2f6;
    --bg-secondary: #ffffff;
    --bg-tertiary:  #e4e8f0;
    --border-color: #c8d0dc;
    --text-primary: #1a2030;
    --text-secondary: #6a7488;
    --accent-primary: #c89820;
    --accent-secondary: #30a088;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
    font-size: 16px;
    background: var(--bg-primary);
    color: var(--text-primary);
}

body { display: flex; flex-direction: column; }

@media (min-width: 769px) { html, body { overflow: hidden; } }
@media (max-width: 768px) { html, body { height: auto; min-height: 100vh; overflow-y: auto; overflow-x: hidden; } }

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ═══════════════════════════════════════════════════════════════════════════════
   TOP BAR — 54px, cosmic dark with gold accent
   ═══════════════════════════════════════════════════════════════════════════════ */
.topbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 5px 14px;
    gap: 10px;
    min-height: var(--topbar-h);
    flex-shrink: 0;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.topbar-center {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    justify-content: center;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* Brand — MunHub with crescent moon icon */
.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.brand-logo {
    width: 32px; height: 32px;
    min-width: 32px; min-height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1c2740, #0c1220);
    border: 1.5px solid var(--accent-primary);
    overflow: hidden;
}
.brand-logo img { width: 100%; height: 100%; }
.brand-name {
    font-size: 1.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}
.brand-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
@media (max-width: 1250px) { .brand-sub { display: none; } }

/* About info button (next to brand) */
.about-btn {
    width: 24px; height: 24px;
    min-width: 24px;
    display: flex; align-items: center; justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
    font-family: serif;
}
.about-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(240,192,64,0.08);
}

/* Status pill */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    font-size: 0.82rem;
    white-space: nowrap;
    flex-shrink: 0;
}
.status-dot {
    width: 7px; height: 7px;
    min-width: 7px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse 2s infinite;
}
.status-indicator.connected .status-dot { background: var(--success); animation: none; }
.status-indicator.error     .status-dot { background: var(--danger); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* Time buttons — Desktop inline */
.time-buttons {
    display: flex;
    gap: 2px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    flex-shrink: 1;
    min-width: 0;
}
.time-buttons::-webkit-scrollbar { display: none; }
.time-btn {
    padding: 3px 7px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.time-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
.time-btn.rt-disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}
.time-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #0c1220;
    font-weight: 600;
}

/* Mobile time dropdown */
.time-range-select {
    display: none;
    padding: 5px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}
.time-range-select:focus { outline: none; border-color: var(--accent-primary); }

/* Mode switch */
.mode-switch {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.mode-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: color 0.2s;
    white-space: nowrap;
}
.mode-label.active { color: var(--accent-primary); }
.switch { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; inset: 0;
    background: var(--accent-secondary);
    border-radius: 18px;
    transition: 0.25s;
}
.slider::before {
    content: '';
    position: absolute;
    height: 14px; width: 14px;
    left: 3px; bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.25s;
}
.switch input:checked + .slider { background: var(--accent-primary); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* Action buttons */
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.action-btn:hover {
    background: var(--bg-primary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}
.action-btn .action-icon {
    display: inline-flex;
    align-items: center;
}
.action-btn .action-icon svg {
    width: 16px; height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}
.action-btn-accent {
    background: linear-gradient(135deg, var(--accent-primary), #d4a020);
    border-color: transparent;
    color: #0c1220;
    font-weight: 600;
}
.action-btn-accent:hover {
    opacity: 0.9;
    color: #0c1220;
    border-color: transparent;
}

/* Icon-only button (theme toggle) */
.icon-btn {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}
.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

/* ── Mobile topbar ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .topbar {
        padding: 5px 8px;
        gap: 4px;
        min-height: auto;
        flex-wrap: wrap;
        max-width: 100vw;
        overflow-x: hidden;
    }
    .topbar-left { order: 1; flex: 0 0 auto; }
    .topbar-right { order: 2; margin-left: auto; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
    .topbar-center { order: 3; width: 100%; justify-content: flex-start; gap: 6px; }
    .action-text { display: none; }
    .action-btn { padding: 5px 8px; font-size: 0.85rem; gap: 0; }
    .time-buttons { display: none; }
    .time-range-select { display: block; }
    .mode-label { font-size: 0.7rem; }
    .brand-sub { display: none; }
}
@media (max-width: 480px) {
    .status-indicator .status-text { display: none; }
    .brand-name { font-size: 1rem; }
    .brand-logo { width: 26px; height: 26px; min-width: 26px; }
    .mode-switch { display: none; }
    .action-btn { padding: 4px 6px; }
    .about-btn { width: 22px; height: 22px; min-width: 22px; font-size: 0.7rem; }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   APP BODY
   ═══════════════════════════════════════════════════════════════════════════════ */
.app-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
@media (min-width: 769px) { .app-body { overflow: hidden; } }

/* ── Profile Panel (overlay) ───────────────────────────────────────────── */
.profile-overlay-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(6,10,20,0.5);
    z-index: 300;
}
.profile-overlay-backdrop.open { display: block; }

.profile-panel {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 320px;
    max-width: 85vw;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 310;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
}
.profile-panel.open { transform: translateX(0); }

.profile-panel-head {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.profile-panel-head h2 { font-size: 1.05rem; font-weight: 600; }
.profile-panel-close {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    color: var(--text-secondary);
    font-size: 1.2rem;
    width: 30px; height: 30px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.profile-panel-close:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.profile-panel-search {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-color);
}
.profile-panel-search input {
    width: 100%; padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.92rem;
}
.profile-panel-search input:focus { outline: none; border-color: var(--accent-primary); }
.profile-panel-search input::placeholder { color: var(--text-secondary); }

.profile-tree { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px 0; }

.tree-section { border-bottom: 1px solid var(--border-color); }
.tree-section:last-child { border-bottom: none; }
.tree-section-head {
    display: flex; align-items: center; gap: 6px;
    padding: 10px 14px; cursor: pointer; user-select: none;
    transition: background 0.1s;
}
.tree-section-head:hover { background: var(--bg-tertiary); }
.tree-arrow { font-size: 0.72rem; color: var(--text-secondary); transition: transform 0.2s; width: 14px; text-align: center; }
.tree-section.open .tree-arrow { transform: rotate(90deg); }
.tree-icon { font-size: 0.88rem; flex-shrink: 0; }
.tree-section-label { font-size: 0.92rem; font-weight: 600; color: var(--text-primary); flex: 1; }
.tree-count { font-size: 0.78rem; background: var(--bg-tertiary); color: var(--text-secondary); padding: 2px 7px; border-radius: 10px; min-width: 22px; text-align: center; }

.tree-section-body { display: none; padding: 0 0 6px 0; }
.tree-section.open .tree-section-body { display: block; }

.tree-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px 8px 36px;
    cursor: pointer; font-size: 0.92rem; color: var(--text-secondary);
    transition: all 0.1s; border-left: 3px solid transparent;
}
.tree-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.tree-item.active { background: rgba(240,192,64,0.08); color: var(--accent-primary); border-left-color: var(--accent-primary); font-weight: 600; }
.tree-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item-info { font-size: 0.72rem; color: var(--text-secondary); opacity: 0.7; }

.profile-panel-actions { padding: 10px 14px; border-top: 1px solid var(--border-color); display: flex; flex-direction: column; gap: 6px; }
.panel-btn { width: 100%; padding: 9px 14px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 6px; color: var(--text-primary); font-size: 0.92rem; cursor: pointer; transition: all 0.15s; text-align: center; }
.panel-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
.panel-btn-primary { background: linear-gradient(135deg, var(--accent-primary), #d4a020); border-color: transparent; color: #0c1220; font-weight: 600; }
.panel-btn-primary:hover { opacity: 0.9; color: #0c1220; }

/* ── Content ───────────────────────────────────────────────────────────── */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; min-height: 0;
}
@media (min-width: 769px) { .content { overflow: hidden; } }

/* Stats bar */
.stats-bar {
    height: var(--stats-h);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 0 12px;
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.stats-bar::-webkit-scrollbar { display: none; }
.stat-item { display: flex; align-items: center; gap: 4px; white-space: nowrap; flex-shrink: 0; }
.stat-label { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 0.9rem; font-weight: 700; color: var(--accent-primary); font-family: 'JetBrains Mono', 'Cascadia Code', monospace; }

.stat-item.stat-type-btn { margin-left: auto; }
.global-type-btn {
    padding: 2px 7px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.global-type-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }

@media (max-width: 768px) {
    .stats-bar { height: auto; min-height: 32px; gap: 6px; padding: 4px 8px; flex-wrap: wrap; justify-content: flex-start; }
    .stat-label { font-size: 0.66rem; }
    .stat-value { font-size: 0.8rem; }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   CHARTS GRID — 2x2 desktop, 1-column scrollable mobile
   ═══════════════════════════════════════════════════════════════════════════════ */
.charts-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 3px;
    padding: 3px;
    min-height: 0;
}
@media (min-width: 769px) { .charts-grid { overflow: hidden; } }

@media (min-width: 769px) and (max-width: 1024px) {
    .charts-grid { gap: 2px; padding: 2px; }
}

@media (max-width: 768px) {
    .charts-grid {
        grid-template-columns: 1fr;
        grid-template-rows: none;
        overflow-y: auto;
        gap: 3px;
        padding: 3px;
    }
}

.chart-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
@media (max-width: 768px) {
    .chart-panel { min-height: 250px; height: 290px; flex-shrink: 0; }
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 8px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    flex-shrink: 0;
    gap: 4px;
    min-height: 30px;
}
.chart-header h3 {
    font-size: 0.88rem; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    flex-shrink: 1; min-width: 0;
}
.chart-actions { display: flex; gap: 3px; align-items: center; flex-shrink: 0; }

.chart-source-select {
    padding: 2px 5px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
}
.chart-source-select:hover { border-color: var(--accent-primary); }
.chart-source-select:focus { outline: none; border-color: var(--accent-primary); }

/* Chart action buttons */
.chart-btn {
    padding: 2px 5px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s;
    white-space: nowrap;
    line-height: 1;
}
.chart-btn:hover {
    background: var(--bg-primary);
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

/* Chart info (ℹ) button */
.chart-info-btn {
    padding: 1px 5px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 700;
    font-family: serif;
    transition: all 0.15s;
    width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.chart-info-btn:hover {
    border-color: var(--info);
    color: var(--info);
    background: rgba(80,144,224,0.1);
}

.chart-container {
    flex: 1;
    position: relative;
    min-height: 0;
    padding: 2px;
}
.chart-container canvas { width: 100% !important; height: 100% !important; }

/* Terminal-in-chart */
.chart-terminal {
    flex: 1;
    background: #060a14;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Courier New', monospace;
    font-size: 0.85rem; color: #5090e0;
    padding: 8px;
    overflow-y: auto; overflow-x: hidden;
    line-height: 1.5;
}
.chart-terminal .terminal-line { padding: 1px 0; border-bottom: 1px solid rgba(224,230,240,0.03); }
.chart-terminal .terminal-line:nth-child(even) { background: rgba(224,230,240,0.015); }
.chart-terminal .term-system { color: var(--warning); }
.chart-terminal .term-error  { color: var(--danger); }
.chart-terminal .term-good   { color: var(--success); }

/* ═══════════════════════════════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════════════════════════════ */
.modal, .modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(6,10,20,0.7); z-index: 1000;
    align-items: center; justify-content: center;
}
.modal.active, .modal-overlay { display: flex; }

.modal-content {
    background: var(--bg-secondary); border-radius: 10px; border: 1px solid var(--border-color);
    max-width: 520px; width: 92%; max-height: 85vh; overflow-y: auto;
    box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}
.modal-content.modal-sm { max-width: 440px; }
.modal-content.modal-lg { max-width: 740px; }
.modal-content.modal-xl { max-width: 900px; }

.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 20px; border-bottom: 1px solid var(--border-color);
    position: sticky; top: 0; background: var(--bg-secondary); z-index: 1;
}
.modal-header h2 { font-size: 1.1rem; }
.modal-close {
    background: none; border: none; color: var(--text-secondary);
    font-size: 1.3rem; cursor: pointer; width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 5px; transition: all 0.15s;
}
.modal-close:hover { background: var(--danger); color: #fff; }
.modal-body { padding: 20px; }

.settings-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 640px) { .settings-grid { grid-template-columns: 1fr 1fr; } }

.settings-section { background: var(--bg-tertiary); border-radius: 8px; padding: 14px; border: 1px solid var(--border-color); }
.settings-section h3 { font-size: 0.92rem; color: var(--accent-primary); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.5px; }

.setting-group { margin-bottom: 12px; }
.setting-group:last-child { margin-bottom: 0; }
.setting-group label { display: block; font-size: 0.88rem; color: var(--text-secondary); margin-bottom: 4px; }
.setting-group input[type="text"],
.setting-group input[type="email"],
.setting-group input[type="password"],
.setting-group input[type="datetime-local"],
.setting-group select {
    width: 100%; padding: 8px 10px;
    background: var(--bg-secondary); border: 1px solid var(--border-color);
    border-radius: 6px; color: var(--text-primary); font-size: 0.92rem;
}
.setting-group input:focus, .setting-group select:focus { outline: none; border-color: var(--accent-primary); }
.setting-group input[type="datetime-local"]::-webkit-calendar-picker-indicator { filter: invert(0.8); cursor: pointer; }

.warning-box { background: rgba(224,80,80,0.1); border: 1px solid var(--danger); border-radius: 6px; padding: 10px 14px; font-size: 0.88rem; color: var(--danger); margin-bottom: 12px; }
.help-text { font-size: 0.88rem; color: var(--text-secondary); margin: 4px 0 10px; }

.btn { padding: 7px 14px; border-radius: 6px; font-size: 0.88rem; cursor: pointer; border: 1px solid var(--border-color); background: var(--bg-secondary); color: var(--text-primary); transition: all 0.15s; }
.btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
.btn-primary { background: var(--accent-primary); border-color: var(--accent-primary); color: #0c1220; font-weight: 600; }
.btn-primary:hover { background: #d4a020; border-color: #d4a020; }
.btn-teal { background: var(--accent-secondary); border-color: var(--accent-secondary); color: #0c1220; font-weight: 600; }
.btn-teal:hover { background: #30a088; border-color: #30a088; }
.btn-purple { background: #7060c0; border-color: #7060c0; color: #fff; }
.btn-green  { background: var(--success); border-color: var(--success); color: #0c1220; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.connection-result { font-size: 0.88rem; padding: 6px 0; min-height: 18px; }
.connection-result.success { color: var(--success); }
.connection-result.error   { color: var(--danger); }

.storage-stats { background: var(--bg-secondary); padding: 10px 12px; border-radius: 6px; font-size: 0.88rem; }
.storage-stats p { margin-bottom: 3px; }
.storage-stats span { color: var(--accent-primary); font-weight: 600; }

/* ═══════════════════════════════════════════════════════════════════════════════
   CONNECT DETECTOR SETUP MODAL
   ═══════════════════════════════════════════════════════════════════════════════ */
.setup-steps { display: flex; flex-direction: column; gap: 12px; }
.setup-step { background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 8px; padding: 14px 16px; }
.setup-step h4 { font-size: 0.92rem; color: var(--accent-primary); margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.setup-step h4 .step-num { width: 22px; height: 22px; background: var(--accent-primary); color: #0c1220; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 0.78rem; font-weight: 700; }
.setup-step p { font-size: 0.88rem; color: var(--text-secondary); margin-bottom: 6px; line-height: 1.5; }
.setup-step select, .setup-step input[type="text"] { width: 100%; padding: 8px 10px; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 6px; color: var(--text-primary); font-size: 0.92rem; margin-bottom: 5px; }
.setup-step select:focus, .setup-step input:focus { outline: none; border-color: var(--accent-primary); }
.setup-option { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 0.88rem; }
.setup-option input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent-primary); }
.setup-option label { cursor: pointer; color: var(--text-primary); }
.setup-option .option-note { font-size: 0.78rem; color: var(--text-secondary); margin-left: 4px; }
.setup-actions { display: flex; gap: 10px; margin-top: 6px; }
.setup-actions .btn { flex: 1; text-align: center; padding: 9px; font-size: 0.92rem; }

/* ═══════════════════════════════════════════════════════════════════════════════
   AUTH
   ═══════════════════════════════════════════════════════════════════════════════ */
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 8px; }
.auth-links a { color: var(--accent-primary); font-size: 0.88rem; text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }
.auth-error { background: rgba(224,80,80,0.1); border: 1px solid var(--danger); border-radius: 6px; padding: 10px; color: var(--danger); font-size: 0.92rem; text-align: center; margin-top: 10px; }

/* ═══════════════════════════════════════════════════════════════════════════════
   USER MENU
   ═══════════════════════════════════════════════════════════════════════════════ */
.user-menu { display: flex; align-items: center; position: relative; }
.user-btn { display: flex; align-items: center; gap: 5px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 20px; padding: 3px 9px 3px 3px; cursor: pointer; color: var(--text-primary); transition: all 0.15s; }
.user-btn:hover { border-color: var(--accent-primary); }
.user-avatar { width: 26px; height: 26px; background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary)); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: bold; color: #0c1220; }
.user-name { font-size: 0.85rem; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-dropdown { position: absolute; top: 100%; right: 0; margin-top: 6px; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 8px; min-width: 200px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); opacity: 0; visibility: hidden; transform: translateY(-8px); transition: all 0.15s; z-index: 1001; }
.user-dropdown.show { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-header { padding: 10px 14px; border-bottom: 1px solid var(--border-color); }
.dropdown-header span { display: block; }
.dropdown-header span:first-child { font-size: 0.92rem; color: var(--text-primary); }
.user-role { font-size: 0.78rem; padding: 2px 7px; border-radius: 10px; margin-top: 3px; display: inline-block; background: var(--bg-tertiary); color: var(--text-secondary); }
.user-role.role-admin { background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary)); color: #0c1220; }
.dropdown-divider { height: 1px; background: var(--border-color); margin: 4px 0; }
.dropdown-item { display: block; width: 100%; padding: 9px 14px; background: none; border: none; color: var(--text-primary); font-size: 0.92rem; cursor: pointer; text-align: left; transition: background 0.1s; }
.dropdown-item:hover { background: var(--bg-tertiary); }
.dropdown-danger:hover { background: rgba(224,80,80,0.12); color: var(--danger); }

/* ═══════════════════════════════════════════════════════════════════════════════
   ADMIN PANEL
   ═══════════════════════════════════════════════════════════════════════════════ */
.admin-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.admin-tab { padding: 7px 14px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 6px; color: var(--text-primary); cursor: pointer; font-size: 0.92rem; transition: all 0.15s; }
.admin-tab:hover { border-color: var(--accent-primary); }
.admin-tab.active { background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary)); border-color: transparent; color: #0c1220; }
.admin-panel { background: var(--bg-tertiary); border-radius: 8px; padding: 12px; max-height: 400px; overflow-y: auto; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border-color); font-size: 0.92rem; }
.admin-table th { color: var(--text-secondary); font-weight: 500; }
.admin-table tr:last-child td { border-bottom: none; }
.role-select, .visibility-select { background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 4px; padding: 3px 7px; color: var(--text-primary); font-size: 0.88rem; cursor: pointer; }
.role-select:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-small { padding: 3px 8px; font-size: 0.82rem; border-radius: 4px; border: none; cursor: pointer; }
.text-muted { color: var(--text-secondary); font-size: 0.82rem; }

/* ═══════════════════════════════════════════════════════════════════════════════
   ABOUT MODAL — Project credits
   ═══════════════════════════════════════════════════════════════════════════════ */
.about-content { text-align: center; }
.about-logo { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 50%; border: 2px solid var(--accent-primary); overflow: hidden; }
.about-logo img { width: 100%; height: 100%; }
.about-title { font-size: 1.5rem; font-weight: 700; background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; margin-bottom: 4px; }
.about-subtitle { color: var(--text-secondary); font-size: 0.92rem; margin-bottom: 16px; }
.about-version { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 20px; }
.about-section { text-align: left; margin-bottom: 16px; }
.about-section h4 { font-size: 0.88rem; color: var(--accent-primary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; padding-bottom: 4px; border-bottom: 1px solid var(--border-color); }
.about-credits { list-style: none; padding: 0; }
.about-credits li { padding: 6px 0; font-size: 0.88rem; color: var(--text-primary); border-bottom: 1px solid rgba(40,51,80,0.5); display: flex; justify-content: space-between; align-items: center; }
.about-credits li:last-child { border-bottom: none; }
.about-credits .credit-role { font-size: 0.78rem; color: var(--text-secondary); }
.about-links { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.about-links a { display: inline-flex; align-items: center; gap: 4px; color: var(--accent-primary); font-size: 0.88rem; text-decoration: none; padding: 6px 12px; border: 1px solid var(--border-color); border-radius: 6px; transition: all 0.15s; }
.about-links a:hover { border-color: var(--accent-primary); background: rgba(240,192,64,0.08); }
.about-desc { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; margin-bottom: 16px; }

/* ═══════════════════════════════════════════════════════════════════════════════
   CHART INFO TOOLTIP
   ═══════════════════════════════════════════════════════════════════════════════ */
.chart-info-popup {
    position: absolute;
    top: 40px; left: 8px; right: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 14px;
    z-index: 50;
    box-shadow: 0 8px 20px rgba(0,0,0,0.4);
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
    max-width: 340px;
    animation: fadeIn 0.15s ease;
}
.chart-info-popup h4 { color: var(--accent-primary); margin-bottom: 6px; font-size: 0.9rem; }
.chart-info-popup .close-info {
    position: absolute; top: 6px; right: 8px;
    background: none; border: none; color: var(--text-secondary);
    cursor: pointer; font-size: 1rem;
}
.chart-info-popup .close-info:hover { color: var(--danger); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

/* ═══════════════════════════════════════════════════════════════════════════════
   COLOR MANAGEMENT PANEL
   ═══════════════════════════════════════════════════════════════════════════════ */
.color-picker-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 0.85rem;
}
.color-picker-row label {
    flex: 1;
    color: var(--text-primary);
    margin-bottom: 0;
}
.color-picker-row input[type="color"] {
    width: 28px; height: 24px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: none;
    cursor: pointer;
    padding: 0;
}
.color-picker-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 1px; }
.color-picker-row input[type="color"]::-webkit-color-swatch { border: none; border-radius: 2px; }
.color-random-btn {
    padding: 3px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.15s;
}
.color-random-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }

/* ═══════════════════════════════════════════════════════════════════════════════
   CHART CUSTOMIZATION (dot size, bar width, tension)
   ═══════════════════════════════════════════════════════════════════════════════ */
.chart-customize-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 0.85rem;
}
.chart-customize-row label {
    min-width: 80px;
    color: var(--text-secondary);
    margin-bottom: 0;
    font-size: 0.82rem;
}
.chart-customize-row input[type="range"] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    background: var(--border-color);
    border-radius: 2px;
    outline: none;
}
.chart-customize-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px; height: 14px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
}
.chart-customize-row .range-value {
    min-width: 28px;
    text-align: right;
    color: var(--accent-primary);
    font-weight: 600;
    font-size: 0.82rem;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════════════════════════════════════════ */
.toast-container { position: fixed; bottom: 14px; right: 14px; z-index: 2000; }
.toast { padding: 10px 16px; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 8px; margin-top: 6px; font-size: 0.92rem; animation: slideIn 0.25s ease; max-width: 360px; }
.toast.success { border-left: 4px solid var(--success); }
.toast.error   { border-left: 4px solid var(--danger); }
.toast.info    { border-left: 4px solid var(--info); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ═══════════════════════════════════════════════════════════════════════════════
   TABLET (769-1024px)
   ═══════════════════════════════════════════════════════════════════════════════ */
@media (min-width: 769px) and (max-width: 1024px) {
    .topbar { padding: 4px 10px; gap: 6px; }
    .time-btn { padding: 2px 5px; font-size: 0.75rem; }
    .action-btn { padding: 4px 8px; font-size: 0.82rem; }
    .stat-label { font-size: 0.7rem; }
    .stat-value { font-size: 0.85rem; }
    .chart-header h3 { font-size: 0.82rem; }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   DOWNLOAD FORMAT MODAL
   ═══════════════════════════════════════════════════════════════════════════════ */
.download-options { display: flex; flex-direction: column; gap: 8px; }
.download-option {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}
.download-option:hover { border-color: var(--accent-primary); }
.download-option-icon { font-size: 1.2rem; width: 28px; text-align: center; }
.download-option-info { flex: 1; }
.download-option-title { font-weight: 600; font-size: 0.92rem; color: var(--text-primary); }
.download-option-desc { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }

/* ═══════════════════════════════════════════════════════════════════════════════
   DB MIGRATION ENHANCED
   ═══════════════════════════════════════════════════════════════════════════════ */
.migrate-option-group { margin-bottom: 14px; }
.migrate-option-group h4 { font-size: 0.88rem; color: var(--accent-primary); margin-bottom: 6px; }
.migrate-checkbox-list { display: flex; flex-direction: column; gap: 4px; max-height: 200px; overflow-y: auto; padding: 4px; }
.migrate-checkbox-list label {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 8px; border-radius: 4px; font-size: 0.85rem;
    cursor: pointer; transition: background 0.1s;
}
.migrate-checkbox-list label:hover { background: var(--bg-tertiary); }
.migrate-checkbox-list input[type="checkbox"] { accent-color: var(--accent-primary); width: 16px; height: 16px; }
.migrate-select-all { font-size: 0.78rem; color: var(--accent-primary); cursor: pointer; border: none; background: none; margin-bottom: 4px; }
.migrate-select-all:hover { text-decoration: underline; }
