:root {
  --bg: #fbfbfd;
  --bg-alt: #ffffff;
  --bg-sunken: #f2f3f7;
  --fg: #16181d;
  --fg-muted: #5c6270;
  --line: #e2e4ea;
  --accent: #0b57d0;
  --accent-soft: #e8f0fe;
  --canary: #b06000;
  --canary-soft: #fff1dc;
  --ok: #146c2e;
  --ok-soft: #e6f4ea;
  --bad: #b3261e;
  --bad-soft: #fce8e6;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .05);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg: #131417;
  --bg-alt: #1b1d22;
  --bg-sunken: #0f1013;
  --fg: #e6e8ee;
  --fg-muted: #9aa0ad;
  --line: #2a2d35;
  --accent: #8ab4f8;
  --accent-soft: #1c2b41;
  --canary: #f2b263;
  --canary-soft: #33260f;
  --ok: #81c995;
  --ok-soft: #14291b;
  --bad: #f28b82;
  --bad-soft: #33191a;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 20px rgb(0 0 0 / .3);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

.muted { color: var(--fg-muted); }
.num { text-align: right; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg-alt) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-in {
  max-width: 1500px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.brand h1 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.tag { margin: 2px 0 0; font-size: 12.5px; color: var(--fg-muted); }
.tag a { color: inherit; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.stats { font-size: 12.5px; color: var(--fg-muted); font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg-alt); color: var(--fg);
  font: inherit; font-size: 12.5px; text-decoration: none; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  font-weight: 550;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: 4px 9px; font-size: 12px; }

/* ---------- layout ---------- */
.layout {
  max-width: 1500px; margin: 0 auto; padding: 18px 20px 60px;
  display: grid; grid-template-columns: 268px minmax(0, 1fr); gap: 22px;
  align-items: start;
}

/* ---------- sidebar ---------- */
.side {
  position: sticky; top: 74px;
  max-height: calc(100vh - 96px);
  display: flex; flex-direction: column;
  background: var(--bg-alt); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.side-head { padding: 10px; border-bottom: 1px solid var(--line); }
.side-head input { width: 100%; min-width: 0; }
.devlist { overflow-y: auto; padding: 6px; flex: 1; }

/* the "All devices" entry keeps the same alignment as device rows */
.dev.all { margin-bottom: 4px; font-weight: 600; }

.devgroup {
  padding: 10px 8px 4px; font-size: 10.5px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .07em; color: var(--fg-muted);
}
.dev {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 8px; align-items: center; width: 100%;
  padding: 6px 9px; border: 0; border-radius: 7px;
  background: none; color: var(--fg); font: inherit; font-size: 13px;
  text-align: left; cursor: pointer;
}
.dev:hover { background: var(--bg-sunken); }
.dev:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.dev[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.dev .dev-label { grid-column: 1; min-width: 0; line-height: 1.35; }
.dev .code {
  grid-column: 1; grid-row: 2;
  font: 11px/1.4 var(--mono); color: var(--fg-muted);
}
.dev[aria-current="true"] .code { color: var(--accent); }
.dev .n {
  grid-column: 2; grid-row: 1 / span 2;
  font-size: 11px; color: var(--fg-muted); font-variant-numeric: tabular-nums;
}
.dev.all .n { grid-row: 1; }

/* ---------- main ---------- */
.main { min-width: 0; }

.devhead h2 { margin: 0 0 2px; font-size: 21px; letter-spacing: -.015em; }
.devhead p { margin: 0 0 16px; font-size: 12.5px; }
.devhead code { font: 11.5px var(--mono); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card {
  background: var(--bg-alt); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.card .kind {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em;
  background: var(--ok-soft); color: var(--ok); margin-bottom: 8px;
}
.card.canary .kind { background: var(--canary-soft); color: var(--canary); }
.card .rel { font: 600 16px/1.3 var(--mono); letter-spacing: -.02em; }
.card .sub { font-size: 12px; color: var(--fg-muted); margin: 3px 0 11px; }
.card .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card .sz { font-size: 12.5px; color: var(--fg-muted); font-variant-numeric: tabular-nums; }

/* ---------- controls ---------- */
.controls {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  padding: 10px 0; margin-bottom: 6px;
  position: sticky; top: 74px; z-index: 20;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
}
input[type="search"], select {
  padding: 7px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg-alt); color: var(--fg); font: inherit; font-size: 13px;
}
input[type="search"] { flex: 1 1 240px; min-width: 180px; }
input[type="search"]:focus, select:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--fg-muted); cursor: pointer; user-select: none; }
.chk input { accent-color: var(--accent); }
.count { margin-left: auto; font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* ---------- table ---------- */
.tablewrap {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-alt); overflow: auto; max-height: calc(100vh - 210px);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg-sunken); color: var(--fg-muted);
  font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em;
  text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-sunken); }
.rel { font: 500 12.5px var(--mono); white-space: nowrap; }
.track { color: var(--fg-muted); font-size: 12.5px; }
.pid, .prod { font: 11.5px var(--mono); color: var(--fg-muted); white-space: nowrap; }
.sz { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--fg-muted); }
td.act { text-align: right; white-space: nowrap; }
td.act .btn { margin-left: 6px; }

.pill {
  display: inline-block; margin-left: 7px; padding: 1px 6px; border-radius: 999px;
  font-size: 10px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em;
  vertical-align: 1px;
}
.pill.canary { background: var(--canary-soft); color: var(--canary); }
.pill.active { background: var(--ok-soft); color: var(--ok); }
.pill.dead { background: var(--bad-soft); color: var(--bad); }

.empty { padding: 40px; text-align: center; }

.notice {
  margin-bottom: 14px; padding: 11px 14px; border-radius: var(--radius);
  background: var(--bad-soft); color: var(--bad); font-size: 13px;
  border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent);
}

/* ---------- footer / toast ---------- */
.foot {
  max-width: 1500px; margin: 0 auto; padding: 0 20px 40px;
  font-size: 12px; color: var(--fg-muted); line-height: 1.7;
}
.foot code { font: 11.5px var(--mono); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  padding: 9px 18px; border-radius: 999px; z-index: 100;
  background: var(--fg); color: var(--bg); font-size: 13px; box-shadow: var(--shadow);
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .top { position: static; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 14px 12px 40px; }
  .side { position: static; max-height: 300px; }
  .controls { position: static; }
  .tablewrap { max-height: none; }
  .top-in { padding: 10px 12px; }
  .tag { display: none; }
  thead th:nth-child(4), tbody td:nth-child(4) { display: none; }
}

@media (max-width: 600px) {
  .top-actions { width: 100%; margin-left: 0; flex-wrap: wrap; gap: 6px; }
  .stats { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ================= flash.html ================= */

.plain { color: inherit; text-decoration: none; }
.plain:hover { color: var(--accent); }

.flashwrap { max-width: 1240px; margin: 0 auto; padding: 18px 20px 60px; }

.warn {
  padding: 13px 16px; margin-bottom: 18px; border-radius: var(--radius);
  background: var(--canary-soft); color: var(--fg);
  border: 1px solid color-mix(in srgb, var(--canary) 35%, transparent);
  font-size: 13px; line-height: 1.65;
}
.warn code { font: 12px var(--mono); }

.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }

.panel {
  background: var(--bg-alt); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 10px; font-size: 15px; letter-spacing: -.01em; }
.panel h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--fg-muted); }
.panel hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

.connrow { display: flex; align-items: center; gap: 12px; }
.state { font-size: 13px; color: var(--fg-muted); }
.state.good { color: var(--ok); font-weight: 600; }
.state.bad { color: var(--bad); font-weight: 600; }

.hint { margin: 8px 0 0; font-size: 12px; color: var(--fg-muted); line-height: 1.6; }
.hint code { font: 11.5px var(--mono); }
.keys {
  display: inline-block; padding: 0 5px; border: 1px solid var(--line);
  border-radius: 4px; background: var(--bg-sunken); font: 11px var(--mono);
}

.vars { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 4px 14px;
  margin: 14px 0 0; font-size: 12.5px; }
.vars dt { color: var(--fg-muted); font: 11.5px var(--mono); }
.vars dd { margin: 0; font: 12px var(--mono); overflow-wrap: anywhere; }
.vars dd.good { color: var(--ok); font-weight: 600; }
.vars dd.bad { color: var(--bad); font-weight: 600; }

.lockwarn {
  margin-top: 12px; padding: 10px 13px; border-radius: 8px; font-size: 12.5px;
  background: var(--bad-soft); color: var(--bad);
  border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent);
}
.lockwarn code { font: 11.5px var(--mono); }

.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.cmdrow { display: flex; gap: 8px; }
.cmdrow input { flex: 1; padding: 7px 11px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg-alt); color: var(--fg);
  font: 12.5px var(--mono); }
.cmdrow input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: 11.5px; color: var(--fg-muted);
  margin-bottom: 5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.field select, .field input[type="text"] {
  width: 100%; padding: 7px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg-alt); color: var(--fg); font: inherit; font-size: 13px;
}
.field input[type="file"] {
  width: 100%; padding: 8px; border: 1px dashed var(--line); border-radius: 8px;
  background: var(--bg-sunken); color: var(--fg); font-size: 12.5px;
}
.field input[type="file"]::file-selector-button {
  margin-right: 10px; padding: 4px 11px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg-alt); color: var(--fg);
  font: inherit; font-size: 12px; cursor: pointer;
}
#partcustom { width: 100%; padding: 7px 11px; margin: -4px 0 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg-alt);
  color: var(--fg); font: 13px var(--mono); }
#wipeconfirm { width: 100%; padding: 7px 11px; border: 1px solid var(--bad);
  border-radius: 8px; background: var(--bg-alt); color: var(--fg);
  font: 13px var(--mono); }

.chk.danger { color: var(--bad); font-weight: 600; margin-top: 12px; }
.chk.danger input { accent-color: var(--bad); }

.proghead { display: flex; align-items: baseline; gap: 12px; }
.proghead h2 { margin-bottom: 8px; }
.proghead .muted { margin-left: auto; font-size: 12.5px; font-variant-numeric: tabular-nums; }
progress {
  width: 100%; height: 8px; border: 0; border-radius: 999px;
  background: var(--bg-sunken); accent-color: var(--accent);
  overflow: hidden; margin-bottom: 14px;
}
progress::-webkit-progress-bar { background: var(--bg-sunken); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px;
  transition: width .15s ease; }

.logwrap { max-height: 320px; overflow: auto; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg-sunken); }
.log { margin: 0; padding: 10px 12px; font: 11.5px/1.65 var(--mono);
  white-space: pre-wrap; overflow-wrap: anywhere; color: var(--fg-muted); }
.log .l-err  { color: var(--bad); }
.log .l-warn { color: var(--canary); }
.log .l-ok   { color: var(--ok); }

.reconnect {
  margin-top: 18px; padding: 13px 16px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--fg); font-size: 13px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}

@media (max-width: 900px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .flashwrap { padding: 14px 12px 40px; }
}

/* ---- factory-zip extraction ---- */

.extrow { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; margin-top: 10px; }
.extrow input[type="file"] {
  flex: 1 1 320px; padding: 8px; border: 1px dashed var(--line); border-radius: 8px;
  background: var(--bg-sunken); color: var(--fg); font-size: 12.5px;
}
.extrow input[type="file"]::file-selector-button {
  margin-right: 10px; padding: 5px 12px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg-alt); color: var(--fg);
  font: inherit; font-size: 12px; cursor: pointer;
}
.extrow .btn { align-self: center; }

.ziplist { margin-top: 14px; border: 1px solid var(--line); border-radius: 8px;
  overflow: auto; max-height: 380px; background: var(--bg-sunken); }
.ztable { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ztable th {
  position: sticky; top: 0; z-index: 2; background: var(--bg-sunken);
  color: var(--fg-muted); font-size: 10.5px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .06em; text-align: left;
  padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.ztable td { padding: 6px 12px; border-bottom: 1px solid var(--line); }
.ztable tbody tr:last-child td { border-bottom: 0; }
.ztable tbody tr:hover { background: var(--bg-alt); }
.ztable tr.star td:first-child { color: var(--accent); font-weight: 600; }
.ztable .rel { font: 500 12.5px var(--mono); white-space: nowrap; }
.ztable td.act { text-align: right; white-space: nowrap; }
.ztable td.act .btn { margin-left: 6px; }
#zipnote { font-size: 12px; }
#zipnote code { font: 11.5px var(--mono); }

/* ---- remote extraction / proxy ---- */

.opt {
  display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 10px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em;
  vertical-align: 2px;
}

#urlin, #proxy {
  flex: 1 1 320px; padding: 7px 11px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg-alt); color: var(--fg);
  font: 12px var(--mono); min-width: 0;
}
#urlin:focus, #proxy:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.proxybox {
  margin-top: 12px; padding: 10px 13px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg-sunken);
}
.proxybox > summary {
  cursor: pointer; font-size: 12.5px; font-weight: 600; list-style: none;
  display: flex; align-items: center; gap: 8px;
}
.proxybox > summary::-webkit-details-marker { display: none; }
.proxybox > summary::before { content: "▸"; color: var(--fg-muted); font-size: 11px; }
.proxybox[open] > summary::before { content: "▾"; }
.proxybox > summary .muted, .proxybox > summary .state { margin-left: auto; font-weight: 400; }
.proxybox .hint { margin-top: 10px; }
.proxybox .extrow { margin-top: 8px; }
.proxybox .extrow .btn { align-self: center; flex: none; }
#proxyhint:empty { display: none; }
#proxyhint { color: var(--canary); }

.costline { margin-top: 8px; font-variant-numeric: tabular-nums; }
.costline strong { color: var(--ok); font-weight: 650; }
