:root {
  --page: #f6f6f3;
  --surface: #ffffff;
  --surface-soft: #f4f3ef;
  --sidebar: #fbfbf9;

  --border: #e7e5df;
  --border-strong: #d6d4cc;

  --text: #1b1b18;
  --text-2: #6c6b64;
  --text-muted: #9a988f;

  --accent: #2f6fed;
  --accent-bg: #e9f0fd;
  --accent-text: #1a4fb0;

  --green: #1f7a55;   --green-bg: #e3f4ec;
  --amber: #9a6a00;   --amber-bg: #fbefd8;
  --red: #c23b34;     --red-bg: #fbe9e7;
  --purple: #6a4bc0;  --purple-bg: #ece8fb;

  --radius: 9px;
  --radius-lg: 13px;
  --shadow: 0 1px 2px rgba(20, 20, 18, .04);

  /* Native UI stack — no download, no FOUT, renders on first paint. Segoe UI on
     Windows / SF on macOS are what the OS chrome itself uses, so it reads as a real
     desktop tool rather than a web page pretending to be one. */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI Variable Text', 'Segoe UI',
          Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', Consolas, monospace;
}

[data-theme="dark"] {
  --page: #191917;
  --surface: #222220;
  --surface-soft: #2b2b27;
  --sidebar: #1d1d1b;
  --border: #34332e;
  --border-strong: #46453d;
  --text: #ededea;
  --text-2: #b2b1a7;
  --text-muted: #84837a;
  --accent: #5b8def;
  --accent-bg: #1f2c44;
  --accent-text: #a9c6f7;
  --green: #5fce99;  --green-bg: #16301f;
  --amber: #e3a73f;  --amber-bg: #372c14;
  --red: #ec7a72;    --red-bg: #3a1f1d;
  --purple: #b09cf8; --purple-bg: #272042;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-weight: 600; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.sm { width: 15px; height: 15px; }

/* ---------- shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 224px; flex: none; background: var(--sidebar);
  border-right: 1px solid var(--border); padding: 16px 12px;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 6px 8px 16px; }
.brand .logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); flex: none; display: flex; align-items: center; justify-content: center; }
.brand .logo .icon { stroke: #fff; width: 15px; height: 15px; }
.brand-name { font-size: 14px; font-weight: 600; }

.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); padding: 14px 8px 6px; font-weight: 600; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 9px; border-radius: var(--radius); color: var(--text-2); font-size: 13.5px; font-weight: 500; cursor: pointer; }
.nav-item:hover { background: var(--surface-soft); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent-text); }
.nav-spacer { flex: 1; }
.nav-user { display: flex; align-items: center; gap: 8px; padding: 8px; font-size: 12px; color: var(--text-2); border-top: 1px solid var(--border); margin-top: 8px; padding-top: 14px; }
.nav-user form { margin: 0 0 0 auto; }
.nav-user button { padding: 4px 8px; font-size: 11.5px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; flex: none; border-bottom: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 0 26px;
  position: sticky; top: 0; z-index: 5;
}
.crumbs { font-size: 13.5px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.crumbs b { color: var(--text); font-weight: 600; }
.content { padding: 24px 26px 48px; max-width: 1180px; display: flex; flex-direction: column; gap: 16px; }

.login-shell { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 40px; background: var(--page); }

/* ---------- buttons ---------- */
button {
  font-family: inherit; font-size: 13px; cursor: pointer; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); padding: 7px 13px; border-radius: var(--radius);
  display: inline-flex; align-items: center; gap: 6px; transition: background .12s;
}
button:hover { background: var(--surface-soft); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #2a63d4; }
button.ghost { border-color: transparent; background: transparent; }
button.danger { color: var(--red); border-color: transparent; background: transparent; }
button.danger:hover { background: var(--red-bg); border-color: var(--red-bg); }
.btn-xs { font-size: 12px; padding: 5px 10px; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.row-actions form { display: inline; margin: 0; }

/* ---------- disclosure (advanced options) ---------- */
/* Native <details> so it costs no JS and works before any script parses. */
details.disclose { border-top: 1px solid var(--border); margin-top: 15px; padding-top: 13px; }
details.disclose > summary {
  cursor: pointer; list-style: none; font-size: 13px; font-weight: 500; color: var(--text-2);
  display: flex; align-items: center; gap: 7px; user-select: none; padding: 2px 0;
}
details.disclose > summary::-webkit-details-marker { display: none; }
details.disclose > summary::before {
  content: ""; width: 6px; height: 6px; flex: none; border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor; transform: rotate(-45deg); margin-left: 3px;
  transition: transform .15s;
}
details.disclose[open] > summary::before { transform: rotate(45deg); }
details.disclose > summary:hover { color: var(--text); }
details.disclose .disclose-body { padding-top: 14px; }

/* ---------- cards / kpi ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 17px 19px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-head h3 { font-size: 14.5px; }
.card-head .hint { font-size: 12px; color: var(--text-muted); }

.grid { display: grid; gap: 14px; }
.kpi-grid { grid-template-columns: repeat(4, 1fr); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 15px 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12.5px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 25px; font-weight: 600; margin-top: 7px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi.danger .value { color: var(--red); }
.kpi.warning .value { color: var(--amber); }

@media (max-width: 1080px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) { .kpi-grid { grid-template-columns: 1fr; } }

/* Narrow window: collapse the sidebar to an icon rail rather than letting a fixed
   224px column eat most of the viewport. Labels go, icons and targets stay. */
@media (max-width: 860px) {
  .sidebar { width: 56px; padding: 14px 8px; align-items: center; }
  .sidebar .brand-name,
  .sidebar .nav-label,
  .sidebar .nav-item > :not(.icon),
  .nav-user .avatar ~ * :not(button) { display: none; }
  .nav-item { justify-content: center; padding: 9px 0; }
  .nav-user { flex-direction: column; gap: 6px; font-size: 0; }
  .nav-user button { font-size: 11px; }
  .brand { padding: 6px 0 14px; justify-content: center; }
  .topbar { padding: 0 14px; }
  .content { padding: 16px 14px 40px; }
}

/* ---------- badges ---------- */
.badge { font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 20px; display: inline-flex; align-items: center; gap: 5px; }
.badge.green  { background: var(--green-bg);  color: var(--green); }
.badge.amber  { background: var(--amber-bg);  color: var(--amber); }
.badge.red    { background: var(--red-bg);    color: var(--red); }
.badge.blue   { background: var(--accent-bg); color: var(--accent-text); }
.badge.gray   { background: var(--surface-soft); color: var(--text-2); }
.badge.purple { background: var(--purple-bg); color: var(--purple); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { text-align: left; font-weight: 500; color: var(--text-muted); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.sev-error td:first-child { box-shadow: inset 3px 0 var(--red); }
tr.sev-warning td:first-child { box-shadow: inset 3px 0 var(--amber); }
tr.sev-notice td:first-child { box-shadow: inset 3px 0 var(--accent); }

table.sortable thead th:not([data-nosort]) { cursor: pointer; user-select: none; }
table.sortable thead th:not([data-nosort]):hover { color: var(--text); }
.sort-caret { font-size: 10px; color: var(--accent); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 4px; flex-wrap: wrap; }
.tab { padding: 9px 12px; font-size: 13.5px; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-text); border-bottom-color: var(--accent); }

/* ---------- forms ---------- */
.field { margin-bottom: 0; }
.field > label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-2); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 9px 11px; font-family: inherit; font-size: 13.5px; outline: none;
  background: var(--surface); color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg);
}
.field .hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.field-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.field-row > .field { flex: 1; min-width: 160px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); }
.check input { width: auto; }

/* ---------- expandable list items (config rows that edit in place) ---------- */
.item-list { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; background: var(--surface); }
.item { border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: none; }
.item > summary {
  display: flex; align-items: center; gap: 12px; padding: 10px 13px; cursor: pointer;
  list-style: none; font-size: 13.5px;
}
.item > summary::-webkit-details-marker { display: none; }
.item > summary:hover { background: var(--surface-soft); }
.item[open] > summary { background: var(--surface-soft); border-bottom: 1px solid var(--border); }
.item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .item-body { padding: 15px 13px; background: var(--surface-soft); }
.mono { font-family: var(--font-mono); font-size: 12.5px; }

/* ---------- avatar ---------- */
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--purple-bg); color: var(--purple); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex: none; }

/* ---------- misc ---------- */
.muted { color: var(--text-muted); }
.empty { color: var(--text-muted); font-size: 13.5px; padding: 6px 2px; }
