:root {
  --bg: #0f1420; --panel: #171e2e; --panel2: #1e273b; --line: #2a3348;
  --text: #e8edf6; --muted: #8b97ad; --brand: #3b82f6; --brand2: #22d3ee;
  --ok: #34d399; --warn: #fbbf24; --bad: #f87171; --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand2); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--brand), var(--brand2)); display: grid; place-items: center; color: #04121f; font-weight: 900; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(59,130,246,.18), transparent), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.login-card h1 { font-size: 20px; margin: 16px 0 4px; }
.login-card p.sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
input, select, textarea { width: 100%; padding: 10px 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); }
button { cursor: pointer; border: none; border-radius: 10px; padding: 10px 14px; font-size: 14px; font-weight: 600; background: var(--brand); color: white; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.sm { padding: 6px 10px; font-size: 12px; }
button.danger { background: #3a2230; color: var(--bad); border: 1px solid #5b2a3a; }
button.ok { background: #16342c; color: var(--ok); border: 1px solid #1f5244; }
button:hover { filter: brightness(1.08); }
.full { width: 100%; margin-top: 18px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* App shell */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 4px; }
.side .nav { margin-top: 18px; display: flex; flex-direction: column; gap: 2px; }
.side .nav a { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500; }
.side .nav a:hover { background: var(--panel2); color: var(--text); }
.side .nav a.active { background: linear-gradient(90deg, rgba(59,130,246,.18), transparent); color: var(--text); box-shadow: inset 2px 0 0 var(--brand); }
.side .spacer { flex: 1; }
.side .who { font-size: 12px; color: var(--muted); padding: 10px 12px; border-top: 1px solid var(--line); }
.main { padding: 24px 28px; overflow: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.topbar h2 { margin: 0; font-size: 23px; letter-spacing: -.01em; }
.pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); }
.pill.admin { color: var(--brand2); border-color: #1e4a5a; }

.grid { display: grid; gap: 16px; }
.cards { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.cards .card { transition: transform .12s ease, border-color .12s ease; }
.cards .card:hover { border-color: #38435e; }
.stat { font-size: 30px; font-weight: 800; }
.stat .lbl { display: block; font-size: 12px; color: var(--muted); font-weight: 500; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: var(--panel2); }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--panel2); border: 1px solid var(--line); }
.tag.block { color: var(--bad); border-color: #5b2a3a; }
.tag.allow { color: var(--ok); border-color: #1f5244; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--ok); } .dot.off { background: #475267; }
.hidden { display: none !important; }
.section { margin-bottom: 28px; }
.form-inline { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; align-items: end; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live .dot { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
.student-tab { font-size: 12px; color: var(--muted); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel2); border: 1px solid var(--line); padding: 12px 16px; border-radius: 10px; font-size: 14px; z-index: 50; }

/* Live screens */
.cards.monitor { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.screencard { padding: 12px; }
.screen { position: relative; aspect-ratio: 16/10; background: #000; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; cursor: pointer; }
.screen img { width: 100%; height: 100%; object-fit: cover; display: none; }
.screen:hover { border-color: var(--brand); }
.screen-ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.screen-dot { position: absolute; top: 8px; right: 8px; box-shadow: 0 0 0 2px #000; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 100; padding: 24px; }
.modal-inner { position: relative; max-width: 96vw; max-height: 92vh; }
.modal-inner img { max-width: 96vw; max-height: 84vh; border-radius: 10px; border: 1px solid var(--line); }
.modal-x { position: absolute; top: -14px; right: -14px; width: 36px; height: 36px; border-radius: 50%; background: var(--panel2); border: 1px solid var(--line); color: var(--text); font-size: 16px; }
.modal-cap { text-align: center; margin-top: 10px; font-weight: 600; }

/* Filter mode switch */
.modeswitch { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode { text-align: left; background: var(--panel2); border: 1px solid var(--line); color: var(--text); padding: 14px 16px; border-radius: 12px; display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.mode strong { font-size: 15px; }
.mode span { font-size: 12px; color: var(--muted); font-weight: 400; }
.mode.on { border-color: var(--brand); background: linear-gradient(180deg, rgba(59,130,246,.14), rgba(59,130,246,.04)); box-shadow: 0 0 0 1px var(--brand) inset; }
.mode.on strong { color: var(--brand2); }
.catgrid { display: flex; flex-wrap: wrap; gap: 8px; }
.catchip { display: inline-flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: 13px; cursor: pointer; }
.catchip input { width: auto; }
@media (max-width: 640px) { .modeswitch { grid-template-columns: 1fr; } .grid[style*="1fr 1fr"] { grid-template-columns: 1fr !important; } }
@media (max-width: 720px) { .app { grid-template-columns: 1fr; } .side { flex-direction: row; overflow-x: auto; } .side .nav { flex-direction: row; margin: 0; } .side .spacer, .side .who, .side .brand { display: none; } }
