:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e4e7ec;
  --accent: #c0392b;
  --accent-ink: #ffffff;
  --accent-soft: #fbeceb;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a20;
    --panel-2: #1d2129;
    --text: #e6e8eb;
    --muted: #9aa3af;
    --line: #2a2f38;
    --accent: #e5533f;
    --accent-soft: #3a1d1a;
    --ok: #4ade80;
    --ok-soft: #133021;
    --warn: #fbbf24;
    --warn-soft: #3a2c10;
    --bad: #f87171;
    --bad-soft: #3a1717;
    --info: #93b4ff;
    --info-soft: #1a2440;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 10px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); min-height: 1em; margin: 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.right { text-align: right; }

/* ---------- inputs & buttons ---------- */
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 1px; border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
label.check input { width: auto; }

.btn {
  font: inherit; font-weight: 500;
  border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px; cursor: pointer;
  background: var(--panel-2); color: var(--text);
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { background: var(--panel-2); }
.btn.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.btn.danger { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.xs { padding: 3px 8px; font-size: 12px; }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; padding: 0; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.muted { background: var(--panel-2); color: var(--muted); }
.pill.info { background: var(--info-soft); color: var(--info); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { font-size: 22px; }
.login-card p { margin: 0; }

/* ---------- layout ---------- */
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand .logo { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.brand .sub { font-weight: 500; color: var(--muted); font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tab { background: none; border: 0; font: inherit; color: var(--muted); padding: 8px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.top-actions { display: flex; align-items: center; gap: 10px; }

.main { max-width: 1200px; margin: 0 auto; padding: 20px; }
.view { display: flex; flex-direction: column; gap: 16px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); cursor: default; text-align: left; font: inherit; color: inherit; }
button.card { cursor: pointer; }
button.card:hover { border-color: var(--accent); }
.card .label { color: var(--muted); font-size: 12px; }
.card .value { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.card .foot { color: var(--muted); font-size: 12px; margin-top: 2px; }
.card.ok .value { color: var(--ok); }
.card.warn .value { color: var(--warn); }
.card.bad .value { color: var(--bad); }

.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.panel.flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.sw.ok { background: var(--ok); }
.sw.fail { background: var(--bad); }

/* chart */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 170px; padding-top: 6px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; height: 100%; justify-content: flex-end; }
.chart .stack { width: 100%; max-width: 28px; display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; background: var(--panel-2); min-height: 2px; }
.chart .seg.ok { background: var(--ok); }
.chart .seg.fail { background: var(--bad); }
.chart .lbl { font-size: 10px; color: var(--muted); white-space: nowrap; }
.chart .empty { color: var(--muted); font-size: 13px; margin: auto; }

/* lists */
.mini-list { display: flex; flex-direction: column; }
.mini-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.mini-item:last-child { border-bottom: 0; }
.mini-item .main-txt { min-width: 0; }
.mini-item .main-txt > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* toolbar & table */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1 1 260px; }
.toolbar select { flex: 0 0 auto; width: auto; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table.clickable tbody tr { cursor: pointer; }
.table.clickable tbody tr:hover td { background: var(--panel-2); }
.table.compact th, .table.compact td { padding: 6px 8px; }
.table .empty-row td { text-align: center; color: var(--muted); padding: 28px 12px; }
.table code { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.sub-line { color: var(--muted); font-size: 12px; }
.bar { display: inline-block; width: 50px; height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; vertical-align: middle; margin-left: 6px; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.bar.full > i { background: var(--warn); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.pager .btns { display: flex; gap: 6px; }

/* dialogs */
.dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--panel); color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.dialog.small { width: min(400px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(10, 12, 16, .45); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 6px; }
.dlg-body { padding: 10px 18px; }
.dlg-body h3 { margin-bottom: 6px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span2 { grid-column: 1 / -1; }
.key-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; }
.key-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--panel-2); border-radius: 8px; padding: 8px 10px; }
.key-item code { font-size: 15px; letter-spacing: .03em; }

/* drawer */
.backdrop { position: fixed; inset: 0; background: rgba(10, 12, 16, .35); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--panel); border-left: 1px solid var(--line); z-index: 21; overflow-y: auto; box-shadow: -10px 0 30px rgba(0, 0, 0, .15); }
.drawer-inner { padding: 18px 20px 30px; display: flex; flex-direction: column; gap: 6px; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.key-line { display: flex; align-items: center; gap: 4px; margin: 2px 0 6px; }
.key-line code { font-size: 18px; font-weight: 600; letter-spacing: .03em; }
.drawer-sec { padding: 14px 0; border-bottom: 1px solid var(--line); }
.drawer-sec:last-child { border-bottom: 0; }
.quick { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.danger-zone p { margin: 10px 0 0; }

/* toasts */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 13px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.toast.err { background: var(--bad); color: #fff; }

/* responsive */
@media (max-width: 900px) {
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  .tabs { order: 3; flex-basis: 100%; }
  .main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .toolbar select { flex: 1 1 45%; }
}
