:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  --primary-soft: #e8efff;
  --success: #059669;
  --success-soft: #e3f7ef;
  --warning: #b45309;
  --warning-soft: #fdf2dc;
  --danger: #dc2626;
  --danger-soft: #fde8e8;
  --sidebar: #0b1220;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #64748b;
  --sidebar-active: #1e293b;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .04);
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #0a0f1a;
  --surface: #111827;
  --surface-2: #0f1623;
  --border: #1f2a3c;
  --text: #e5e9f0;
  --muted: #8b98ad;
  --primary: #3b82f6;
  --primary-600: #60a5fa;
  --primary-soft: #16233d;
  --success: #34d399;
  --success-soft: #0f2a22;
  --warning: #fbbf24;
  --warning-soft: #2c230f;
  --danger: #f87171;
  --danger-soft: #2f1517;
  --sidebar: #070b14;
  --sidebar-active: #152033;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.hidden { display: none !important; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  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 20px 16px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #2563eb, #06b6d4); color: #fff; font-weight: 800; font-size: 14px; letter-spacing: .5px;
}
.brand b { color: #fff; font-size: 15px; display: block; }
.brand small { color: var(--sidebar-muted); font-size: 11.5px; }
.nav { padding: 8px 12px 16px; flex: 1; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--sidebar-muted); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500; margin: 1px 0;
}
.nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #3b82f6; }
.nav a svg.i { width: 17px; height: 17px; opacity: .85; }
.sidebar-foot { padding: 14px 20px; border-top: 1px solid #1a2336; font-size: 12px; color: var(--sidebar-muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 28px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700; text-transform: uppercase; font-size: 13px;
}
.user-chip .meta { line-height: 1.2; }
.user-chip .meta small { color: var(--muted); font-size: 11.5px; }
.content { padding: 28px; max-width: 1280px; width: 100%; margin: 0 auto; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }
.grid { display: grid; gap: 16px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.stat { padding: 18px 20px; display: flex; gap: 14px; align-items: flex-start; }
.stat .ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.stat .ico.g { background: var(--success-soft); color: var(--success); }
.stat .ico.w { background: var(--warning-soft); color: var(--warning); }
.stat .ico.r { background: var(--danger-soft); color: var(--danger); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.meter { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .6s ease; }
.meter.warn > span { background: #f59e0b; }
.meter.crit > span { background: var(--danger); }
.gauge-row { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 6px; }
.gauge-row b { font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg.i { width: 16px; height: 16px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: 32px; padding: 0; height: 32px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.loading { pointer-events: none; opacity: .7; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.warn { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 4px; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg.i { width: 36px; height: 36px; opacity: .45; margin-bottom: 8px; }
.empty h4 { margin: 0 0 4px; color: var(--text); font-size: 15px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; }
.input, select.input, textarea.input {
  height: 38px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; width: 100%; outline: none;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: 8px 0 0 8px; }
.input-group .addon { display: flex; align-items: center; padding: 0 12px; border: 1px solid var(--border); border-left: 0; border-radius: 0 8px 8px 0; background: var(--surface-2); color: var(--muted); white-space: nowrap; font-size: 13px; }
.input-group .addon.pre { border-left: 1px solid var(--border); border-right: 0; border-radius: 8px 0 0 8px; }
.input-group .addon.pre + .input { border-radius: 0 8px 8px 0; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; white-space: pre-wrap; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: flex; gap: 7px; align-items: center; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs a svg.i { width: 16px; height: 16px; }

/* Definition list */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 10px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

pre.code {
  background: #0b1220; color: #d6deeb; padding: 16px; border-radius: 10px; overflow: auto; max-height: 520px; margin: 0;
  line-height: 1.55; border: 1px solid var(--border);
}

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); display: grid; place-items: center; padding: 20px; z-index: 100; animation: fade .15s ease; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: pop .18s ease; border: 1px solid var(--border); }
.modal.lg { max-width: 860px; }
.modal.xl { max-width: 1100px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* Toast */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--text); color: var(--surface); padding: 11px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 380px; font-weight: 500; animation: pop .2s ease; display: flex; gap: 10px; align-items: flex-start; }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: #047857; color: #fff; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero {
  background: radial-gradient(circle at 20% 20%, #1e3a8a 0, transparent 50%), radial-gradient(circle at 80% 80%, #0e7490 0, transparent 45%), #0b1220;
  color: #e2e8f0; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
}
.login-hero h2 { font-size: 34px; font-weight: 750; letter-spacing: -.02em; color: #fff; max-width: 460px; margin: 24px 0 12px; }
.login-hero p { color: #94a3b8; max-width: 440px; font-size: 15px; }
.login-hero ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.login-hero li { display: flex; gap: 10px; align-items: center; color: #cbd5e1; }
.login-hero li svg.i { color: #38bdf8; }
.login-form { display: grid; place-items: center; padding: 40px 24px; background: var(--surface); }
.login-form form { width: 100%; max-width: 360px; }
.login-form h1 { font-size: 24px; margin-bottom: 4px; }
.login-form .sub { color: var(--muted); margin: 0 0 26px; }

/* File manager */
.fm-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.fm-path { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; font-size: 13px; flex: 1; min-width: 200px; }
.fm-path a { padding: 3px 6px; border-radius: 6px; color: var(--text); font-weight: 500; }
.fm-path a:hover { background: var(--surface-2); text-decoration: none; }
.fm-path span { color: var(--muted); }
.fm-name { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.fm-name svg.i { color: var(--muted); }
.fm-name.dir svg.i { color: #f59e0b; }
.fm-drop { outline: 2px dashed var(--primary); outline-offset: -6px; }
textarea.editor { font-family: var(--mono); font-size: 13px; line-height: 1.55; min-height: 60vh; white-space: pre; tab-size: 4; background: var(--surface-2); }

.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; gap: 12px; padding: 11px 20px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.list .when { color: var(--muted); font-size: 12px; white-space: nowrap; margin-left: auto; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 16px; }
.alert { padding: 12px 14px; border-radius: 10px; display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; }
.alert.info { background: var(--primary-soft); color: var(--primary); }
.alert.warn { background: var(--warning-soft); color: var(--warning); }
.alert svg.i { margin-top: 1px; }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-block { padding: 48px; display: grid; place-items: center; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(2,6,23,.5); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px; }
  .g-2, .g-3, .g-4 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .user-chip .meta { display: none; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 10px; }
  .hide-sm { display: none; }
}
