:root {
  color-scheme: light dark;
  --bg: #f5f5f3; --panel: #fff; --fg: #1b1b19; --muted: #6a6862; --line: #e2e0da;
  --accent: #2455e6; --accent-fg: #fff; --err: #b42318; --ok: #1f7a3d; --warn: #9a6400; --hover: #efeee9;
  --radius: 10px; --side: 232px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111110; --panel: #1a1a19; --fg: #ecebe7; --muted: #9b9993; --line: #2c2b28; --accent: #7ea0ff; --accent-fg: #0d0d0c; --err: #ff8a7a; --ok: #6bd08b; --warn: #f0b85a; --hover: #232321; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 system-ui, -apple-system, "Noto Sans Thai", "Segoe UI", sans-serif; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: .5rem .9rem; }
button:hover { background: var(--hover); }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--err); }
button:disabled { opacity: .5; cursor: default; }
input, select { width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: grid; gap: .3rem; font-weight: 600; font-size: .9rem; }
.boot { padding: 2rem; color: var(--muted); }
.err { color: var(--err); font-weight: 600; }
.ok { color: var(--ok); }
.muted { color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; }

/* sign-in and setup */
.auth { max-width: 24rem; margin: 10vh auto; padding: 0 1rem; }
.auth h1 { font-size: 1.4rem; margin: 0 0 .25rem; }
.auth form { display: grid; gap: .9rem; margin-top: 1rem; }
.secret { font-family: ui-monospace, Menlo, monospace; letter-spacing: .08em; word-break: break-all; background: var(--hover); padding: .6rem; border-radius: 8px; user-select: all; }

/* layout */
.layout { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); background: var(--panel); padding: 1rem .6rem; display: flex; flex-direction: column; gap: .15rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 1.1rem; padding: .3rem .7rem 1rem; }
.side a { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .5rem .7rem; border-radius: 8px; color: var(--fg); text-decoration: none; }
.side a:hover { background: var(--hover); }
.side a[aria-current="page"] { background: var(--hover); font-weight: 600; }
.side .group { margin: .9rem .7rem .3rem; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.side .foot { margin-top: auto; padding: .7rem; font-size: .85rem; color: var(--muted); display: grid; gap: .4rem; }
.dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--ok); }
main { padding: 1.5rem 2rem 3rem; min-width: 0; }
main h1 { margin: 0 0 1rem; font-size: 1.4rem; }
.bar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.bar input { max-width: 18rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .8rem; }
.menu-btn { display: none; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.tag { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .8rem; border: 1px solid var(--line); }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.row-actions button, .row-actions select { padding: .3rem .6rem; font-size: .85rem; width: auto; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--fg); max-width: 28rem; width: calc(100% - 2rem); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog form { display: grid; gap: .8rem; }
.copy { display: flex; gap: .4rem; }
.copy input { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; }

main.wide { padding-bottom: 0; }
section.block { margin-top: 1.6rem; }
form.grid-form { display: grid; gap: .7rem; margin-bottom: 1rem; }
form.grid-form h2 { font-size: 1.05rem; margin: 0; }
textarea { width: 100%; font: inherit; color: inherit; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: transparent; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); align-items: start; }
.warn-text { color: var(--warn); font-weight: 600; }
.tag.warn { color: var(--warn); border-color: currentColor; }
ul.alerts { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
li.alert { display: flex; gap: .7rem; align-items: flex-start; background: var(--panel); border: 1px solid var(--line); border-left-width: 4px; border-radius: var(--radius); padding: .7rem .9rem; }
li.alert.bad { border-left-color: var(--err); }
li.alert.warn { border-left-color: var(--warn); }
a.card.status { display: grid; gap: .2rem; color: var(--fg); text-decoration: none; }
a.card.status:hover { background: var(--hover); }
section.block h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
.stat { display: grid; gap: .15rem; }
.stat strong { font-size: 1.5rem; font-weight: 700; }
.small { font-size: .82rem; }
.tag.good { color: var(--ok); border-color: currentColor; }
.tag.bad { color: var(--err); border-color: currentColor; }
.dot.off { background: var(--err); }
ul.checks { list-style: none; padding: 0; margin: .4rem 0 0; display: grid; gap: .2rem; }
ul.checks li { display: flex; align-items: center; gap: .3rem; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding: .5rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.bar-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end;
  background: linear-gradient(to top, var(--accent) calc(var(--q) * 100%), var(--err) calc(var(--q) * 100%) calc((var(--q) + var(--b)) * 100%), transparent 0); border-radius: 3px 3px 0 0; min-width: 4px; }
iframe.embed { display: block; width: 100%; height: calc(100vh - 5.5rem); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(80vw, var(--side)); z-index: 10; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgb(0 0 0 / .25); }
  .layout.open .side { transform: none; }
  .menu-btn { display: inline-block; margin-bottom: 1rem; }
  main { padding: 1rem; }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }
