:root {
  --blue: #044cc8;
  --blue-dark: #033a9b;
  --brown: #602f14;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --line: #e2e5ea;
  --text: #17202e;
  --muted: #66707f;
  --danger: #b3261e;
  --ok: #18794e;
  --warn: #a15c07;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --blue: #5b8def;
    --blue-dark: #7aa4f4;
    --bg: #101317;
    --surface: #191d23;
    --line: #2b3038;
    --text: #e8eaee;
    --muted: #98a1ae;
    --danger: #f2807a;
    --ok: #5cc99a;
    --warn: #e5a54b;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

h1 { font-size: 20px; margin: 12px 0 4px; }
h2 { font-size: 16px; margin: 0; overflow-wrap: anywhere; }
h3 { font-size: 13px; margin: 20px 0 8px; color: var(--muted); font-weight: 600; }
code, .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }

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

input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
input[type="checkbox"] { width: auto; }
textarea { resize: vertical; }

button { font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }

label { display: grid; gap: 4px; font-weight: 500; }
label small { font-weight: 400; color: var(--muted); }
label.check { display: flex; align-items: baseline; gap: 8px; font-weight: 400; flex-wrap: wrap; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 12px; justify-items: stretch; }
.login-card img { justify-self: start; }
.login-card p { margin: 0; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 2; }
.brand { display: flex; align-items: center; gap: 8px; }
.topbar nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
.tab { border: 0; background: transparent; color: var(--muted); font-weight: 500; }
.tab.active { color: var(--blue); background: color-mix(in srgb, var(--blue) 10%, transparent); }
.me { display: flex; align-items: center; gap: 10px; }

.page { padding: 20px; max-width: 1240px; margin: 0 auto; }
.stats { display: flex; gap: 28px; margin-bottom: 16px; flex-wrap: wrap; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; font-weight: 650; }
.stat span { color: var(--muted); font-size: 12.5px; }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1 1 260px; width: auto; }
.toolbar select { flex: 0 1 280px; width: auto; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; min-width: 760px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover { background: color-mix(in srgb, var(--blue) 5%, transparent); }
td .sub { color: var(--muted); font-size: 12.5px; }
td.nowrap { white-space: nowrap; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; border: 1px solid currentColor; white-space: nowrap; }
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--danger); }
.badge.neutral { color: var(--muted); }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 12px; }

.stack { display: grid; gap: 16px; }
.narrow { max-width: 620px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
fieldset { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 16px; margin: 0; display: grid; gap: 12px; min-width: 0; }
legend { font-weight: 600; padding: 0 6px; }
#config-form > button { justify-self: start; }
.report { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }

.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); background: var(--surface); border-left: 1px solid var(--line); box-shadow: -8px 0 28px rgb(0 0 0 / 12%); overflow-y: auto; padding: 20px; z-index: 5; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.device { padding: 8px 0; border-bottom: 1px solid var(--line); }
.device:last-child { border-bottom: 0; }
.device .sub { color: var(--muted); font-size: 12.5px; }

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

@media (max-width: 640px) {
  .page { padding: 12px 16px; }
  .topbar { padding: 10px 16px; }
}
