:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1c1f24; --muted: #6b7280; --line: #e2e5ea;
  --accent: #2563eb; --danger: #b91c1c; --rail: #1c1f24; --rail-ink: #c9ced6;
  --radius: 8px; --rail-w: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); display: flex; min-height: 100vh; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }

/* layer 1: navrail */
#rail { width: var(--rail-w); flex: none; background: var(--rail); color: var(--rail-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 20; }
.rail-item { position: relative; }
.rail-link { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 0; color: inherit; text-decoration: none; font-size: 11px; }
.rail-link .icon { font-size: 20px; line-height: 1; }
.rail-item.active .rail-link, .rail-item:hover .rail-link { color: #fff; background: rgba(255,255,255,.08); }
.rail-spacer { flex: 1; }
.rail-user { padding: 12px 6px; text-align: center; font-size: 11px; overflow: hidden; }
.rail-user a { color: inherit; }

/* layer 2: flyouts */
.flyout { display: none; position: absolute; left: var(--rail-w); top: 0; min-width: 220px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 0 var(--radius) var(--radius) 0; box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 4px 0 6px; font-size: 14px; }
.rail-item:hover .flyout, .rail-item:focus-within .flyout { display: block; }
.flyout .head { padding: 8px 14px; font-weight: 600; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.flyout a { display: block; padding: 8px 14px; color: inherit; text-decoration: none; white-space: nowrap; }
.flyout a:hover { background: var(--bg); }
.flyout .sub { color: var(--muted); font-size: 12px; margin-left: 6px; }
.flyout .note { padding: 8px 14px; color: var(--muted); }

#main { flex: 1; min-width: 0; padding: 24px; max-width: 1200px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

/* layer 3: sidebar */
.with-sidebar { display: flex; gap: 24px; align-items: flex-start; }
.sidebar { width: 200px; flex: none; }
.sidebar a { display: block; padding: 8px 12px; border-radius: var(--radius); color: inherit; text-decoration: none; border: 1px solid transparent; }
.sidebar a.active { background: var(--panel); border-color: var(--line); font-weight: 600; }
.with-sidebar > section { flex: 1; min-width: 0; }

/* layer 4: tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab { background: none; border: 0; padding: 10px 14px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.active { color: var(--ink); border-color: var(--accent); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.widgets { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.widget h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 10px; }
.widget .big { font-size: 30px; font-weight: 600; line-height: 1.1; margin-bottom: 8px; }
.widget .row { padding: 4px 0; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg); }
td a { text-decoration: none; }
.kv th { width: 130px; text-transform: none; font-size: 14px; letter-spacing: 0; }

.btn { font: inherit; padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; }
.btn:hover { border-color: #b9bec7; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); color: inherit; text-decoration: none; margin: 2px 2px 2px 0; }
.badge.warn { background: #fef3c7; border-color: #fcd34d; }
.badge.good { background: #dcfce7; border-color: #86efac; }

form.stack label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
form.stack input, form.stack select, form.stack textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); }
form.stack input:disabled, form.stack select:disabled { background: var(--bg); }
.err { color: var(--danger); min-height: 1.3em; font-size: 13px; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: min(480px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius); z-index: 100; }
.empty { color: var(--muted); padding: 28px; text-align: center; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }
.auth { margin: auto; width: min(380px, 92vw); }
.auth h1 { margin-bottom: 4px; }
.auth .sub { margin-bottom: 16px; }

@media (max-width: 760px) {
  #rail { position: fixed; top: auto; bottom: 0; left: 0; right: 0; width: auto; height: auto; flex-direction: row; justify-content: space-around; }
  .rail-link { padding: 8px 0; }
  .flyout, .rail-spacer, .rail-user { display: none !important; }
  #main { padding: 16px 16px 84px; }
  .with-sidebar { flex-direction: column; }
  .sidebar { width: auto; display: flex; gap: 4px; overflow-x: auto; }
  .sidebar a { white-space: nowrap; }
}
