/* Clickwork dashboard: light console style, follows the system dark mode. */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e7eb;
  --border-soft: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --accent: #4f6bff;
  --accent-soft: #eef2ff;
  --accent-text: #3046c5;
  --on: #22c55e;
  --off: #cbd5e1;
  --ok-bg: #ecfdf5; --ok-fg: #047857;
  --idle-bg: #f1f5f9; --idle-fg: #64748b;
  --info-bg: #eff6ff; --info-fg: #1d4ed8;
  --bad-bg: #fef2f2; --bad-fg: #b91c1c;
  --warn-bg: #fffbeb; --warn-border: #fde68a; --warn-fg: #92400e;
  --primary-bg: #0f172a; --primary-fg: #ffffff;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, .22);
  --radius: 12px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0e14;
    --surface: #131823;
    --surface-2: #10141d;
    --border: #232a38;
    --border-soft: #1b2130;
    --text: #e6e9ef;
    --muted: #8b95a7;
    --faint: #5d6778;
    --accent: #6b83ff;
    --accent-soft: #1b2340;
    --accent-text: #a9b7ff;
    --on: #22c55e;
    --off: #3a4354;
    --ok-bg: #0f2a20; --ok-fg: #4ade80;
    --idle-bg: #1b2130; --idle-fg: #8b95a7;
    --info-bg: #14223f; --info-fg: #8fb2ff;
    --bad-bg: #331417; --bad-fg: #fca5a5;
    --warn-bg: #2a2110; --warn-border: #5c4512; --warn-fg: #fcd34d;
    --primary-bg: #e6e9ef; --primary-fg: #0b0e14;
    --shadow-sm: none;
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 8px 13px; font-weight: 600; font-size: 13px; line-height: 1.2;
  background: var(--primary-bg); color: var(--primary-fg);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .5; cursor: default; filter: none; }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); filter: none; }
.btn.danger { background: var(--bad-fg); color: #fff; }
.btn.danger.ghost { background: var(--surface); color: var(--bad-fg); border-color: var(--border); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.icon-btn {
  border: 0; background: transparent; color: var(--faint); cursor: pointer;
  width: 30px; height: 30px; border-radius: 8px; display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

label.field { display: block; font-weight: 600; font-size: 12.5px; margin: 0 0 12px; }
label.field input {
  display: block; width: 100%; margin-top: 5px;
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); font-weight: 400; font-size: 14px;
}
label.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 6px 0; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.error { color: var(--bad-fg); background: var(--bad-bg); border-radius: 8px; padding: 8px 11px; font-size: 13px; margin: 8px 0 0; }
.note { color: var(--ok-fg); font-size: 13px; margin: 8px 0 0; }
.warn {
  background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-fg);
  border-radius: 8px; padding: 9px 11px; font-size: 12.5px; margin: 12px 0;
}

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 14px; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #4f6bff, #22c1a5);
}
.sidebar .brand { margin: 2px 4px 26px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--faint); font-weight: 500; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border-soft); padding-top: 12px; }
.conn { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); margin: 0 4px 10px; }
.conn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.conn.live::before { background: var(--on); box-shadow: 0 0 0 3px color-mix(in srgb, var(--on) 25%, transparent); }
.sidebar-foot form .btn { width: 100%; }

.content { flex: 1; min-width: 0; padding: 28px 32px 40px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.015em; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.topbar, .tabbar { display: none; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow-sm); }
.stat b { display: block; font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.stat span { font-size: 12px; color: var(--muted); }

/* ---------- board cards ---------- */
.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 16px 8px; box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head .name { font-weight: 650; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta { font-size: 12px; color: var(--muted); margin: 3px 0 12px; }
.pill {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-size: 11.5px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); }
.pill.idle { background: var(--idle-bg); color: var(--idle-fg); }
.pill.info { background: var(--info-bg); color: var(--info-fg); }
.pill.bad { background: var(--bad-bg); color: var(--bad-fg); }
.pill.plain::before { display: none; }

.ota-line { font-size: 12px; margin: -4px 0 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.progress { height: 4px; border-radius: 9px; background: var(--accent-soft); overflow: hidden; margin: -4px 0 12px; }
.progress i { display: block; height: 100%; width: 40%; border-radius: 9px; background: var(--accent); animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }

.relay {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 0; border-top: 1px solid var(--border-soft); min-height: 42px;
}
.relay-name { display: flex; align-items: center; gap: 6px; min-width: 0; }
.relay-name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 10.5px; font-weight: 700; letter-spacing: .02em; color: var(--accent-text); background: var(--accent-soft); border-radius: 4px; padding: 1px 5px; }
.hint { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.hint.err { color: var(--bad-fg); }

.switch {
  position: relative; flex: none; width: 38px; height: 22px; border-radius: 999px; border: 0; padding: 0;
  background: var(--off); cursor: pointer; transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: left .15s;
}
.switch[aria-checked="true"] { background: var(--on); }
.switch[aria-checked="true"]::after { left: 19px; }
.switch.pending { background: color-mix(in srgb, var(--on) 45%, var(--off)); }
.switch.pending::after { left: 11px; }
.switch:disabled { opacity: .45; cursor: default; }

.empty {
  border: 1.5px dashed var(--border); border-radius: var(--radius); padding: 40px 20px;
  text-align: center; color: var(--muted);
}
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 15px; }
.empty .btn { margin-top: 14px; }

/* ---------- menu ---------- */
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: 34px; z-index: 5; min-width: 160px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 5px;
}
.menu-list button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13px;
}
.menu-list button:hover { background: var(--surface-2); }
.menu-list button.danger { color: var(--bad-fg); }

/* ---------- firmware ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 1.5px dashed color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface));
  border-radius: var(--radius); padding: 26px 18px; text-align: center; color: var(--muted);
  cursor: pointer; margin-bottom: 18px; transition: background .15s, border-color .15s;
}
.drop strong { color: var(--accent-text); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop svg { color: var(--accent); }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); background: var(--surface-2); padding: 10px 16px; font-weight: 600; white-space: nowrap;
}
td { padding: 12px 16px; border-top: 1px solid var(--border-soft); vertical-align: middle; }
td.actions { text-align: right; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- dialogs ---------- */
dialog {
  border: 0; padding: 0; border-radius: 14px; width: min(460px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
.dlg { padding: 22px; }
.dlg h2 { margin: 0 0 4px; font-size: 17px; letter-spacing: -.01em; }
.dlg > p.lead { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.dlg-actions .spacer { flex: 1; }
.steps { display: flex; gap: 6px; margin-bottom: 16px; font-size: 12px; }
.steps span { flex: 1; text-align: center; padding: 6px; border-radius: 7px; background: var(--surface-2); color: var(--muted); }
.steps span.on { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.code {
  font-family: var(--mono); font-size: 11.5px; line-height: 1.55; word-break: break-all;
  background: #0f172a; color: #e2e8f0; border-radius: 8px; padding: 12px; user-select: all;
}
.relay-edit { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: end; }
.relay-edit label.field { margin: 0; }
.relay-edit .check { margin: 0 0 9px; white-space: nowrap; }
.confirm-box { background: var(--bad-bg); border-radius: 10px; padding: 12px; margin-top: 14px; font-size: 13px; }
.confirm-box p { margin: 0 0 10px; }
.board-pick { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; padding: 4px 12px; }
.board-pick .check { padding: 6px 0; margin: 0; border-bottom: 1px solid var(--border-soft); }
.board-pick .check:last-child { border-bottom: 0; }

/* ---------- add-board wizard ---------- */
dialog.wiz { width: min(340px, calc(100vw - 32px)); }
.wiz form { padding: 18px 20px 20px; }
.wiz-top { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.wiz-top .icon-btn { margin-left: -6px; }
.wiz-top .wiz-close { margin: 0 -6px 0 0; }
.wiz-top .icon-btn[hidden] { display: inline-grid !important; visibility: hidden; }
.wiz-dots { display: flex; gap: 5px; flex: 1; }
.wiz-dots i { flex: 1; height: 4px; border-radius: 9px; background: var(--border); transition: background .2s; }
.wiz-dots i.on { background: var(--accent); }
.wiz-help-btn {
  width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; display: grid; place-items: center;
}
.wiz-help-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.wiz-step h2 { margin: 0 0 3px; font-size: 18px; letter-spacing: -.015em; }
.wiz-sub { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.wiz-step input {
  display: block; width: 100%; margin: 0 0 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface); font-size: 14px;
}
.wiz-step input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.wiz-next { width: 100%; padding: 10px; margin-top: 6px; }
.wiz-art {
  height: 150px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border-soft);
  display: grid; place-items: center; margin-bottom: 16px; padding: 10px;
}
.wiz-art .code { width: 100%; max-height: 128px; overflow: hidden; font-size: 10.5px; }
.art-a { fill: color-mix(in srgb, var(--accent) 16%, var(--surface)); stroke: color-mix(in srgb, var(--accent) 35%, var(--surface)); }
.art-b { fill: color-mix(in srgb, #22c1a5 16%, var(--surface)); stroke: color-mix(in srgb, #22c1a5 40%, var(--surface)); }
.art-cap { fill: var(--muted); font-family: var(--font); font-size: 10px; }
.art-pin { fill: var(--text); font-weight: 600; }
.art-gnd { stroke: var(--text); }
.keys { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; }
kbd {
  font-family: var(--mono); font-size: 12.5px; font-weight: 600; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-bottom-width: 3px;
  border-radius: 7px; padding: 5px 10px;
}
.wiz-help {
  background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: 10px;
  padding: 10px 12px; margin: -4px 0 14px; font-size: 12.5px; line-height: 1.6; color: var(--muted);
}
.wiz-help b { color: var(--text); }
.linkish { border: 0; background: none; padding: 0; color: var(--accent-text); font-weight: 600; font-size: 12.5px; cursor: pointer; }
.wiz-live { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 14px; font-size: 12.5px; color: var(--info-fg); }
.spin { width: 12px; height: 12px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--info-fg) 25%, transparent); border-top-color: var(--info-fg); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.big-check {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ok-bg); color: var(--ok-fg); font-size: 26px; font-weight: 700;
}

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow-sm);
}
.login-card .brand { margin-bottom: 22px; }
.login-card h1 { font-size: 19px; margin: 0 0 4px; letter-spacing: -.01em; }
.login-card p.lead { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-card .btn { width: 100%; padding: 10px; margin-top: 4px; }

/* ---------- tablets: icon-only sidebar ---------- */
@media (min-width: 761px) and (max-width: 1100px) {
  .sidebar { width: 68px; padding: 18px 10px; align-items: center; }
  .sidebar .lbl, .sidebar .count { display: none; }
  .sidebar .brand { margin: 2px 0 26px; }
  .nav a { justify-content: center; padding: 10px; }
  .sidebar-foot { width: 100%; display: flex; flex-direction: column; align-items: center; }
  .sidebar .conn { font-size: 0; margin: 0 0 12px; }
  .sidebar-foot form .btn { width: 44px; padding: 9px; }
  .content { padding: 24px 24px 40px; }
}

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    position: sticky; top: 0; z-index: 4; padding: 12px 16px;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
  }
  .topbar .conn { margin: 0; }
  .content { padding: 18px 16px 90px; }
  .page-head h1 { font-size: 20px; }
  .page-head p { display: none; }
  .stats { gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 17px; }
  .board-grid { grid-template-columns: 1fr; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a, .tabbar button {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 11px; color: var(--muted); text-decoration: none; padding: 4px 0;
    border: 0; background: transparent; cursor: pointer;
  }
  .tabbar a.active { color: var(--accent-text); font-weight: 600; }
  .tabbar form { flex: 1; display: flex; }
  th:nth-child(2), td:nth-child(2), th:nth-child(3), td:nth-child(3) { display: none; }
  .relay { min-height: 48px; }
}
