@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* ���� �� ��������� - Premium Dark (Midnight/Cyan) */
    --bg-color: #0b1121;
    --bg-gradient: radial-gradient(circle at top left, #172445, #0b1121 40%, #04060d);
    --surface: rgba(30, 41, 59, 0.4);
    --surface-hover: rgba(30, 41, 59, 0.6);
    --border: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(255, 255, 255, 0.15);
    --bg-card: #1e293b;
    
    --text: #f8fafc;
    --text-muted: #94a3b8;
    
    --primary: #3b82f6;
    --primary-gradient: linear-gradient(135deg, #3b82f6, #6366f1);
    --primary-glow: rgba(99, 102, 241, 0.4);
    
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.4);
    
    --danger: #ef4444;
    --warn: #f59e0b;
    
    --sidebar-width: 260px;
    --radius: 16px;
}

/* ������� ���� (���� �������� �������������) */
body.light {
    --bg-color: #f1f5f9;
    --bg-gradient: radial-gradient(circle at top left, #ffffff, #f1f5f9 60%);
    --surface: rgba(255, 255, 255, 0.7);
    --surface-hover: rgba(255, 255, 255, 1);
    --border: rgba(0, 0, 0, 0.05);
    --border-highlight: rgba(0, 0, 0, 0.1);
    --text: #0f172a;
    --text-muted: #64748b;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', system-ui, sans-serif; }

body { 
    background: var(--bg-color); 
    background-image: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text); 
    display: flex; 
    min-height: 100vh; 
    overflow-x: hidden; 
    transition: all 0.3s ease;
    -webkit-font-smoothing: antialiased;
}

/* === ��������� ��������� === */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }

/* === SIDEBAR (������� ����) === */
.sidebar {
    width: var(--sidebar-width); 
    background: var(--surface); 
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 25px 0; 
    position: fixed; height: 100vh; z-index: 100;
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0,0,0,0.1);
}
.logo { 
    padding: 0 25px 25px; font-size: 1.4rem; font-weight: 700; 
    display: flex; justify-content: space-between; align-items: center; 
    border-bottom: 1px solid var(--border); margin-bottom: 15px;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
body.light .logo { background: linear-gradient(to right, #0f172a, #3b82f6); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.nav-btn { 
    background: transparent; border: none; color: var(--text-muted); 
    padding: 14px 25px; text-align: left; font-size: 0.95rem; font-weight: 500;
    cursor: pointer; transition: all 0.3s; display: block; width: 100%; 
    position: relative; overflow: hidden;
}
.nav-btn:hover { color: var(--text); background: var(--surface-hover); }
.nav-btn.active { 
    color: #fff; background: var(--primary-glow);
    border-right: 4px solid var(--primary);
    text-shadow: 0 0 10px rgba(255,255,255,0.3);
}
.spacer { flex-grow: 1; }

/* === MAIN CONTENT === */
.main { 
    flex-grow: 1; margin-left: var(--sidebar-width); 
    padding: 30px; max-width: 1600px; width: 100%; 
    transition: margin 0.3s; 
}
.tab-content { display: none; animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards; opacity: 0; transform: translateY(20px); }
.tab-content.active { display: block; }
@keyframes slideUp { to { opacity: 1; transform: translateY(0); } }

/* === MOBILE HEADER === */
.mobile-header { display: none; justify-content: space-between; align-items: center; margin-bottom: 20px; background: var(--surface); padding: 15px 20px; border-radius: var(--radius); border: 1px solid var(--border); backdrop-filter: blur(12px); }
.hamburger { background: none; border: none; font-size: 1.5rem; color: var(--text); cursor: pointer; }
@media (max-width: 850px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; padding: 15px; }
    .mobile-header { display: flex; }
}

/* === GLASS CARDS === */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 24px; }
.card { 
    background: var(--surface); 
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 24px; 
    border-radius: var(--radius); 
    border: 1px solid var(--border); 
    box-shadow: 0 10px 30px -10px rgba(0,0,0,0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}
.card:hover { 
    transform: translateY(-2px); 
    box-shadow: 0 20px 40px -10px rgba(0,0,0,0.4);
    border-color: var(--border-highlight);
}
h2, h3, h4 { margin-bottom: 16px; color: var(--text); font-weight: 600; letter-spacing: -0.02em; }

/* === INPUTS & BUTTONS === */
.input, .select, textarea { 
    width: 100%; padding: 12px 16px; 
    border: 1px solid var(--border); border-radius: 10px; 
    background: rgba(0,0,0,0.2); color: var(--text); 
    font-size: 0.95rem; outline: none; transition: all 0.3s; 
}
body.light .input, body.light .select, body.light textarea { background: rgba(255,255,255,0.5); }
.input:focus, .select:focus, textarea:focus { 
    border-color: var(--primary); 
    box-shadow: 0 0 0 4px var(--primary-glow); 
    background: rgba(0,0,0,0.4);
}

.btn { 
    padding: 10px 20px; border: none; border-radius: 10px; font-size: 0.95rem; font-weight: 500;
    cursor: pointer; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); 
    background: var(--surface); color: var(--text); border: 1px solid var(--border); 
}
.btn:hover:not(:disabled) { background: var(--border-highlight); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary { 
    background: var(--primary-gradient); color: #fff; border: none; 
    box-shadow: 0 4px 15px var(--primary-glow);
}
.btn-primary:hover:not(:disabled) { 
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6); 
    filter: brightness(1.1);
}
.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 0 12px var(--primary-glow);
}
.btn-danger { background: linear-gradient(135deg, #ef4444, #b91c1c); color: #fff; border: none; box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3); }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(1); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }

/* === POWER BUTTON (������) === */
.power-btn { 
    width: 90px; height: 90px; border-radius: 50%; font-size: 2.5rem; border: none; 
    background: var(--surface); color: var(--text-muted); cursor: pointer; 
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.2), 0 4px 10px rgba(0,0,0,0.1); 
    margin-bottom: 20px;
    border: 1px solid var(--border);
}
.power-btn:hover { transform: scale(1.05); }
.power-btn.on { 
    background: var(--primary-gradient); color: #fff; 
    box-shadow: 0 0 30px var(--primary-glow), inset 0 2px 5px rgba(255,255,255,0.3); 
    border: none;
    animation: pulseGlow 2s infinite alternate;
}
@keyframes pulseGlow {
    from { box-shadow: 0 0 20px var(--primary-glow), inset 0 2px 5px rgba(255,255,255,0.3); }
    to { box-shadow: 0 0 40px rgba(99, 102, 241, 0.8), inset 0 2px 5px rgba(255,255,255,0.3); }
}

/* === ����������� ������� === */
.table-responsive { width: 100%; overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); background: rgba(0,0,0,0.1); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; white-space: nowrap; }
th, td { padding: 16px 20px; text-align: left; border-bottom: 1px solid var(--border); transition: background 0.2s; }
th { 
    background: rgba(0,0,0,0.2); font-weight: 600; color: var(--text-muted); 
    text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.08em; 
}
body.light th { background: rgba(0,0,0,0.03); }
tbody tr:hover td { background: var(--surface-hover); }
tr:last-child td { border-bottom: none; }
tr.offline td { opacity: 0.5; filter: grayscale(0.5); }

/* === APPLE-LIKE SWITCH === */
.switch { position: relative; display: inline-block; width: 48px; height: 26px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(255,255,255,0.1); transition: .3s; border-radius: 26px; border: 1px solid var(--border); }
body.light .slider { background-color: rgba(0,0,0,0.1); }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 2px; bottom: 2px; background-color: #fff; transition: .3s cubic-bezier(0.2, 0.8, 0.2, 1); border-radius: 50%; box-shadow: 0 2px 5px rgba(0,0,0,0.3); }
input:checked + .slider { background: var(--success); border-color: var(--success); }
input:checked + .slider:before { transform: translateX(22px); }

/* === BADGES (�������� ������) === */
.badge { padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; display: inline-block; letter-spacing: 0.02em; }
.badge-new { background: var(--primary-glow); color: #93c5fd; border: 1px solid rgba(59, 130, 246, 0.3); }
.badge-online { background: var(--success-glow); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-offline { background: rgba(239, 68, 68, 0.2); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); }
.badge-source { background: rgba(255,255,255,0.05); color: var(--text-muted); border: 1px solid var(--border); }
body.light .badge-online { background: rgba(16, 185, 129, 0.15); color: var(--success); }
body.light .badge-offline { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

/* === PROGRESS & PING === */
.progress-bar { height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; overflow: hidden; margin-top: 8px; }
body.light .progress-bar { background: rgba(0,0,0,0.1); }
.progress-fill { height: 100%; background: var(--primary-gradient); transition: width 0.5s ease-out; border-radius: 3px; }
.ping-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; box-shadow: 0 0 8px currentColor; }
.ping-good { color: #34d399; background: #34d399; }
.ping-warn { color: #fbbf24; background: #fbbf24; }
.ping-bad { color: #f87171; background: #f87171; }

/* === MODALS === */
.modal-overlay { 
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; 
    background: rgba(0,0,0,0.7); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    display: none; align-items: center; justify-content: center; z-index: 1000; 
    opacity: 0; animation: modalFadeIn 0.3s forwards; 
}
.modal-content { 
    background: var(--bg-color); 
    background-image: var(--bg-gradient);
    padding: 30px; border-radius: 24px; width: 90%; max-width: 450px; 
    border: 1px solid var(--border-highlight);
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); 
    transform: scale(0.95); animation: modalPop 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; 
    max-height: 90vh; display: flex; flex-direction: column; 
}
@keyframes modalFadeIn { to { opacity: 1; } }
@keyframes modalPop { to { transform: scale(1); } }

.fo-filter-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}
.fo-filter-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text);
}
.fo-filter-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 10px var(--primary-glow);
}

/* === TOAST === */
#toast { 
    position: fixed; bottom: -60px; left: 50%; transform: translateX(-50%); 
    background: var(--primary-gradient); color: #fff; padding: 14px 28px; 
    border-radius: 30px; font-weight: 500; font-size: 0.95rem;
    box-shadow: 0 10px 25px rgba(59,130,246,0.5); 
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1); z-index: 2000; opacity: 0; 
}
#toast.show { bottom: 40px; opacity: 1; }
/* === OVERVIEW DASHBOARD LAYOUT & RESPONSIVENESS === */

/* Уровень 1: Телеметрия */
.telemetry-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.telemetry-item {
    background: var(--surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 14px 18px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.telemetry-label {
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}
.telemetry-val {
    font-weight: 700;
    font-size: 1.05rem;
    margin-top: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Уровень 1: Пульт управления */
.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
    gap: 20px;
    margin-bottom: 20px;
}
.card-power {
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 250px;
}
.power-subrow {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 15px;
    border-top: 1px solid var(--border);
    text-align: left;
}
.card-routing {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 250px;
}
.node-status-box {
    margin: 12px 0;
    background: rgba(0, 0, 0, 0.15);
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.quick-chips-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

/* Уровень 2: Speedtest Pro & Монитор трафика */
.speedtest-pro-card, .traffic-monitor-card {
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
}
.st-arena-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 20px;
    align-items: stretch;
    margin-bottom: 20px;
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: 14px;
    border: 1px solid var(--border);
}
.st-metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    gap: 15px;
}
.chart-canvas-wrap {
    width: 100%;
    height: 160px;
    position: relative;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    padding: 6px;
    overflow: hidden;
}
#speedChart, #stWaveformChart {
    width: 100% !important;
    height: 100% !important;
    display: block;
}
.daily-stats-row {
    display: flex;
    justify-content: space-between;
    margin-top: 14px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    font-size: 0.9rem;
    flex-wrap: wrap;
    gap: 8px;
}

/* Уровень 3: Нижняя сетка аналитики */
.bottom-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

/* Эффекты свечения */
#stGaugeArc {
    filter: drop-shadow(0 0 6px rgba(99, 102, 241, 0.4));
}
#speedtestCard {
    transition: box-shadow 0.3s ease;
}
#stWaveformChart {
    filter: drop-shadow(0 0 4px rgba(56, 189, 248, 0.2));
}

/* Адаптивность для планшетов и смартфонов */
@media (max-width: 900px) {
    .st-arena-grid {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 820px) {
    .telemetry-bar {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin-bottom: 16px;
    }
    .main {
        padding: 12px;
        max-width: 100vw;
    }
    .card {
        padding: 16px;
        border-radius: 14px;
    }
    .controls-grid, .bottom-grid {
        gap: 14px;
        margin-bottom: 16px;
    }
    .speedtest-pro-card, .traffic-monitor-card {
        margin-bottom: 16px;
    }
}
@media (max-width: 480px) {
    .telemetry-item {
        padding: 10px 12px;
    }
    .telemetry-val {
        font-size: 0.92rem;
    }
    .st-arena-grid {
        padding: 14px 10px;
        gap: 14px;
    }
    .st-metric-grid {
        grid-template-columns: 1fr;
    }
    .node-status-box {
        padding: 10px 12px;
    }
    .daily-stats-row {
        flex-direction: column;
        gap: 6px;
    }
}

/* ==========================================================================
   🖥️ ТЕРМИНАЛ И КОНСОЛЬ (MODERN LIVE CONSOLE)
   ========================================================================== */
#live_logs.active {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 65px);
    max-height: calc(100vh - 65px);
    min-height: 480px;
    overflow: hidden;
    min-width: 0;
    width: 100%;
}

.terminal-card {
    background: #090d16 !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5) !important;
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    width: 100%;
    padding: 14px 18px;
    overflow: hidden;
    box-sizing: border-box;
}

.terminal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-wrap: wrap;
    min-width: 0;
}

.terminal-traffic-light {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    padding-right: 4px;
}
.tl-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.tl-red { background: #ef4444; box-shadow: 0 0 6px rgba(239, 68, 68, 0.6); }
.tl-yellow { background: #f59e0b; box-shadow: 0 0 6px rgba(245, 158, 11, 0.6); }
.tl-green { background: #10b981; box-shadow: 0 0 6px rgba(16, 185, 129, 0.6); }

.terminal-service-pills {
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.04);
    padding: 3px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    flex-wrap: wrap;
}

.t-pill {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}
.t-pill:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}
.t-pill.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 0 12px var(--primary-glow);
}

.terminal-quick-tools {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-wrap: wrap;
}

.t-tool-btn {
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 600;
}

.terminal-controls-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 0;
    flex-wrap: wrap;
    min-width: 0;
}

.terminal-search-box {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 3px 8px;
    gap: 6px;
    flex-grow: 1;
    min-width: 140px;
    max-width: 320px;
}
.terminal-search-box input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 0.8rem;
    width: 100%;
}
.terminal-search-box button {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.78rem;
}

.terminal-filter-chips {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}

.t-chip {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    font-size: 0.74rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.t-chip:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}
.t-chip.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--primary);
    color: #60a5fa;
}

.terminal-stream-actions {
    display: flex;
    gap: 5px;
    align-items: center;
    margin-left: auto;
}

.terminal-body-wrap {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    width: 100%;
    position: relative;
    background: #060910;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.terminal-status-strip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 12px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    user-select: none;
}

.terminal-log-viewer {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: auto;
    padding: 6px 10px;
    font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
    font-size: 0.81rem;
    line-height: 1.45;
    color: #e2e8f0;
    min-height: 0;
    min-width: 0;
    width: 100%;
}

.terminal-log-viewer::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.terminal-log-viewer::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}
.terminal-log-viewer::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.terminal-line {
    display: flex;
    gap: 8px;
    align-items: baseline;
    padding: 1px 4px;
    margin: 0;
    border-radius: 4px;
    transition: background 0.1s ease;
    min-width: 0;
    max-width: 100%;
}
.terminal-line:hover {
    background: rgba(255, 255, 255, 0.05);
}

.tl-num {
    color: #475569;
    min-width: 36px;
    text-align: right;
    user-select: none;
    font-size: 0.74rem;
    flex-shrink: 0;
}
.tl-time {
    color: #64748b;
    font-size: 0.76rem;
    white-space: nowrap;
    flex-shrink: 0;
}
.tl-tag {
    font-size: 0.70rem;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 700;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}
.tl-lvl-info { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }
.tl-lvl-warn { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.tl-lvl-err { background: rgba(239, 68, 68, 0.2); color: #f87171; box-shadow: 0 0 6px rgba(239, 68, 68, 0.4); }

.tl-route-hy2 { background: rgba(16, 185, 129, 0.18); color: #34d399; }
.tl-route-vless { background: rgba(168, 85, 247, 0.18); color: #c084fc; }
.tl-route-direct { background: rgba(59, 130, 246, 0.18); color: #60a5fa; }
.tl-route-block { background: rgba(244, 63, 94, 0.2); color: #fb7185; }

.tl-content {
    flex-grow: 1;
    min-width: 0;
    white-space: pre-wrap;
    word-break: break-all;
    overflow-wrap: anywhere;
}

.tl-host {
    color: #a5f3fc;
    font-weight: 600;
}
.tl-ip {
    color: #cbd5e1;
    font-weight: 600;
}

.terminal-scroll-bottom {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 16px var(--primary-glow);
    display: none;
    z-index: 10;
    animation: bounce 1.5s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translate(-50%, 0); }
    50% { transform: translate(-50%, -4px); }
}

/* === 🔬 TEST MODAL === */
.test-modal-content {
    width: 800px;
    max-width: 95%;
    max-height: 85vh;
}
.test-terminal-output {
    flex-grow: 1;
    min-height: 250px;
    max-height: 52vh;
    overflow-y: auto;
    overflow-x: auto;
    background: #040711;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 14px;
    font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    color: #e2e8f0;
    white-space: pre-wrap;
    word-break: break-all;
}
.test-terminal-output::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.test-terminal-output::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

@media (max-width: 850px) {
    #live_logs.active {
        height: calc(100vh - 125px);
        max-height: calc(100vh - 125px);
        min-height: 380px;
    }
    .terminal-card {
        padding: 10px !important;
    }
    .terminal-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .terminal-controls-bar {
        gap: 8px;
    }
    .terminal-search-box {
        max-width: 100%;
        min-width: 140px;
    }
    .terminal-filter-chips {
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }
    .terminal-stream-actions {
        margin-left: 0;
        width: 100%;
        justify-content: flex-end;
    }
}

/* Failover Modal Filters & Animation */
.fo-filter-btn {
    padding: 5px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.15s ease;
}

.fo-filter-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.fo-filter-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.spin {
    display: inline-block;
    animation: foSpin 1s linear infinite;
}

@keyframes foSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Custom dark select & option styles */
select, .fo-select {
    background-color: #1e293b !important;
    color: #f8fafc !important;
    border: 1px solid rgba(255, 255, 255, 0.18) !important;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.84rem;
    font-weight: 500;
    outline: none;
    cursor: pointer;
}

select:focus, .fo-select:focus {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

select option, .fo-select option {
    background-color: #0f172a !important;
    color: #f8fafc !important;
    padding: 8px 10px;
}



