:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1d2330; --muted: #6b7385; --line: #e3e6ec;
  --accent: #2563eb; --ok: #16a34a; --bad: #dc2626; --warn: #d97706; --chip: #eef1f6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141a; --panel: #1a1e26; --text: #e6e9ef; --muted: #8c94a6; --line: #2a303b;
    --accent: #60a5fa; --ok: #4ade80; --bad: #f87171; --warn: #fbbf24; --chip: #242a35;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", sans-serif; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
h2 { margin: 0; font-size: 18px; } h3 { margin: 0 0 8px; font-size: 14px; }
.muted { color: var(--muted); } .small { font-size: 12px; font-weight: normal; } .pad { padding: 16px; }
.grow { flex: 1; } .error { color: var(--bad); margin: 8px 0 0; }

.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
button { font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.warn { background: var(--warn); border-color: var(--warn); }
input, select { font: inherit; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }

.center { flex: 1; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; min-width: 0; }
.login { width: min(360px, 100%); display: grid; gap: 12px; }
.login label { display: grid; gap: 4px; }

.layout { flex: 1; display: grid; grid-template-columns: 280px 1fr; min-height: 0; }
.side { border-right: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 12px; }
.side input { width: 100%; }
.devices { list-style: none; margin: 10px 0 0; padding: 0; }
.devices li { display: grid; grid-template-columns: 12px 1fr; gap: 2px 8px; align-items: center; padding: 8px; border-radius: 8px; cursor: pointer; }
.devices li:hover { background: var(--chip); }
.devices li.active { background: var(--chip); outline: 1px solid var(--accent); }
.devices .sub { grid-column: 2; font-size: 12px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.off { background: var(--bad); }

.detail { overflow: auto; padding: 16px; display: block; }
#device { display: grid; gap: 14px; }
.head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.chart { width: 100%; height: 60px; margin-top: 10px; background: var(--chip); border-radius: 6px; }
.chart polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 10px; }
.row label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.row label.inline { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 6px; }
.table td { border-bottom: 1px solid var(--line); padding: 6px; vertical-align: top; overflow-wrap: anywhere; }
.table td:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tr.clickable { cursor: pointer; } .table tr.clickable:hover { background: var(--chip); }
.table tr.new td { animation: flash 1.5s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 22%, transparent); } to { background: transparent; } }
pre.json { margin: 0; font-size: 12px; white-space: pre-wrap; background: var(--chip); padding: 8px; border-radius: 6px; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--chip); font-size: 12px; white-space: nowrap; }
.chip.ok { color: var(--ok); } .chip.bad { color: var(--bad); } .chip.warn { color: var(--warn); } .chip.info { color: var(--accent); }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); max-height: 35vh; }
}
