:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1a1d23;
  --text-dim: #6b7280;
  --accent: #3b6fe0;
  --danger: #d64545;
  --online: #2fa84f;
  --offline: #9aa0a8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --border: #2b2f37;
    --text: #eef0f3;
    --text-dim: #9aa1ab;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar h1 { font-size: 18px; margin: 0; }

.topbar-actions { display: flex; align-items: center; }

.status-pill {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  margin-right: 12px;
}
.status-pill.online { background: rgba(47, 168, 79, 0.15); color: var(--online); }
.status-pill.offline { background: rgba(154, 160, 168, 0.15); color: var(--offline); }

.btn {
  border: 1px solid var(--border);
  background: var(--accent);
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.btn-ghost { background: transparent; color: var(--text); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 24px 24px 0;
  padding: 16px 20px;
}

.panel h2 {
  font-size: 14px;
  margin: 0 0 10px;
  color: var(--text);
}

.panel h2 .hint {
  font-weight: normal;
  color: var(--text-dim);
  font-size: 12px;
}

.panel-actions { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.panel-actions input {
  flex: 1;
  min-width: 180px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-size: 12px;
}
.chip button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 50%;
}
.chip button:hover { color: var(--danger); }

.violation-feed {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
}
.violation-feed li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.violation-feed li:last-child { border-bottom: none; }
.violation-feed .time { color: var(--text-dim); font-size: 11px; white-space: nowrap; }
.violation-feed .empty { color: var(--text-dim); font-size: 13px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  padding: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.online { background: var(--online); }
.dot.offline { background: var(--offline); }

.card-body { font-size: 13px; color: var(--text-dim); display: flex; flex-direction: column; gap: 2px; }

.badge {
  display: inline-block;
  margin-top: 4px;
  background: rgba(214, 69, 69, 0.15);
  color: var(--danger);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  width: fit-content;
}

.card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.card-actions button {
  flex: 1 1 auto;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.card-actions button:hover { border-color: var(--accent); color: var(--accent); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.hidden { display: none !important; }

.modal-content {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  width: min(480px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header { display: flex; justify-content: space-between; align-items: center; }

#modalScreen {
  width: 100%;
  border-radius: 8px;
  margin: 12px 0;
  background: #000;
  min-height: 160px;
  object-fit: contain;
}

.modal-actions { display: flex; gap: 8px; margin-top: 10px; }
.modal-actions input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.app-list { list-style: none; padding: 0; margin: 12px 0 0; max-height: 200px; overflow-y: auto; }
.app-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  gap: 8px;
}
.app-list li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-list li button {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.login-box { text-align: center; }
.login-box input {
  width: 100%;
  padding: 10px;
  margin: 12px 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

/* ── Modes panel ─────────────────────────────────────────────── */
.panel-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.panel-header-row h2 { margin: 0; }

.modes-list { display: flex; flex-direction: column; gap: 10px; }
.mode-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--bg);
}
.mode-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mode-card-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.mode-live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--offline); flex-shrink: 0; }
.mode-live-dot.active { background: var(--online); box-shadow: 0 0 0 3px rgba(47,168,79,0.18); }
.mode-card-meta { font-size: 12px; color: var(--text-dim); margin-top: 4px; line-height: 1.5; }
.mode-card-actions { display: flex; gap: 6px; flex-shrink: 0; }
.mode-card-actions button {
  border: 1px solid var(--border); background: transparent; color: var(--text);
  padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
.mode-card-actions button:hover { border-color: var(--accent); color: var(--accent); }
.mode-card-actions button.danger:hover { border-color: var(--danger); color: var(--danger); }
.modes-empty { color: var(--text-dim); font-size: 13px; }

/* ── Wizard ─────────────────────────────────────────────────── */
.modal-content.wizard { width: min(440px, 94vw); }
.wizard-steps {
  display: flex; gap: 6px; margin: 4px 0 16px;
}
.wizard-steps .wstep {
  flex: 1; text-align: center; font-size: 11px; color: var(--text-dim);
  padding-bottom: 6px; border-bottom: 2px solid var(--border);
}
.wizard-steps .wstep.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.wizard-steps .wstep.done { color: var(--online); border-bottom-color: var(--online); }
.wizard-caption { font-size: 13px; color: var(--text-dim); margin: 0 0 12px; text-align: center; }
.wizard-search {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  margin-bottom: 12px;
}
.wizard-nav { display: flex; gap: 8px; margin-top: 18px; }
.wizard-nav .btn { flex: 1; }
.wizard-nav .btn-ghost { flex: 0 0 auto; }

/* ── Calendar ───────────────────────────────────────────────── */
.cal { user-select: none; margin-bottom: 14px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-size: 14px; font-weight: 600; }
.cal-nav {
  border: 1px solid var(--border); background: transparent; color: var(--text);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 16px;
}
.cal-nav:hover { border-color: var(--accent); color: var(--accent); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--text-dim); padding: 4px 0; }
.cal-day {
  text-align: center; padding: 9px 0; border-radius: 8px; cursor: pointer;
  font-size: 13px; color: var(--text);
}
.cal-day.empty { visibility: hidden; }
.cal-day:hover { background: var(--bg); }
.cal-day.today { outline: 1px solid var(--border); }
.cal-day.selected { background: var(--accent); color: #fff; font-weight: 600; }

/* ── Wheel time picker ──────────────────────────────────────── */
.wheel-time {
  position: relative; display: flex; align-items: center; justify-content: center;
  gap: 4px; height: 200px;
}
.wheel-time .wheel-highlight {
  position: absolute; left: 0; right: 0; top: 80px; height: 40px;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: 8px; pointer-events: none;
}
.wheel {
  height: 200px; overflow-y: scroll; scroll-snap-type: y mandatory;
  padding: 80px 0; width: 68px; text-align: center;
  scrollbar-width: none; -ms-overflow-style: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 32%, #000 68%, transparent);
          mask-image: linear-gradient(to bottom, transparent, #000 32%, #000 68%, transparent);
}
.wheel::-webkit-scrollbar { display: none; }
.wheel-item {
  height: 40px; line-height: 40px; scroll-snap-align: center;
  font-size: 20px; color: var(--text-dim); transition: color .12s, transform .12s;
}
.wheel-item.active { color: var(--text); font-weight: 700; transform: scale(1.12); }
.wheel-colon { font-size: 22px; font-weight: 700; color: var(--text); }

/* ── App pick list ──────────────────────────────────────────── */
.app-pick-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.app-pick {
  display: flex; align-items: center; gap: 10px; padding: 9px 8px;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.app-pick:last-child { border-bottom: none; }
.app-pick input { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.app-pick .app-pick-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-pick .app-cfg-btn {
  border: 1px solid var(--border); background: transparent; color: var(--text-dim);
  padding: 3px 8px; border-radius: 6px; font-size: 11px; cursor: pointer; flex-shrink: 0;
}
.app-pick .app-cfg-btn:hover { border-color: var(--accent); color: var(--accent); }
.app-pick .app-cfg-btn.set { border-color: var(--online); color: var(--online); }

.mode-summary { font-size: 13px; color: var(--text-dim); line-height: 1.7; }

/* ── Student menu & toggles ─────────────────────────────────── */
.menu-subhead { font-size: 12px; color: var(--text-dim); margin: 8px 0; text-transform: uppercase; letter-spacing: .06em; }
.mode-toggle-list { display: flex; flex-direction: column; gap: 4px; }
.mode-toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 4px; border-bottom: 1px solid var(--border);
}
.mode-toggle-row:last-child { border-bottom: none; }
.mode-toggle-info { font-size: 13px; }
.mode-toggle-info small { display: block; color: var(--text-dim); font-size: 11px; margin-top: 2px; }
.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px;
  transition: background .15s; cursor: pointer;
}
.switch .slider::before {
  content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .15s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ── Weekday picker ─────────────────────────────────────────── */
.days-picker { display: flex; gap: 6px; justify-content: center; margin-bottom: 18px; flex-wrap: wrap; }
.day-chip {
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: transparent; color: var(--text);
  font-size: 13px; cursor: pointer; user-select: none; transition: background .12s, border-color .12s;
}
.day-chip:hover { border-color: var(--accent); }
.day-chip.on { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

.card-actions button.danger-btn:hover { border-color: var(--danger); color: var(--danger); }
