/* ── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: #1a1a1a;
  background: #efefef;
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebars ─────────────────────────────────────────── */
#sidebar-left,
#sidebar-right {
  flex-shrink: 0;
  min-width: 0;
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px;
  transition: width 0.2s ease, padding 0.2s ease, border-color 0.2s ease;
}

#sidebar-left {
  width: 270px;
  border-right: 1px solid #ddd;
  overflow-y: auto;
}

#sidebar-right {
  width: 240px;
  border-left: 1px solid #ddd;
  overflow-y: auto;
}

#sidebar-left.collapsed {
  width: 0;
  padding: 0;
  border-right-color: transparent;
}

#sidebar-right.collapsed {
  width: 0;
  padding: 0;
  border-left-color: transparent;
}

/* ── Sidebar collapse tabs ────────────────────────────── */
.sidebar-tab {
  flex-shrink: 0;
  width: 14px;
  align-self: stretch;
  background: #f5f5f5;
  border: none;
  border-left: 1px solid #e0e0e0;
  border-right: 1px solid #e0e0e0;
  cursor: pointer;
  color: #bbb;
  font-size: 9px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: background 0.12s, color 0.12s;
  writing-mode: vertical-rl;
  letter-spacing: 0.1em;
}
.sidebar-tab:hover {
  background: #e8e8e8;
  color: #555;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
#sidebar-header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #111;
}
.btn-new-class {
  flex-shrink: 0;
  padding: 4px 8px;
  font-size: 11px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  color: #888;
  white-space: nowrap;
}
.btn-new-class:hover { background: #fff0f0; color: #c33; border-color: #c33; }

.section {
  margin-bottom: 18px;
}

.section-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
  margin-bottom: 7px;
}

/* Inputs */
#class-name {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid #d0d0d0;
  border-radius: 5px;
  font-size: 14px;
  font-family: inherit;
}
#class-name:focus { outline: none; border-color: #888; }

#students-textarea {
  width: 100%;
  height: 120px;
  padding: 8px 9px;
  border: 1px solid #d0d0d0;
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  line-height: 1.6;
}
#students-textarea:focus { outline: none; border-color: #888; }

.dup-warning {
  display: none;
  margin-top: 5px;
  font-size: 11px;
  color: #a05000;
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 4px;
  padding: 4px 8px;
  word-break: break-word;
}

#student-count { font-weight: 400; color: #aaa; font-size: 11px; }

/* Sub-rows (for list save/load and exclusions) */
.sub-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.mt-4 { margin-top: 4px; }
.mt-6 { margin-top: 6px; }

.input-sm {
  flex: 1;
  min-width: 0;
  padding: 5px 7px;
  border: 1px solid #d0d0d0;
  border-radius: 5px;
  font-size: 12px;
  font-family: inherit;
}
.input-sm:focus { outline: none; border-color: #888; }

.select-sm {
  flex: 1;
  min-width: 0;
  padding: 5px 6px;
  border: 1px solid #d0d0d0;
  border-radius: 5px;
  font-size: 12px;
  font-family: inherit;
  background: #fff;
}
.select-sm:focus { outline: none; border-color: #888; }

.btn-sm {
  flex-shrink: 0;
  padding: 5px 9px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn-sm:hover { background: #f0f0f0; }
.btn-sm-danger { color: #c00; }
.btn-sm-danger:hover { background: #fff0f0; border-color: #c00; }

.excl-og { font-size: 11px; color: #888; flex-shrink: 0; }
.mb-6 { margin-bottom: 6px; }

/* Stepper (+/−) */
.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
}
.stepper-btn {
  width: 26px;
  height: 26px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #444;
  padding: 0;
  font-family: inherit;
  flex-shrink: 0;
}
.stepper-btn:hover { background: #f0f0f0; border-color: #999; }
.stepper-btn:active { background: #e5e5e5; }
.stepper-val {
  font-size: 13px;
  color: #333;
  min-width: 22px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Collapsible lists */
.details-lists {
  margin-top: 8px;
}
.details-summary {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #aaa;
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 0;
}
.details-summary::-webkit-details-marker { display: none; }
.details-summary::before {
  content: '▶';
  font-size: 8px;
  transition: transform 0.15s;
  display: inline-block;
}
details[open] .details-summary::before { transform: rotate(90deg); }

.range-sm {
  width: 70px;
  cursor: pointer;
  accent-color: #333;
}
.text-scale-val {
  font-size: 12px;
  color: #555;
  min-width: 34px;
  text-align: right;
}
.select-narrow {
  width: 90px;
  padding: 5px 6px;
  border: 1px solid #d0d0d0;
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}
.select-narrow:focus { outline: none; border-color: #888; }

/* Exclusion list */
#exclusion-list {
  list-style: none;
  margin-top: 5px;
}
#exclusion-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  padding: 3px 0;
  border-bottom: 1px solid #f0f0f0;
  gap: 6px;
}
#exclusion-list li:last-child { border-bottom: none; }
#exclusion-list li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.excl-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #c00;
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
}
.excl-remove:hover { opacity: 0.7; }

/* Config input rows */
.input-row {
  display: flex;
  align-items: center;
  margin-bottom: 7px;
  gap: 8px;
}
.input-label { flex: 1; font-size: 13px; color: #444; }
.input-row input[type="number"],
.input-row select {
  width: 90px;
  padding: 5px 7px;
  border: 1px solid #d0d0d0;
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}
.input-row input[type="number"]:focus,
.input-row select:focus { outline: none; border-color: #888; }

#saved-maps, #saved-lists {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d0d0d0;
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}
#saved-maps:focus, #saved-lists:focus { outline: none; border-color: #888; }

/* Buttons */
.btn-primary {
  width: 100%;
  padding: 10px 12px;
  background: #111;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: #333; }
.btn-primary:active { background: #000; }

.btn-row {
  display: flex;
  gap: 5px;
}

.btn-secondary {
  flex: 1;
  padding: 6px 8px;
  background: #fff;
  color: #333;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s;
}
.btn-secondary:hover { background: #f0f0f0; border-color: #999; }
.btn-secondary:active { background: #e5e5e5; }
.btn-secondary.mt-6 { margin-top: 6px; width: 100%; flex: none; }
.btn-danger { color: #c33; }
.btn-danger:hover { background: #fff0f0; border-color: #c33; }

/* Mismatch warning */
#mismatch-warning {
  display: none;
  padding: 8px 10px;
  border-radius: 5px;
  font-size: 12px;
  margin-top: 4px;
}
#mismatch-warning.show {
  display: block;
  background: #fff8e1;
  color: #7a5f00;
  border: 1px solid #ffe082;
  margin-bottom: 14px;
}
#overflow-list { font-size: 11px; color: #999; margin-top: 3px; word-break: break-word; }

.btn-fix-desks {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 6px 10px;
  background: #7a5f00;
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-fix-desks:hover { background: #5a4500; }
.btn-trim-desks {
  background: #555 !important;
}
.btn-trim-desks:hover { background: #333 !important; }

.privacy-note {
  font-size: 11px;
  color: #888;
  line-height: 1.5;
  margin-bottom: 2px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  font-size: 11px;
  color: #bbb;
  text-align: center;
}
kbd {
  background: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 10px;
  font-family: inherit;
}

/* ── Context menu ─────────────────────────────────────── */
#context-menu {
  position: fixed;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.13);
  z-index: 9000;
  min-width: 160px;
  display: none;
  overflow: hidden;
}
#context-menu.show { display: block; }
.ctx-item {
  padding: 8px 13px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.ctx-item:hover { background: #f5f5f5; }
.ctx-danger { color: #c33; }
.ctx-danger:hover { background: #fff0f0; }
.ctx-sep { height: 1px; background: #eee; margin: 2px 0; }

/* ── Classroom wrapper ────────────────────────────────── */
#classroom-wrapper {
  flex: 1;
  overflow: auto;
  background: #efefef;
  padding: 28px 32px;
}

#print-header { display: none; }

#classroom {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  padding: 24px;
  min-width: min-content;
}

/* Blackboard position variants */
#classroom.bb-bottom { flex-direction: column-reverse; }
#classroom.bb-left   { flex-direction: row; }
#classroom.bb-right  { flex-direction: row-reverse; }

/* Vertical blackboard (left/right) */
#classroom.bb-left #blackboard,
#classroom.bb-right #blackboard {
  width: 52px;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  align-self: flex-start;
}
#classroom.bb-left #blackboard-label,
#classroom.bb-left #classroom-title {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}
#classroom.bb-right #blackboard-label,
#classroom.bb-right #classroom-title {
  writing-mode: vertical-rl;
}

/* ── Blackboard ───────────────────────────────────────── */
#blackboard {
  position: relative;
  height: 54px;
  background: #2d5a27;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-shrink: 0;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* Resize handles */
.bb-handle {
  position: absolute;
  z-index: 5;
}
/* top/bottom orientation: handles on left and right edges */
#classroom.bb-top .bb-handle,
#classroom.bb-bottom .bb-handle {
  top: 0; bottom: 0; width: 10px;
  cursor: ew-resize;
}
#classroom.bb-top .bb-handle-before,
#classroom.bb-bottom .bb-handle-before { left: 0; }
#classroom.bb-top .bb-handle-after,
#classroom.bb-bottom .bb-handle-after  { right: 0; }

/* left/right orientation: handles on top and bottom edges */
#classroom.bb-left .bb-handle,
#classroom.bb-right .bb-handle {
  left: 0; right: 0; height: 10px;
  cursor: ns-resize;
}
#classroom.bb-left .bb-handle-before,
#classroom.bb-right .bb-handle-before { top: 0; }
#classroom.bb-left .bb-handle-after,
#classroom.bb-right .bb-handle-after  { bottom: 0; }

/* Reset button */
#bb-reset {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 50%;
  color: rgba(255,255,255,0.75);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  z-index: 6;
  padding: 0;
}
#blackboard:hover #bb-reset { opacity: 1; }
#bb-reset:hover { background: rgba(255,255,255,0.25); }

/* Visual indicator dot on hover */
.bb-handle::after {
  content: '';
  position: absolute;
  background: rgba(255,255,255,0.45);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}
.bb-handle:hover::after { opacity: 1; }
#classroom.bb-top .bb-handle::after,
#classroom.bb-bottom .bb-handle::after {
  top: 50%; left: 2px; right: 2px; height: 18px;
  transform: translateY(-50%);
}
#classroom.bb-left .bb-handle::after,
#classroom.bb-right .bb-handle::after {
  left: 50%; top: 2px; bottom: 2px; width: 18px;
  transform: translateX(-50%);
}
#blackboard-label {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
}
#classroom-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}

/* ── Grid ─────────────────────────────────────────────── */
#grid-container { position: relative; }

.grid-cell {
  position: absolute;
  width: 80px;
  height: 80px;
  border: 1px dashed #e2e2e2;
  border-radius: 4px;
  z-index: 1;
  transition: background 0.08s, border-color 0.08s;
}
.grid-cell.drag-over {
  background: #eaf0ff;
  border: 2px solid #4466dd;
}

.group-bg {
  position: absolute;
  background: #f5f5f5;
  border: 1px solid #e4e4e4;
  border-radius: 8px;
  z-index: 2;
  pointer-events: none;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* ── Desks ────────────────────────────────────────────── */
.desk {
  position: absolute;
  width: 80px;
  height: 80px;
  background: #111;
  color: #fff;
  border-radius: 5px;
  z-index: 3;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 500;
  line-height: 1.3;
  padding: 7px;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  transition: box-shadow 0.1s;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.desk:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.desk:active { cursor: grabbing; }
.desk.dragging { opacity: 0.3; cursor: grabbing; }
.desk.drag-over {
  outline: 2px dashed #4466dd;
  outline-offset: -2px;
  box-shadow: none;
}

/* Empty desk */
.desk-empty {
  background: transparent !important;
  border: 2px dashed #ccc;
  color: #bbb;
  box-shadow: none;
}
.desk-empty:hover { border-color: #aaa; box-shadow: none; }

/* Wide desk (size 2) */
.desk-wide { width: 168px; } /* 2*88 - 8 */

/* Locked desk indicator */
.desk-locked::after {
  content: '🔒';
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 8px;
  line-height: 1;
  opacity: 0.75;
}

/* Teacher desk */
.desk-teacher {
  background: #3a5c3a !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  letter-spacing: 0.03em;
  cursor: grab;
}
.desk-teacher:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.3); }

/* Inline edit input */
.desk-inline-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255,255,255,0.5);
  color: #fff;
  font-size: inherit;
  font-family: inherit;
  font-weight: inherit;
  text-align: center;
  outline: none;
  padding: 0;
}
.desk-empty .desk-inline-input {
  color: #777;
  border-bottom-color: #aaa;
}

/* ── Toast ────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #222;
  color: #fff;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 0.18s, transform 0.18s;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Stats banner ─────────────────────────────────────── */
.stats-banner {
  display: none;
  font-size: 12px;
  color: #777;
  padding-bottom: 10px;
  gap: 14px;
}
.stats-banner.visible { display: flex; }
.stats-banner span { display: inline-flex; align-items: center; gap: 3px; }

/* ── Row / Col controls ───────────────────────────────── */
#grid-area {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

#col-controls {
  height: 28px;
  margin-left: 28px; /* offset to align with grid (row-controls width) */
  position: relative;
  flex-shrink: 0;
}

#grid-row-wrap {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
}

#row-controls {
  width: 28px;
  flex-shrink: 0;
  position: relative;
}

/* Individual row / col control slots */
.row-ctrl {
  position: absolute;
  left: 0;
  width: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.col-ctrl {
  position: absolute;
  top: 0;
  height: 28px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

/* Buttons inside each control — hidden until hover */
.ctrl-btn {
  opacity: 0;
  transition: opacity 0.13s;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 10px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  font-family: inherit;
  color: #444;
  white-space: nowrap;
}
.row-ctrl:hover .ctrl-btn,
.col-ctrl:hover .ctrl-btn { opacity: 1; }

.ctrl-delete { color: #b00; border-color: #e8b0b0; }
.ctrl-delete:hover { background: #fff0f0; border-color: #b00; }
.ctrl-move   { color: #447; border-color: #aac; }
.ctrl-move:hover { background: #f0f0ff; border-color: #447; }
.ctrl-cancel { color: #888; }
.ctrl-cancel:hover { background: #f5f5f5; }

/* Move-mode target colours (always visible) */
.rc-valid {
  background: rgba(34, 170, 80, 0.18);
  border-radius: 4px;
  outline: 2px solid #22aa50;
  outline-offset: -2px;
  opacity: 1 !important;
}
.rc-invalid {
  background: rgba(200, 40, 40, 0.12);
  border-radius: 4px;
  outline: 2px solid #cc3333;
  outline-offset: -2px;
  opacity: 1 !important;
}
.rc-selected {
  background: rgba(80, 120, 220, 0.18);
  border-radius: 4px;
  outline: 2px dashed #4466dd;
  outline-offset: -2px;
  opacity: 1 !important;
}
/* Show buttons inside move-mode slots */
.rc-valid .ctrl-btn,
.rc-invalid .ctrl-btn,
.rc-selected .ctrl-btn { opacity: 1; }

/* ── Print ────────────────────────────────────────────── */
@media print {
  /* @page size is set dynamically via JS (updatePrintPageStyle) */

  body { display: block; background: #fff; overflow: visible; height: auto; }

  #sidebar-left, #sidebar-right, .sidebar-tab { display: none !important; }
  #context-menu { display: none !important; }

  #classroom-wrapper {
    padding: 0;
    background: #fff;
    overflow: visible;
    display: block;
  }

  #print-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 12pt;
    margin-bottom: 6mm;
    padding-bottom: 3mm;
    border-bottom: 1px solid #ccc;
  }
  #print-header strong { font-size: 14pt; }

  #classroom {
    box-shadow: none;
    padding: 0;
    display: block;
    background: #fff;
  }

  /* Keep blackboard colour in print */
  #blackboard,
  .desk,
  .desk-teacher,
  .group-bg {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Hide drag helpers */
  .grid-cell {
    border: 1px dashed #eee;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .grid-cell.drag-over { background: transparent; border-style: dashed; }
  .desk.dragging, .desk.drag-over { opacity: 1; outline: none; }

  #mismatch-warning, #overflow-list, #toast { display: none !important; }
  #row-controls, #col-controls { display: none !important; }
  .desk-locked::after { display: none !important; }
  .stats-banner { display: none !important; }
  .dup-warning { display: none !important; }
  .bb-handle { display: none !important; }
  #bb-reset  { display: none !important; }
}
