﻿:root {
    --bg: #0B0E14;
    --panel: #131820;
    --panel-border: #1E2530;
    --panel-hover: #1A2030;
    --text-main: #E8ECF0;
    --text-dim: #5A6577;
    --accent: #3B82F6;
    --green: #22C55E;
    --amber: #F59E0B;
    --red: #EF4444;
    --cyan: #06B6D4;
    --purple: #8B5CF6;
    --orange: #F59E0B;
    --sidebar-w: 240px;
    --topbar-h: 56px;
}

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

body {
    background: var(--bg);
    color: var(--text-main);
    font-family: 'Inter', system-ui, sans-serif;
    min-height: 100vh;
    line-height: 1.5;
    overflow-x: hidden;
}

::selection { background: rgba(59,130,246,0.3); color: #fff; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }

/* ===== SIDEBAR ===== */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--panel);
    border-right: 1px solid var(--panel-border);
    color: var(--text-dim);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: transform .2s ease;
}
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
}
.sidebar-overlay.active { display: block; }

.sidebar-brand {
    padding: 18px 20px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--panel-border);
    min-height: 56px;
}
.sidebar-brand i { color: var(--accent); }

.sidebar-menu { padding: 10px 0; flex: 1; overflow-y: auto; }

.menu-label {
    padding: 14px 20px 5px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--text-dim);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    font-size: 0.85rem;
    color: var(--text-dim);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all .15s;
    cursor: pointer;
    min-height: 44px;
}
.menu-item:hover {
    color: var(--text-main);
    background: rgba(255,255,255,0.03);
}
.menu-item.active {
    color: var(--accent);
    border-left-color: var(--accent);
    background: rgba(59,130,246,0.08);
}
.menu-item i { font-size: 1.1rem; width: 20px; text-align: center; }

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--panel-border);
    font-size: 0.7rem;
    color: var(--text-dim);
}

/* ===== MAIN AREA ===== */
.main-area {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    min-width: 0;
}

/* ===== TOPBAR ===== */
.topbar {
    height: var(--topbar-h);
    background: var(--panel);
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 0.8rem;
    color: var(--text-dim);
    flex-shrink: 0;
}

.live-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--green);
    display: inline-block;
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%,100% { opacity:1; }
    50% { opacity:0.4; }
}

.topbar-btn {
    border: 1px solid var(--panel-border);
    background: transparent;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all .15s;
    white-space: nowrap;
    min-height: 36px;
}
.topbar-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.btn-pdf:hover {
    border-color: var(--red);
    color: var(--red);
}
.btn-excel-all:hover {
    border-color: var(--green);
    color: var(--green);
}

.refresh-info {
    font-size: 0.75rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 4px;
}

.content { padding: 20px 24px; max-width: 1400px; }

.page { display: none; }
.page.active { display: block; }

/* ===== FILTER BAR ===== */
.filter-bar {
    background: var(--panel);
    border-bottom: 1px solid var(--panel-border);
    padding: 10px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    position: sticky;
    top: var(--topbar-h);
    z-index: 99;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-dim);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}
.filter-label i { font-size: 0.85rem; color: var(--accent); }

.filter-input {
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    padding: 5px 8px;
    font-size: 0.8rem;
    font-family: inherit;
    color: var(--text-main);
    background: var(--bg);
    outline: none;
    transition: all .15s;
    min-height: 36px;
}
.filter-input:focus { border-color: var(--accent); }
.filter-time { width: 70px; }

.filter-quick { gap: 4px; }

.qbtn {
    border: 1px solid var(--panel-border);
    background: transparent;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-dim);
    cursor: pointer;
    transition: all .15s;
    min-height: 36px;
    min-width: 44px;
}
.qbtn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.qbtn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-apply {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 5px 14px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all .15s;
    min-height: 36px;
}
.btn-apply:hover { opacity: 0.9; }

.btn-reset {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    padding: 5px 12px;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all .15s;
    min-height: 36px;
}
.btn-reset:hover {
    border-color: var(--red);
    color: var(--red);
}

/* ===== STAT CARDS ===== */
.stat-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.stat {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: border-color 0.2s;
    position: relative;
    min-height: 80px;
}
.stat:hover { border-color: rgba(59,130,246,0.3); }
.stat-icon {
    width: 40px; height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.stat-icon.blue { background: rgba(59,130,246,0.12); color: var(--accent); }
.stat-icon.cyan { background: rgba(6,182,212,0.12); color: var(--cyan); }
.stat-icon.green { background: rgba(34,197,94,0.12); color: var(--green); }
.stat-icon.orange { background: rgba(245,158,11,0.12); color: var(--amber); }
.stat-icon.red { background: rgba(239,68,68,0.12); color: var(--red); }
.stat-icon.purple { background: rgba(139,92,246,0.12); color: var(--purple); }
.stat-num {
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.5px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-main);
    word-break: break-all;
}
.stat-sub { font-size: clamp(0.65rem, 1.2vw, 0.72rem); color: var(--text-dim); margin-top: 2px; }

/* ===== INFO BAR ===== */
.info-bar {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 12px 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 28px;
    font-size: 0.85rem;
    color: var(--text-dim);
    flex-wrap: wrap;
}
.info-bar strong { color: var(--text-main); }

/* ===== CHART CARD ===== */
.ccard {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 18px 20px;
    margin-bottom: 16px;
}
.ccard-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    gap: 8px;
}
.ccard-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ccard-title .dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.ccard-actions { display: flex; gap: 6px; flex-shrink: 0; }

.chart-btn {
    border: 1px solid var(--panel-border);
    background: transparent;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 3px;
    transition: all .15s;
    min-height: 32px;
    min-width: 32px;
}
.chart-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.cbox { position: relative; width: 100%; height: 380px; }

/* ===== TABLE ===== */
.table-wrap {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    overflow: hidden;
}
.table-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--panel-border);
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text-main);
}

.iot-table { width: 100%; border-collapse: collapse; }
.iot-table thead th {
    background: rgba(255,255,255,0.02);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-dim);
    padding: 10px 14px;
    border-bottom: 1px solid var(--panel-border);
    text-align: left;
    white-space: nowrap;
    letter-spacing: 0.3px;
}
.iot-table tbody td {
    padding: 9px 14px;
    font-size: 0.82rem;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    white-space: nowrap;
    color: var(--text-main);
    font-family: 'JetBrains Mono', monospace;
}
.iot-table tbody tr { transition: background .15s ease; }
.iot-table tbody tr:hover { background: rgba(255,255,255,0.02); }

.pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.72rem;
    font-weight: 600;
}
.pill-blue { background: rgba(59,130,246,0.12); color: var(--accent); }
.pill-green { background: rgba(34,197,94,0.12); color: var(--green); }
.pill-orange { background: rgba(245,158,11,0.12); color: var(--amber); }
.pill-red { background: rgba(239,68,68,0.12); color: var(--red); }

.pager {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--panel-border);
}
.pager button {
    background: transparent;
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    padding: 5px 14px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-dim);
    cursor: pointer;
    transition: all .15s;
    min-height: 36px;
}
.pager button:hover:not(:disabled) {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.pager button:disabled { opacity: 0.3; cursor: default; }
.page-label { font-size: 0.8rem; color: var(--text-dim); }

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal-box {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    width: 100%;
    max-width: 1100px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--panel-border);
    gap: 8px;
}
.modal-title { font-size: 1rem; font-weight: 600; color: var(--text-main); }
.modal-actions { display: flex; gap: 6px; align-items: center; }
.modal-close { color: var(--red) !important; }
.modal-close:hover {
    border-color: var(--red) !important;
    color: var(--red) !important;
}

.modal-body {
    flex: 1;
    padding: 20px;
    position: relative;
    min-height: 300px;
}
.modal-body canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ===== TOAST ===== */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toast {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideIn .25s ease;
    max-width: 300px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.info { border-left: 3px solid var(--accent); }
.toast.error { border-left: 3px solid var(--red); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===== MENU TOGGLE ===== */
.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px; height: 44px;
    border: none;
    background: transparent;
    font-size: 1.4rem;
    color: var(--text-main);
    cursor: pointer;
    border-radius: 6px;
}
.menu-toggle:hover { background: rgba(255,255,255,0.05); }

/* ===== FLOATING HOME BUTTON ===== */
.fab-home {
    position: fixed;
    bottom: 24px;
    left: 24px;
    background: var(--accent);
    color: #fff;
    padding: 12px 20px;
    border-radius: 50px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 99;
    transition: transform .2s, box-shadow .2s;
    box-shadow: 0 4px 12px rgba(59,130,246,0.3);
    min-height: 48px;
}
.fab-home:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59,130,246,0.4);
}

/* ===== RESPONSIVE: TABLET (768px - 1024px) ===== */
@media (max-width: 1024px) {
    .stat-row {
        grid-template-columns: repeat(2, 1fr);
    }
    .topbar-right {
        gap: 8px;
    }
    .topbar-btn span.btn-text {
        display: none;
    }
    .content { padding: 16px; }
    .ccard { padding: 14px 16px; }
    .filter-bar { padding: 8px 16px; gap: 10px; }
}

/* ===== LARGE DESKTOP (> 1400px) ===== */
@media (min-width: 1400px) {
    .content { padding: 24px 32px; }
    .stat-row { gap: 16px; }
    .stat { padding: 20px 24px; }
    .ccard { padding: 24px; }
    .ccard-title { font-size: 1.05rem; }
    .cbox { height: 420px; }
    .filter-bar { padding: 12px 32px; }
}

/* ===== RESPONSIVE: MOBILE (< 768px) ===== */
@media (max-width: 768px) {
    :root {
        --topbar-h: 52px;
    }

    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,0.5);
    }
    .main-area {
        margin-left: 0;
    }
    .menu-toggle {
        display: flex !important;
    }

    /* Topbar */
    .topbar {
        padding: 0 12px;
    }
    .topbar-right {
        gap: 6px;
        font-size: 0.7rem;
    }
    .topbar-btn {
        padding: 5px 8px;
        font-size: 0.72rem;
    }
    .topbar-btn span.btn-text {
        display: none;
    }
    .refresh-info span:not(.live-dot) {
        display: none;
    }

    /* Filter */
    .filter-bar {
        padding: 8px 12px;
        gap: 8px;
    }
    .filter-quick {
        display: none;
    }
    .filter-group {
        gap: 4px;
    }
    .filter-label {
        font-size: 0.65rem;
    }
    .filter-input {
        font-size: 0.75rem;
        padding: 4px 6px;
        min-height: 34px;
    }
    .filter-time {
        width: 60px;
    }

    /* Stat cards */
    .stat-row {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
    }
    .stat {
        padding: 12px 14px;
        gap: 10px;
        min-height: 70px;
    }
    .stat-icon {
        width: 36px; height: 36px;
        font-size: 1rem;
    }
    .stat-num {
        font-size: clamp(1rem, 4vw, 1.4rem);
    }
    .stat-sub {
        font-size: 0.6rem;
    }

    /* Content */
    .content {
        padding: 12px;
    }

    /* Chart cards */
    .ccard {
        padding: 12px;
        margin-bottom: 12px;
    }
    .ccard-head {
        margin-bottom: 10px;
    }
    .ccard-title {
        font-size: 0.82rem;
    }
    .cbox {
        height: 250px;
    }

    /* Table */
    .table-wrap {
        font-size: 0.75rem;
    }
    .iot-table thead th {
        padding: 8px 10px;
        font-size: 0.65rem;
    }
    .iot-table tbody td {
        padding: 7px 10px;
        font-size: 0.75rem;
    }

    /* Info bar */
    .info-bar {
        gap: 12px;
        padding: 8px 14px;
        font-size: 0.72rem;
    }

    /* Modal */
    .modal-overlay {
        padding: 10px;
    }
    .modal-box {
        max-height: 95vh;
    }
    .modal-head {
        padding: 10px 14px;
    }
    .modal-body {
        padding: 12px;
        min-height: 250px;
    }
    .modal-title {
        font-size: 0.85rem;
    }

    /* Toast */
    .toast-container {
        top: 12px;
        right: 12px;
        left: 12px;
    }
    .toast {
        max-width: 100%;
        font-size: 0.75rem;
    }

    /* FAB */
    .fab-home {
        bottom: 16px;
        left: 16px;
        padding: 10px 16px;
        font-size: 13px;
    }
}

/* ===== RESPONSIVE: SMALL MOBILE (< 480px) ===== */
@media (max-width: 480px) {
    .stat-row {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .stat {
        padding: 10px 10px;
        gap: 8px;
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
    }
    .stat-icon {
        width: 32px; height: 32px;
        font-size: 0.9rem;
    }
    .stat-num {
        font-size: clamp(0.9rem, 5vw, 1.3rem);
    }
    .cbox {
        height: 220px;
    }
    .ccard-actions {
        gap: 4px;
    }
    .chart-btn {
        padding: 4px 6px;
        min-height: 28px;
        min-width: 28px;
    }
}
