:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --off: #9ca3af;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #181b21;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #2a2f38;
    --accent: #3b82f6;
    --danger: #ef4444;
    --ok: #22c55e;
    --off: #555c68;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
header {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
header h1 { font-size: 18px; margin: 0; }
nav { display: flex; gap: 4px; }
nav button {
  border: 0; background: none; color: var(--muted); padding: 8px 14px; border-radius: 8px;
  font: inherit; cursor: pointer;
}
nav button.active { background: var(--bg); color: var(--text); font-weight: 600; }
main { padding: 24px; max-width: 1200px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }
h2 { font-size: 16px; margin: 0 0 4px; }
.section-head { margin-bottom: 16px; }
.section-head.row { display: flex; justify-content: space-between; align-items: center; }
.hint { color: var(--muted); margin: 0; font-size: 13px; }
.empty { color: var(--muted); }

button, select, input[type=text], input[type=number] {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.card .title { display: flex; align-items: center; gap: 8px; }
.card .title input { flex: 1; font-weight: 600; border-color: transparent; padding-left: 4px; }
.card .title input:hover, .card .title input:focus { border-color: var(--border); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.meta { color: var(--muted); font-size: 12px; }
.meta.warn { color: var(--accent); }
.meta.error { color: var(--danger); }
.field { display: flex; align-items: center; gap: 8px; }
.field label { width: 70px; color: var(--muted); font-size: 13px; }
.field select { flex: 1; min-width: 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions .spacer { flex: 1; }

.split { display: grid; grid-template-columns: 260px 1fr; gap: 24px; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.list li {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; border: 1px solid transparent;
  display: flex; justify-content: space-between; gap: 8px;
}
.list li:hover { background: var(--panel); }
.list li.active { background: var(--panel); border-color: var(--border); font-weight: 600; }
.list li .count { color: var(--muted); font-weight: normal; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; min-height: 200px; }
.panel .row { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.panel .row input[type=text] { flex: 1; min-width: 160px; font-weight: 600; }
.items { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-direction: column; gap: 6px; }
.items li {
  display: flex; align-items: center; gap: 10px; padding: 6px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg);
}
.items li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.items li input[type=number] { width: 64px; }
.items .num { color: var(--muted); width: 20px; text-align: right; }
.thumb { width: 64px; height: 36px; border-radius: 4px; object-fit: cover; background: #000; flex: none; }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.picker button { padding: 6px; text-align: left; display: flex; flex-direction: column; gap: 4px; }
.picker .thumb { width: 100%; height: 72px; }
.picker span { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  border: 2px dashed var(--border); border-radius: 12px; padding: 28px; cursor: pointer;
  background: var(--panel); margin-bottom: 16px;
}
.dropzone.over { border-color: var(--accent); }
#upload-progress .bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin: 4px 0 12px; }
#upload-progress .bar div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.tile video, .tile img { width: 100%; aspect-ratio: 16/9; object-fit: cover; background: #000; display: block; }
.tile .body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.tile .body .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .body .actions { justify-content: space-between; align-items: center; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  transition: transform .2s; pointer-events: none; max-width: calc(100% - 32px);
}
#toast.show { transform: translateX(-50%) translateY(0); }
@media (max-width: 600px) {
  main { padding: 16px; }
  header { padding: 12px 16px; }
}

/* ---- sign-in, pairing dialog, users ---- */
body.loading main, body.loading nav, body.loading .me { visibility: hidden; }
.me { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack h2 { margin: 0; }
.stack .meta { margin: 0; }
label.field { display: flex; align-items: center; gap: 10px; }
label.field > span { width: 90px; flex: none; color: var(--muted); font-size: 13px; }
label.field input, label.field select { flex: 1; min-width: 0; }
input[type=password] {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
}
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 20px;
  background: var(--panel); color: var(--text); width: min(460px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.forms { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 16px; }
.forms .panel { min-height: 0; }
.list.users li { cursor: default; background: var(--panel); border-color: var(--border); align-items: center; }
.list.users li > span:first-child { flex: 1; }
.meta.error:empty { display: none; }
@media (max-width: 600px) {
  label.field { flex-direction: column; align-items: stretch; gap: 4px; }
  label.field > span { width: auto; }
  .me #whoami { display: none; }
}
