:root {
  --bg: #f6f7f9; --panel: #ffffff; --panel-2: #f1f3f6; --border: #e3e6eb; --text: #14161a;
  --muted: #6b7280; --accent: #4f46e5; --accent-soft: #eef0ff; --ok: #16a34a; --ok-soft: #e8f7ee;
  --warn: #b45309; --warn-soft: #fdf3e3; --err: #dc2626; --err-soft: #fdecec; --run: #2563eb; --run-soft: #e8f0fe;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f12; --panel: #16181d; --panel-2: #1d2027; --border: #2a2e37; --text: #e8eaee;
    --muted: #9aa1ad; --accent: #8b8cf8; --accent-soft: #23244a; --ok: #4ade80; --ok-soft: #13291c;
    --warn: #fbbf24; --warn-soft: #2d2410; --err: #f87171; --err-soft: #321616; --run: #60a5fa; --run-soft: #142338;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 650; font-size: 15px; display: flex; gap: 8px; align-items: center; padding: 0 8px; }
.logo { color: var(--accent); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: var(--text); padding: 7px 10px; border-radius: 7px; }
.sidebar nav a:hover { background: var(--panel-2); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 0 10px; font-size: 13px; }
.view { padding: 28px 32px 60px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { margin-top: 4px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }

/* panels */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card .card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.card.flush .card-head { padding: 14px 18px 0; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-size: 24px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12.5px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; word-break: break-word; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--panel-2); }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 550;
  padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.run { background: var(--run-soft); color: var(--run); }
.badge.run::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* buttons + forms */
.btn { font: inherit; font-weight: 550; border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 7px 13px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; cursor: pointer; text-align: left; }
button.link:hover { color: var(--text); }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }
label .help { font-weight: 400; color: var(--muted); font-size: 12.5px; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { font-family: var(--mono); font-size: 12.5px; min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px 18px; }
.form-grid .wide { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin: 0 0 16px; background: var(--panel); }
legend { font-weight: 650; padding: 0 6px; }
details.adv > summary { cursor: pointer; color: var(--muted); margin-bottom: 12px; }
.types { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.type-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; display: block; font-weight: 400; }
.type-card input { display: none; }
.type-card b { display: block; margin-bottom: 2px; }
.type-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.error { color: var(--err); font-size: 13px; min-height: 1em; }
.search-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.search-bar input { flex: 1; min-width: 200px; }
.search-bar select { width: auto; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; overflow-y: hidden; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* results, code */
.result { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; background: var(--panel); }
.result .t { font-weight: 600; margin-bottom: 4px; }
.result .f { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.result .a { color: var(--muted); font-size: 13px; }
pre.code { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px;
  overflow: auto; font-family: var(--mono); font-size: 12.5px; margin: 0; max-height: 420px; white-space: pre; }
.code-head { display: flex; justify-content: space-between; align-items: center; margin: 16px 0 6px; }
.keybox { font-family: var(--mono); background: var(--panel-2); border: 1px dashed var(--accent); padding: 12px; border-radius: 8px; word-break: break-all; }
.progress { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--run); transition: width .4s; }

/* dialog, toast, login */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 22px; background: var(--panel); color: var(--text);
  width: min(520px, 92vw); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 12, 16, .45); }
dialog .actions { justify-content: flex-end; margin-top: 18px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text);
  color: var(--bg); padding: 9px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 10; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--err); color: #fff; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: min(360px, 100%);
  display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-card .brand { padding: 0; font-size: 18px; }
.login-card p { margin: -8px 0 4px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; padding: 10px 12px; }
  .sidebar nav { flex-direction: row; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; gap: 12px; }
  .view { padding: 18px 16px 40px; }
}
