:root {
    color-scheme: light;
    accent-color: var(--primary);
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e3e8ef;
    --border-strong: #cdd5e0;
    --text: #1b2433;
    --text-muted: #667085;
    --primary: #2457d6;
    --primary-hover: #1c46ae;
    --primary-soft: #e8eefc;
    --sidebar: #111a2e;
    --sidebar-text: #aab4c8;
    --sidebar-active: #ffffff;
    --sidebar-hover: #1b2640;
    --success: #12805c;
    --success-soft: #e3f5ee;
    --warning: #a35c00;
    --warning-soft: #fdf1dc;
    --danger: #c0352b;
    --danger-soft: #fce8e6;
    --info: #2457d6;
    --info-soft: #e8eefc;
    --neutral-soft: #eef1f5;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg: #0d1320;
        --surface: #151d2e;
        --surface-2: #1a2338;
        --border: #263149;
        --border-strong: #34405c;
        --text: #e6eaf2;
        --text-muted: #94a0b8;
        --primary: #5b8cff;
        --primary-hover: #7aa2ff;
        --primary-soft: #1d2b4d;
        --sidebar: #0a0f1a;
        --sidebar-hover: #151d2e;
        --success: #4cc79a;
        --success-soft: #133328;
        --warning: #f0b45a;
        --warning-soft: #3a2a12;
        --danger: #f07167;
        --danger-soft: #3d1a18;
        --info: #7aa2ff;
        --info-soft: #1d2b4d;
        --neutral-soft: #222c42;
        --shadow: none;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 var(--font);
}

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

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

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

.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px;
    color: #fff;
    font-weight: 650;
    font-size: 15px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 12px;
    letter-spacing: .5px;
}

.nav { display: flex; flex-direction: column; gap: 2px; padding: 4px 10px; flex: 1; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-weight: 500;
}
.nav-link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-link.is-active { background: var(--sidebar-hover); color: var(--sidebar-active); }
.nav-link .pill { margin-left: auto; }
.nav-section { padding: 16px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: #6b7690; }

.sidebar-foot { padding: 14px 18px; border-top: 1px solid #1f2a42; font-size: 13px; }
.sidebar-foot .user { color: #fff; font-weight: 600; }
.sidebar-foot .links { display: flex; gap: 12px; margin-top: 4px; }
.sidebar-foot a, .sidebar-foot button { color: var(--sidebar-text); background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.sidebar-foot a:hover, .sidebar-foot button:hover { color: #fff; text-decoration: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 28px 32px 48px; max-width: 1280px; width: 100%; }

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 16px 20px 0; }

.grid { display: grid; gap: 20px; }
.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)); }

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
}
.stat-label { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }
.stat-value.danger { color: var(--danger); }
.stat-foot { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font: 600 13px/1.2 var(--font);
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-link { border: 0; background: none; padding: 0; color: var(--primary); font-weight: 600; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { background: none; border: 0; color: inherit; padding: 6px; cursor: pointer; display: inline-grid; place-items: center; }
form.inline { display: inline; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-weight: 600; font-size: 13px; }
.field .hint { color: var(--text-muted); font-size: 12px; }
.field .field-error { color: var(--danger); font-weight: 600; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=url], input[type=search], input[type=file], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: 14px/1.4 var(--font);
}
textarea { min-height: 90px; resize: vertical; font-family: var(--mono); font-size: 13px; }
input[type=file] { padding: 5px 6px; }
input[type=file]::file-selector-button {
    margin-right: 10px;
    padding: 5px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: 600 13px/1.2 var(--font);
    cursor: pointer;
}
input[type=file]::file-selector-button:hover { background: var(--neutral-soft); }
::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .75; }
::-webkit-calendar-picker-indicator:hover { opacity: 1; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.form-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.form-section { padding-top: 20px; margin-top: 20px; border-top: 1px solid var(--border); }
.form-section > h3 { margin-bottom: 14px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { min-width: 150px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
.empty { padding: 36px 20px; text-align: center; color: var(--text-muted); }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--neutral-soft);
    color: var(--text-muted);
    white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.pill { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 0 7px; line-height: 18px; }

/* Alerts */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-weight: 500; border: 1px solid transparent; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-info { background: var(--info-soft); color: var(--info); }

/* Tabs */
.tabs { display: flex; gap: 4px; box-shadow: inset 0 -1px 0 var(--border); margin-bottom: 20px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.tab { padding: 10px 14px; color: var(--text-muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }

/* Misc */
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 13px; }
.code {
    font-family: var(--mono);
    font-size: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    overflow: auto;
    max-height: 360px;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
}
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
.kv dt { color: var(--text-muted); font-weight: 600; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.pagination { display: flex; gap: 6px; justify-content: flex-end; align-items: center; padding: 12px 16px; border-top: 1px solid var(--border); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.status-dot.ok { background: var(--success); }
.status-dot.bad { background: var(--danger); }
.connection { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.connection:last-child { border-bottom: 0; padding-bottom: 0; }
.connection:first-child { padding-top: 0; }
.connection-name { font-weight: 600; }

/* Auth pages */
body.bare { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.center-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.center-card .brand-mark { width: 40px; height: 40px; font-size: 14px; }
.center-card .code { max-height: 280px; }
.bare-alert { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); width: min(400px, calc(100% - 32px)); }

/* Responsive */
@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 30;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    body.sidebar-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .4); }
    .topbar {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 12px;
        background: var(--sidebar);
        color: #fff;
        position: sticky;
        top: 0;
        z-index: 20;
    }
    .topbar-title { font-weight: 650; }
    .content { padding: 20px 16px 40px; }
    .grid-2, .grid-3, .form-grid { grid-template-columns: minmax(0, 1fr); }
    .form-grid .span-2 { grid-column: auto; }
}

@media (max-width: 520px) {
    .grid-4 { grid-template-columns: minmax(0, 1fr); }
    .center-card { padding: 24px 20px; }
}

.input-auto { width: auto; }
.stack-gap { margin-bottom: 16px; }
details summary { cursor: pointer; }
.details-body { margin-top: 8px; }
.tabs-flat { box-shadow: none; margin-bottom: 0; }
.card.flush .tabs-flat .tab { padding-left: 0; padding-right: 0; margin-right: 18px; }
tr.is-muted td { color: var(--text-muted); }
.input-wide { min-width: 240px; flex: 1; }
.filter-check { align-self: flex-end; padding-bottom: 9px; }
.cell-note { margin-top: 3px; max-width: 320px; }
.card.flush > .card-head:has(.filters) { padding-bottom: 16px; border-bottom: 1px solid var(--border); margin-bottom: 0; }
.stack-gap-sm { margin-bottom: 8px; }
.alert-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
