/* ============================================
   Signal Lab Design System — Lite Edition
   ============================================ */
:root {
    --bg: #0a0a14;
    --panel: rgba(16, 14, 30, 0.78);
    --panel-strong: #12121e;
    --accent: #a78bfa;
    --accent-soft: rgba(167, 139, 250, 0.15);
    --accent-hot: #fb923c;
    --text: #e2e8f0;
    --muted: #8889a4;
    --border: rgba(130, 120, 180, 0.12);
    --radius: 16px;
    --radius-sm: 10px;
    --font: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: "JetBrains Mono", "SF Mono", "Fira Code", monospace;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[x-cloak] { display: none !important; }

html, body { height: 100%; }
body {
    background:
        radial-gradient(circle at 15% 18%, rgba(139,92,246,0.10), transparent 45%),
        radial-gradient(circle at 80% 15%, rgba(167,139,250,0.06), transparent 45%),
        radial-gradient(circle at 50% 80%, rgba(99,102,241,0.05), transparent 50%),
        linear-gradient(160deg, #08080f 0%, #0a0a18 60%, #0e0e1e 100%);
    background-attachment: fixed;
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.accent { color: var(--accent); }
.hot { color: var(--accent-hot); }

h1,h2,h3 { font-weight: 600; color: #fff; }
h2 { font-size: 20px; }
h3 { font-size: 16px; margin-bottom: 12px; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(14,14,26,0.4); }
::-webkit-scrollbar-thumb { background: rgba(136,137,164,0.25); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(136,137,164,0.4); }

/* ================================================
   LAYOUT: shell (sidebar + main)
   ================================================ */
.shell { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.nav {
    position: fixed; left: 0; top: 0; bottom: 0; width: 240px;
    padding: 24px 16px;
    background: rgba(8,8,18,0.65);
    border-right: 1px solid rgba(136,137,164,0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 100;
    display: flex; flex-direction: column;
    transition: transform .3s ease;
}
.nav-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.nav-emblem {
    width: 40px; height: 40px; border-radius: 12px;
    background: linear-gradient(135deg, #a78bfa, #8b5cf6);
    display: grid; place-items: center;
    color: #0a0a14; font-weight: 700; font-size: 14px;
    box-shadow: 0 8px 20px rgba(167,139,250,0.25);
}
.nav-title strong { font-size: 16px; color: #fff; display: block; }
.nav-title span { font-size: 11px; color: var(--muted); }

.nav-menu { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 14px; color: var(--muted);
    transition: all .15s ease;
}
.nav-item:hover { background: rgba(167,139,250,0.06); color: var(--text); }
.nav-item.active {
    background: var(--accent-soft); color: var(--accent);
    box-shadow: inset 3px 0 0 var(--accent);
}

.nav-footer { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 8px; }
.nav-user {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 12px; color: var(--muted); cursor: pointer;
    padding: 6px 8px; border-radius: 8px;
}
.nav-user:hover { background: rgba(255,255,255,0.04); }
.nav-logout { font-size: 16px; opacity: .6; transition: opacity .15s; }
.nav-logout:hover { opacity: 1; color: var(--accent-hot); }

/* ---- Main ---- */
.main { margin-left: 240px; flex: 1; min-width: 0; }

.top-bar {
    position: sticky; top: 0; z-index: 80;
    padding: 16px 28px;
    display: flex; justify-content: space-between; align-items: center;
    background: rgba(12,12,22,0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}
.top-bar h1 { font-size: 18px; margin: 0; }
.top-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.content { padding: 24px 28px; }

/* ================================================
   COMPONENTS
   ================================================ */

/* ---- Card ---- */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(16px);
    padding: 20px;
    margin-bottom: 20px;
    transition: transform .2s, box-shadow .2s;
}
.card:hover { box-shadow: 0 8px 32px rgba(0,0,0,0.25); }

/* ---- Tags ---- */
.tag {
    display: inline-block; padding: 3px 10px; border-radius: 99px;
    font-size: 11px; font-weight: 600; white-space: nowrap;
}
.tag-green { background: rgba(34,197,94,0.15); color: #4ade80; }
.tag-red { background: rgba(251,146,60,0.15); color: #fdba74; }
.tag-blue { background: rgba(96,165,250,0.15); color: #93c5fd; }

/* ---- Buttons ---- */
button, .btn-primary, .btn-outline, .btn-sm, .btn-danger {
    cursor: pointer; border: none; font-size: 13px; font-family: var(--font);
    border-radius: var(--radius-sm); transition: all .15s ease;
}
.btn-primary {
    background: linear-gradient(135deg, #a78bfa, #8b5cf6);
    color: #0a0a14; font-weight: 600;
    padding: 10px 20px;
    box-shadow: 0 0 12px rgba(167,139,250,0.25);
}
.btn-primary:hover { box-shadow: 0 0 22px rgba(167,139,250,0.45); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-outline {
    background: transparent; color: var(--text);
    border: 1px solid var(--border); padding: 10px 20px;
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 8px; }
.btn-sm.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.btn-sm.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger { background: rgba(251,146,60,0.15); color: #fdba74; padding: 5px 12px; border-radius: 8px; }
.btn-danger:hover { background: rgba(251,146,60,0.3); }
button.btn-danger:not(.btn-sm) { padding: 10px 20px; }

.btn-sm:disabled { opacity: .4; cursor: not-allowed; }

/* ---- Forms ---- */
input, select, textarea {
    width: 100%;
    background: rgba(14,14,26,0.6);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--font);
    outline: none;
    transition: border-color .15s;
    margin-bottom: 12px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: rgba(136,137,164,0.45); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
textarea { resize: vertical; min-height: 80px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .5px; }
.form-row { display: flex; gap: 12px; }
.form-row > div { flex: 1; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 14px; text-transform: none; margin: 8px 0; }
.checkbox-label input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--accent); }

/* ---- Tables ---- */
.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left; padding: 12px 16px;
    font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
    color: var(--muted); background: rgba(255,255,255,0.02);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody td {
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
tbody tr { transition: background .15s; }
tbody tr:hover { background: rgba(167,139,250,0.04); }
.actions-cell { display: flex; gap: 6px; }

/* ---- Pagination ---- */
.pagination {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px;
}
.pagination > div { display: flex; align-items: center; gap: 8px; }

/* ---- Filter Bar ---- */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { margin-bottom: 0; }
.filter-bar input { flex: 1; min-width: 200px; }
.filter-bar select { width: auto; min-width: 120px; }

/* ---- Page Header ---- */
.page-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 20px;
}
.page-header h2 { margin-bottom: 2px; }
.header-actions { display: flex; gap: 8px; }

/* ================================================
   MODALS
   ================================================ */
.modal-overlay {
    position: fixed; inset: 0; z-index: 500;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(4px);
    display: flex; justify-content: center; align-items: center;
    animation: fadeIn .15s;
}
.modal {
    background: var(--panel-strong);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px; width: 420px; max-width: calc(100vw - 32px);
    max-height: 85vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(2,6,23,0.7);
    animation: slideUp .2s;
}
.modal.wide { width: 520px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.result-list { max-height: 300px; overflow-y: auto; margin: 12px 0; }
.result-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 10px; border-radius: 6px;
    font-size: 13px;
}
.result-row:nth-child(odd) { background: rgba(255,255,255,0.02); }

/* ---- Side Panel (devices) ---- */
.side-panel {
    position: fixed; right: 0; top: 0; bottom: 0; width: 380px;
    max-width: 90vw;
    background: var(--panel-strong);
    border-left: 1px solid var(--border);
    display: flex; flex-direction: column;
    animation: slideRight .2s;
    z-index: 501;
}
.sp-header { display: flex; justify-content: space-between; align-items: center; padding: 20px; border-bottom: 1px solid var(--border); }
.sp-body { flex: 1; padding: 20px; overflow-y: auto; }
.sp-row { margin-bottom: 16px; }
.sp-row label { margin-bottom: 4px; }
.sp-row span { display: block; word-break: break-all; }
.sp-footer { padding: 16px 20px; border-top: 1px solid var(--border); }

/* ================================================
   LOGIN
   ================================================ */
.login-wrap {
    min-height: 100vh;
    display: flex; justify-content: center; align-items: center;
    padding: 20px;
}
.login-card {
    width: 380px; max-width: 100%;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(20px);
    padding: 36px 30px;
    text-align: center;
    box-shadow: 0 30px 70px rgba(2,6,23,0.6);
}
.login-logo {
    width: 56px; height: 56px; margin: 0 auto 16px;
    border-radius: 16px;
    background: linear-gradient(135deg, #a78bfa, #8b5cf6);
    display: grid; place-items: center;
    font-size: 20px; font-weight: 700; color: #0a0a14;
    box-shadow: 0 12px 30px rgba(167,139,250,0.3);
}
.login-card h2 { margin-bottom: 4px; }
.login-card form { margin-top: 24px; text-align: left; }
.login-card .btn-primary { width: 100%; margin-top: 4px; }
.login-footer { margin-top: 20px; font-size: 11px; }

/* ================================================
   DASHBOARD
   ================================================ */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.metric-box {
    position: relative; overflow: hidden;
    padding: 18px 20px;
    border-radius: var(--radius);
    background: rgba(167,139,250,0.04);
    border: 1px solid rgba(167,139,250,0.12);
}
.metric-box::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, #a78bfa, #8b5cf6); opacity: .7;
}
.metric-label {
    font-size: 11px; color: var(--accent);
    text-transform: uppercase; letter-spacing: .8px;
    margin-bottom: 6px; display: block;
}
.metric-value {
    font-size: 28px; font-weight: 700; color: #fff;
    text-shadow: 0 0 16px rgba(167,139,250,0.25);
}
.metric-value.accent { color: var(--accent); }
.metric-value.hot { color: var(--accent-hot); }

.card-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.card-grid > .card.wide { grid-column: 1; }
.card-grid-half { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.metric-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }

.dist-list { display: flex; flex-direction: column; gap: 10px; }
.dist-row { display: flex; align-items: center; gap: 12px; padding: 6px 0; }
.dist-label { color: var(--muted); min-width: 60px; display: flex; align-items: center; gap: 6px; }
.dist-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dist-value { font-weight: 600; color: #fff; font-size: 15px; min-width: 36px; text-align: right; }
.dist-bar { flex: 1; height: 6px; background: rgba(136,137,164,0.1); border-radius: 3px; overflow: hidden; }
.dist-bar > span { display: block; height: 100%; border-radius: 3px; transition: width .4s ease; }

/* ---- Online/Offline indicators ---- */
.online-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 6px rgba(52,211,153,0.5); }
.offline-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #475569; }

/* ---- Chart empty state ---- */
.chart-empty { height: 200px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }

.center-spin { padding: 60px; text-align: center; color: var(--muted); }

/* ================================================
   TOAST
   ================================================ */
.toast {
    position: fixed; bottom: 24px; right: 24px; z-index: 9999;
    padding: 10px 20px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 500;
    background: var(--panel-strong); color: var(--text);
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.success { border-color: rgba(34,197,94,0.4); color: #4ade80; }
.toast.error { border-color: rgba(251,146,60,0.4); color: #fdba74; }

/* ---- Mobile Toggle ---- */
.mobile-toggle {
    display: none; position: fixed; top: 14px; left: 14px; z-index: 200;
    width: 40px; height: 40px; border-radius: 10px;
    background: rgba(16,14,30,0.9); border: 1px solid var(--border);
    color: var(--text); font-size: 18px;
    backdrop-filter: blur(12px);
}
.mobile-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; backdrop-filter: blur(3px); }
.mobile-overlay.active { display: block; }

/* ================================================
   ANIMATIONS
   ================================================ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideRight { from { transform: translateX(100%); } to { transform: translateX(0); } }

/* ================================================
   RESPONSIVE
   ================================================ */
@media (max-width: 768px) {
    .mobile-toggle { display: grid; place-items: center; }
    .nav { transform: translateX(-100%); width: 260px; z-index: 150; }
    .nav.open { transform: translateX(0); }
    .main { margin-left: 0 !important; }
    .top-bar { padding-left: 64px; }
    .content { padding: 16px; }
    .page-header { flex-direction: column; gap: 10px; }
    .card-grid { grid-template-columns: 1fr; }
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .filter-bar { flex-direction: column; }
    .filter-bar input { min-width: auto; }
    .modal { width: calc(100vw - 24px); }
    .side-panel { width: 100%; max-width: 100vw; }
    table { min-width: 580px; }
}

@media (max-width: 480px) {
    .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .metric-box { padding: 14px; }
    .metric-value { font-size: 22px; }
    .content { padding: 12px; }
    .form-row { flex-direction: column; gap: 0; }
}
