:root {
  --bg: #fff; --side: #f5f5f7; --bar: #f6f6f6; --line: #d9d9de; --ink: #1d1d1f; --dim: #6e6e73;
  --accent: #0a7aff; --sel: rgba(10, 122, 255, .12); --field: #fff;
  --red: #d70015; --redbg: #fff0f0; --stage: #b25000; --stagebg: #fff4e5; --green: #248a3d;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e; --side: #2c2c2e; --bar: #2b2b2d; --line: #3a3a3c; --ink: #f2f2f7; --dim: #98989d;
    --accent: #3b8eff; --sel: rgba(59, 142, 255, .22); --field: #1c1c1e;
    --red: #ff6961; --redbg: #3a1f1f; --stage: #ffb340; --stagebg: #3a2d17; --green: #30d158;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--field); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.on { background: var(--sel); border-color: var(--accent); color: var(--accent); }
button.plain { border: 0; background: none; padding: 4px 6px; color: var(--dim); }
button.danger { color: var(--red); }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], textarea, select {
  border: 1px solid var(--line); border-radius: 8px; background: var(--field); padding: 6px 8px; outline: none; min-width: 0;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--sel); }
textarea { width: 100%; resize: vertical; display: block; }
h2 { font-size: 13px; font-weight: 600; color: var(--dim); margin: 22px 0 6px; }
h2.today { color: var(--ink); }
.empty { color: var(--dim); text-align: center; margin: 60px 0; }
.empty.big { margin-top: 40vh; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 16px 2px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border-radius: 99px; padding: 5px 13px; font-size: 14px; }
.who { color: var(--dim); font-size: 14px; }
.meta { color: var(--dim); font-size: 13px; }

/* ---------- student ---------- */
.student #app { max-width: 640px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.student header { padding: max(14px, env(safe-area-inset-top)) 16px 8px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.student header h1 { font-size: 20px; margin: 0; }
.student header span { color: var(--dim); font-size: 14px; }
.student header .off { margin-left: auto; color: var(--red); }
.student main { flex: 1; padding: 4px 16px 90px; }
.student nav {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: center;
  background: var(--bar); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.student nav button { flex: 1; max-width: 160px; border: 0; background: none; border-radius: 0; padding: 14px 0; color: var(--dim); font-size: 15px; position: relative; }
.student nav button.on { color: var(--accent); font-weight: 600; background: none; }
.student nav i { font-style: normal; background: var(--red); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 600; padding: 1px 6px; margin-left: 5px; vertical-align: 2px; }
@media (prefers-color-scheme: dark) { .student nav i { color: #000; } }
.alert { display: block; width: calc(100% - 32px); margin: 0 16px 8px; text-align: left; background: var(--redbg); border-color: var(--red); color: var(--red); font-weight: 600; }
.late { margin: 12px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--stagebg); color: var(--stage); font-weight: 600; }

.item { display: grid; grid-template-columns: 82px 1fr auto; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); align-items: start; }
h2 + .item { border-top: 0; }
.item .time b { display: block; font-variant-numeric: tabular-nums; }
.item .time span { color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; }
.item .title { font-weight: 600; }
.item .room { margin-top: 5px; padding: 2px 9px; font-size: 13px; border-radius: 6px; color: var(--accent); }
.item .tag { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.item .stagetag { color: var(--stage); background: var(--stagebg); border-radius: 5px; padding: 1px 7px; }
.item .nowtag { color: #fff; background: var(--green); border-radius: 5px; padding: 1px 7px; }
@media (prefers-color-scheme: dark) { .item .nowtag { color: #000; } }
.item .wait { color: var(--accent); }
.item.past { opacity: .42; }
.item.now { background: var(--side); margin: 0 -16px; padding-left: 16px; padding-right: 16px; border-top-color: transparent; }
.item.now + .item { border-top-color: transparent; }

.mapbox { overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; max-height: 68vh; background: #fff; }
.mapin { position: relative; }
.mapin img { display: block; width: 100%; }
.pin {
  position: absolute; transform: translate(-50%, -50%); padding: 1px 7px; font-size: 12px; font-weight: 600; white-space: nowrap;
  border-radius: 6px; background: #1d1d1f; color: #fff; border: 1.5px solid #fff; line-height: 1.35;
}
.pin.on { background: #0a7aff; color: #fff; border-color: #fff; z-index: 2; box-shadow: 0 0 0 4px rgba(10, 122, 255, .35); }
.zoom { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; }
.zoom button { width: 44px; font-size: 18px; line-height: 1; padding: 7px 0; }
.roomrow { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: 10px 0; background: none; }
.roomrow.on { background: var(--sel); margin: 0 -16px; padding: 10px 16px; width: calc(100% + 32px); color: var(--ink); }
.roomrow span { font-size: 14px; }

.note { padding: 12px 0; border-top: 1px solid var(--line); }
.note:first-child { border-top: 0; }
.note .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.note.urgent .text { color: var(--red); font-weight: 600; }
.note.new .meta::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; }

.askform { margin-top: 8px; }
.askform .row { display: flex; gap: 8px; margin-top: 8px; }
.askform .row input { flex: 1; }
.qa { padding: 12px 0; border-top: 1px solid var(--line); }
h2 + .qa { border-top: 0; }
.qa .q { font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.qa .a { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- admin ---------- */
.admin { font-size: 14px; }
.admin .bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left)); background: var(--bar); border-bottom: 1px solid var(--line);
}
.admin .bar .title { font-weight: 600; font-size: 15px; }
.admin .bar .spacer { flex: 1; }
.admin .bar .saved { color: var(--dim); font-size: 12px; min-width: 44px; text-align: right; }
.admin .tabs { display: flex; gap: 2px; }
.admin .tabs button { border: 0; background: none; padding: 5px 10px; color: var(--dim); }
.admin .tabs button.on { background: var(--sel); color: var(--accent); font-weight: 600; }
.admin .tabs i { font-style: normal; background: var(--red); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; margin-left: 5px; }
.admin main { padding: 14px max(14px, env(safe-area-inset-right)) 80px max(14px, env(safe-area-inset-left)); max-width: 1100px; margin: 0 auto; }
.admin .tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.admin .tools .spacer { flex: 1; }
.admin .tools label { display: flex; gap: 6px; align-items: center; }
.admin input[type=number] { width: 64px; }
.login { max-width: 280px; margin: 22vh auto 0; display: flex; flex-direction: column; gap: 10px; padding: 0 16px; }
.login h1 { font-size: 20px; margin: 0 0 6px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; }
.list button.ev { display: flex; width: 100%; gap: 12px; text-align: left; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: none; padding: 12px 4px; }
.list button.ev b { flex: 1; }
.list button.ev span { color: var(--dim); }

table.sched { width: 100%; border-collapse: collapse; }
table.sched th { text-align: left; font-weight: 500; font-size: 12px; color: var(--dim); padding: 0 4px 4px; }
table.sched td { padding: 3px 4px; vertical-align: top; }
table.sched tr.day td { padding-top: 16px; font-weight: 600; }
table.sched input[type=text] { width: 100%; }
table.sched td.t { width: 1%; white-space: nowrap; }
table.sched tr.live td { background: var(--sel); }
.gsel { text-align: left; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gsel.none { color: var(--dim); }
.pop { position: absolute; z-index: 20; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .18); padding: 6px; max-height: 320px; overflow: auto; min-width: 180px; }
.pop label { display: flex; gap: 8px; padding: 5px 8px; border-radius: 6px; align-items: center; }
.pop label:hover { background: var(--side); }
@media (max-width: 760px) {
  table.sched thead { display: none; }
  table.sched tr { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 0; border-top: 1px solid var(--line); }
  table.sched td { padding: 0; width: auto !important; }
  table.sched td.title { flex: 1 1 100%; order: -1; }
  table.sched tr.day { border: 0; padding-bottom: 0; }
}
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; align-items: start; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } }
.admin .mapbox { max-height: none; margin: 0; }
.admin .mapbox.placing { cursor: crosshair; outline: 2px solid var(--accent); }
.rooms .r { display: grid; grid-template-columns: 1fr auto auto; gap: 4px; padding: 6px; border-radius: 8px; }
.rooms .r.on { background: var(--sel); }
.rooms .r input.note { grid-column: 1 / -1; font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; max-width: 460px; }
.field > span { font-size: 12px; color: var(--dim); }
.field .row, .rowf { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.field .row input { flex: 1; }
.glist { display: flex; flex-direction: column; gap: 4px; max-width: 460px; }
.glist .row { display: flex; gap: 4px; }
.glist .row input { flex: 1; }
.compose { max-width: 640px; margin-bottom: 20px; }
.compose .rowf { margin-top: 8px; }
.compose .rowf .spacer { flex: 1; }
.admin .note, .admin .qa { max-width: 640px; }
.admin .note .rowf, .admin .qa .rowf { margin-top: 6px; }
.admin .qa textarea { margin-top: 6px; }
.admin .qa.open .q::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--red); margin-right: 6px; }
canvas.qr { width: 150px; height: 150px; image-rendering: pixelated; background: #fff; padding: 6px; border-radius: 6px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1d1d1f; color: #fff; border-radius: 10px; padding: 9px 14px; display: none; gap: 12px; align-items: center; z-index: 50; font-size: 14px; }
#toast.show { display: flex; }
#toast button { background: none; border: 0; color: #6cb2ff; padding: 0; font-weight: 600; }

/* door signs */
#print { display: none; }
@media print {
  @page { size: A4 landscape; margin: 14mm; }
  body.printing #app, body.printing #toast { display: none; }
  body.printing #print { display: block; color: #000; }
  .sign { height: 180mm; page-break-after: always; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; position: relative; }
  .sign:last-child { page-break-after: auto; }
  .sign h1 { font-size: 34mm; line-height: 1.05; margin: 0; }
  .sign .g { font-size: 12mm; margin-top: 10mm; }
  .sign .n { font-size: 7mm; margin-top: 6mm; }
  .sign .foot { position: absolute; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-end; font-size: 5mm; }
  .sign canvas { width: 30mm; height: 30mm; image-rendering: pixelated; }
}
table.sched td.title { min-width: 170px; }
table.sched input[type=date], table.sched input[type=time] { padding: 6px 4px; }
.admin main { overflow-x: auto; }
