:root {
  --bg: #f3f4f2;
  --surface: #ffffff;
  --surface-2: #f8f9f7;
  --border: #dcdfda;
  --text: #1d221e;
  --muted: #5e665f;
  --accent: #2f6f4e;
  --accent-soft: #e3efe8;
  --ok: #2f7a45;
  --warn: #9a6b1f;
  --bad: #a63a2f;
  --down: #6b2a8a;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151816;
    --surface: #1d211e;
    --surface-2: #232825;
    --border: #343a36;
    --text: #e6eae6;
    --muted: #9aa39c;
    --accent: #6cbf8f;
    --accent-soft: #23362b;
    --ok: #6cbf8f;
    --warn: #d6a656;
    --bad: #e07a6c;
    --down: #c49be0;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #151816;
  --surface: #1d211e;
  --surface-2: #232825;
  --border: #343a36;
  --text: #e6eae6;
  --muted: #9aa39c;
  --accent: #6cbf8f;
  --accent-soft: #23362b;
  --ok: #6cbf8f;
  --warn: #d6a656;
  --bad: #e07a6c;
  --down: #c49be0;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p { margin: 0 0 10px; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.pad { padding: 16px; }
.small { font-size: 13px; }

header.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header.top .brand { font-weight: 700; margin-right: auto; }

nav.tabs { display: flex; flex-wrap: wrap; gap: 4px; }

nav.tabs button, .btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  cursor: pointer;
}

nav.tabs button.on { background: var(--accent-soft); border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 8px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.badge-count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 12px; text-align: center; }

main { max-width: 1180px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid .card { margin-bottom: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 8px; }

.level { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.level::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.level.ok { color: var(--ok); } .level.ok::before { background: var(--ok); }
.level.warn { color: var(--warn); } .level.warn::before { background: var(--warn); }
.level.bad { color: var(--bad); } .level.bad::before { background: var(--bad); }
.level.down { color: var(--down); } .level.down::before { background: var(--down); }

dl.facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 8px 0 0; font-size: 14px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th, table.list td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.list th { color: var(--muted); font-weight: 600; }
table.list td.num { text-align: right; white-space: nowrap; }

.alert { border-left: 3px solid var(--muted); padding: 6px 10px; margin-bottom: 8px; background: var(--surface-2); border-radius: 6px; }
.alert.bad { border-left-color: var(--bad); }
.alert.warn { border-left-color: var(--warn); }
.alert.ok { border-left-color: var(--ok); }

form.fields { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); align-items: end; }
form.fields .wide { grid-column: 1 / -1; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  width: 100%;
  min-width: 0;
}

textarea { min-height: 90px; resize: vertical; }
label.check input { width: auto; }

.answer { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: 10px; }
.secret { font-family: ui-monospace, Menlo, monospace; word-break: break-all; background: var(--accent-soft); padding: 10px; border-radius: 8px; }

.login { max-width: 360px; margin: 10vh auto; }
.error { color: var(--bad); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 8px;
  z-index: 20;
}

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(560px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
