:root {
  --bg: #0f1419; --panel: #1a212b; --panel-2: #141a22; --line: #2a3441;
  --fg: #e6edf3; --muted: #8b98a5; --accent: #3b82f6; --accent-2: #2563eb;
  --green: #22c55e; --red: #ef4444; --amber: #f59e0b;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.boot { padding: 40px; color: var(--muted); text-align: center; }

/* ---- header ---- */
.topbar { display: flex; align-items: center; gap: 24px; height: 52px; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-size: 16px; font-weight: 700; letter-spacing: .3px; white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; height: 100%; }
.nav a { display: flex; align-items: center; padding: 0 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--fg); text-decoration: none; }
.nav a.active { color: var(--fg); border-bottom-color: var(--accent); }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: 8px; white-space: nowrap; }

/* ---- buttons & forms ---- */
.btn { background: var(--accent); color: #fff; border: 1px solid var(--accent); padding: 7px 14px; border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--accent-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn.ghost.danger { background: transparent; color: var(--red); border-color: var(--line); }
.btn.small { padding: 4px 10px; font-size: 12px; }
input, select { background: var(--bg); border: 1px solid var(--line); color: var(--fg); padding: 7px 10px; border-radius: 6px; font: inherit; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
label > input, label > select { color: var(--fg); font-size: 14px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--fg); font-size: 14px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin: 0; }
legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
.form-error { color: var(--red); min-height: 1.2em; font-size: 13px; }

/* ---- login ---- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { font-size: 22px; text-align: center; margin-bottom: 4px; }

/* ---- layout ---- */
.split { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 52px); }
.list-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-tools { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.device-list { overflow: auto; flex: 1; }
.device { padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer; border-left: 3px solid transparent; }
.device:hover { background: var(--panel-2); }
.device.sel { background: #0b1f3a; border-left-color: var(--accent); }
.device .name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.device .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.detail-pane { overflow: auto; padding: 20px; }
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.detail-head h2 { font-size: 20px; }
.page { padding: 20px; max-width: 1100px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h2 { font-size: 20px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; }

.empty { color: var(--muted); padding: 32px 16px; text-align: center; }
.empty-state { background: var(--panel); border: 1px dashed var(--line); border-radius: 8px; padding: 32px; text-align: center; }

/* ---- status ---- */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.off { background: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.done, .badge.online { color: var(--green); border-color: var(--green); }
.badge.failed { color: var(--red); border-color: var(--red); }
.badge.pending { color: var(--amber); border-color: var(--amber); }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: 4px; }

/* ---- console ---- */
.console { display: flex; gap: 8px; }
.console input { flex: 1; font-family: var(--mono); min-width: 0; }
pre { background: #0a0e13; border: 1px solid var(--line); border-radius: 6px; padding: 12px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 8px 0 0; max-height: 320px; font-family: var(--mono); font-size: 12.5px; }
pre.err { color: var(--red); }
.job { border-bottom: 1px solid var(--line); padding: 10px 0; }
.job:last-child { border-bottom: 0; }
.job .cmd { font-family: var(--mono); color: var(--accent); word-break: break-all; }
.job .when { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* ---- install modal ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 4px 0 12px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 8px 12px; font: inherit; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--fg); border-bottom-color: var(--accent); }
.code { position: relative; }
.code pre { padding-right: 76px; margin: 6px 0 12px; }
.code .btn { position: absolute; top: 8px; right: 8px; }
.note { background: #2a2110; border: 1px solid #5c4613; color: #f5d68a; border-radius: 6px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }
.token-row { display: flex; gap: 8px; align-items: center; }
.token-row code { flex: 1; font-family: var(--mono); font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; word-break: break-all; }
ul.downloads { list-style: none; padding: 0; margin: 0 0 12px; }
ul.downloads li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }

/* ---- modal & toasts ---- */
#modal { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; }
#modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); }
.modal { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; }
.modal.wide { max-width: 760px; }
.modal h2 { font-size: 17px; margin-bottom: 12px; }
#toasts { position: fixed; bottom: 16px; right: 16px; z-index: 20; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--green); border-radius: 6px; padding: 10px 14px; box-shadow: 0 4px 16px rgba(0, 0, 0, .4); }
.toast.error { border-left-color: var(--red); }

@media (max-width: 800px) {
  .topbar { flex-wrap: wrap; height: auto; gap: 4px 12px; padding: 8px 16px 0; }
  .nav { order: 3; width: 100%; height: 40px; overflow-x: auto; }
  .nav a { padding: 0 10px; }
  .split { grid-template-columns: 1fr; height: auto; }
  .list-pane { border-right: 0; border-bottom: 1px solid var(--line); max-height: 45vh; }
  .detail-pane, .page { padding: 16px; }
  .cards { grid-template-columns: 1fr; }
}
