:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #14161a;
  --muted: #5d6470;
  --line: #e3e6eb;
  --brand: #f97316;
  --brand-strong: #ea580c;
  --brand-text: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #a16207;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --idle: #475569;
  --idle-bg: #e2e8f0;
  --shadow: 0 10px 30px rgba(15, 17, 20, .12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1114;
    --surface: #171a1f;
    --surface-2: #1e2228;
    --text: #eef0f3;
    --muted: #9aa3ae;
    --line: #2a2f37;
    --ok: #4ade80;
    --ok-bg: rgba(74, 222, 128, .12);
    --warn: #fbbf24;
    --warn-bg: rgba(251, 191, 36, .12);
    --bad: #f87171;
    --bad-bg: rgba(248, 113, 113, .12);
    --idle: #cbd5e1;
    --idle-bg: rgba(203, 213, 225, .1);
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
  .logo-light { display: none; }
}
@media (prefers-color-scheme: light) { .logo-dark { display: none; } }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.mt8 { margin-top: 8px; }
.small { font-size: 12px; }

/* Buttons & inputs */
button { cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line); background: var(--surface); }
button:hover { background: var(--surface-2); }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); font-weight: 600; }
button.primary:hover { background: var(--brand-strong); }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button.link { border: 0; padding: 0; background: none; color: var(--brand-strong); font-weight: 600; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
}
label { display: block; font-weight: 600; margin: 14px 0 6px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 8px 0; }
label.check input { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 14px 0 0; padding: 4px 12px 8px; }
legend { font-weight: 600; padding: 0 4px; }
.error { color: var(--bad); margin: 10px 0 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-card .logo { height: 34px; }
.login-card h1 { font-size: 18px; margin: 18px 0 4px; }
.login-card button { width: 100%; margin-top: 18px; padding: 10px; }
.hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; }

/* Shell */
.topbar { display: flex; align-items: center; gap: 24px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { height: 26px; }
.product { color: var(--muted); font-weight: 600; border-left: 1px solid var(--line); padding-left: 12px; }
.tabs { display: flex; gap: 4px; margin-right: auto; }
.tabs button { border: 0; background: none; color: var(--muted); font-weight: 600; }
.tabs button[aria-selected="true"] { color: var(--text); background: var(--surface-2); }
.content { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; text-align: left; }
.stat:hover { border-color: var(--brand); background: var(--surface); }
.stat .value { font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }

/* Toolbar & table */
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1 1 260px; }
.toolbar select { flex: 0 1 200px; width: auto; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
.primary-text { font-weight: 600; }
.secondary-text { color: var(--muted); font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 32px; margin: 0; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.badge.idle { color: var(--idle); background: var(--idle-bg); }

/* Dialogs */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: min(460px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog.wide { width: min(760px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 12, 15, .5); }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.actions.start { justify-content: flex-start; margin-top: 0; }
.code-row { display: flex; gap: 8px; align-items: center; margin: 16px 0 8px; }
.code-row code { flex: 1; font-size: 18px; font-weight: 700; letter-spacing: .04em; padding: 12px; border-radius: 8px; background: var(--surface-2); border: 1px dashed var(--brand); text-align: center; overflow-wrap: anywhere; }
.warning { color: var(--warn); background: var(--warn-bg); padding: 10px 12px; border-radius: 8px; font-weight: 600; }
pre { background: var(--surface-2); border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Detail */
.detail-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.detail-head .close { padding: 4px 10px; }
dl.grid { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 16px 0; }
dl.grid dt { color: var(--muted); }
dl.grid dd { margin: 0; overflow-wrap: anywhere; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin: 22px 0 8px; }
.machine { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; }
.machine-head { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.edit-grid .full { grid-column: 1 / -1; }
.audit-mini { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.audit-mini table td, .audit-mini table th { padding: 8px 12px; font-size: 13px; }

/* Downloads */
.intro { margin-bottom: 16px; }
.intro h2 { font-size: 16px; margin: 0 0 4px; }
.intro p { margin: 0; max-width: 760px; }
.intro code { font-size: 12px; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }
.release { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; margin-bottom: 10px; }
.release.latest { border-color: var(--brand); }
.release h3 { margin: 0; font-size: 16px; display: flex; gap: 10px; align-items: center; }
.release .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.release .hash { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--muted);
  overflow-wrap: anywhere; margin-top: 6px; }
.release .release-actions { display: flex; gap: 8px; }

/* Toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 10; font-weight: 600; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  .product { display: none; }
  .tabs { order: 3; width: 100%; }
  .edit-grid { grid-template-columns: 1fr; }
  th:nth-child(3), td:nth-child(3), th:nth-child(5), td:nth-child(5) { display: none; }
}
