:root {
    color-scheme: dark;
    --bg: #080d18;
    --bg-soft: #0d1424;
    --panel: #111a2d;
    --panel-2: #162039;
    --panel-3: #1b2743;
    --border: #22304d;
    --border-soft: #1a2740;
    --text: #e9eefb;
    --muted: #8e9cba;
    --accent: #5b8cff;
    --accent-2: #9d6bff;
    --success: #2fd18b;
    --danger: #ff6b81;
    --warn: #ffb84d;
    --info: #49c5f0;
    --radius: 14px;
    --shadow: 0 18px 50px rgba(0, 0, 0, .28);
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
    margin: 0;
    background:
        radial-gradient(900px 500px at 0% -10%, rgba(91, 140, 255, .13), transparent 60%),
        radial-gradient(700px 400px at 100% 0%, rgba(157, 107, 255, .1), transparent 55%),
        var(--bg);
    color: var(--text);
    font: 14.5px/1.55 var(--font);
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.015em; }
h1 { font-size: 26px; }
h2 { font-size: 18px; }
h3 { font-size: 15.5px; }
p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.tight { margin: 0; }
.break { word-break: break-all; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.right { text-align: right; }
.stack { display: grid; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.divider { height: 1px; background: var(--border-soft); margin: 18px 0; }

/* ---------- shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 244px;
    flex: 0 0 244px;
    background: rgba(8, 13, 24, .86);
    border-right: 1px solid var(--border-soft);
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 22px;
    backdrop-filter: blur(14px);
    z-index: 20;
}

.brand { display: flex; align-items: center; gap: 11px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 11px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    font-weight: 800; font-size: 14px; color: #fff;
    box-shadow: 0 8px 24px rgba(91, 140, 255, .3);
}
.brand-text { display: grid; line-height: 1.2; }
.brand-text strong { font-size: 14.5px; letter-spacing: -.01em; }
.brand-text span { font-size: 11px; color: var(--muted); }

.nav { display: grid; gap: 4px; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: #5d6b8a; padding: 8px 10px 4px; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 11px; border-radius: 10px;
    color: #b6c2dd; font-weight: 520; font-size: 13.5px;
    border: 1px solid transparent;
}
.nav-item:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav-item.active {
    background: linear-gradient(90deg, rgba(91, 140, 255, .17), rgba(157, 107, 255, .08));
    border-color: rgba(91, 140, 255, .28);
    color: #fff;
}
.nav-icon { width: 18px; height: 18px; display: grid; place-items: center; color: #7f91b5; }
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon svg { width: 17px; height: 17px; }

.sidebar-foot { margin-top: auto; display: grid; gap: 10px; }
.sidebar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 10px; border-radius: 11px;
    background: var(--panel); border: 1px solid var(--border-soft);
}
.avatar {
    width: 32px; height: 32px; flex: 0 0 32px; border-radius: 9px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #2a3d68, #364d82);
    font-size: 12px; font-weight: 700; color: #dfe8ff;
}
.sidebar-user .who { min-width: 0; line-height: 1.25; }
.sidebar-user .who strong { display: block; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .who span { display: block; font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-btn {
    background: transparent; border: 1px solid var(--border); color: var(--muted);
    border-radius: 9px; padding: 7px 10px; font: inherit; font-size: 12px; cursor: pointer;
}
.logout-btn:hover { color: var(--text); border-color: #3a4a70; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    padding: 26px 32px 18px;
    display: flex; align-items: flex-end; justify-content: space-between; gap: 18px;
    border-bottom: 1px solid var(--border-soft);
    background: rgba(8, 13, 24, .38);
}
.topbar h1 { font-size: 25px; }
.topbar .subtitle { color: var(--muted); font-size: 13px; margin-top: 4px; }
.content { padding: 26px 32px 60px; max-width: 1500px; width: 100%; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    border: 1px solid transparent; border-radius: 10px;
    padding: 9px 14px; font: inherit; font-size: 13px; font-weight: 620;
    color: #fff; background: var(--accent); cursor: pointer; white-space: nowrap;
    transition: filter .15s, transform .05s, background .15s;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #4b76e8); box-shadow: 0 8px 22px rgba(91, 140, 255, .22); }
.btn-ghost { background: var(--panel); border-color: var(--border); color: #c7d3eb; }
.btn-ghost:hover { border-color: #34466b; color: #fff; }
.btn-danger { background: rgba(255, 107, 129, .12); border-color: rgba(255, 107, 129, .35); color: #ff9eaa; }
.btn-danger:hover { background: rgba(255, 107, 129, .2); }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-xs { padding: 4px 8px; font-size: 11px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn-icon { padding: 7px 9px; }

/* ---------- cards ---------- */
.card {
    background: linear-gradient(180deg, rgba(22, 32, 57, .72), rgba(17, 26, 45, .88));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-head {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-soft);
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { font-size: 15px; }
.card-head .hint { margin: 2px 0 0; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }
.card-foot { padding: 13px 18px; border-top: 1px solid var(--border-soft); background: rgba(8, 13, 24, .22); }
.card-accent { border-top: 2px solid var(--accent); }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); align-items: start; }

/* ---------- stats ---------- */
.stat { padding: 18px; position: relative; }
.stat-label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; }
.stat-value { font-size: 30px; font-weight: 720; letter-spacing: -.03em; margin: 6px 0 2px; line-height: 1.05; }
.stat-value small { font-size: 14px; color: var(--muted); font-weight: 500; }
.stat-foot { color: var(--muted); font-size: 12px; }
.stat-icon {
    position: absolute; right: 16px; top: 16px; width: 34px; height: 34px;
    border-radius: 10px; display: grid; place-items: center;
    background: rgba(91, 140, 255, .1); color: var(--accent); font-size: 15px;
}
.stat-icon.green { background: rgba(47, 209, 139, .1); color: var(--success); }
.stat-icon.purple { background: rgba(157, 107, 255, .12); color: #b795ff; }
.stat-icon.amber { background: rgba(255, 184, 77, .1); color: var(--warn); }

/* ---------- badges / positions ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 8px; border-radius: 999px;
    font-size: 11px; font-weight: 620; letter-spacing: .01em;
    border: 1px solid transparent; white-space: nowrap;
}
.badge-success { background: rgba(47, 209, 139, .11); border-color: rgba(47, 209, 139, .28); color: #7ff0bd; }
.badge-danger { background: rgba(255, 107, 129, .1); border-color: rgba(255, 107, 129, .28); color: #ff9eaa; }
.badge-info { background: rgba(73, 197, 240, .1); border-color: rgba(73, 197, 240, .26); color: #93e3ff; }
.badge-muted { background: rgba(142, 156, 186, .1); border-color: rgba(142, 156, 186, .22); color: #b3bfd8; }
.badge-warn { background: rgba(255, 184, 77, .1); border-color: rgba(255, 184, 77, .26); color: #ffd18a; }

.pos {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 38px; padding: 3px 8px; border-radius: 7px;
    font-size: 12px; font-weight: 720; font-variant-numeric: tabular-nums;
    border: 1px solid transparent;
}
.pos-top { background: rgba(47, 209, 139, .13); border-color: rgba(47, 209, 139, .3); color: #7ff0bd; }
.pos-good { background: rgba(73, 197, 240, .1); border-color: rgba(73, 197, 240, .26); color: #93e3ff; }
.pos-mid { background: rgba(255, 184, 77, .1); border-color: rgba(255, 184, 77, .26); color: #ffd18a; }
.pos-none { background: rgba(142, 156, 186, .08); border-color: rgba(142, 156, 186, .18); color: #8e9cba; }

/* ---------- tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
    text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
    color: #7585a6; font-weight: 650; padding: 11px 14px;
    border-bottom: 1px solid var(--border); background: rgba(8, 13, 24, .24);
    white-space: nowrap;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: rgba(91, 140, 255, .035); }
table.data .num { font-variant-numeric: tabular-nums; }
.cell-url { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.cell-title { font-weight: 600; color: #dbe5fa; }
.cell-sub { color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 12px; font-weight: 600; color: #c2cee6; }
.field .hint { margin: 0; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=search], select, textarea {
    width: 100%; background: #0a1120; color: var(--text);
    border: 1px solid var(--border); border-radius: 9px;
    padding: 9px 11px; font: inherit; font-size: 13px; outline: none;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 140, 255, .15); }
input::placeholder, textarea::placeholder { color: #5c6b8b; }
textarea { min-height: 96px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #7f91b5 50%), linear-gradient(135deg, #7f91b5 50%, transparent 50%); background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.hint { color: var(--muted); font-size: 11.5px; line-height: 1.45; }
.checkline { display: flex; align-items: flex-start; gap: 9px; font-size: 12.5px; color: #c2cee6; cursor: pointer; }
.checkline input[type=checkbox], .checkline input[type=radio] { width: 16px; height: 16px; margin: 1px 0 0; accent-color: var(--accent); flex: 0 0 auto; }
.checkline .hint { display: block; }
.inline-form { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.fieldset { border: 1px solid var(--border-soft); border-radius: 11px; padding: 14px; display: grid; gap: 12px; }
.fieldset legend { padding: 0 7px; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }

/* ---------- tabs ---------- */
.tabs {
    display: flex; gap: 3px; overflow-x: auto;
    border-bottom: 1px solid var(--border-soft);
    margin: 20px 0 22px; padding-bottom: 1px;
}
.tab {
    padding: 9px 13px 10px; border-radius: 9px 9px 0 0;
    color: var(--muted); font-size: 13px; font-weight: 560; white-space: nowrap;
    border: 1px solid transparent; border-bottom: 0;
}
.tab:hover { color: var(--text); text-decoration: none; background: rgba(22, 32, 57, .5); }
.tab.active {
    color: #fff; background: var(--panel);
    border-color: var(--border); border-bottom-color: var(--panel);
    margin-bottom: -1px; font-weight: 650;
}
.tab .count { font-size: 10.5px; color: var(--muted); margin-left: 4px; }

/* ---------- flash / toast ---------- */
.flash {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 11px 14px; border-radius: 11px; margin-bottom: 16px;
    font-size: 13px; border: 1px solid;
}
.flash-success { background: rgba(47, 209, 139, .08); border-color: rgba(47, 209, 139, .3); color: #a5f5cf; }
.flash-error { background: rgba(255, 107, 129, .08); border-color: rgba(255, 107, 129, .3); color: #ffb4be; }
.flash-info { background: rgba(73, 197, 240, .08); border-color: rgba(73, 197, 240, .28); color: #b2ecff; }
.flash-icon { flex: 0 0 auto; font-weight: 800; }

#toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 9px; z-index: 1000; max-width: min(360px, calc(100vw - 40px)); }
.toast {
    padding: 11px 14px; border-radius: 11px; font-size: 12.5px;
    background: #152039; border: 1px solid var(--border); box-shadow: var(--shadow);
    animation: toast-in .2s ease-out;
}
.toast.success { border-color: rgba(47, 209, 139, .4); color: #a5f5cf; }
.toast.error { border-color: rgba(255, 107, 129, .45); color: #ffb4be; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 38px 20px; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 14px; margin-bottom: 5px; }
.toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filters select, .filters input { width: auto; min-width: 130px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; }
.section-title h2 { font-size: 16px; }
.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 6px 12px; font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.list-clean { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.list-clean li { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12.5px; padding-bottom: 9px; border-bottom: 1px solid var(--border-soft); }
.list-clean li:last-child { border-bottom: 0; padding-bottom: 0; }
.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row input { font-family: var(--mono); font-size: 12px; }
details.panel { border: 1px solid var(--border-soft); border-radius: 11px; background: rgba(8, 13, 24, .24); }
details.panel > summary { cursor: pointer; padding: 12px 14px; font-size: 12.5px; font-weight: 600; color: #c2cee6; list-style: none; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before { content: "＋"; color: var(--muted); margin-right: 7px; font-weight: 400; }
details.panel[open] > summary::before { content: "－"; }
details.panel .panel-body { padding: 0 14px 14px; }
.note { border-left: 2px solid var(--accent); padding: 2px 0 2px 12px; color: var(--muted); font-size: 12.5px; }
.warn-note { border-left-color: var(--warn); }
.danger-zone { border-color: rgba(255, 107, 129, .25); background: rgba(255, 107, 129, .035); }
.tag { display: inline-flex; align-items: center; gap: 5px; background: var(--panel-2); border: 1px solid var(--border-soft); padding: 2px 7px; border-radius: 6px; font-size: 10.5px; color: #aab8d4; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.live { background: var(--success); box-shadow: 0 0 0 3px rgba(47, 209, 139, .12); }
.dot.off { background: #506180; }

/* ---------- chart ---------- */
.chart-box { padding: 6px 4px 0; }
.chart-box svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-legend { display: flex; gap: 16px; font-size: 11.5px; color: var(--muted); padding: 0 8px 10px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 40px 18px; }
.auth-card { width: 100%; max-width: 430px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; justify-content: center; }
.auth-card .card-body { padding: 26px; }
.auth-title { text-align: center; margin-bottom: 20px; }
.auth-title h1 { font-size: 22px; }
.auth-title p { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.auth-foot { text-align: center; font-size: 12.5px; color: var(--muted); margin-top: 16px; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-main { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
    .app-shell { display: block; }
    .sidebar {
        width: auto; height: auto; position: static; flex: none;
        border-right: 0; border-bottom: 1px solid var(--border-soft);
        padding: 14px 16px; gap: 12px;
    }
    .brand-text span { display: none; }
    .nav { display: flex; flex-wrap: wrap; gap: 4px; }
    .nav-label { display: none; }
    .nav-item { padding: 7px 10px; font-size: 12.5px; }
    .nav-icon { display: none; }
    .sidebar-foot { margin-top: 0; display: flex; align-items: center; justify-content: space-between; }
    .sidebar-user { border: 0; background: transparent; padding: 0; }
    .topbar { padding: 20px 18px 14px; }
    .content { padding: 20px 18px 50px; }
    .grid-2, .grid-3, .grid-4, .form-grid, .form-grid.three { grid-template-columns: minmax(0, 1fr); }
    .stat-value { font-size: 26px; }
}

/* Admin role split helpers */
.grow { flex: 1 1 auto; }
.badge + .grow { text-align: left; }

/* In-app setup guides */
.guide-steps { margin: 0; padding: 0; list-style: none; counter-reset: guide; }
.guide-step {
    display: flex; gap: 14px; padding: 14px 0;
    border-bottom: 1px solid var(--border-soft);
}
.guide-step:first-child { padding-top: 0; }
.guide-step:last-child { border-bottom: 0; padding-bottom: 0; }
.guide-step strong { font-size: 13.5px; }
.guide-step p { margin: 4px 0 0; }
.guide-num {
    flex: 0 0 auto; width: 28px; height: 28px; border-radius: 8px;
    display: grid; place-items: center; font-size: 12px; font-weight: 700;
    background: rgba(91, 140, 255, .12); color: #9fbcff;
    border: 1px solid rgba(91, 140, 255, .25);
}
.guide-code-row { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.guide-code-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.guide-code {
    display: inline-block; max-width: 100%; padding: 4px 7px; border-radius: 6px;
    background: rgba(8, 13, 24, .5); border: 1px solid var(--border-soft);
    color: #c8d8f6; font-size: 11.5px; word-break: break-all;
}
.guide-code-block { white-space: pre-wrap; line-height: 1.6; }

