:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --page: #0f172a;
  --panel: #172238;
  --panel-raised: #1e2b43;
  --border: #2c3b53;
  --muted: #94a3b8;
  --blue: #3b82f6;
  --orange: #f59e0b;
  --tile: 27px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 360px;
  min-height: 100vh;
  background: var(--page);
}

button, input { font: inherit; }
button { color: inherit; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 84px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: #111c31;
}

.brand, .metrics, .section-heading, .legend, .roster-heading, .mode-row {
  display: flex;
  align-items: center;
}

.brand { gap: 13px; }
.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  background: #1d3c70;
  color: #93c5fd;
  font-size: 22px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 17px; letter-spacing: .01em; }
.brand p, .section-heading p, .roster-heading p { margin-top: 4px; color: var(--muted); font-size: 12px; }

.metrics { gap: 20px; }
.metric { display: grid; gap: 2px; min-width: 65px; text-align: center; }
.metric span:first-child { color: #f8fafc; font-size: 18px; font-weight: 700; }
.metric span:last-child { color: var(--muted); font-size: 11px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
  gap: 22px;
  max-width: 1800px;
  margin: 0 auto;
  padding: 24px 28px;
}

.workspace { min-width: 0; }
.section-heading { justify-content: space-between; gap: 14px; margin: 0 0 15px; }
h2 { font-size: 15px; font-weight: 650; }
.status-dirty { color: #fbbf24 !important; }
.status-error { color: #fca5a5 !important; }
.legend { flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: 11px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend-swatch, .tool-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgb(255 255 255 / 18%); }
.swatch-empty { background: #f8fafc; }
.swatch-chair { background: #1e293b; }
.swatch-reserved { background: #2563eb; }
.swatch-stage { background: #f59e0b; }
.swatch-view { background: #64748b; }

.board-scroll {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #101a2d;
  overscroll-behavior: contain;
  max-height: 70vh;
}

.board {
  display: grid;
  grid-template-columns: 30px repeat(40, var(--tile)) 30px;
  grid-template-rows: 24px repeat(60, var(--tile)) 24px;
  width: max-content;
  user-select: none;
  touch-action: none;
}

.coordinate {
  display: grid;
  place-items: center;
  color: #9eacc0;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.column-coordinate { font-size: 9px; }
.row-coordinate { font-size: 10px; }

/* Base Aisle / Empty Cell Styling */
.cell {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  padding: 0;
  border: 1px solid #ccd3dc;
  border-radius: 0;
  background: #f8fafc;
  color: #fff;
  font-size: 8px;
  line-height: 1;
  cursor: crosshair;
  touch-action: manipulation;
}

.cell.chair, .cell.reserved {
  border-radius: 4px 4px 2px 2px;
  box-shadow: inset 0 2px 0 rgb(255 255 255 / 25%), 0 1px 2px rgb(0 0 0 / 0.4);
}

.cell.chair { 
  border-color: #394253; 
  background: #1e293b; 
  color: #38bdf8; 
} 

.cell.reserved { 
  border-color: #78a9ff; 
  background: #2563eb; 
  color: #ffffff; 
} 

.cell.stage { 
  border-color: #fbc66b; 
  background: #f59e0b; 
  color: #0f172a;
  border-radius: 2px;
}

.cell.selected { outline: 2px solid #f8fafc; outline-offset: -3px; box-shadow: inset 0 0 0 2px #0f172a; z-index: 1; }
.cell:focus-visible { position: relative; z-index: 2; outline: 2px solid #facc15; outline-offset: 1px; }
.cell.is-chair { font-weight: 700; text-shadow: 0 1px 2px #000; }
.board-help { margin: 10px 2px 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.sidebar { display: grid; gap: 16px; }
.panel {
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
}
.panel > h2 { margin-bottom: 15px; }
.mode-row { justify-content: space-between; font-size: 13px; font-weight: 600; }

.switch { position: relative; display: inline-flex; width: 42px; height: 24px; cursor: pointer; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-track { width: 42px; height: 24px; border: 1px solid #52627b; border-radius: 999px; background: #29374e; transition: background .15s ease; }
.switch-track::after { position: absolute; top: 4px; left: 4px; width: 14px; height: 14px; border-radius: 50%; background: #e2e8f0; content: ""; transition: transform .15s ease; }
.switch input:checked + .switch-track { border-color: var(--blue); background: #2563eb; }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid #facc15; outline-offset: 2px; }
.hint { margin-top: 9px; color: var(--muted); font-size: 11px; line-height: 1.5; }

.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0 17px; }
.tool-button {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #1a2740;
  color: #cbd5e1;
  font-size: 11px;
  text-align: left;
  cursor: pointer;
}
.tool-button:hover { background: #25344e; }
.tool-button.is-active { border-color: #5792f5; background: #1b3764; color: #eff6ff; }
.tool-button .tool-swatch { flex: 0 0 12px; }
.field-label { display: block; margin-bottom: 7px; color: #cbd5e1; font-size: 11px; font-weight: 600; }
.text-input {
  width: 100%;
  height: 39px;
  padding: 0 10px;
  border: 1px solid #3a4a62;
  border-radius: 7px;
  outline: none;
  background: #101a2d;
  color: #f8fafc;
  font-size: 12px;
}
.text-input:focus { border-color: #60a5fa; box-shadow: 0 0 0 2px rgb(59 130 246 / 20%); }
.text-input::placeholder { color: #718096; }
.button { border: 0; border-radius: 8px; font-size: 12px; font-weight: 650; cursor: pointer; transition: background .15s ease, opacity .15s ease; }
.button-primary { padding: 11px 16px; background: #2563eb; color: white; white-space: nowrap; }
.button-primary:hover:not(:disabled) { background: #1d4ed8; }
.button-secondary { min-height: 39px; margin-top: 10px; padding: 9px 12px; background: #244a7c; color: #eff6ff; }
.button-secondary:hover:not(:disabled) { background: #2c5b95; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.full-width { width: 100%; }
.text-button { margin-top: 8px; padding: 5px; border: 0; background: transparent; color: #93c5fd; font-size: 11px; cursor: pointer; }
.text-button:disabled { color: #718096; cursor: not-allowed; }

/* Enhanced Roster Card Styles */
.roster-panel { min-height: 170px; }
.roster-heading { justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.count-pill { display: inline-grid; min-width: 25px; height: 25px; place-items: center; padding: 0 7px; border-radius: 999px; background: #243a5d; color: #bfdbfe; font-size: 11px; font-weight: 700; }
.roster-list { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.roster-item { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid #2b3d57; border-radius: 8px; background: #1a2740; }
.roster-header-line { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.roster-name { color: #f1f5f9; font-size: 13px; font-weight: 650; overflow-wrap: anywhere; }
.roster-total-badge { color: #38bdf8; font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.roster-coordinates { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; color: #93c5fd; font-size: 11px; letter-spacing: 0.02em; background: #101a2d; padding: 5px 8px; border-radius: 6px; border: 1px solid #23344e; word-break: break-all; }
.empty-state { color: var(--muted); font-size: 11px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }

/* Fullscreen Editor Mode Overlay */
.fullscreen-overlay { position: fixed; inset: 0; z-index: 9999; background: var(--page); display: flex; flex-direction: column; overflow: hidden; }
.fullscreen-topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; background: #111c31; border-bottom: 1px solid var(--border); }
.fullscreen-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.fullscreen-tools .tool-button { min-height: 36px; padding: 6px 12px; font-size: 11px; }
.fullscreen-workspace { flex: 1; overflow: auto; padding: 16px; display: grid; place-items: center; background: #101a2d; }
.fullscreen-workspace .board { margin: auto; }

/* Print Styles: Floor Plan on Page 1, Summary on Page 2 */
@media print {
  body { background: white !important; color: black !important; }
  .topbar, .sidebar, .fullscreen-overlay, .board-help, .button, .text-button { display: none !important; }
  .layout { display: block !important; padding: 0 !important; }
  .workspace { width: 100% !important; }
  .board-scroll { overflow: visible !important; border: none !important; background: white !important; max-height: none !important; }
  .section-heading::after { content: " — TSC Seating Allocation Floor Plan"; font-weight: bold; }
  
  /* Force page break before printing summary metrics & roster */
  .workspace { page-break-after: always; break-after: page; }
}

@media (max-width: 1050px) {
  .layout { grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; padding: 18px; }
  .topbar { padding-inline: 18px; }
  .legend { max-width: 350px; }
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; gap: 14px; padding: 15px; }
  .metrics { width: 100%; justify-content: space-between; gap: 4px; }
  .metric { min-width: 55px; }
  .metric span:first-child { font-size: 15px; }
  .layout { grid-template-columns: 1fr; padding: 16px 12px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .legend { max-width: none; }
  .sidebar { grid-template-columns: 1fr; }
}