:root {
  --bg: #f5f6f8; --panel: #ffffff; --text: #1d2330; --muted: #6a7385; --border: #dfe3ea;
  --accent: #2f7d4f; --accent-text: #ffffff; --danger: #b3261e; --warn-bg: #fff4d6; --warn-border: #e2b53e;
  --code: #f0f2f5; --switch-off: #c5cbd5; --knob: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --panel: #1c2027; --text: #e4e7ec; --muted: #9aa3b2; --border: #2d333d;
    --accent: #4caf73; --accent-text: #0d1a12; --danger: #ef6b62; --warn-bg: #3a3020; --warn-border: #a6842c;
    --code: #232833; --switch-off: #3d4451; --knob: #e9ecf1;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
a { color: var(--accent); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
button { font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel); color: var(--text); cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.small { padding: 2px 8px; font-size: 12px; }
input, select, textarea { font: inherit; width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
/* every yes/no setting is a rounded switch (the checkbox itself, so forms and scripts read it as before) */
input[type=checkbox] {
  -webkit-appearance: none; appearance: none; position: relative; flex-shrink: 0;
  width: 34px; height: 20px; padding: 0; margin: 0; vertical-align: middle; cursor: pointer;
  border: 1px solid var(--switch-off); border-radius: 999px; background: var(--switch-off);
  transition: background .15s, border-color .15s;
}
input[type=checkbox]::before {
  content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--knob); box-shadow: 0 1px 2px rgba(0, 0, 0, .35); transition: transform .15s;
}
input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
input[type=checkbox]:checked::before { transform: translateX(14px); }
input[type=checkbox]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=checkbox]:disabled { opacity: .45; cursor: not-allowed; }
@media (prefers-reduced-motion: reduce) { input[type=checkbox], input[type=checkbox]::before { transition: none; } }
label input[type=checkbox] { margin-top: 0; }
td input[type=checkbox] { vertical-align: -5px; }
label { display: block; margin-bottom: 10px; font-weight: 500; }
label input, label select, label textarea { margin-top: 4px; font-weight: 400; }
label.check { display: flex; gap: 4px 8px; align-items: center; flex-wrap: wrap; }
label.check .hint { flex-basis: 100%; margin: 0 0 0 42px; } /* under the label text, past the switch */
.hint { color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 2px; }
.error { color: var(--danger); min-height: 1em; margin: 8px 0 0; }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; }

.app { display: flex; min-height: 100vh; }
.sidebar { width: 210px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border); padding: 16px 0; }
.sidebar a { display: block; padding: 6px 20px; color: var(--text); text-decoration: none; }
.sidebar a.active { background: var(--bg); border-left: 3px solid var(--accent); padding-left: 17px; font-weight: 600; }
.brand { font-weight: 700; font-size: 17px; padding: 0 20px 12px; }
.brand span { color: var(--muted); font-weight: 400; }
.nav-group { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 14px 20px 4px; }
main { flex: 1; padding: 24px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.page-desc { color: var(--muted); margin: 0 0 16px; max-width: 820px; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
td.actions { text-align: right; }
td.actions button { margin-left: 4px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.hex { white-space: pre-wrap; word-break: break-all; max-width: 640px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; background: var(--code); }
.badge.ok { background: var(--accent); color: var(--accent-text); }
.badge.bad { background: var(--danger); color: #fff; }
.empty { color: var(--muted); padding: 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .k { color: var(--muted); font-size: 12px; }
.section { margin-top: 24px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 10; }
.modal-box { width: 100%; max-width: 760px; }
textarea.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; tab-size: 2; white-space: pre; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.warning { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; }
.docs { max-width: 980px; }
.docs h1 { font-size: 24px; margin-top: 0; }
.docs h2 { font-size: 19px; margin-top: 28px; padding-top: 8px; border-top: 1px solid var(--border); }
.docs h3 { font-size: 15px; margin-top: 22px; }
.docs h4 { font-size: 14px; margin-top: 16px; }
.docs code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--code); padding: 1px 4px; border-radius: 4px; }
.docs pre { background: var(--code); padding: 12px 14px; border-radius: 6px; overflow-x: auto; }
.docs pre code { padding: 0; background: none; }
.docs td, .docs th { white-space: normal; }
.docs .table-wrap { margin: 8px 0 14px; }
.docs hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.device-row { display: flex; gap: 12px; align-items: center; margin: 4px 0 12px; flex-wrap: wrap; }
.device-code { font-size: 28px; font-weight: 700; letter-spacing: .15em; user-select: all; background: var(--code); padding: 6px 14px; border-radius: 6px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; }

@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; padding: 8px; }
  .sidebar a { padding: 4px 10px; }
  .sidebar a.active { border-left: none; padding-left: 10px; }
  .brand, .nav-group { display: none; }
  main { padding: 16px; }
}
/* tokens: masked like a password without being one, so browsers and password managers leave them alone */
input.token { -webkit-text-security: disc; text-security: disc; font-family: ui-monospace, Consolas, monospace; }
/* a choice between a few options: | LEFT | CENTER | RIGHT |, the selected one highlighted */
.field { margin-bottom: 10px; font-weight: 500; }
.segmented { display: inline-flex; flex-wrap: wrap; margin-top: 4px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--bg); }
.segmented button { border: none; border-radius: 0; border-right: 1px solid var(--border); background: transparent; padding: 5px 14px; font-weight: 400; color: var(--text); }
.segmented button:last-child { border-right: none; }
.segmented button:hover { background: var(--code); }
.segmented button.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* advanced options: hidden until "Show advanced options" */
.adv-hidden { display: none !important; }
.adv-toggle { margin: 6px 0 10px; }

.graphs .card { margin-bottom: 12px; }
.graph-head { margin: 0 0 8px; font-size: 15px; }
.graph-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.graph-title { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
canvas.graph { display: block; width: 100%; height: 150px; }
