:root {
  --bg: #f4f6fa; --panel: #ffffff; --panel2: #eef1f7; --text: #18202f; --muted: #66708a; --line: #dde2ee;
  --accent: #2f6fed; --accent-text: #ffffff; --ok: #1a9e5c; --warn: #c9830a; --bad: #d23a3a;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131b; --panel: #171c27; --panel2: #1f2533; --text: #e6e9f2; --muted: #8b95ad; --line: #2a3142;
    --accent: #5b8cff; --accent-text: #0b1020; --ok: #35c27e; --warn: #e0a030; --bad: #ef6a6a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5em; font-weight: 650; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 18px; padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 750; font-size: 1.15rem; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.brand svg { width: 22px; height: 22px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); }
.nav a.active, .nav a:hover { background: var(--panel2); color: var(--text); text-decoration: none; }
.container { max-width: 1280px; margin: 0 auto; padding: 18px; }

/* controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.danger:hover:not(:disabled) { background: var(--bad); color: #fff; }
button.small { padding: 3px 8px; font-size: 12.5px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: 16px; height: 16px; padding: 0; vertical-align: middle; }
label { display: inline-flex; gap: 6px; align-items: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { color: var(--muted); font-size: 12.5px; }

/* cards */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel + .panel { margin-top: 14px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 8px; cursor: pointer; position: relative; }
.card:hover { border-color: var(--accent); }
.card.pending { border-color: var(--warn); }
.card .title { font-weight: 650; font-size: 1.02rem; word-break: break-word; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 9px; border-radius: 99px;
  background: var(--panel2); color: var(--muted); }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.on { color: var(--ok); } .chip.on::before { background: var(--ok); }
.chip.warn { color: var(--warn); } .chip.warn::before { background: var(--warn); }
.chip.off::before { background: var(--muted); }
.bar { height: 6px; border-radius: 4px; background: var(--panel2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar > i.hot { background: var(--bad); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 14px 0; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; position: sticky; top: 0; background: var(--panel); }
th.sort { cursor: pointer; }
tr:hover td { background: var(--panel2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* misc */
pre.out { background: #0b0e14; color: #d7dce8; padding: 12px; border-radius: 8px; overflow: auto; max-height: 420px;
  white-space: pre-wrap; word-break: break-word; margin: 0; }
.term { height: 52vh; min-height: 280px; max-height: 70vh; }
.term .echo { color: #7fb0ff; }
.term .err { color: #ff8a8a; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--panel2); border-left: 4px solid var(--accent); }
.notice.warn { border-color: var(--warn); } .notice.bad { border-color: var(--bad); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; display: inline-block; animation: spin 0.8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.screenbox { background: #000; border-radius: 8px; overflow: hidden; display: flex; justify-content: center; }
.screenbox canvas { max-width: 100%; height: auto; outline: none; cursor: crosshair; display: block; }
.screenbox:fullscreen { align-items: center; }
.screenbox:fullscreen canvas { max-height: 100vh; width: auto; }

/* modal & toast */
#modal-root .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center;
  justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px;
  width: min(520px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
#toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  padding: 10px 14px; border-radius: 8px; max-width: 360px; box-shadow: 0 4px 18px rgba(0,0,0,.25); }
.toast.bad { border-left-color: var(--bad); } .toast.ok { border-left-color: var(--ok); }

/* login */
.login { max-width: 360px; margin: 12vh auto; }
.login .panel { padding: 24px; }
.login .brand { justify-content: center; font-size: 1.6rem; margin-bottom: 18px; }
.login .brand svg { width: 30px; height: 30px; }
.bulkbar { position: sticky; bottom: 12px; margin-top: 14px; display: flex; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--accent); padding: 10px 14px; border-radius: 10px; flex-wrap: wrap; }
.checkcell { width: 28px; }
@media (max-width: 640px) {
  .container { padding: 12px; }
  .topbar { padding: 8px 12px; gap: 8px; }
}
.grid > .panel + .panel { margin-top: 0; }
label.field { display: flex; align-items: stretch; }
