:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1d2430;
  --muted: #667085;
  --line: #e4e7ec;
  --brand: #2d5bd7;
  --brand-ink: #ffffff;
  --ok: #157f3b;
  --ok-bg: #e7f6ec;
  --warn: #9a6700;
  --warn-bg: #fff6d6;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --info-bg: #eaf0ff;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--brand); }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }

/* Layout */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.top .brand { font-weight: 700; font-size: 15px; }
.top .brand span { color: var(--muted); font-weight: 500; }
.top .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; padding: 0 24px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button {
  border: 0; background: none; padding: 12px 14px; cursor: pointer; color: var(--muted);
  font: inherit; font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.active { color: var(--ink); border-bottom-color: var(--brand); }
main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid .card + .card { margin-top: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }

/* Forms */
label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; background: #fff; color: var(--ink);
}
textarea { font-family: var(--mono); font-size: 12px; min-height: 220px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c9d6fb; border-color: var(--brand); }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff;
  color: var(--ink); padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f2f4f7; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 8px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: progress; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
td.row { display: table-cell; white-space: nowrap; }
td.row > * + * { margin-left: 6px; }
.grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }
.kv dd .btn { font-family: inherit; }

/* Badges & notices */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f2f4f7; color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--brand); }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--info-bg); }
.notice.warn { background: var(--warn-bg); }
.notice.bad { background: var(--bad-bg); }
.notice.ok { background: var(--ok-bg); }
.kv { display: grid; grid-template-columns: max-content 1fr auto; gap: 6px 12px; align-items: center; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 13px; word-break: break-all; }
.stat { font-size: 26px; font-weight: 700; }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 8px; }
pre { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px; overflow: auto; font-size: 12px; max-height: 360px; }

/* Toast */
#toast { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 20; }
#toast div { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 420px; box-shadow: 0 6px 18px rgba(0,0,0,.18); }
#toast div.bad { background: var(--bad); }

/* Login / result pages */
body.center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.narrow { width: 100%; max-width: 420px; }
