:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f1ede4;
  --text: #1f1c17;
  --muted: #6b6457;
  --border: #e3ddd0;
  --accent: #b87708;
  --accent-strong: #8f5b00;
  --accent-soft: #fbefd6;
  --ok: #2f7d4f;
  --warn: #b25b00;
  --bad: #b3261e;
  --chart-1: #b87708;
  --chart-2: #2b6cb0;
  --chart-3: #2f7d4f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15130f;
    --surface: #1f1c17;
    --surface-2: #2a261f;
    --text: #f1ece2;
    --muted: #a99f8d;
    --border: #3a342a;
    --accent: #f0b33a;
    --accent-strong: #ffc85c;
    --accent-soft: #3a2c10;
    --ok: #5fc48a;
    --warn: #f0a050;
    --bad: #ff7b72;
    --chart-1: #f0b33a;
    --chart-2: #6aa8f0;
    --chart-3: #5fc48a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent-strong); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: .75rem 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.logo { width: 22px; height: 22px; background: url(/favicon.svg) center / contain no-repeat; }
nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
nav a { color: var(--muted); text-decoration: none; font-weight: 500; }
nav a.active { color: var(--text); border-bottom: 2px solid var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 16px 3rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

.device-card { display: block; text-decoration: none; color: inherit; transition: border-color .15s; }
.device-card:hover, .device-card:focus-visible { border-color: var(--accent); }
.device-card .head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.device-card .name { font-weight: 600; font-size: 1.05rem; }
.big { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .5rem; }
.kv { font-variant-numeric: tabular-nums; }
.kv b { font-weight: 600; }

.badge { display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.up { color: var(--ok); } .down { color: var(--bad); }

.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin: 1rem 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; }
.tile .label { color: var(--muted); font-size: .8rem; }
.tile .value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.segmented button { border: 0; border-radius: 0; background: var(--surface); color: var(--text); padding: .4rem .8rem; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; }

.chart-box { position: relative; height: 280px; }
.chart-box.small { height: 180px; }

form.stack { display: grid; gap: .75rem; max-width: 380px; }
label { display: grid; gap: .25rem; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem .65rem; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: .5rem 1rem;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
button.danger { background: var(--surface); color: var(--bad); border-color: var(--bad); }
button.link { background: none; border: 0; padding: 0; color: var(--muted); font-weight: 500; }
button:disabled { opacity: .6; cursor: default; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.error { color: var(--bad); }
.login-wrap { max-width: 380px; margin: 3rem auto; }
.secret {
  font-family: ui-monospace, Consolas, monospace; font-size: 1.1rem; background: var(--accent-soft);
  padding: .5rem .75rem; border-radius: 8px; user-select: all; word-break: break-all;
}

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; }
td .actions { flex-wrap: nowrap; }
td button { padding: .25rem .6rem; font-size: .85rem; }

.notes { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.notes li { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; white-space: pre-wrap; }
.notes .meta { color: var(--muted); font-size: .8rem; display: flex; justify-content: space-between; gap: .5rem; white-space: normal; }

#toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; 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(480px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }

.mt-0 { margin-top: 0; } .mt-half { margin-top: .5rem; } .mt-1 { margin-top: 1rem; } .mb-1 { margin-bottom: 1rem; }
form.stack.wide { max-width: none; }
.align-end { align-items: end; }
