:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2330; --muted: #667085; --line: #e3e6ec;
  --accent: #2f6fde; --danger: #c4314b; --ok: #1e8a4c; --warn: #b7791f;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --panel: #1c2027; --text: #e6e8ec; --muted: #98a2b3; --line: #2c323c; --accent: #6b9cff; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
header { background: var(--panel); border-bottom: 1px solid var(--line); padding: 8px 16px; display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
header .brand { font-weight: 700; margin-right: 8px; }
header nav { display: flex; flex-wrap: wrap; gap: 4px 12px; flex: 1; }
header form { margin: 0; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.4rem; margin: 4px 0 16px; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.stat b { display: block; font-size: 1.6rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; word-break: break-all; }
.muted { color: var(--muted); }
form.stack { display: grid; gap: 12px; max-width: 720px; }
form.inline { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0; }
label { display: grid; gap: 4px; font-weight: 600; font-size: .9rem; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label small { font-weight: 400; color: var(--muted); }
input, textarea, select, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=datetime-local], textarea, select {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
}
form.inline input[type=text], form.inline input[type=search] { width: auto; min-width: 200px; }
textarea { min-height: 120px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .85rem; }
button, .button { display: inline-block; padding: 7px 14px; border: 1px solid var(--accent); border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; font-weight: 600; }
button.secondary, .button.secondary { background: transparent; color: var(--accent); }
button.danger { background: var(--danger); border-color: var(--danger); }
button.link { background: none; border: 0; color: var(--accent); padding: 0; font-weight: 400; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; border: 1px solid; }
.flash.ok { border-color: var(--ok); color: var(--ok); }
.flash.error { border-color: var(--danger); color: var(--danger); }
.validation, .field-validation-error { color: var(--danger); font-size: .85rem; font-weight: 400; }
.validation ul { margin: 0; padding-left: 18px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .78rem; border: 1px solid var(--line); }
.badge.on { border-color: var(--ok); color: var(--ok); }
.badge.off { border-color: var(--danger); color: var(--danger); }
.badge.warn { border-color: var(--warn); color: var(--warn); }
.pager { display: flex; gap: 12px; align-items: center; margin: 12px 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; word-break: break-all; }
.login { max-width: 360px; margin: 10vh auto; }
.placeholder { border: 1px dashed var(--line); border-radius: 8px; padding: 12px; color: var(--muted); }
@media (max-width: 600px) {
  main { padding: 12px; }
  th, td { padding: 6px; }
  form.inline input[type=text], form.inline input[type=search] { min-width: 0; width: 100%; }
}
/* Live page */
.live-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.live-head h1 { margin-right: auto; }
.live-status { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .85rem; }
.live-status i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.live-status[data-state=ok] i { background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: live-pulse 2s infinite; }
.live-status[data-state=bad] i { background: var(--danger); }
.live-status[data-state=bad] { color: var(--danger); }
@keyframes live-pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); } 70%, 100% { box-shadow: 0 0 0 7px transparent; } }
@media (prefers-reduced-motion: reduce) { .live-status[data-state=ok] i { animation: none; } }
.live-maint { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; }
.live-maint.is-on { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--panel)); }
.live-maint form.inline input[type=text] { min-width: 280px; }
.live-tiles .stat { position: relative; border-left: 3px solid var(--line); }
.live-tiles .stat[data-tone=good] { border-left-color: var(--ok); }
.live-tiles .stat[data-tone=warn] { border-left-color: var(--warn); }
.live-tiles .stat[data-tone=warn] b { color: var(--warn); }
.live-tiles .stat[data-tone=bad] { border-left-color: var(--danger); }
.live-tiles .stat[data-tone=bad] b { color: var(--danger); }
.live-tiles .stat b { font-variant-numeric: tabular-nums; }
.meter { display: block; height: 4px; margin-top: 8px; border-radius: 2px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.meter i[data-tone=warn] { background: var(--warn); }
.meter i[data-tone=bad] { background: var(--danger); }
.card h2 { margin-top: 0; }
.card h2 small { font-weight: 400; font-size: .8rem; margin-left: 6px; }
.chart { position: relative; min-height: 180px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { stroke: none; opacity: .14; }
.chart .bar { stroke: none; opacity: .85; }
.chart .cursor { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart-empty { display: grid; place-items: center; height: 180px; color: var(--muted); border: 1px dashed var(--line); border-radius: 6px; }
.chart-tip { position: absolute; top: 4px; min-width: 120px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); font-size: .8rem; box-shadow: 0 4px 14px rgb(0 0 0 / 12%); pointer-events: none; }
.chart-tip b { display: block; margin-bottom: 2px; }
.line.k1, .key.k1::before { stroke: var(--accent); background: var(--accent); }
.area.k1, .bar.k1 { fill: var(--accent); }
.line.k2, .key.k2::before { stroke: var(--warn); background: var(--warn); }
.area.k2, .bar.k2 { fill: var(--warn); }
.line.k3, .key.k3::before { stroke: var(--danger); background: var(--danger); }
.area.k3, .bar.k3 { fill: var(--danger); }
.line.k4, .key.k4::before { stroke: var(--ok); background: var(--ok); }
.area.k4, .bar.k4 { fill: var(--ok); }
.key { white-space: nowrap; }
.key::before { content: ""; display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin: 0 4px 3px 0; vertical-align: middle; }
.table-wrap.flat { border: 0; }
td.bad { color: var(--danger); font-weight: 600; }
@media (max-width: 600px) { .live-maint form.inline input[type=text] { min-width: 0; } }
.live-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.live-charts .card { margin-bottom: 0; }
.live-charts + .grid2 { margin-top: 16px; }
.card dl + h2 { margin-top: 20px; }
@media (max-width: 760px) { .live-charts { grid-template-columns: 1fr; } }
.live-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 760px) { .live-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
