/* ============================================================
   RESET & BASE
============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:   #0984e3;
  --secondary: #636e72;
  --danger:    #d63031;
  --success:   #00b894;
  --bg:        #f0f2f5;
  --surface:   #ffffff;
  --border:    #dfe6e9;
  --text:      #2d3436;
  --text-muted:#636e72;
  --header-h:  52px;
  --tabs-h:    40px;
  --toolbar-h: 48px;
  --footer-h:  28px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* ============================================================
   BUTTONS
============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 14px;
  border: none; border-radius: 6px;
  cursor: pointer; font-size: 13px; font-weight: 500;
  white-space: nowrap; transition: opacity .15s, transform .1s;
  line-height: 1.4;
}
.btn:hover  { opacity: .85; }
.btn:active { transform: scale(.97); }

.btn-primary   { background: var(--primary);   color: #fff; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-danger    { background: var(--danger);    color: #fff; }
.btn-success   { background: var(--success);   color: #fff; }
.btn-sm        { padding: 4px 10px; font-size: 12px; }

.btn-icon {
  background: none; border: none; cursor: pointer;
  padding: 2px 5px; font-size: 13px; border-radius: 4px;
  opacity: .65; transition: opacity .15s, background .15s;
}
.btn-icon:hover { opacity: 1; background: rgba(0,0,0,.08); }

/* ============================================================
   HEADER
============================================================ */
header {
  height: var(--header-h);
  background: #1e272e;
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  z-index: 10; position: relative;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.logo        { font-size: 1.5rem; }
header h1    { font-size: 1.1rem; font-weight: 600; }
.header-right{ display: flex; gap: 8px; }

/* ============================================================
   ROOM TABS BAR
============================================================ */
.room-bar {
  height: var(--tabs-h);
  background: #2d3436;
  display: flex; align-items: center;
  padding: 0 14px; gap: 8px;
  flex-shrink: 0; overflow-x: auto;
}
.room-tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }

.room-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 14px; border-radius: 5px 5px 0 0;
  cursor: pointer; color: #b2bec3; font-size: 13px;
  background: rgba(255,255,255,.06); border: none;
  transition: background .15s, color .15s; white-space: nowrap;
}
.room-tab:hover { color: #fff; background: rgba(255,255,255,.12); }
.room-tab.active{ color: #fff; background: var(--primary); }

.tab-edit {
  font-size: 11px; opacity: .6; cursor: pointer;
  padding: 1px 3px; border-radius: 3px;
}
.tab-edit:hover { opacity: 1; background: rgba(255,255,255,.2); }

/* ============================================================
   TOOLBAR
============================================================ */
.toolbar {
  height: var(--toolbar-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px; flex-shrink: 0; flex-wrap: wrap; overflow: hidden;
}
.toolbar-group { display: flex; align-items: center; gap: 6px; }
.toolbar-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }

.mode-btn {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
}
.mode-btn:hover { background: var(--border); }
.mode-btn.active{ background: var(--primary); color: #fff; border-color: var(--primary); }

.toolbar select {
  padding: 5px 8px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px; background: var(--surface);
  color: var(--text); cursor: pointer;
}

/* ============================================================
   APP BODY  (3-column)
============================================================ */
.app-body {
  display: flex;
  height: calc(100vh - var(--header-h) - var(--tabs-h) - var(--toolbar-h) - var(--footer-h));
  overflow: hidden;
}

.panel { display: flex; flex-direction: column; background: var(--surface); overflow: hidden; }

.panel-left, .panel-right {
  width: 258px; flex-shrink: 0;
}
.panel-left  { border-right: 1px solid var(--border); }
.panel-right { border-left:  1px solid var(--border); }
.panel-centre{ flex: 1; overflow: hidden; display: flex; flex-direction: column; }

.panel-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.panel-header h2  { font-size: 13px; font-weight: 600; }
.panel-actions    { display: flex; gap: 5px; flex-wrap: wrap; }

/* ============================================================
   STUDENT LIST
============================================================ */
.student-list { flex: 1; overflow-y: auto; padding: 8px; }

.empty-msg {
  padding: 20px 10px; color: var(--text-muted);
  font-size: 12px; text-align: center; line-height: 1.6;
}

.student-card {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; margin-bottom: 5px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: grab;
  transition: box-shadow .15s, border-color .15s;
  position: relative;
}
.student-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.1); border-color: var(--primary); }
.student-card:active{ cursor: grabbing; }
.student-card.is-seated { opacity: .55; }
.student-card.is-seated::after {
  content: "✔ seated";
  position: absolute; right: 34px; top: 50%; transform: translateY(-50%);
  font-size: 10px; color: var(--success); font-weight: 600;
}

.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; flex-shrink: 0;
  background-size: cover; background-position: center;
}
.avatar.male   { background-color: #0984e3; }
.avatar.female { background-color: #e84393; }
.avatar.other  { background-color: #6c5ce7; }

.s-info       { flex: 1; min-width: 0; }
.s-name       { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.s-details    { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.s-actions    { display: flex; gap: 1px; flex-shrink: 0; }

/* ============================================================
   ROOM HEADER / CONFIG
============================================================ */
.room-header {
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0; flex-wrap: wrap; gap: 8px;
}
.room-header h2   { font-size: 15px; font-weight: 600; }
.room-config      { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.room-config label{
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text-muted);
}
.room-config input[type="number"] {
  width: 52px; padding: 3px 6px;
  border: 1px solid var(--border); border-radius: 5px; font-size: 12px;
}
.room-config-group { display: flex; align-items: center; gap: 6px; }
.room-config-sep   { font-size: 11px; color: var(--text-muted); font-weight: 500; white-space: nowrap; }

/* ── Direction buttons ── */
.dir-btn {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
  padding: 3px 8px; min-width: 28px;
  font-size: 13px; border-radius: 5px;
  cursor: pointer; transition: all .12s;
}
.dir-btn:hover  { background: var(--border); }
.dir-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ============================================================
   GRID
============================================================ */
.grid-scroll {
  flex: 1; overflow: auto; padding: 20px;
  display: flex; align-items: flex-start; justify-content: center;
}

.grid-wrapper { display: flex; flex-direction: column; align-items: center; gap: 10px; }

/* ── Front of class direction variants ── */
#grid-wrapper[data-front-dir="top"]    { flex-direction: column; }
#grid-wrapper[data-front-dir="bottom"] { flex-direction: column-reverse; }
#grid-wrapper[data-front-dir="left"]   { flex-direction: row; }
#grid-wrapper[data-front-dir="right"]  { flex-direction: row-reverse; }

/* Vertical label for left/right directions */
#grid-wrapper[data-front-dir="left"] .front-label,
#grid-wrapper[data-front-dir="right"] .front-label {
  writing-mode: vertical-rl;
  padding: 18px 4px;
  letter-spacing: 2px;
}
#grid-wrapper[data-front-dir="left"] .front-label {
  transform: rotate(180deg);
}

.front-label {
  background: #2d3436; color: #fff;
  padding: 3px 22px; border-radius: 4px;
  font-size: 11px; letter-spacing: 1.5px; font-weight: 600;
  white-space: nowrap;
}

.room-grid { display: grid; gap: 6px; }

/* ── Freeform canvas ── */
.room-grid.freeform {
  display: block;
  position: relative;
  background-color: #f0f2f5;
  background-image: radial-gradient(circle, #b2bec3 1px, transparent 1px);
  background-size: 42px 42px;
  border: 1px dashed #b2bec3;
  border-radius: 8px;
  overflow: visible;
  flex-shrink: 0;
}
.room-grid.layout-canvas { cursor: crosshair; }

.no-room-msg {
  color: var(--text-muted); font-style: italic; padding: 60px 20px; text-align: center;
}

/* ── SEAT CELLS ── */
.seat-cell {
  width: 78px; height: 78px;
  border-radius: 8px; border: 2px solid var(--border);
  background: #fafbfc;
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden; transition: all .15s;
  user-select: none;
}

.seat-cell.has-student { background: #fff; border-color: #b2bec3; }

.seat-cell.seat-disabled {
  background: transparent; border: 2px dashed #dee2e6; cursor: default;
}
.seat-cell.seat-disabled * { display: none; }

/* mode-specific cursor / hover */
.seat-cell.toggleable  { cursor: pointer; }
.seat-cell.toggleable:hover { border-color: var(--success); background: #e8f5e9; }
.seat-cell.seat-disabled.toggleable:hover { border-color: var(--success); background: #f0fff4; }

.seat-cell.cluster-mode { cursor: pointer; }
.seat-cell.cluster-mode:hover { border-color: #fdcb6e; background: #fffde7; }
.seat-cell.in-cluster   { border-width: 3px; }

.seat-cell.drag-over { border-color: var(--primary) !important; background: #e3f2fd !important; transform: scale(1.04); }

/* ── Freeform absolute seat ── */
.seat-cell.freeform-seat {
  position: absolute;
}
/* In layout mode: desks show a move cursor */
.seat-cell.layout-draggable {
  cursor: move;
  touch-action: none;
}
.seat-cell.layout-draggable:hover {
  border-color: #6c5ce7;
  background: #f3f0ff;
  box-shadow: 0 2px 12px rgba(108,92,231,.3);
}
.seat-cell.dragging {
  opacity: .8;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  z-index: 100;
}

/* ── MINI STUDENT (inside seat) ── */
.mini-student {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; width: 100%; height: 100%; padding: 5px 3px;
  cursor: grab; border-radius: 6px;
}
.mini-student:active { cursor: grabbing; }
.mini-student:hover  { background: rgba(0,0,0,.04); }
.mini-pinned         { cursor: not-allowed !important; }

.mini-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; flex-shrink: 0;
  background-size: cover; background-position: center;
}
.mini-avatar.male   { background-color: #0984e3; }
.mini-avatar.female { background-color: #e84393; }
.mini-avatar.other  { background-color: #6c5ce7; }

.mini-name {
  font-size: 10px; font-weight: 600; text-align: center;
  width: 100%; color: var(--text); line-height: 1.2;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}

/* ── SEAT INFO BAR ── */
.seat-info-bar {
  min-height: 28px; padding: 4px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
  flex-shrink: 0; display: flex; align-items: center;
}

/* ============================================================
   CLUSTER PANEL
============================================================ */
.cluster-list { flex: 1; overflow-y: auto; padding: 8px; }

.cluster-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px; margin-bottom: 5px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); transition: box-shadow .15s;
}
.cluster-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.cluster-item.cluster-dragging { opacity: .4; }
.cluster-item.cluster-drag-over { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); }

.cluster-drag-handle {
  font-size: 14px; color: var(--text-muted); cursor: grab; flex-shrink: 0;
  padding: 0 2px; user-select: none;
}
.cluster-drag-handle:active { cursor: grabbing; }

.cluster-dot   { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; }
.cluster-name  { font-size: 13px; font-weight: 500; flex: 1; min-width: 0; }
.cluster-count { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.cluster-actions{ display: flex; gap: 2px; }
.cluster-ability-badge {
  font-size: 10px; font-weight: 700; padding: 1px 5px;
  border-radius: 4px; background: var(--primary); color: #fff;
  white-space: nowrap; flex-shrink: 0;
}

.cluster-legend {
  padding: 6px 10px; border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-muted);
  flex-shrink: 0;
}

/* ============================================================
   MODALS
============================================================ */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 1000;
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 12px;
  width: 100%; max-width: 440px;
  max-height: 90vh; overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.modal-wide { max-width: 680px; }

.modal-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-header h3  { font-size: 15px; font-weight: 600; }
.modal-close {
  background: none; border: none; font-size: 18px;
  cursor: pointer; color: var(--text-muted); line-height: 1;
  padding: 2px 6px; border-radius: 4px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body {
  padding: 18px; overflow-y: auto; flex: 1;
}

.modal-footer {
  padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0;
}

/* ── FORM ELEMENTS ── */
.form-row { display: flex; gap: 16px; }
.form-col  { flex: 1; display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.form-group {
  display: flex; flex-direction: column; gap: 5px;
}
.form-group label {
  font-size: 12px; font-weight: 500; color: var(--text-muted);
}
.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; color: var(--text); background: var(--surface);
  transition: border .15s;
}
.form-group input:focus,
.form-group select:focus { outline: none; border-color: var(--primary); }

/* photo upload */
.photo-upload-row  { display: flex; align-items: center; gap: 10px; }
.photo-preview-box {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; flex-shrink: 0;
  background-size: cover; background-position: center;
  overflow: hidden;
}
.photo-file-label { cursor: pointer; }

/* constraint lists */
.constraint-list {
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px; max-height: 130px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 3px;
}
.constraint-list .empty-msg { padding: 8px 4px; font-size: 11px; }

.chk-label {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; cursor: pointer; padding: 2px 3px;
  border-radius: 4px;
}
.chk-label:hover { background: var(--bg); }
.chk-label input  { cursor: pointer; }

/* ============================================================
   SCROLLBAR
============================================================ */
::-webkit-scrollbar          { width: 6px; height: 6px; }
::-webkit-scrollbar-track    { background: transparent; }
::-webkit-scrollbar-thumb    { background: #b2bec3; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--secondary); }

/* ============================================================
   MOBILE NAVIGATION BAR
============================================================ */
.mobile-tab-bar {
  display: none;
  background: #1e272e;
  border-top: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
  z-index: 20;
}
.mobile-tab {
  flex: 1;
  background: none;
  border: none;
  border-top: 2px solid transparent;
  color: #b2bec3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 0;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.mobile-tab.active { color: #fff; border-top-color: var(--primary); }
.mobile-tab .tab-icon  { font-size: 20px; line-height: 1; }
.mobile-tab .tab-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }

/* ============================================================
   RESPONSIVE: ≤ 860px — show mobile nav, panel switching
============================================================ */
@media (max-width: 860px) {
  :root { --mobile-nav-h: 56px; }

  /* Show mobile nav bar */
  .mobile-tab-bar { display: flex; }

  /* Account for mobile nav bar in app body height */
  .app-body {
    height: calc(100vh - var(--header-h) - var(--tabs-h) - var(--toolbar-h) - var(--footer-h) - var(--mobile-nav-h));
  }

  /* All panels fill the full width */
  .panel-left, .panel-right, .panel-centre {
    width: 100% !important;
    flex-shrink: 0;
  }

  /* Default: show only room (centre) panel */
  .panel-left, .panel-right { display: none; }

  /* Students tab → show left panel, hide others */
  .app-body[data-active-panel="students"] .panel-left   { display: flex; }
  .app-body[data-active-panel="students"] .panel-centre { display: none; }

  /* Clusters tab → show right panel, hide others */
  .app-body[data-active-panel="clusters"] .panel-right  { display: flex; }
  .app-body[data-active-panel="clusters"] .panel-centre { display: none; }
}

/* ============================================================
   RESPONSIVE: ≤ 600px — phone-specific tweaks
============================================================ */
@media (max-width: 600px) {
  /* ── Header: compact, hide title to save space ── */
  header { padding: 0 10px; }
  header h1 { display: none; }
  .header-right { gap: 4px; }
  .header-right .btn { padding: 4px 8px; font-size: 11px; gap: 2px; }

  /* ── Toolbar: single-row horizontal scroll ── */
  .toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
    padding: 0 10px;
    scrollbar-width: none;
  }
  .toolbar::-webkit-scrollbar { display: none; }

  /* ── Room header: allow horizontal scroll for config buttons ── */
  .room-header { overflow-x: auto; }
  .room-config { flex-wrap: nowrap; }

  /* ── Modals: full-width bottom sheet ── */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal, .modal-wide {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 14px 14px 0 0;
  }

  /* ── Form rows: stack columns vertically ── */
  .form-row { flex-direction: column; }

  /* ── Class set modal: stack layout ── */
  .classset-layout { flex-direction: column; }
  .classset-list-col { width: 100%; }
}

/* ── Dark mode: mobile tab bar ── */
body.dark-mode .mobile-tab-bar { background: #0f1319; border-top-color: rgba(255,255,255,.06); }

/* ============================================================
   AUTOSAVE BADGE
============================================================ */
.autosave-badge {
  font-size: 11px; color: #81ecec; opacity: 0;
  transition: opacity .3s;
  margin-left: 6px;
}
.autosave-badge.visible { opacity: 1; }

/* ============================================================
   ROOM TABS — ARCHIVED
============================================================ */
.archived-tab {
  opacity: .6;
  font-style: italic;
}
.archived-tab.active { opacity: 1; }

.toggle-archived-btn { flex-shrink: 0; }
.active-archived { background: var(--primary) !important; }

/* ============================================================
   BUTTON — WARNING
============================================================ */
.btn-warning { background: #e17055; color: #fff; }

/* ============================================================
   CLASS SET BAR
============================================================ */
.class-set-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: #f8f9fa;
  flex-shrink: 0;
}
.class-set-bar select {
  flex: 1; padding: 4px 7px;
  border: 1px solid var(--border); border-radius: 5px;
  font-size: 12px; background: var(--surface); color: var(--text);
  cursor: pointer;
}
.class-set-bar select:focus { outline: none; border-color: var(--primary); }

/* ============================================================
   CLASS SET MODAL
============================================================ */
.classset-layout {
  display: flex; gap: 14px; min-height: 320px;
}
.classset-list-col {
  width: 180px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.classset-list-header {
  display: flex; align-items: center; justify-content: space-between;
}
.classset-list {
  flex: 1; border: 1px solid var(--border); border-radius: 6px;
  overflow-y: auto; min-height: 80px;
}
.classset-list-item {
  padding: 8px 10px; font-size: 13px; cursor: pointer;
  border-bottom: 1px solid var(--border); transition: background .12s;
}
.classset-list-item:last-child { border-bottom: none; }
.classset-list-item:hover { background: var(--bg); }
.classset-list-item.active { background: var(--primary); color: #fff; }

.classset-edit-col {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
}

/* ============================================================
   STUDENT SEARCH BAR
============================================================ */
.student-search-bar {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: #f8f9fa;
  flex-shrink: 0;
}
.student-search-bar input {
  width: 100%; padding: 5px 9px;
  border: 1px solid var(--border); border-radius: 5px;
  font-size: 12px; background: var(--surface); color: var(--text);
  transition: border .15s;
}
.student-search-bar input:focus { outline: none; border-color: var(--primary); }

/* ============================================================
   PRINT STYLES
============================================================ */
@media print {
  /* Hide all interactive UI chrome */
  .header-right,
  .room-bar,
  .toolbar,
  .panel-left,
  .panel-right,
  .room-config,
  .seat-info-bar,
  .mobile-tab-bar,
  .app-footer,
  .autosave-badge { display: none !important; }

  /* Let the page scroll fully */
  html, body {
    overflow: visible !important;
    height: auto !important;
    background: white !important;
  }

  /* Dark header → white for print */
  header {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
    border-bottom: 2px solid #333 !important;
  }
  header h1, .logo { color: black !important; }

  .app-body {
    height: auto !important;
    overflow: visible !important;
    display: block !important;
  }

  footer.app-footer { display: none !important; }

  .panel-centre {
    width: 100% !important;
    overflow: visible !important;
  }

  /* Room title only, no config controls */
  .room-header {
    border-bottom: 1px solid #ccc !important;
    padding: 8px 14px !important;
  }

  .grid-scroll {
    overflow: visible !important;
    flex: none !important;
    padding: 16px !important;
    justify-content: flex-start !important;
  }

  /* Preserve seat colours */
  .seat-cell,
  .mini-avatar,
  .cluster-dot {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* ============================================================
   DARK MODE
============================================================ */
body.dark-mode {
  --bg:        #1a1f2e;
  --surface:   #252b3b;
  --border:    #3a4259;
  --text:      #e4e8f0;
  --text-muted:#8892a4;
}
body.dark-mode header       { background: #0f1319; }
body.dark-mode .room-bar    { background: #0f1319; }
body.dark-mode .mode-btn    { background: var(--bg); color: var(--text); border-color: var(--border); }
body.dark-mode .mode-btn.active { background: var(--primary); color: #fff; }
body.dark-mode .room-grid   { background-color: var(--bg); }
body.dark-mode .seat-cell   { background: var(--surface); border-color: var(--border); color: var(--text); }
body.dark-mode .seat-cell.seat-disabled { background: transparent; }
body.dark-mode .mini-name   { color: var(--text); }
body.dark-mode .toolbar     { background: var(--surface); border-color: var(--border); }
body.dark-mode .toolbar select { background: var(--surface); color: var(--text); border-color: var(--border); }
body.dark-mode .modal       { background: var(--surface); }
body.dark-mode .modal-header,
body.dark-mode .modal-footer { border-color: var(--border); }
body.dark-mode .form-group input,
body.dark-mode .form-group select,
body.dark-mode .form-group textarea { background: var(--bg); color: var(--text); border-color: var(--border); }
body.dark-mode .constraint-list { border-color: var(--border); }
body.dark-mode .chk-label:hover  { background: var(--bg); }
body.dark-mode .student-card     { background: var(--surface); border-color: var(--border); }
body.dark-mode .cluster-item     { background: var(--surface); border-color: var(--border); }
body.dark-mode .class-set-bar    { background: var(--surface); }
body.dark-mode .class-set-bar select { background: var(--surface); color: var(--text); }
body.dark-mode .student-search-bar   { background: var(--surface); }
body.dark-mode .student-search-bar input { background: var(--bg); color: var(--text); }
body.dark-mode .room-grid.freeform   { background-color: var(--surface); background-image: radial-gradient(circle, var(--border) 1px, transparent 1px); border-color: var(--border); }
body.dark-mode .classset-list        { border-color: var(--border); }
body.dark-mode .classset-list-item:hover { background: var(--bg); }
body.dark-mode .classset-list-item.active { background: var(--primary); }
body.dark-mode .seat-ctx-menu { background: var(--surface); border-color: var(--border); }
body.dark-mode .seat-ctx-item:hover { background: var(--bg); }
body.dark-mode .seat-tooltip  { background: #0f1319; border-color: var(--border); }
body.dark-mode .flag-checkboxes { background: var(--bg); border-color: var(--border); }
body.dark-mode .flag-chk-label:hover { background: var(--surface); }

/* ============================================================
   CAPACITY BADGE
============================================================ */
.room-name-row {
  display: flex; align-items: center; gap: 10px;
}
.capacity-badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px; font-weight: 600;
  background: var(--bg); color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap; transition: background .2s, color .2s;
}
.capacity-badge.full  { background: #d4edda; color: #155724; border-color: #c3e6cb; }
.capacity-badge.empty { background: var(--bg); color: var(--text-muted); }
body.dark-mode .capacity-badge.full { background: #1a4a2a; color: #81c995; border-color: #2d6e3d; }

/* ============================================================
   STUDENT FLAGS
============================================================ */
.flag-checkboxes {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg);
}
.flag-chk-label {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; cursor: pointer; padding: 3px 6px;
  border-radius: 4px;
}
.flag-chk-label:hover { background: var(--border); }
.flag-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.student-flags {
  display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px;
}
.flag-pill {
  display: inline-flex; align-items: center; padding: 1px 6px;
  border-radius: 8px; font-size: 10px; font-weight: 600; color: #fff;
  white-space: nowrap;
}
.mini-flags {
  display: flex; gap: 2px; flex-wrap: wrap; justify-content: center;
  margin-top: 1px;
}
.mini-flag-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}

/* ============================================================
   LABELED SEATS (teacher desk / whiteboard / etc.)
============================================================ */
.seat-cell.labeled-seat {
  background: #f0f4ff; border: 2px solid #b0bec5; cursor: default;
}
body.dark-mode .seat-cell.labeled-seat { background: #1e2436; border-color: #4a5568; }
.labeled-seat-content {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; width: 100%; height: 100%; padding: 5px;
}
.labeled-seat-icon { font-size: 22px; line-height: 1; }
.labeled-seat-name {
  font-size: 9px; font-weight: 600; text-align: center;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%;
}

/* ============================================================
   SEAT CONTEXT MENU
============================================================ */
.seat-ctx-menu {
  position: fixed; z-index: 2000;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.18);
  min-width: 180px; overflow: hidden;
}
.seat-ctx-title {
  padding: 7px 12px; font-size: 11px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.seat-ctx-item {
  display: block; width: 100%;
  padding: 8px 12px; text-align: left;
  background: none; border: none; border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text); cursor: pointer;
  transition: background .12s;
}
.seat-ctx-item:last-child { border-bottom: none; }
.seat-ctx-item:hover { background: var(--bg); }
.seat-ctx-clear { color: var(--danger); font-weight: 500; }
.seat-ctx-clear:hover { background: #fff0f0; }
.seat-ctx-divider { margin: 0; border: none; border-top: 1px solid var(--border); }

/* ============================================================
   SEAT TOOLTIP
============================================================ */
.seat-tooltip {
  position: fixed; z-index: 1500;
  background: #1e272e; color: #fff;
  border-radius: 8px; padding: 10px 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,.35);
  max-width: 220px; min-width: 160px;
  pointer-events: none; font-size: 12px;
  border: 1px solid rgba(255,255,255,.1);
}
.tt-name   { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.tt-details { color: #b2bec3; display: flex; gap: 8px; margin-bottom: 4px; }
.tt-flags  { display: flex; flex-wrap: wrap; gap: 3px; margin-bottom: 4px; }
.tt-flag   { padding: 1px 6px; border-radius: 8px; font-size: 10px; font-weight: 600; color: #fff; }
.tt-notes  { color: #b2bec3; font-style: italic; font-size: 11px; line-height: 1.4; border-top: 1px solid rgba(255,255,255,.1); margin-top: 4px; padding-top: 4px; }
.tt-violations { border-top: 1px solid rgba(255,100,100,.3); margin-top: 6px; padding-top: 6px; }
.tt-violation  { color: #ff7675; font-size: 11px; line-height: 1.5; }

/* ============================================================
   STATS MODAL
============================================================ */
.stats-grid {
  display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.stats-card {
  flex: 1; min-width: 80px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; text-align: center;
}
.stats-number { font-size: 28px; font-weight: 700; color: var(--primary); line-height: 1; }
.stats-number.stats-male   { color: #0984e3; }
.stats-number.stats-female { color: #e84393; }
.stats-number.stats-other  { color: #6c5ce7; }
.stats-label  { font-size: 11px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }
.stats-section { margin-bottom: 16px; }
.stats-section h4 { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.stats-constraint { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; flex-wrap: wrap; }
.stats-constraint-label { flex: 1; min-width: 160px; }
.stats-constraint-value { font-weight: 700; }
.stats-danger { color: var(--danger); }
.stats-constraint-bar { flex: 2; min-width: 100px; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.stats-bar-fill { height: 100%; border-radius: 3px; transition: width .4s; }
.stats-bar-success { background: var(--success); }
.stats-cluster {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.stats-cluster:last-child { border-bottom: none; }
.stats-cluster-name  { flex: 1; font-weight: 500; }
.stats-cluster-count { color: var(--text-muted); font-size: 12px; }
.stats-cluster-gender { font-size: 11px; color: var(--text-muted); }

/* ============================================================
   HISTORY MODAL
============================================================ */
.history-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-meta { display: flex; flex-direction: column; gap: 2px; }
.history-date   { font-size: 12px; color: var(--text); font-weight: 500; }
.history-method { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }
.history-count  { font-size: 11px; color: var(--text-muted); }

/* ============================================================
   UNDO / REDO BUTTON DISABLED STATE
============================================================ */
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover { opacity: .5; }
.btn:disabled:active { transform: none; }

/* ============================================================
   ABSENT STUDENTS
============================================================ */
.student-absent { opacity: 0.45; text-decoration: line-through; }
.mini-absent .mini-avatar { opacity: 0.4; }
.mini-absent .mini-name   { opacity: 0.4; }

/* ============================================================
   NOTES DOT (seat cell indicator)
============================================================ */
.notes-dot {
  font-size: 9px;
  line-height: 1;
  cursor: default;
  margin-left: 2px;
  display: inline-block;
}

/* ============================================================
   TOOLBAR CHECKBOX LABEL
============================================================ */
.toolbar-chk-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

/* ============================================================
   PIN BADGE (seat cell overlay)
============================================================ */
.pin-badge {
  position: absolute;
  top: 1px;
  right: 2px;
  font-size: 9px;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
}

/* ============================================================
   AUDIT VIOLATION HIGHLIGHT
============================================================ */
.audit-violation {
  outline: 2px solid #e74c3c !important;
  outline-offset: -2px;
}

/* ============================================================
   FOOTER
============================================================ */
.app-footer {
  height: var(--footer-h);
  background: #1e272e;
  color: #636e72;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  font-size: 11px;
  flex-shrink: 0;
  z-index: 10; position: relative;
}
.version-badge {
  font-size: 10px;
  color: #4a5568;
  font-family: monospace;
}
body.dark-mode .app-footer { background: #0f1319; }
body.dark-mode .version-badge { color: #4a5568; }

/* ============================================================
   HELP MODAL
============================================================ */
.modal-help { max-width: 780px; }

.help-toc {
  display: flex; flex-wrap: wrap; gap: 6px 10px;
  padding: 10px 14px; margin-bottom: 16px;
  background: var(--bg); border-radius: 8px;
  font-size: 12px; border: 1px solid var(--border);
  align-items: center;
}
.help-toc strong { color: var(--text-muted); margin-right: 4px; }
.help-toc a {
  color: var(--primary); text-decoration: none;
  padding: 2px 6px; border-radius: 4px;
  transition: background .12s;
}
.help-toc a:hover { background: rgba(9,132,227,.1); text-decoration: underline; }

.help-section {
  margin-bottom: 22px; padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.help-section:last-child { border-bottom: none; margin-bottom: 0; }

.help-section h4 {
  font-size: 14px; font-weight: 700; margin-bottom: 10px;
  color: var(--text);
}
.help-section h5 {
  font-size: 12px; font-weight: 600; margin: 10px 0 6px;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px;
}

.help-section p {
  font-size: 13px; line-height: 1.6; margin-bottom: 8px;
  color: var(--text);
}

.help-section ul {
  padding-left: 18px; margin-bottom: 6px;
}
.help-section ul li {
  font-size: 13px; line-height: 1.65; margin-bottom: 4px; color: var(--text);
}
.help-section em { color: var(--text-muted); }

.help-table {
  border-collapse: collapse; width: 100%; font-size: 13px;
}
.help-table tr { border-bottom: 1px solid var(--border); }
.help-table tr:last-child { border-bottom: none; }
.help-table td { padding: 5px 10px; vertical-align: top; }
.help-table td:first-child { white-space: nowrap; color: var(--text-muted); }

kbd {
  display: inline-block; padding: 1px 5px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; font-family: monospace; font-size: 11px;
  box-shadow: 0 1px 0 var(--border);
}

body.dark-mode .help-toc { background: var(--bg); border-color: var(--border); }
body.dark-mode .help-section { border-color: var(--border); }
body.dark-mode kbd { background: var(--surface); border-color: var(--border); }

/* ============================================================
   TEMPLATES MODAL
============================================================ */
.templates-actions-bar {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-bottom: 14px;
}

.templates-list { display: flex; flex-direction: column; gap: 6px; }

.template-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface);
  cursor: pointer; transition: box-shadow .15s, border-color .15s;
}
.template-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.template-item.template-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(9,132,227,.2);
}

.template-icon { font-size: 18px; flex-shrink: 0; }

.template-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.template-name { font-size: 13px; font-weight: 500; }
.template-meta { font-size: 11px; color: var(--text-muted); }

.template-actions { display: flex; gap: 2px; flex-shrink: 0; }

body.dark-mode .template-item { background: var(--surface); border-color: var(--border); }
