:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --sunken: #f4f4f5;
  --line: #e4e4e7;
  --text: #18181b;
  --muted: #71717a;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #ca8a04;
  --radius: 8px;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0c0e;
    --panel: #141417;
    --sunken: #1b1b1f;
    --line: #27272a;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --accent: #fb7a32;
    --accent-ink: #120700;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 14px; font-weight: 600; margin: 0 0 12px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden, [hidden] { display: none !important; }

.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; padding: 0 10px 18px; }
.brand-mark { width: 18px; height: 18px; border-radius: 5px; background: var(--accent); }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 14px 10px 4px; }
.nav a {
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--muted);
}
.nav a:hover { color: var(--text); background: var(--sunken); }
.nav a.active { color: var(--text); background: var(--sunken); font-weight: 500; }
.side-foot { margin-top: auto; padding: 10px; }

main { padding: 28px 36px 60px; max-width: 1240px; width: 100%; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.head .actions { display: flex; gap: 8px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
  white-space: nowrap;
}
.btn:hover { background: var(--sunken); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; box-shadow: none; background: transparent; }
.btn:disabled { opacity: 0.5; cursor: default; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  width: 100%;
  min-width: 0;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
input[type='checkbox'] { width: auto; accent-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
label.field > span { font-weight: 500; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
.form { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form .full { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 500; color: var(--muted); background: var(--sunken); }
tr:last-child td { border-bottom: none; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: var(--sunken); }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: var(--panel); }
.empty { padding: 36px; text-align: center; color: var(--muted); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 500; border: 1px solid var(--line); color: var(--muted); }
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }

.keybox { display: flex; align-items: center; gap: 8px; font-family: var(--mono); background: var(--sunken); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; word-break: break-all; }
.keybox span { flex: 1; }
pre.code { background: var(--sunken); border: 1px solid var(--line); border-radius: 6px; padding: 12px; overflow: auto; font-family: var(--mono); font-size: 12px; line-height: 1.55; margin: 0; max-height: 460px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { background: none; border: none; font: inherit; color: var(--muted); padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.chart { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .bars { width: 100%; max-width: 38px; display: flex; flex-direction: column-reverse; border-radius: 4px; overflow: hidden; }
.chart .ok { background: var(--accent); }
.chart .bad { background: color-mix(in srgb, var(--bad) 70%, transparent); }
.chart .day { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px; z-index: 40; overflow: auto; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; width: 100%; max-width: 620px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); }
.modal.wide { max-width: 860px; }
.modal header { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal .body { padding: 18px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.toast-wrap { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 6px; font-size: 13px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2); }
.toast.bad { background: var(--bad); color: #fff; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 360px; padding: 26px; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv.wide { grid-template-columns: 210px 1fr; }
.kv dd { margin: 0; word-break: break-all; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12px; background: var(--sunken); border: 1px solid var(--line); border-radius: 5px; padding: 2px 4px 2px 8px; }
.chip button { border: none; background: none; color: var(--muted); cursor: pointer; padding: 0 3px; font-size: 14px; line-height: 1; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.step { display: flex; gap: 12px; }
.step b { width: 22px; height: 22px; border-radius: 50%; background: var(--sunken); border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; flex: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--line); }
  .nav-label, .side-foot { display: none; }
  main { padding: 20px 16px; }
  .g4, .g3, .g2, .form { grid-template-columns: 1fr 1fr; }
}
