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

:root {
    --bg: #eef1f6;
    --surface: #ffffff;
    --border: #e4e9f2;
    --text: #111827;
    --muted: #6b7280;
    --faint: #9aa4b2;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --sidebar-bg: #0c1424;
    --sidebar-fg: #c7d0e0;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --amber: #d97706;
    --amber-bg: #fef3c7;
    --blue: #2563eb;
    --blue-bg: #dbeafe;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16,24,40,.05), 0 10px 30px rgba(16,24,40,.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: none; }

.ic { width: 18px; height: 18px; flex: none; }

/* ------------------------------------------------------------------ *
 *  Layout: sidebar + main
 * ------------------------------------------------------------------ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 244px;
    flex: none;
    background: linear-gradient(180deg, #0c1424, #0a111f);
    color: var(--sidebar-fg);
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 20;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 20px 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,.07);
}

.brand-logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #14b8a6, #0f766e);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 6px 16px rgba(20,184,166,.35);
    flex: none;
}
.brand-logo .ic { width: 20px; height: 20px; }

.brand-text { font-weight: 800; font-size: 17px; color: #fff; letter-spacing: .02em; }
.brand-text span { display: block; font-weight: 500; font-size: 11px; color: #7fd1c6; letter-spacing: .18em; text-transform: uppercase; }

.side-nav { padding: 14px 12px; flex: 1; }

.nav-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .14em;
    color: #5b6a83;
    padding: 0 10px;
    margin: 12px 0 6px;
}
.nav-label:first-child { margin-top: 0; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 10px;
    border-radius: 10px;
    color: var(--sidebar-fg);
    font-size: 13.5px;
    font-weight: 500;
    margin-bottom: 2px;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
    background: linear-gradient(90deg, #0f766e, #0d9488);
    color: #fff;
    box-shadow: 0 6px 18px rgba(13,148,136,.28);
}

.nav-router {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 10px;
    border-radius: 9px;
    color: var(--sidebar-fg);
    font-size: 12.5px;
    margin-bottom: 1px;
}
.nav-router:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-router .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-router .st { font-size: 11px; color: #5b6a83; }

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    flex: none;
}
.dot.online { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.dot.offline { background: #64748b; }
.dot.warn { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245,158,11,.2); }

.side-empty { padding: 6px 10px; font-size: 12px; color: #5b6a83; }

.side-foot {
    border-top: 1px solid rgba(255,255,255,.07);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.who { display: flex; align-items: center; gap: 10px; flex: 1; overflow: hidden; }
.who .avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1d4ed8, #0f766e);
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}
.who b { display: block; color: #fff; font-size: 13px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { display: block; font-size: 11px; color: #5b6a83; text-transform: capitalize; }
.logout {
    width: 34px; height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    color: #94a3b8;
}
.logout:hover { background: rgba(255,255,255,.08); color: #fca5a5; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.tophead {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    padding: 22px 26px 0;
}
.tophead h1 { font-size: 21px; font-weight: 800; letter-spacing: -.01em; }
.tophead .crumb { font-size: 12px; color: var(--faint); margin-top: 1px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.datechip {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: 999px;
    padding: 6px 13px;
    font-size: 12px;
    font-weight: 600;
}
.btn.logout-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--muted);
}
.btn.logout-btn:hover { background: var(--red-bg); color: var(--red); border-color: transparent; }

.content { padding: 22px 26px 40px; width: 100%; max-width: 1280px; }

/* ------------------------------------------------------------------ *
 *  Cards, tables, stats
 * ------------------------------------------------------------------ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.card h2 { font-size: 15px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h2 .count { font-weight: 600; color: var(--faint); font-size: 13px; }

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.stat::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: transparent;
}
.stat.green::before { background: var(--green); }
.stat.blue::before { background: var(--blue); }
.stat.orange::before { background: var(--amber); }
.stat.teal::before { background: var(--brand); }
.stat.red::before { background: var(--red); }
.stat .num { font-size: 27px; font-weight: 800; letter-spacing: -.02em; }
.stat .lbl { color: var(--muted); font-size: 12px; font-weight: 600; margin-top: 2px; }
.stat .sub { color: var(--faint); font-size: 12px; margin-top: 2px; }
.stat.green .num { color: var(--green); }
.stat.blue .num { color: var(--blue); }
.stat.orange .num { color: var(--amber); }
.stat.teal .num { color: var(--brand); }
.stat.red .num { color: var(--red); }

table { width: 100%; border-collapse: collapse; }
.card table { display: block; overflow-x: auto; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid #eef2f7; font-size: 13px; vertical-align: middle; }
th {
    color: var(--muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tr:hover td { background: #f8fafc; }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    white-space: nowrap;
}
.badge.active, .badge.completed, .badge.online { background: var(--green-bg); color: #15803d; }
.badge.expired, .badge.failed, .badge.offline { background: var(--red-bg); color: #b91c1c; }
.badge.pending, .badge.processing { background: var(--amber-bg); color: #a16207; }
.badge.neutral { background: #e2e8f0; color: #475569; }

.actions form { display: inline; }
.actions .btn { margin: 2px 2px 2px 0; }

.btn {
    background: var(--brand);
    color: #fff;
    border: 0;
    padding: 8px 15px;
    border-radius: 9px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    justify-content: center;
    transition: background .15s, transform .05s;
}
.btn:hover { background: var(--brand-dark); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #b91c1c; }
.btn.ghost { background: var(--surface); color: #334155; border: 1px solid #cbd5e1; }
.btn.ghost:hover { background: #f1f5f9; color: #111827; }
.btn.block { width: 100%; }
.btn.sm { padding: 5px 11px; font-size: 12px; border-radius: 8px; }
.btn.lg { padding: 11px 18px; font-size: 14px; }
.btn.ic-btn { padding: 7px; }

input[type=text], input[type=password], input[type=search], input[type=number], select {
    border: 1px solid #cbd5e1;
    border-radius: 9px;
    padding: 8px 11px;
    font-size: 13px;
    background: var(--surface);
    color: var(--text);
    width: 100%;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(15,118,110,.12);
}
label { display: block; font-size: 12px; color: #475569; font-weight: 600; margin: 12px 0 4px; }

.form-grid { max-width: 560px; }
.form-grid .btn { margin-top: 16px; }
.form-grid .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.checkline { display: flex; align-items: center; gap: 9px; margin-top: 14px; }
.checkline input { width: auto; }
.checkline label { margin: 0; font-weight: 500; }

.searchbar { display: flex; gap: 8px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.searchbar input[type=search] { flex: 1; max-width: 360px; }

.pager { display: flex; align-items: center; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pager .pinfo { color: var(--muted); font-size: 12px; margin-right: 8px; }
.pager a, .pager span {
    padding: 5px 11px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    background: var(--surface);
    text-decoration: none;
    min-width: 30px;
    text-align: center;
}
.pager a:hover { border-color: var(--brand); color: var(--brand); }
.pager span.cur { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager span.dis { opacity: .45; }

/* ------------------------------------------------------------------ *
 *  Meters / progress bars (router resources)
 * ------------------------------------------------------------------ */
.meter { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; font-size: 12.5px; }
.meter .meter-label { width: 46px; color: var(--muted); font-weight: 600; flex: none; }
.meter .bar {
    flex: 1;
    height: 8px;
    background: #e8edf4;
    border-radius: 999px;
    overflow: hidden;
}
.meter .bar i {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #0d9488, #10b981);
    transition: width .6s ease;
}
.meter .bar i.warn { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.meter .bar i.danger { background: linear-gradient(90deg, #ef4444, #f87171); }
.meter .meter-val { width: 64px; text-align: right; color: var(--text); font-weight: 700; flex: none; }

/* ------------------------------------------------------------------ *
 *  Router tiles / grids
 * ------------------------------------------------------------------ */
.router-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 14px;
}
.router-tile {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px 16px;
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
}
.router-tile:hover { border-color: #cbd5e1; box-shadow: var(--shadow); }
.rt-top { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.rt-top b { font-size: 14px; font-weight: 700; }
.rt-ip { margin-left: auto; color: var(--faint); font-family: Consolas, Menlo, monospace; font-size: 12px; }
.rt-meta { font-size: 12px; color: var(--muted); margin: 2px 0 10px; }
.rt-foot { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.rt-users { font-size: 12px; color: var(--muted); }

.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 1100px) { .cols2 { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ *
 *  Router detail
 * ------------------------------------------------------------------ */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 6px;
}
.info-item {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 10px 13px;
}
.info-item .k { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.info-item .v { font-size: 14px; font-weight: 700; margin-top: 2px; }
.info-item .v.mono { font-family: Consolas, Menlo, monospace; font-size: 13px; }

.warn-box {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--amber-bg);
    border: 1px solid #fcd34d;
    color: #92400e;
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 20px;
    font-size: 13px;
}
.warn-box .ic { color: var(--amber); }

/* ------------------------------------------------------------------ *
 *  Alerts & helpers
 * ------------------------------------------------------------------ */
.error { background: var(--red-bg); color: #b91c1c; border-radius: 10px; padding: 11px 14px; margin-bottom: 14px; font-size: 13px; border: 1px solid #fca5a5; }
.flash { background: var(--green-bg); color: #15803d; border-radius: 10px; padding: 11px 14px; margin-bottom: 16px; font-size: 13px; border: 1px solid #86efac; }
.impersonate { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
    background: var(--amber-bg); color: #92400e; border: 1px solid #fcd34d; border-radius: 10px;
    padding: 11px 14px; margin-bottom: 16px; font-size: 13px; }
.impersonate b { color: #78350f; }
.impersonate span { display: block; margin-top: 2px; color: #a16207; }
.impersonate form { margin: 0; }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }
.empty { text-align: center; color: var(--faint); padding: 30px 0; }
.muted { color: var(--faint); }
.mono { font-family: Consolas, Menlo, monospace; font-size: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------ *
 *  Auth pages (login / setup)
 * ------------------------------------------------------------------ */
.auth-body {
    min-height: 100vh;
    background: radial-gradient(1000px 600px at 80% -10%, rgba(20,184,166,.14), transparent 60%),
                radial-gradient(800px 500px at 0% 110%, rgba(37,99,235,.10), transparent 55%),
                #eef1f6;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-wrap {
    display: flex;
    width: 100%;
    max-width: 950px;
    background: var(--surface);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 24px 70px rgba(16,24,40,.14);
    border: 1px solid var(--border);
}

.auth-brand {
    width: 45%;
    background: linear-gradient(160deg, #0f172a, #0c1b2e 55%, #0b3b36);
    color: #fff;
    padding: 40px 36px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}
.auth-brand::after {
    content: "";
    position: absolute;
    width: 420px; height: 420px;
    right: -180px; top: -160px;
    background: radial-gradient(circle, rgba(20,184,166,.25), transparent 70%);
    pointer-events: none;
}
.auth-brand .ab-brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 18px; }
.auth-brand .ab-brand b { color: #5eead4; font-weight: 700; }
.auth-brand h2 { font-size: 27px; line-height: 1.28; margin: 34px 0 10px; font-weight: 800; letter-spacing: -.01em; }
.auth-brand > p { color: #94a3b8; font-size: 13.5px; margin-bottom: 24px; }
.auth-brand ul { list-style: none; display: flex; flex-direction: column; gap: 12px; margin-top: auto; }
.auth-brand ul li { display: flex; align-items: center; gap: 11px; font-size: 13px; color: #cbd5e1; }
.auth-brand ul li .tick {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: rgba(20,184,166,.18);
    display: flex; align-items: center; justify-content: center;
    color: #5eead4; flex: none;
}
.auth-brand ul li .tick .ic { width: 13px; height: 13px; }
.auth-brand .ab-foot { margin-top: 34px; font-size: 11px; color: #5b6a83; }

.auth-panel {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 44px 40px;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 23px; font-weight: 800; letter-spacing: -.01em; }
.auth-card > p { color: var(--muted); font-size: 13.5px; margin: 5px 0 20px; }

.auth-form .btn { margin-top: 22px; padding: 12px; }
.auth-alt { margin: 18px 0 0; text-align: center; }
.auth-alt a { color: #0d9488; font-weight: 600; }
.input-wrap { position: relative; }
.input-wrap .ic {
    position: absolute;
    left: 11px; top: 50%;
    transform: translateY(-50%);
    width: 17px; height: 17px;
    color: var(--faint);
    pointer-events: none;
}
.input-wrap input { padding-left: 37px; }

/* ------------------------------------------------------------------ *
 *  Responsive
 * ------------------------------------------------------------------ */
@media (max-width: 960px) {
    .layout { display: block; }
    .sidebar {
        position: static;
        width: 100%;
        height: auto;
        max-height: none;
    }
    .side-nav { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 10px 12px; }
    .nav-label { display: none; }
    .nav-item { margin-bottom: 0; }
    .nav-router { }
    .side-foot { display: none; }
    .sidebar .brand { padding: 14px 16px; }
    .main { }
    .tophead { padding: 18px 16px 0; flex-direction: column; align-items: flex-start; }
    .content { padding: 18px 16px 34px; }
    .auth-brand { display: none; }
    .auth-panel { padding: 38px 26px; }
    .form-grid .row2 { grid-template-columns: 1fr; }
}