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

/* ── DARK THEME (default) ── */
:root {
    --bg:       #0f172a;
    --surface:  #1e293b;
    --surface2: #334155;
    --border:   #475569;
    --text:     #e2e8f0;
    --text2:    #94a3b8;
    --green:    #22c55e;
    --red:      #ef4444;
    --yellow:   #f59e0b;
    --blue:     #3b82f6;
    --purple:   #8b5cf6;
}

/* ── LIGHT THEME ── */
body.light {
    --bg:       #f1f5f9;
    --surface:  #ffffff;
    --surface2: #e2e8f0;
    --border:   #cbd5e1;
    --text:     #1e293b;
    --text2:    #64748b;
    --green:    #16a34a;
    --red:      #dc2626;
    --yellow:   #d97706;
    --blue:     #2563eb;
}

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background .3s, color .3s;
}

/* ── NAV ── */
nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    display: flex;
    align-items: center;
    height: 52px;
    gap: 4px;
    position: sticky; top: 0; z-index: 100;
}
nav .brand {
    font-size: 17px; font-weight: 700;
    color: var(--blue); margin-right: 12px;
    text-decoration: none; white-space: nowrap;
}
nav a {
    color: var(--text2); text-decoration: none;
    padding: 5px 12px; border-radius: 6px;
    font-size: 13px; transition: all .2s;
}
nav a:hover, nav a.active {
    background: var(--surface2); color: var(--text);
}
nav .nav-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* Theme toggle */
.theme-toggle {
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--text2); width: 32px; height: 32px;
    border-radius: 8px; cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    transition: all .2s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--blue); }

/* ── LAYOUT ── */
.container { max-width: 1500px; margin: 0 auto; padding: 20px; }

/* ── CARDS ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px; padding: 20px; margin-bottom: 20px;
}
.card h2 {
    font-size: 14px; color: var(--text2);
    margin-bottom: 16px; text-transform: uppercase; letter-spacing: .5px;
}

/* ── STAT CARDS ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px; margin-bottom: 20px;
}
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 18px; text-align: center;
    cursor: pointer; transition: transform .15s, border-color .15s;
}
.stat-card:hover { transform: translateY(-2px); border-color: var(--blue); }
.stat-card.active { border-color: var(--blue); background: var(--surface2); }
.stat-card .num { font-size: 34px; font-weight: 700; line-height: 1; }
.stat-card .lbl { font-size: 12px; color: var(--text2); margin-top: 6px; }
.stat-card.online  .num { color: var(--green); }
.stat-card.offline .num { color: var(--red); }
.stat-card.warning .num { color: var(--yellow); }
.stat-card.total   .num { color: var(--blue); }

/* ── BADGES ── */
.badge {
    display: inline-block; padding: 3px 10px;
    border-radius: 20px; font-size: 11px;
    font-weight: 600; text-transform: uppercase;
}
body.light .badge.online  { background:#dcfce7; color:#16a34a; }
body.light .badge.offline { background:#fee2e2; color:#dc2626; }
body.light .badge.warning { background:#fef3c7; color:#d97706; }
body.light .badge.unknown { background:#f1f5f9; color:#64748b; }
.badge.online  { background:#14532d; color:var(--green); }
.badge.offline { background:#7f1d1d; color:var(--red); }
.badge.warning { background:#78350f; color:var(--yellow); }
.badge.unknown { background:var(--surface2); color:var(--text2); }

/* ── TABLE ── */
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left; padding: 10px 14px;
    font-size: 11px; color: var(--text2);
    text-transform: uppercase; letter-spacing: .5px;
    border-bottom: 1px solid var(--border);
}
td { padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
tr:hover td { background: var(--surface2); }

/* ── FORMS ── */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px; margin-bottom: 14px;
}
label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 5px; }
input[type=text], input[type=password], input[type=email],
input[type=number], input[type=date], select, textarea {
    width: 100%; background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text); padding: 8px 12px;
    border-radius: 8px; font-size: 13px;
    outline: none; transition: border .2s;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); }

/* ── BUTTONS ── */
.btn {
    display: inline-block; padding: 8px 18px;
    border-radius: 8px; font-size: 13px;
    font-weight: 600; border: none;
    cursor: pointer; text-decoration: none;
    transition: opacity .2s; white-space: nowrap;
}
.btn:hover { opacity: .85; }
.btn-primary { background: var(--blue);   color: #fff; }
.btn-danger  { background: var(--red);    color: #fff; }
.btn-success { background: var(--green);  color: #fff; }
.btn-warning { background: var(--yellow); color: #000; }
.btn-gray    { background: var(--surface2); color: var(--text); }
.btn-sm      { padding: 4px 10px; font-size: 12px; }

/* ── ALERTS/FLASH ── */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
body.light .alert-success { background: #dcfce7; color: #16a34a; }
body.light .alert-danger  { background: #fee2e2; color: #dc2626; }
body.light .alert-warning { background: #fef3c7; color: #d97706; }
.alert-success { background: #14532d; color: var(--green); }
.alert-danger  { background: #7f1d1d; color: var(--red); }
.alert-warning { background: #78350f; color: var(--yellow); }

/* ── DEVICE CARDS ── */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}
.device-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 16px;
    cursor: pointer; transition: transform .15s, border-color .15s;
}
.device-card:hover { transform: translateY(-2px); border-color: var(--blue); }
.device-card.online  { border-left: 4px solid var(--green); }
.device-card.offline { border-left: 4px solid var(--red); animation: blink-border 1.5s infinite; }
.device-card.warning { border-left: 4px solid var(--yellow); }
.device-card.unknown { border-left: 4px solid var(--border); }
@keyframes blink-border {
    0%,100% { border-left-color: var(--red); }
    50%      { border-left-color: transparent; }
}
.device-card .d-name  { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.device-card .d-ip    { font-size: 12px; color: var(--text2); font-family: monospace; }
.device-card .d-stats { font-size: 12px; color: var(--text2); margin-top: 10px; display: flex; gap: 12px; }

/* ── PULSE DOT ── */
.pulse {
    display: inline-block; width: 9px; height: 9px;
    border-radius: 50%; margin-right: 6px; vertical-align: middle;
}
.pulse.online  { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulsate 1.5s infinite; }
.pulse.offline { background: var(--red); }
.pulse.warning { background: var(--yellow); animation: pulsate 2s infinite; }
.pulse.unknown { background: var(--border); }
@keyframes pulsate { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── TOOLBAR ── */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }

/* ── REFRESH INDICATOR ── */
.refresh-ring {
    width: 28px; height: 28px; border-radius: 50%;
    border: 3px solid var(--border);
    border-top-color: var(--blue);
    animation: spin 1s linear infinite;
    display: none;
}
.refresh-ring.active { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }
.refresh-info { font-size: 12px; color: var(--text2); display: flex; align-items: center; gap: 8px; }

/* ── GROUP FILTER TABS ── */
.group-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.group-tab {
    padding: 5px 14px; border-radius: 20px;
    border: 1px solid var(--border); background: transparent;
    color: var(--text2); font-size: 12px; cursor: pointer;
    transition: all .2s;
}
.group-tab:hover, .group-tab.active {
    background: var(--blue); border-color: var(--blue); color: #fff;
}

/* ── ALARM BANNER ── */
.alarm-banner {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--red); color: #fff;
    padding: 10px 20px; text-align: center;
    font-weight: 700; font-size: 15px;
    z-index: 999; display: none;
    animation: blink-bg 1s infinite;
}
.alarm-banner.show { display: block; }
@keyframes blink-bg { 0%,100%{background:#ef4444} 50%{background:#991b1b} }

/* ── MODAL ── */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.6); z-index: 500;
    align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; padding: 28px; width: 520px;
    max-width: 95vw; max-height: 90vh; overflow-y: auto;
    position: relative;
}
.modal-close {
    position: absolute; top: 16px; right: 16px;
    background: transparent; border: none;
    color: var(--text2); font-size: 20px; cursor: pointer;
}

/* ── LOGIN ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; padding: 40px; width: 100%; max-width: 380px;
}
.login-box h1 { font-size: 24px; margin-bottom: 6px; color: var(--blue); }
.login-box p  { color: var(--text2); font-size: 13px; margin-bottom: 24px; }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
    nav { flex-wrap: wrap; height: auto; padding: 8px; gap: 4px; }
    .stats-grid { grid-template-columns: repeat(2,1fr); }
    .device-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    #dash-grid { grid-template-columns: 1fr !important; }
}
