/* CODE12 Test Farm — design system. One stylesheet for every page (replaces app.css + farm.css). */
:root {
  --bg: #f5f6f8; --panel: #fff; --subtle: #f9fafb; --line: #e5e7eb; --line-2: #d1d5db;
  --text: #111827; --text-2: #374151; --muted: #6b7280; --faint: #9ca3af;
  --primary: #2563eb; --primary-d: #1d4ed8; --primary-bg: #eff6ff; --ring: rgba(37, 99, 235, .25);
  --green: #15803d; --green-bg: #ecfdf3; --amber: #b45309; --amber-bg: #fffbeb;
  --red: #b91c1c; --red-bg: #fef2f2; --blue: #1d4ed8; --blue-bg: #eff6ff; --gray-bg: #f3f4f6;
  --side: #0f172a; --side-2: #1e293b; --side-text: #cbd5e1; --side-muted: #64748b;
  --r-sm: 6px; --r: 8px; --r-lg: 12px;
  --sh-sm: 0 1px 2px rgba(16, 24, 40, .05); --sh: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --sh-lg: 0 20px 40px -12px rgba(16, 24, 40, .25);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.3; font-weight: 650; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 17px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
h4 { font-size: 13.5px; font-weight: 600; margin: 16px 0 8px; color: var(--text-2); }
code { font-family: var(--mono); font-size: 12px; background: var(--gray-bg); border-radius: 4px; padding: 1px 5px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .mono { font-family: var(--mono); font-size: 12px; }
.sub { color: var(--muted); margin: 4px 0 0; max-width: 860px; }

/* icons (SVG sprite in base.html; ic(name) in JS) */
svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round;
  stroke-linejoin: round; vertical-align: -3px; }
svg.i.lg { width: 18px; height: 18px; }

/* ---------------------------------------------------------------- layout */
.layout { display: flex; min-height: 100vh; }
nav.side { width: 232px; flex: none; background: var(--side); color: var(--side-text); display: flex; flex-direction: column;
  padding: 18px 12px 14px; position: sticky; top: 0; height: 100vh; }
nav.side .brand { display: flex; gap: 10px; align-items: center; padding: 2px 8px 18px; color: #fff; text-decoration: none; }
nav.side .brand .logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #3b82f6, #6366f1);
  display: grid; place-items: center; font-weight: 700; font-size: 12px; letter-spacing: .02em; color: #fff; flex: none; }
nav.side .brand b { display: block; font-size: 14.5px; font-weight: 650; line-height: 1.2; }
nav.side .brand span { display: block; font-size: 11.5px; color: var(--side-muted); }
nav.side .navlabel { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--side-muted);
  padding: 14px 10px 6px; }
nav.side a.nav { display: flex; gap: 10px; align-items: center; color: var(--side-text); padding: 8px 10px; border-radius: var(--r);
  margin-bottom: 2px; font-weight: 500; position: relative; text-decoration: none; }
nav.side a.nav:hover { background: var(--side-2); color: #fff; }
nav.side a.nav.active { background: var(--side-2); color: #fff; }
nav.side a.nav.active::before { content: ""; position: absolute; left: -12px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0;
  background: #60a5fa; }
nav.side a.nav svg.i { color: var(--side-muted); } nav.side a.nav.active svg.i, nav.side a.nav:hover svg.i { color: #93c5fd; }
nav.side .bottom { margin-top: auto; border-top: 1px solid var(--side-2); padding: 12px 6px 0; display: flex; gap: 10px; align-items: center; }
nav.side .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--side-2); color: #e2e8f0; display: grid;
  place-items: center; font-weight: 600; font-size: 13px; text-transform: uppercase; flex: none; }
nav.side .who { flex: 1; min-width: 0; line-height: 1.25; } nav.side .who b { color: #fff; font-weight: 600; font-size: 13px; }
nav.side .who span { display: block; font-size: 11.5px; color: var(--side-muted); }
nav.side .logout { background: none; border: 0; color: var(--side-muted); cursor: pointer; padding: 6px; border-radius: var(--r-sm); }
nav.side .logout:hover { background: var(--side-2); color: #fff; }
main { flex: 1; min-width: 0; padding: 26px 32px 40px; max-width: 1480px; }

/* page header: title + subtitle left, actions right */
.page-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 13px; margin-bottom: 8px; display: inline-flex; gap: 4px; align-items: center; color: var(--muted); }
.crumb a { color: var(--muted); } .crumb a:hover { color: var(--primary); }

/* ---------------------------------------------------------------- surfaces */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px 20px; box-shadow: var(--sh-sm); }
.panel > h3:first-child { display: flex; gap: 8px; align-items: center; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.panel-head h3 { margin: 0; display: flex; gap: 8px; align-items: center; }
.panel.flush { padding: 0; overflow: hidden; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); align-items: start; }
.stack > * + * { margin-top: 16px; }
.scroll { overflow: auto; }
.note { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 12px 16px; box-shadow: var(--sh-sm); }
.stat b { display: block; font-size: 22px; font-weight: 650; line-height: 1.25; letter-spacing: -.01em; }
.stat span { font-size: 12.5px; color: var(--muted); }
.stat.warn b { color: var(--amber); } .stat.bad b { color: var(--red); }

/* ---------------------------------------------------------------- controls */
.btn { display: inline-flex; gap: 6px; align-items: center; justify-content: center; height: 34px; padding: 0 13px; font: inherit;
  font-weight: 500; font-size: 13.5px; color: var(--text-2); background: #fff; border: 1px solid var(--line-2); border-radius: var(--r);
  cursor: pointer; white-space: nowrap; box-shadow: var(--sh-sm); text-decoration: none; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--subtle); border-color: #c3c8d0; text-decoration: none; }
.btn:focus-visible { outline: 0; box-shadow: 0 0 0 3px var(--ring); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); border-color: var(--primary-d); }
.btn.danger { color: var(--red); } .btn.danger:hover { background: var(--red-bg); border-color: #fca5a5; }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; } .btn.ghost:hover { background: var(--gray-bg); }
.btn.small { height: 28px; padding: 0 9px; font-size: 12.5px; gap: 5px; }
.btn.icon { width: 30px; padding: 0; } .btn.small.icon { width: 28px; }
input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  font: inherit; font-size: 13.5px; color: var(--text); height: 34px; padding: 0 10px; background: #fff; border: 1px solid var(--line-2);
  border-radius: var(--r); box-shadow: var(--sh-sm); transition: border-color .12s, box-shadow .12s; }
textarea { height: auto; padding: 8px 10px; width: 100%; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; }
select { padding-right: 28px; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
input::placeholder, textarea::placeholder { color: var(--faint); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); vertical-align: -3px; margin: 0; }
input[type=file] { font: inherit; font-size: 13px; }
label { cursor: pointer; } label.chk { display: inline-flex; gap: 8px; align-items: center; }

/* ---------------------------------------------------------------- tables */
table { border-collapse: collapse; width: 100%; }
table.list th { text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  background: var(--subtle); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tbody tr:last-child td { border-bottom: 0; }
table.list tr.click { cursor: pointer; } table.list tbody tr:hover td { background: #fafbfc; }
table.list td.num { font-variant-numeric: tabular-nums; color: var(--muted); }
table.kv td { border: 0; padding: 6px 0; vertical-align: top; }
table.kv td:first-child { color: var(--muted); padding-right: 16px; white-space: nowrap; width: 1%; }

/* ---------------------------------------------------------------- badges, chips */
.badge { display: inline-flex; gap: 6px; align-items: center; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 12px;
  font-weight: 500; white-space: nowrap; border: 1px solid transparent; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.b-ok { background: var(--green-bg); color: var(--green); border-color: #bbf7d0; }
.b-warn { background: var(--amber-bg); color: var(--amber); border-color: #fde68a; }
.b-err { background: var(--red-bg); color: var(--red); border-color: #fecaca; }
.b-run { background: var(--blue-bg); color: var(--blue); border-color: #bfdbfe; }
.b-run::before { animation: pulse 1.2s ease-in-out infinite; }
.b-idle { background: var(--gray-bg); color: var(--muted); border-color: var(--line); }
@keyframes pulse { 50% { opacity: .25; } }
.chip { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); background: var(--subtle); border-radius: 999px;
  padding: 2px 4px 2px 10px; margin: 2px 6px 2px 0; font-size: 12.5px; }
.chip .badge { height: 18px; font-size: 11px; padding: 0 7px; }
.tag { display: inline-block; padding: 0 7px; border-radius: 4px; font-size: 11.5px; background: var(--gray-bg); color: var(--text-2); }

/* ---------------------------------------------------------------- dialog, toast */
.dlg { width: min(640px, 96vw); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; box-shadow: var(--sh-lg); color: var(--text); }
.dlg.wide { width: min(1040px, 96vw); }
.dlg::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.dlg-head h3 { margin: 0; display: flex; gap: 8px; align-items: center; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; max-width: 440px; padding: 11px 16px; border-radius: var(--r);
  background: #111827; color: #fff; box-shadow: var(--sh-lg); font-size: 13.5px; opacity: 0; transform: translateY(6px);
  transition: opacity .18s, transform .18s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; } .toast.err { background: #991b1b; }

/* ---------------------------------------------------------------- logs, help */
.logbox { background: #0b1220; color: #d1d5db; border-radius: var(--r); padding: 12px 14px; max-height: 380px; overflow: auto;
  font: 12px/1.6 var(--mono); white-space: pre-wrap; word-break: break-word; }
.logbox .warn { color: #fbbf24; } .logbox .error { color: #f87171; }
.cmdrow { display: flex; gap: 8px; align-items: flex-start; }
.cmdrow .logbox { flex: 1; margin: 0; padding: 9px 12px; word-break: break-all; }
.helpbox { border: 1px solid #fcd34d; background: var(--amber-bg); border-radius: var(--r); padding: 12px 14px; margin: 0 0 14px; color: #78350f; }
.helpbox .helptitle { font-weight: 600; margin-bottom: 4px; display: flex; gap: 8px; align-items: center; color: #92400e; }
.helpbox ol { margin: 6px 0 0 18px; padding: 0; line-height: 1.65; }
details.helpbox { padding: 7px 12px; margin: 6px 0 0; }
details.helpbox summary { cursor: pointer; font-weight: 600; font-size: 12.5px; color: #92400e; }

/* ---------------------------------------------------------------- domain: devices */
.devgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.dev { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px; background: #fff; display: flex; flex-direction: column; gap: 6px; }
.dev:hover { border-color: #c7d2fe; box-shadow: var(--sh); }
.dev .dev-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.screen { max-height: 70vh; max-width: 100%; border-radius: 16px; border: 6px solid #111827; cursor: crosshair; background: #000; display: block; }
.picker label { display: inline-flex; gap: 6px; align-items: center; margin: 3px 14px 3px 0; }
.bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; width: 80px; display: inline-block; vertical-align: middle; }
.bar > i { display: block; height: 100%; background: var(--primary); }

/* login */
body.auth { display: grid; place-items: center; min-height: 100vh; background: radial-gradient(1200px 600px at 20% -10%, #dbeafe, transparent),
  radial-gradient(900px 500px at 110% 110%, #e0e7ff, transparent), var(--bg); }
.auth-card { width: 380px; max-width: 94vw; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 30px 30px 26px;
  box-shadow: var(--sh-lg); }
.auth-card .logo { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, #3b82f6, #6366f1); color: #fff;
  display: grid; place-items: center; font-weight: 700; margin-bottom: 16px; }
.auth-card label { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin: 14px 0 6px; }
.auth-card input { width: 100%; height: 38px; }
.auth-card .btn { width: 100%; height: 40px; margin-top: 20px; }
.auth-card .err { background: var(--red-bg); color: var(--red); border: 1px solid #fecaca; border-radius: var(--r); padding: 8px 12px;
  font-size: 13px; margin-top: 14px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; } nav.side { width: auto; height: auto; position: static; }
  main { padding: 18px 16px 32px; }
}

/* pagination bar under a table (makePager in app.js) */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.pager b { color: var(--text-2); font-weight: 600; }
.pager .pages { display: flex; align-items: center; gap: 4px; }
.pager .pg { min-width: 32px; padding: 0 8px; }
.pager .pg.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager .gap { padding: 0 4px; color: var(--faint); }
.pager select { height: 30px; padding: 0 6px; }
table.list td.stt, table.list th.stt { width: 52px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
