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

/* Several components set their own display, which would otherwise beat the
   hidden attribute the scripts toggle. */
[hidden] { display: none !important; }

/* ── Mode: klassekart / grupper ───────────────────────── */
body.mode-groups .seating-only        { display: none !important; }
body:not(.mode-groups) .groups-only   { display: none !important; }

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;
}

/* A full-width scrollbar steals enough of the 240px to wrap the group
   settings' labels onto two lines. */
#sidebar-left,
#sidebar-right { scrollbar-width: thin; }

#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; }

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

/* 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; }

/* Rules */
.details-rules .details-body { margin-top: 8px; }
.rule-count { font-weight: 400; letter-spacing: 0; }
.rule-alert { color: #c33; font-size: 11px; letter-spacing: 0; }
/* A closed panel gives nothing away — not even how many rules there are. */
.details-rules:not([open]) .rule-count,
.details-rules:not([open]) .rule-alert { display: none; }
.info-btn-sm { width: 15px; height: 15px; font-size: 9px; letter-spacing: 0; }
#rules-tip { margin-top: 6px; }
#rule-list li.rule-broken .rule-text { color: #c33; }
#rule-list li.rule-broken .rule-text::before { content: '⚠ '; font-size: 11px; }
.rule-hint {
  font-size: 11px;
  color: #999;
  margin-top: 5px;
}
#rule-list {
  list-style: none;
  margin-top: 5px;
  transition: opacity 0.15s;
}
#rule-list.rules-off { opacity: 0.45; }
#rule-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  padding: 3px 0;
  border-bottom: 1px solid #f0f0f0;
  gap: 6px;
}
#rule-list li:last-child { border-bottom: none; }
.rule-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rule-sym { margin: 0 5px; font-size: 11px; }
.rule-unknown { color: #bbb; text-decoration: line-through; }
.check-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  font-size: 12px;
  color: #444;
  cursor: pointer;
  user-select: none;
}
.check-row input { accent-color: #111; cursor: pointer; }
.rule-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #c00;
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
}
.rule-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; }

.print-hint {
  margin: 5px 0 12px;
  font-size: 11px;
  color: #999;
  text-align: center;
}

.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 {
  /* Shifts the blackboard to stay aligned with the desk grid when the
     row/column controls are hidden (print). See syncBlackboard(). */
  --ctrl-shift: 0px;
  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; }

/* ── Mode tabs ────────────────────────────────────────── */
#mode-tabs {
  display: flex;
  width: max-content;
  gap: 2px;
  padding: 3px;
  margin-bottom: 16px;
  background: #e0e0e0;
  border-radius: 9px;
}
.mode-tab {
  border: none;
  background: transparent;
  padding: 6px 15px;
  border-radius: 7px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #666;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.mode-tab:hover { color: #222; }
.mode-tab.active {
  background: #fff;
  color: #111;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* ── Group settings (right sidebar) ───────────────────── */
.seg {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: #eee;
  border-radius: 7px;
}
.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 5px 4px;
  border-radius: 5px;
  font-family: inherit;
  font-size: 12px;
  color: #666;
  cursor: pointer;
  white-space: nowrap;
}
.seg-btn:hover { color: #222; }
.seg-btn.active {
  background: #fff;
  color: #111;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}
.grp-preview { font-size: 12px; color: #666; line-height: 1.45; }

.opt { padding: 9px 0; border-bottom: 1px solid #f0f0f0; }
.opt:first-of-type { padding-top: 2px; }
.opt:last-child { border-bottom: none; }
.opt-row { display: flex; align-items: center; gap: 6px; }
.opt-label { flex: 1; font-size: 13px; color: #333; cursor: pointer; }
.opt-body { margin-top: 8px; }
.opt-hint { font-size: 11px; color: #999; line-height: 1.45; }
.opt-tip {
  margin-top: 7px;
  padding: 7px 9px;
  font-size: 11.5px;
  line-height: 1.5;
  color: #555;
  background: #f5f5f3;
  border-radius: 6px;
}

/* Toggle switch */
.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex-shrink: 0;
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: #d4d4d4;
  cursor: pointer;
  transition: background 0.15s;
}
.switch::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: transform 0.15s;
}
.switch:checked { background: #111; }
.switch:checked::before { transform: translateX(14px); }
.switch:focus-visible { outline: 2px solid #4466dd; outline-offset: 2px; }

.info-btn {
  flex-shrink: 0;
  width: 17px;
  height: 17px;
  padding: 0;
  border: 1px solid #ccc;
  border-radius: 50%;
  background: #fff;
  color: #888;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.info-btn:hover,
.info-btn[aria-expanded="true"] { background: #111; border-color: #111; color: #fff; }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: #4466dd;
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover { color: #223a99; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip {
  padding: 3px 9px;
  border: 1px solid #d6d6d6;
  border-radius: 999px;
  background: #fff;
  font-family: inherit;
  font-size: 12px;
  color: #333;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.chip:hover { border-color: #999; }
.chip-away {
  background: #f3f3f3;
  border-style: dashed;
  color: #aaa;
  text-decoration: line-through;
}
.chip-suggest { border-style: dashed; color: #666; }
.chip-suggest:hover { border-style: solid; color: #111; }

.role-list { list-style: none; margin-top: 6px; counter-reset: role; }
.role-list li {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 0;
  font-size: 12px;
  counter-increment: role;
}
.role-list li::before {
  content: counter(role);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #111;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
}
.role-list li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#grp-role-hint { margin-top: 6px; }
.role-suggest { margin-top: 8px; }

/* ── Groups view ──────────────────────────────────────── */
#groups-view { max-width: 1100px; }

#groups-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 14px;
}
#groups-summary { font-size: 13px; color: #777; }
#groups-summary strong { font-size: 16px; color: #111; margin-right: 2px; }
.groups-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.btn-tool {
  padding: 6px 11px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12.5px;
  color: #333;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn-tool:hover { background: #f3f3f3; border-color: #999; }
.btn-tool-dark { background: #111; border-color: #111; color: #fff; }
.btn-tool-dark:hover { background: #333; border-color: #333; }

.grp-notice {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  line-height: 1.45;
}
.grp-notice span { flex: 1; min-width: 200px; }
.grp-notice-warn  { background: #fff8e1; border: 1px solid #ffe082; color: #7a5f00; }

#groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  align-items: start;
  gap: 14px;
}

.group-card {
  --grp-color: #888;
  background: #fff;
  border-top: 4px solid var(--grp-color);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  transition: box-shadow 0.12s;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.group-card.drag-over { box-shadow: 0 0 0 2px var(--grp-color), 0 6px 16px rgba(0,0,0,0.12); }

.group-card-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 5px; }
.group-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--grp-color);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.group-title { flex: 1; font-size: 13px; font-weight: 600; }
.group-count { font-size: 11px; color: #aaa; font-variant-numeric: tabular-nums; }

.group-members { list-style: none; padding: 0 6px 8px; }
.gm {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  border-radius: 5px;
  font-size: 14px;
  cursor: grab;
  user-select: none;
}
.gm:hover { background: #f5f5f5; }
.gm:active { cursor: grabbing; }
.gm.dragging { opacity: 0.35; }
.gm.drag-over { background: #eef2ff; outline: 2px dashed #4466dd; outline-offset: -2px; }
.gm-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gm-role {
  flex-shrink: 0;
  padding: 1px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--grp-color) 13%, #fff);
  color: color-mix(in srgb, var(--grp-color) 80%, #000);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.gm-empty {
  justify-content: center;
  padding: 12px 6px;
  color: #bbb;
  font-size: 12px;
  font-style: italic;
  cursor: default;
}
.gm-empty:hover { background: none; }

.groups-pop .gm {
  animation: gm-pop 0.34s cubic-bezier(0.2, 0.8, 0.3, 1.25) backwards;
  animation-delay: calc(var(--i, 0) * 22ms);
}
@keyframes gm-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.95); }
}

.groups-empty {
  max-width: 420px;
  margin: 48px auto;
  padding: 32px 28px 26px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  text-align: center;
}
.groups-empty-icon { font-size: 40px; line-height: 1; }
.groups-empty h2 { margin: 10px 0 4px; font-size: 18px; letter-spacing: -0.01em; }
.groups-empty p { margin-bottom: 18px; font-size: 13px; color: #777; }
.btn-draw-big { width: auto; padding: 11px 28px; font-size: 15px; }
.groups-empty .link-btn { display: block; margin: 14px auto 0; font-size: 12px; }

/* ── Tavlemodus ───────────────────────────────────────── */
body.board-open { overflow: hidden; }

#board-view {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  padding: 14px;
  background: #3b2a1c linear-gradient(135deg, #4a3423 0%, #2e2015 100%);
}
.bv-frame {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px 26px 26px;
  overflow: hidden;
  border-radius: 10px;
  color: #f4f1e6;
  background:
    radial-gradient(ellipse at 25% 15%, rgba(255,255,255,0.07), transparent 55%),
    radial-gradient(ellipse at 80% 90%, rgba(0,0,0,0.18), transparent 60%),
    #2d5a27;
  box-shadow: inset 0 0 90px rgba(0,0,0,0.35), 0 0 0 3px #22170e;
}

.bv-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 52px;
  margin-bottom: 14px;
}
#bv-title {
  flex: 1;
  font-size: clamp(20px, 3.2vh, 36px);
  font-weight: 700;
  letter-spacing: 0.01em;
  text-shadow: 0 0 2px rgba(255,255,255,0.35);
}
.bv-actions { display: flex; gap: 8px; }
.bv-btn {
  padding: 7px 14px;
  background: rgba(255,255,255,0.07);
  border: 1.5px solid rgba(255,255,255,0.32);
  border-radius: 8px;
  color: #f4f1e6;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.bv-btn:hover { background: rgba(255,255,255,0.17); border-color: rgba(255,255,255,0.6); }
.bv-btn-big { padding: 20px 44px; border-radius: 14px; font-size: 28px; }

#bv-empty { flex: 1; display: flex; align-items: center; justify-content: center; }

#bv-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--bv-cols, 3), minmax(0, 1fr));
  grid-template-rows: repeat(var(--bv-rows, 2), minmax(0, 1fr));
  gap: 16px;
  font-size: var(--bv-font, 28px);
}
.bv-card {
  --grp-color: #888;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0.5em 0.65em 0.4em;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
}
.bv-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: var(--grp-color);
}
.bv-card-head {
  display: flex;
  align-items: center;
  gap: 0.4em;
  margin-bottom: 0.2em;
  font-size: 0.55em;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.6);
}
.bv-dot { width: 0.9em; height: 0.9em; border-radius: 50%; background: var(--grp-color); }
.bv-members { list-style: none; }
.bv-member {
  display: flex;
  align-items: center;
  width: max-content;
  max-width: 100%;
  list-style: none;
  line-height: 1.42;
  font-weight: 600;
  white-space: nowrap;
  color: #f7f4ea;
  text-shadow: 0 0 2px rgba(255,255,255,0.3);
}
.bv-name { overflow: hidden; text-overflow: ellipsis; }
.bv-role {
  flex-shrink: 0;
  margin-left: 0.55em;
  padding: 0.05em 0.55em;
  border: 1px solid var(--grp-color);
  border-radius: 999px;
  font-size: 0.45em;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-shadow: none;
  color: rgba(255,255,255,0.85);
}
.bv-pending { visibility: hidden; }
.bv-flyer {
  position: fixed;
  z-index: 10002;
  margin: 0;
  padding: 0 0.3em;
  border-radius: 0.25em;
  pointer-events: none;
  will-change: transform;
}

/* The deck sits in the middle of the header, where the names fly from. */
#bv-deck {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: opacity 0.45s;
}
#bv-deck.bv-deck-empty { opacity: 0; }
.bv-deck-stack { position: relative; width: 66px; height: 44px; }
.bv-deck-stack span {
  position: absolute;
  inset: 0;
  border-radius: 7px;
  background: #f4f1e6;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}
.bv-deck-stack span:nth-child(1) { transform: rotate(-9deg) translate(-4px, 3px); background: #e5e0cf; }
.bv-deck-stack span:nth-child(2) { transform: rotate(6deg) translate(3px, 1px); background: #ece7d8; }
.bv-deck-stack span:nth-child(3)::after {
  content: '?';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 800;
  color: #2d5a27;
}
#bv-deck-count {
  min-width: 2ch;
  font-size: 15px;
  color: rgba(255,255,255,0.75);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 800px) {
  .bv-head { flex-wrap: wrap; }
  #bv-deck { position: static; transform: none; }
}

/* ── Print ────────────────────────────────────────────── */
@media print {
  #mode-tabs, #board-view, #groups-toolbar, #groups-notice, #groups-empty { display: none !important; }

  body.mode-groups #classroom-wrapper { min-height: 0; }
  #groups-view { max-width: none; }
  #groups-grid { grid-template-columns: repeat(3, 1fr); gap: 5mm; }
  .group-card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
    border-top: 4px solid var(--grp-color);
  }
  .gm { padding: 3px 6px; font-size: 12pt; }
  .groups-pop .gm { animation: none; }

  /* @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; }

  /* Centre the chart on the sheet, horizontally and vertically, for every
     paper size and orientation.

     100vh is the printable page area (inside the @page margin), so the wrapper
     spans exactly one sheet whatever A4/A3 and portrait/landscape resolve to.
     The header keeps its place at the top; `margin: auto` on the chart then
     splits all remaining space evenly on both axes. Auto margins on the cross
     axis also stop the flex item from stretching, so the chart keeps its own
     width instead of filling the page. */
  #classroom-wrapper {
    padding: 0;
    background: #fff;
    overflow: visible;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  #print-header {
    display: flex;
    flex: 0 0 auto;
    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; }

  /* Must stay flex: `display: block` here silently broke the side-by-side
     layout for a left/right blackboard, stacking the board above the desks. */
  #classroom {
    /* Row/column controls are hidden below, so the grid moves CTRL_SIZE left
       (or up). The board follows it via this offset. */
    --ctrl-shift: -28px;
    /* Set by updatePrintScale(). zoom (not transform) so the layout box really
       shrinks — otherwise the centring and the page count use the old size. */
    zoom: var(--print-zoom, 1);
    box-shadow: none;
    padding: 0;
    display: flex;
    margin: auto;
    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; }
}
