:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #dfe2e7;
  --text: #1c1e21;
  --muted: #667085;
  --accent: #1f3a5f;
  --accent-text: #ffffff;
  --ok: #17794a;
  --ok-bg: #e3f4ea;
  --warn: #9a5b00;
  --warn-bg: #fdf1d8;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --info-bg: #e5edf7;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --surface-2: #23272e;
    --border: #333842;
    --text: #e7e9ec;
    --muted: #9aa3b2;
    --accent: #7fa6d9;
    --accent-text: #10151c;
    --ok: #6fd3a0;
    --ok-bg: #173527;
    --warn: #f0c36a;
    --warn-bg: #3a2e12;
    --bad: #ff8f87;
    --bad-bg: #40201e;
    --info-bg: #1f2c3d;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 1rem; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .87rem; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* Layout ---------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .55rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--accent); letter-spacing: .01em; margin-right: .5rem; }
.nav { display: flex; gap: .15rem; flex-wrap: wrap; }
.nav a {
  padding: .4rem .7rem; border-radius: 6px; color: var(--text); text-decoration: none; font-size: .95rem;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--info-bg); color: var(--accent); font-weight: 600; }
main { max-width: 1280px; margin: 0 auto; padding: 1.25rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem;
}
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; }
.tile .num { font-size: 1.6rem; font-weight: 650; line-height: 1.2; }
.tile .label { color: var(--muted); font-size: .87rem; }
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.toolbar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .8rem; }

/* Controls -------------------------------------------------------------- */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 6px; padding: .42rem .8rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none;
  display: inline-block; line-height: 1.3;
}
button:hover, .btn:hover { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.danger { color: var(--bad); }
button.link, .linkbtn {
  border: 0; background: none; padding: 0 .15rem; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit;
}
button.link.danger { color: var(--bad); }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: .42rem .6rem; max-width: 100%;
}
textarea { width: 100%; resize: vertical; font-family: inherit; }
input[type=search] { min-width: 17rem; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { font-weight: 600; font-size: .92rem; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span {
  position: absolute; inset: 0; border-radius: 26px; background: var(--border); transition: background .15s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Tables ---------------------------------------------------------------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; }
td .sub { color: var(--muted); font-size: .85rem; }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); }

/* Status ---------------------------------------------------------------- */
.badge {
  display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .8rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-bg); color: var(--accent); border-color: transparent; }
.notice { padding: .6rem .8rem; border-radius: 6px; margin-bottom: .8rem; font-size: .93rem; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.info { background: var(--info-bg); }
.rating { font-weight: 650; white-space: nowrap; }
.rating .star { color: #d99a00; }

.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: .8rem; }
.tabs button { border-radius: 99px; padding: .3rem .75rem; font-size: .9rem; }
.tabs button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.tabs .count { opacity: .75; margin-left: .25rem; }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: .6rem; padding: .35rem 0; }
.checklist .mark { flex: none; width: 1.3rem; text-align: center; font-weight: 700; }
.checklist .mark.ok { color: var(--ok); }
.checklist .mark.todo { color: var(--warn); }
.checklist code { word-break: break-all; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .3rem .2rem .6rem;
  border: 1px solid var(--border); border-radius: 99px; background: var(--surface-2); font-size: .9rem;
}
.chip.off { opacity: .5; }
.chip input { margin: 0; }
.chip button { border: 0; background: none; padding: 0 .3rem; color: var(--muted); font-size: 1rem; line-height: 1; }
.chip button:hover { color: var(--bad); }
.chip.suggest { cursor: pointer; padding-right: .6rem; border-style: dashed; }
.chip.suggest:hover { background: var(--info-bg); }

/* Settings -------------------------------------------------------------- */
.field { display: grid; grid-template-columns: minmax(180px, 260px) 1fr; gap: .3rem 1rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: 0; }
.field .help { grid-column: 2; color: var(--muted); font-size: .86rem; }
.field input[type=text], .field input[type=password], .field textarea { width: 100%; max-width: 640px; }
.field input[type=number] { width: 8rem; }
@media (max-width: 720px) { .field { grid-template-columns: 1fr; } .field .help { grid-column: 1; } }
.savebar {
  position: sticky; bottom: 0; display: flex; gap: .8rem; align-items: center; padding: .7rem 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 -2px 8px rgba(0,0,0,.06);
}

/* Login ----------------------------------------------------------------- */
.login { max-width: 360px; margin: 14vh auto 0; }
.login input { width: 100%; margin: .4rem 0 .8rem; }
.login button { width: 100%; }

/* Toasts ---------------------------------------------------------------- */
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; max-width: min(420px, 90vw); }
.toast {
  background: var(--text); color: var(--bg); padding: .6rem .9rem; border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.25); font-size: .93rem;
}
.toast.bad { background: var(--bad); color: #fff; }

details.more summary { cursor: pointer; color: var(--accent); }
pre.json { margin: .4rem 0 0; font-size: .82rem; white-space: pre-wrap; word-break: break-word; color: var(--muted); }
