:root {
  --bg: #f6f3ee; --card: #ffffff; --ink: #2b2620; --muted: #776d62; --line: #e4ddd2;
  --brand: #8a4b12; --brand-2: #b8681d; --brand-soft: #f6e7d4; --ok: #2f7d4f; --ok-soft: #e1f2e7;
  --warn: #a86a00; --warn-soft: #fbefd5; --bad: #b3261e; --bad-soft: #f9e0de; --info: #2d5f8a; --info-soft: #e3edf6;
  --female: #b04a7a; --female-soft: #f7e3ec; --male: #2d5f8a; --male-soft: #e3edf6;
  --radius: 10px; --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 2px 8px rgba(60, 40, 20, .05);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 "Noto Sans", "Segoe UI", system-ui, -apple-system, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* top bar */
.topbar { background: linear-gradient(90deg, #6f3a0c, var(--brand-2)); color: #fff; position: sticky; top: 0; z-index: 30; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.topbar-inner { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; gap: 16px; padding: 0 16px; min-height: 56px; }
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand .wheel { width: 34px; height: 34px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.3)); }
.nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.nav a { color: #fff; padding: 8px 11px; border-radius: 8px; opacity: .92; white-space: nowrap; }
.nav a:hover, .nav a.active { background: rgba(255,255,255,.18); text-decoration: none; opacity: 1; }
.userbox { display: flex; align-items: center; gap: 8px; white-space: nowrap; font-size: .9rem; }
.userbox button { background: rgba(255,255,255,.18); color: #fff; border: 0; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.menu-toggle { display: none; background: none; border: 0; color: #fff; font-size: 24px; cursor: pointer; }

.page { max-width: 1280px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { margin: 0; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .num { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.stat .label { color: var(--muted); font-size: .85rem; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 38px; }
.btn:hover { text-decoration: none; border-color: #cbbfae; background: #fffaf3; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #723d0d; }
.btn.danger { color: var(--bad); border-color: #e7b7b2; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* forms */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
.field { margin-bottom: 4px; }
.field .hint { color: var(--muted); font-size: .8rem; margin-top: 2px; }
input[type=text], input[type=search], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; border: 1px solid #d6ccbd; border-radius: 8px; padding: 8px 10px; font: inherit; background: #fff; color: var(--ink); min-height: 38px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand-2); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 18px; height: 18px; }
.req::after { content: " *"; color: var(--bad); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.error-text { color: var(--bad); font-size: .82rem; margin-top: 2px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { min-width: 150px; }

/* alerts */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alert.ok { background: var(--ok-soft); border-color: #b9dcc6; color: #1f5a37; }
.alert.bad { background: var(--bad-soft); border-color: #eab8b3; color: #7d1a14; }
.alert.warn { background: var(--warn-soft); border-color: #ecd29e; color: #6d4700; }

/* tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th { text-align: left; background: #faf6f0; color: #5b5045; font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 8px 10px; border-bottom: 1px solid #f0ebe3; vertical-align: top; }
table.data tr:hover td { background: #fffaf3; }
table.data td.num, table.data th.num { text-align: right; }
table.data tr.row-left td { background: #fdf0ee; }
table.data tr.row-waiting td { background: #f4f8fc; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eee; color: #555; white-space: nowrap; }
.badge.waiting { background: var(--info-soft); color: var(--info); }
.badge.present { background: var(--warn-soft); color: var(--warn); }
.badge.completed { background: var(--ok-soft); color: var(--ok); }
.badge.left { background: var(--bad-soft); color: var(--bad); }
.badge.F { background: var(--female-soft); color: var(--female); }
.badge.M { background: var(--male-soft); color: var(--male); }
.badge.old { background: var(--brand-soft); color: var(--brand); }

/* tabs */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; scrollbar-width: thin; }
.tabs a { padding: 9px 13px; border-radius: 8px 8px 0 0; color: var(--muted); white-space: nowrap; font-weight: 600; font-size: .9rem; border: 1px solid transparent; border-bottom: 0; }
.tabs a:hover { color: var(--ink); text-decoration: none; background: #fff8ef; }
.tabs a.active { color: var(--brand); background: var(--card); border-color: var(--line); margin-bottom: -1px; }
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.steps a { flex: 1; min-width: 130px; padding: 10px 12px; border-radius: 8px; background: #fff; border: 1px solid var(--line); color: var(--muted); font-weight: 600; font-size: .88rem; }
.steps a .n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: #eee5d8; color: var(--brand); margin-right: 6px; font-size: .8rem; }
.steps a.active { border-color: var(--brand-2); color: var(--brand); background: var(--brand-soft); }
.steps a.done .n { background: var(--ok); color: #fff; }
.steps a:hover { text-decoration: none; }

/* status radios */
.status-group { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.status-group label { margin: 0; padding: 4px 9px; font-size: .78rem; cursor: pointer; border-right: 1px solid var(--line); background: #fff; font-weight: 600; color: var(--muted); white-space: nowrap; }
.status-group label:last-child { border-right: 0; }
.status-group input { display: none; }
.status-group input:checked + span { color: inherit; }
.status-group label.on-waiting { background: var(--info-soft); color: var(--info); }
.status-group label.on-present { background: var(--warn-soft); color: var(--warn); }
.status-group label.on-completed { background: var(--ok-soft); color: var(--ok); }
.status-group label.on-left { background: var(--bad-soft); color: var(--bad); }

.toast { position: fixed; right: 16px; bottom: 16px; background: #2b2620; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 100; opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }
.toast.bad { background: var(--bad); }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(480px, calc(100vw - 32px)); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(30,20,10,.45); }
dialog .dlg-body { padding: 18px; }

.pagination { display: flex; gap: 4px; flex-wrap: wrap; padding: 12px 18px; align-items: center; }
.pagination a, .pagination span { padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: .88rem; }
.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); }
.pagination .disabled { color: #bbb; }

.empty { padding: 30px; text-align: center; color: var(--muted); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 4px 12px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 10%, #fbe3c4, transparent 50%), radial-gradient(circle at 80% 90%, #f1d2ae, transparent 50%), var(--bg); }
.login-card { width: min(400px, 100%); background: #fff; border-radius: 16px; box-shadow: 0 12px 40px rgba(110, 60, 20, .18); padding: 28px; }
.login-card .logo { width: 92px; height: 92px; display: block; margin: 0 auto 8px; filter: drop-shadow(0 3px 6px rgba(120,70,0,.3)); }
.login-photo { background: linear-gradient(rgba(40,25,5,.45), rgba(40,25,5,.55)), url('../img/centre.jpg') center 35% / cover no-repeat fixed; }
.login-photo .login-card { background: rgba(255,255,255,.95); backdrop-filter: blur(4px); }
.login-card h1 { text-align: center; }

/* hall chart */
.hall { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 14px; align-items: start; }
.hall-side h3 { text-align: center; }
.hall-side.F h3 { color: var(--female); }
.hall-side.M h3 { color: var(--male); }
.hall-row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.hall-side { overflow-x: auto; padding-bottom: 4px; min-width: 0; }
.hall-side.F .hall-row { justify-content: flex-end; }
.hall-row .rl { width: 22px; text-align: center; font-weight: 700; color: var(--muted); flex: none; }
.seat { width: 92px; min-height: 58px; border: 1.5px dashed #d8cdbd; border-radius: 8px; background: #fffdf9; padding: 3px; position: relative; flex: none; }
.seat .sl { position: absolute; top: 1px; right: 5px; font-size: .68rem; color: #a99a88; font-weight: 700; }
.seat.blocked { background: repeating-linear-gradient(45deg, #eee, #eee 6px, #f8f8f8 6px, #f8f8f8 12px); border-style: solid; }
.seat.over { border-color: var(--brand-2); background: var(--brand-soft); }
.chip { border-radius: 6px; padding: 4px 6px; font-size: .74rem; line-height: 1.2; cursor: grab; user-select: none; touch-action: none; border: 1px solid; background: #fff; }
.F .chip { border-color: #e7bfd2; background: var(--female-soft); }
.M .chip { border-color: #bcd1e6; background: var(--male-soft); }
.chip .nm { text-align: center; font-weight: 700; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 8px; }
.chip .old-name { text-decoration: underline; text-underline-offset: 2px; }
.chip .meta { color: var(--muted); font-size: .68rem; }
.chip.picked { outline: 3px solid var(--brand-2); }
.chip.dragging { opacity: .4; }
.chip.ghost { position: fixed; pointer-events: none; z-index: 200; width: 88px; opacity: .9; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.teacher-seat { writing-mode: vertical-rl; background: var(--brand); color: #fff; border-radius: 10px; padding: 14px 8px; font-weight: 700; text-align: center; align-self: start; }
.basket { min-height: 70px; border: 2px dashed var(--brand-2); border-radius: 10px; padding: 8px; display: flex; flex-wrap: wrap; gap: 6px; background: #fffaf3; }
.basket .chip { width: 92px; }
.basket.over { background: var(--brand-soft); }

/* printing */
.print-only { display: none; }
@media print {
  @page { margin: 10mm; }
  body { background: #fff; font-size: 12px; }
  .topbar, .no-print, .tabs, .actions, .pagination, .filters, .menu-toggle, .toast { display: none !important; }
  .print-only { display: block; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; }
  table.data th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.data td, table.data th { padding: 4px 6px; border: 1px solid #ccc; }
  .page-break { page-break-after: always; }
  a { color: inherit; }
}

@media screen and (max-width: 900px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .menu-toggle { display: block; margin-left: auto; }
  .topbar-inner { flex-wrap: wrap; }
  .nav { display: none; width: 100%; flex-direction: column; padding-bottom: 10px; order: 3; }
  .nav.open { display: flex; }
  .userbox { order: 2; }
  .hall { grid-template-columns: minmax(0, 1fr); }
  .seat { width: 78px; }
  .basket .chip { width: 78px; }
  .teacher-seat { writing-mode: horizontal-tb; justify-self: center; }
}
@media screen and (max-width: 600px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .kv { grid-template-columns: 1fr; }
  .page { padding: 14px 12px 40px; }
  .userbox span { display: none; }
}

/* payment modes: light colours so cash / online / cheque are easy to tell apart */
.mode-cash { background: #d3efdc !important; border-color: #8fd0a6 !important; }
.mode-online { background: #d3e4f7 !important; border-color: #8db5e3 !important; }
.mode-cheque { background: #fae6b3 !important; border-color: #e3b955 !important; }
.stat.mode-cash .num { color: #1f6b3d; }
.stat.mode-online .num { color: #24588f; }
.stat.mode-cheque .num { color: #8a5a00; }
table.data td.mode-cash, table.data th.mode-cash { background: #dcf2e3 !important; }
table.data td.mode-online, table.data th.mode-online { background: #dce9f8 !important; }
table.data td.mode-cheque, table.data th.mode-cheque { background: #fbecc4 !important; }
table.data tr.row-mode-cash td { background: #dcf2e3; }
table.data tr.row-mode-online td { background: #dce9f8; }
table.data tr.row-mode-cheque td { background: #fbecc4; }
table.data tr.row-mode-cash:hover td { background: #c8ead3; }
table.data tr.row-mode-online:hover td { background: #c6dbf3; }
table.data tr.row-mode-cheque:hover td { background: #f7e0a6; }
table.data tr.row-mode-cash td:first-child { box-shadow: inset 4px 0 0 #2f8a52; }
table.data tr.row-mode-online td:first-child { box-shadow: inset 4px 0 0 #2d6db0; }
table.data tr.row-mode-cheque td:first-child { box-shadow: inset 4px 0 0 #c08a10; }
