:root {
    color-scheme: dark;
    --bg: #0b1020;
    --sidebar: #0e1527;
    --surface: #131d31;
    --surface-hover: #192640;
    --border: #24334d;
    --text: #edf2fc;
    --muted: #8493ad;
    --blue: #638cff;
    --blue-hover: #7da0ff;
    --green: #43d69a;
    --red: #ff697d;
    --orange: #f3b85e;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.muted { color: var(--muted); margin: 5px 0 0; }
.eyebrow {
    color: #7795d5;
    font-size: 10px;
    font-weight: 750;
    letter-spacing: 1.6px;
    margin-bottom: 7px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 27px; line-height: 1.2; margin-bottom: 7px; letter-spacing: -.7px; }
h2 { font-size: 19px; margin-bottom: 5px; letter-spacing: -.3px; }
h3 { margin: 0; font-size: 15px; }

.app-layout { min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 245px;
    padding: 27px 17px;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 10px;
    font-size: 17px;
    font-weight: 750;
    letter-spacing: -.5px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 37px;
    height: 37px;
    border-radius: 11px;
    background: linear-gradient(145deg, #7299ff, #4265d9);
    color: white;
    font-weight: 800;
    font-size: 20px;
    box-shadow: 0 5px 18px #456de94a;
}

.brand-light { color: #8fa7d6; font-weight: 450; margin-left: 3px; }

.nav-caption {
    margin: 48px 11px 12px;
    color: #64748b;
    font-size: 10px;
    font-weight: 750;
    letter-spacing: 1.3px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 13px;
    margin: 3px 0;
    color: #a4b1c8;
    border-radius: 9px;
    font-size: 13px;
    transition: .18s ease;
}

.nav-link:hover, .nav-link.active {
    color: white;
    background: #1b2b49;
}

.nav-link.active { box-shadow: inset 3px 0 #7095ff; }
.nav-icon { width: 19px; text-align: center; font-size: 17px; }

.sidebar-bottom { margin-top: auto; }

.server-indicator {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 14px 11px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: #111c30;
}

.server-indicator strong, .server-indicator small { display: block; }
.server-indicator strong { font-size: 12px; }
.server-indicator small { color: var(--muted); font-size: 11px; margin-top: 3px; }

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 4px #43d69a19;
    flex: 0 0 auto;
}

.logout-button {
    width: 100%;
    background: transparent;
    border: 0;
    text-align: left;
}

.main-content {
    max-width: 1600px;
    margin-left: 245px;
    padding: 38px 45px 22px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 29px;
}

.topbar-status {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #a8b8d1;
    background: #142239;
    border: 1px solid var(--border);
    border-radius: 30px;
    padding: 9px 14px;
    font-size: 12px;
    white-space: nowrap;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 17px;
    margin-bottom: 21px;
}

.stat-card, .panel, .client-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 13px;
}

.stat-card {
    padding: 19px 21px;
    min-height: 133px;
}

.stat-top {
    display: flex;
    justify-content: space-between;
    color: #aab7cd;
    font-size: 12px;
}

.stat-icon {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    color: #8eacff;
    background: #547de51c;
    font-size: 17px;
}

.stat-icon.green { color: var(--green); background: #43d69a17; }
.stat-icon.red { color: var(--red); background: #ff697d17; }

.stat-value {
    margin-top: 8px;
    font-size: 29px;
    font-weight: 750;
    letter-spacing: -1px;
}

.stat-description { color: var(--muted); font-size: 11px; margin-top: 2px; }

.panel { padding: 22px 23px; margin-bottom: 32px; }

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 19px;
}

.heading-icon {
    display: grid;
    place-items: center;
    width: 37px;
    height: 37px;
    border-radius: 10px;
    background: #547de51c;
    color: #8eacff;
    font-size: 22px;
}

.add-form {
    display: flex;
    align-items: end;
    gap: 13px;
}

.input-wrap { flex: 1; min-width: 0; }
.input-wrap label, .login-form label {
    display: block;
    margin-bottom: 7px;
    color: #b8c5d9;
    font-size: 12px;
    font-weight: 600;
}

.input-wrap input, .login-form input {
    width: 100%;
    height: 43px;
    padding: 0 13px;
    border: 1px solid #30415e;
    border-radius: 8px;
    outline: none;
    background: #0e1728;
    color: var(--text);
    transition: border .2s, box-shadow .2s;
}

.input-wrap input:focus, .login-form input:focus, .search-box:focus-within {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px #638cff1c;
}

.input-wrap small { display: block; color: #7586a2; font-size: 10px; margin-top: 6px; }

.button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 7px;
    min-height: 36px;
    padding: 8px 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 650;
    white-space: nowrap;
    transition: .18s ease;
}

.button:hover { filter: brightness(1.13); transform: translateY(-1px); }
.button-primary { background: #4d73df; color: white; }
.button-ghost { background: #1b2940; color: #b8c9e7; border-color: #2b3b57; }
.button-warning { background: #3b3022; color: #f3c477; border-color: #5c482b; }
.button-danger { background: #39232f; color: #ff8998; border-color: #57303e; }
.button-wide { width: 100%; min-height: 44px; margin-top: 17px; }

.clients-section { margin-top: 5px; }
.clients-heading { margin-bottom: 19px; }
.clients-heading h2 { display: flex; align-items: center; gap: 10px; }

.count-badge {
    display: inline-grid;
    place-items: center;
    min-width: 24px;
    height: 23px;
    padding: 0 7px;
    border-radius: 7px;
    color: #9cb5ff;
    background: #638cff20;
    font-size: 11px;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 13px;
    margin-bottom: 17px;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 9px;
    width: min(340px, 100%);
    height: 39px;
    padding: 0 11px;
    background: #111b2d;
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: .2s;
}

.search-box > span { color: #8fa3c4; font-size: 21px; }
.search-box input { width: 100%; min-width: 0; background: transparent; border: 0; outline: 0; color: var(--text); font-size: 12px; }
.search-box input::placeholder, input::placeholder { color: #687b99; }

.filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #111a2a;
}

.filter-button {
    padding: 6px 10px;
    border: 0;
    border-radius: 6px;
    color: #91a0ba;
    background: transparent;
    font-size: 10px;
}

.filter-button:hover { color: white; }
.filter-button.active { background: #2a416a; color: #c7d7ff; }

.client-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px;
}

.client-card {
    min-width: 0;
    padding: 17px;
    transition: border-color .2s, transform .2s;
}

.client-card:hover { border-color: #3b527a; transform: translateY(-2px); }

.client-card-top {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

.client-avatar {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 39px;
    height: 39px;
    border-radius: 11px;
    color: #b8ccff;
    background: linear-gradient(145deg, #293f69, #1b2b49);
    font-size: 16px;
    font-weight: 750;
}

.client-identity { min-width: 0; flex: 1; }
.client-identity h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-ip { display: block; margin-top: 3px; color: #8092b0; font-size: 11px; font-family: monospace; }

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    padding: 5px 8px;
    border-radius: 20px;
    font-size: 9px;
    font-weight: 700;
}

.status-pill i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pill.online { color: var(--green); background: #43d69a13; }
.status-pill.offline { color: var(--orange); background: #f3b85e13; }
.status-pill.disabled { color: #9aa7bd; background: #8795aa18; }

.client-metrics {
    margin-top: 17px;
    padding: 13px 0;
    border-top: 1px solid #26344b;
    border-bottom: 1px solid #26344b;
}

.metric-label { display: block; margin-bottom: 5px; color: #7f90ab; font-size: 10px; }
.client-metrics strong { color: #d4def0; font-size: 11px; font-weight: 650; }

.traffic-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

.client-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 13px;
}

.client-actions form { margin: 0; }
.client-actions .button { min-height: 31px; padding: 6px 9px; font-size: 10px; }

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 45px 15px;
    border: 1px dashed #30415e;
    border-radius: 12px;
    color: #aab8ce;
}

.empty-state span { color: var(--muted); font-size: 12px; }
.empty-icon { font-size: 29px; color: #7188b1; }

.footnote { margin: 15px 0 0; color: #73839d; font-size: 11px; }
.page-footer { display: flex; justify-content: space-between; gap: 15px; margin-top: 35px; padding-top: 16px; border-top: 1px solid var(--border); color: #697b98; font-size: 10px; }

.alert {
    margin: 0 0 16px;
    padding: 12px 14px;
    border: 1px solid #40577a;
    border-radius: 9px;
    background: #1a2a43;
    color: #c7d9f6;
    font-size: 12px;
}

/* QR modal */
.modal { display: none; position: fixed; inset: 0; z-index: 20; align-items: center; justify-content: center; padding: 20px; }
.modal.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: #030711d9; backdrop-filter: blur(5px); }
.modal-content {
    position: relative;
    width: min(390px, 100%);
    padding: 27px;
    border: 1px solid #344765;
    border-radius: 17px;
    background: #131e32;
    text-align: center;
    box-shadow: 0 25px 90px #0009;
    animation: modal-in .18s ease-out;
}

@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

.modal-close {
    position: absolute;
    top: 11px;
    right: 13px;
    width: 31px;
    height: 31px;
    border: 0;
    border-radius: 8px;
    background: #25344d;
    color: white;
    font-size: 21px;
}

.qr-image-wrap {
    display: grid;
    place-items: center;
    margin: 20px auto 13px;
    width: 250px;
    max-width: 100%;
    min-height: 250px;
    padding: 13px;
    border-radius: 12px;
    background: white;
}

.qr-image-wrap img { display: block; width: 100%; height: auto; }
.qr-hint { margin: 0; color: #95a7c4; font-size: 11px; }

/* Login */
.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 20px;
    background: radial-gradient(ellipse at 50% 35%, #1a2b4b 0, #0b1020 58%);
}

.login-card {
    width: min(410px, 100%);
    padding: 36px;
    border: 1px solid #2a3a56;
    border-radius: 18px;
    background: #121d31ed;
    box-shadow: 0 25px 90px #0005;
}

.login-card .brand-mark { margin-bottom: 25px; width: 45px; height: 45px; font-size: 23px; }
.login-card h1 { font-size: 29px; }
.login-form { margin-top: 29px; }
.login-footer { margin-top: 26px; padding-top: 17px; border-top: 1px solid var(--border); color: #70819d; font-size: 10px; text-align: center; letter-spacing: .5px; }

/* Responsive */
@media (min-width: 1500px) {
    .client-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
    .sidebar { width: 205px; }
    .main-content { margin-left: 205px; padding: 30px 25px; }
    .toolbar { align-items: stretch; flex-direction: column; }
    .search-box { width: 100%; }
}

@media (max-width: 760px) {
    .sidebar {
        position: relative;
        inset: auto;
        width: 100%;
        height: auto;
        padding: 12px 16px;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .brand { padding: 0; }
    .brand-mark { width: 34px; height: 34px; }
    .nav-caption, .sidebar > .nav-link, .server-indicator { display: none; }
    .sidebar-bottom { margin: 0; }
    .logout-button { width: auto; padding: 8px; font-size: 0; }
    .logout-button .nav-icon { font-size: 19px; }
    .main-content { margin: 0; padding: 25px 15px 18px; }
    .topbar { align-items: flex-start; margin-bottom: 21px; }
    .topbar-status { padding: 7px 10px; font-size: 10px; }
    h1 { font-size: 23px; }
    .stats-grid { gap: 9px; }
    .stat-card { min-height: 112px; padding: 13px; }
    .stat-top { font-size: 10px; }
    .stat-icon { width: 25px; height: 25px; }
    .stat-value { font-size: 25px; }
    .stat-description { font-size: 9px; }
    .panel { padding: 17px; }
    .add-form { align-items: stretch; flex-direction: column; }
    .add-form .button { min-height: 42px; }
    .client-grid { grid-template-columns: 1fr; }
    .filter-group { overflow-x: auto; flex-wrap: nowrap; }
    .filter-button { white-space: nowrap; }
    .page-footer { flex-direction: column; gap: 5px; }
}

@media (max-width: 420px) {
    .topbar { flex-direction: column; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-card:first-child { grid-column: span 2; }
    .login-card { padding: 27px 22px; }
    .client-actions { gap: 5px; }
    .client-actions .button { padding: 6px 8px; }
}
