:root {
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: rgba(2, 132, 199, 0.1);
  --primary-border: rgba(2, 132, 199, 0.25);
  --secondary: #475569;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --card-header-bg: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --card-bg: #111827;
    --card-header-bg: #1f2937;
    --border: #1f2937;
    --border-strong: #374151;
    --text: #f9fafb;
    --text-muted: #9ca3af;
    --text-subtle: #6b7280;
    --primary-light: rgba(2, 132, 199, 0.18);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 20px 16px;
  min-height: 100vh;
}

.app-container {
  max-width: 1440px;
  margin: 0 auto;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
  background: var(--card-bg);
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-back:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.header-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #fff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.3);
}

h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buttons */
button {
  cursor: pointer;
  border: none;
  outline: none;
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all 0.18s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(2, 132, 199, 0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--card-header-bg);
  border-color: var(--text-muted);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.btn-danger-outline {
  background: transparent;
  border: 1px solid #fca5a5;
  color: var(--danger);
}

.btn-danger-outline:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-print {
  background: #047857;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(4, 120, 87, 0.2);
}

.btn-print:hover {
  background: #065f46;
}

.btn-chip {
  padding: 5px 10px;
  font-size: 0.8rem;
  border-radius: 20px;
  background: var(--card-header-bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
}

.btn-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Safe Initial Banner */
.banner-welcome {
  background: linear-gradient(135deg, rgba(2, 132, 199, 0.08) 0%, rgba(59, 130, 246, 0.03) 100%);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.banner-welcome.hidden {
  display: none;
}

.banner-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 4px;
  margin-bottom: 10px;
}

.banner-content h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.banner-content p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
  max-width: 900px;
}

.banner-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* Layout */
.main-layout {
  display: grid;
  grid-template-columns: 460px 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 1080px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
}

.config-col {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.results-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Cards */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.card-header h2 {
  font-size: 1.02rem;
  font-weight: 700;
  flex: 1;
}

.step-num {
  width: 26px;
  height: 26px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.card-badge {
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--card-header-bg);
  color: var(--primary);
  padding: 3px 9px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.section-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.85rem;
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

textarea {
  font-family: 'Roboto Mono', monospace;
  font-size: 0.82rem;
  resize: vertical;
  line-height: 1.4;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

.input-hint-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hint-text {
  font-size: 0.75rem;
  color: var(--text-subtle);
}

.room-size-buttons {
  display: flex;
  gap: 6px;
  align-items: center;
}

.input-actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  gap: 10px;
}

.parse-stats {
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--card-header-bg);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  border-left: 3px solid var(--primary);
}

.parse-stats.hidden {
  display: none;
}

/* Metric summary card */
.summary-card {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
}

.summary-metric {
  text-align: center;
  padding: 8px 4px;
  border-right: 1px solid var(--border);
}

.summary-metric:last-child {
  border-right: none;
}

.metric-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
  font-family: 'Roboto Mono', monospace;
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-top: 2px;
}

/* Result toolbar */
.result-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.toolbar-left,
.toolbar-tabs,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-label {
  font-size: 0.85rem;
  font-weight: 600;
}

.select-room {
  padding: 6px 10px;
  min-width: 140px;
  font-weight: 600;
}

.toolbar-tabs {
  background: var(--card-header-bg);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.tab-btn {
  padding: 6px 12px;
  font-size: 0.85rem;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
}

.tab-btn.active {
  background: var(--card-bg);
  color: var(--primary);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  stroke: var(--text-subtle);
  margin-bottom: 14px;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 0.9rem;
  max-width: 440px;
  margin: 0 auto;
}

.empty-state.hidden {
  display: none;
}

/* Rooms List View (Interactive) */
.room-block {
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.room-block-header {
  background: var(--card-header-bg);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.room-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.room-badge {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 4px 10px;
  border-radius: 6px;
}

.room-info-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.room-table-wrap {
  overflow-x: auto;
}

.room-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.room-table th,
.room-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.room-table th {
  background: rgba(0,0,0,0.02);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.room-table tbody tr:hover {
  background: var(--primary-light);
}

.sbd-cell {
  font-family: 'Roboto Mono', monospace;
  font-weight: 700;
  color: var(--primary);
}

.gender-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.gender-Nam {
  background: rgba(2, 132, 199, 0.12);
  color: #0284c7;
}

.gender-Nữ {
  background: rgba(236, 72, 153, 0.12);
  color: #ec4899;
}

/* Visual Seating Chart in Web UI */
.seating-chart-room {
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}

.blackboard-area {
  background: #1e293b;
  color: #f8fafc;
  text-align: center;
  padding: 8px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 2px;
  margin-bottom: 20px;
  text-transform: uppercase;
  border: 2px solid #334155;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.desks-grid {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.desk-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.desk-col-header {
  text-align: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  background: var(--card-header-bg);
  padding: 4px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.desk-slot {
  background: var(--card-bg);
  border: 2px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px;
  position: relative;
  transition: all 0.2s;
  min-height: 82px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.desk-slot:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 10px var(--primary-light);
}

.desk-slot.occupied {
  border-left: 4px solid var(--primary);
}

.desk-slot.empty {
  border-style: dashed;
  opacity: 0.6;
  justify-content: center;
  align-items: center;
  color: var(--text-subtle);
  font-style: italic;
  font-size: 0.8rem;
}

.desk-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.desk-number {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-subtle);
  background: var(--card-header-bg);
  padding: 2px 5px;
  border-radius: 4px;
}

.desk-sbd {
  font-family: 'Roboto Mono', monospace;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--primary);
}

.desk-name {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.25;
  margin: 4px 0 2px 0;
  word-break: break-word;
}

.desk-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.teacher-desk {
  background: #f1f5f9;
  border: 2px dashed #94a3b8;
  padding: 8px 16px;
  border-radius: 6px;
  display: inline-block;
  font-weight: 600;
  font-size: 0.82rem;
  color: #475569;
  margin-bottom: 14px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: var(--card-bg);
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  animation: popIn 0.2s ease-out;
}

@keyframes popIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-icon.warning {
  color: var(--warning);
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-body {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 20px;
}

.modal-subtext {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-subtle);
  font-style: italic;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #f8fafc;
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 2000;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: all 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ----------------------------------------------------
   PRINT STYLES: Standard A4 Exam Regulations
   ---------------------------------------------------- */
.print-only {
  display: none;
}

@media print {
  body {
    background: #fff !important;
    color: #000 !important;
    padding: 0 !important;
    margin: 0 !important;
    font-size: 11pt !important;
    font-family: 'Times New Roman', Times, serif, sans-serif !important;
  }

  .no-print {
    display: none !important;
  }

  .print-only {
    display: block !important;
  }

  @page {
    size: A4 portrait;
    margin: 12mm 15mm 15mm 15mm;
  }

  .print-page {
    page-break-after: always;
    page-break-inside: avoid;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
  }

  .print-page:last-child {
    page-break-after: auto;
  }

  /* Printable Header */
  .p-header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
  }

  .p-org-left {
    text-align: center;
    font-size: 10pt;
    line-height: 1.3;
  }

  .p-org-left .p-school {
    font-weight: 700;
    text-transform: uppercase;
  }

  .p-org-left .p-council {
    font-weight: 600;
  }

  .p-country-right {
    text-align: center;
    font-size: 10pt;
    line-height: 1.3;
  }

  .p-country-title {
    font-weight: 700;
    text-transform: uppercase;
  }

  .p-country-sub {
    font-weight: 600;
    border-bottom: 1px solid #000;
    display: inline-block;
    padding-bottom: 2px;
  }

  .p-main-title {
    text-align: center;
    margin: 10px 0 6px 0;
  }

  .p-main-title h1 {
    font-size: 14pt;
    font-weight: 800;
    text-transform: uppercase;
    color: #000;
  }

  .p-main-title h2 {
    font-size: 12pt;
    font-weight: 700;
    margin-top: 3px;
    color: #000;
  }

  .p-meta-line {
    text-align: center;
    font-size: 10pt;
    font-style: italic;
    margin-bottom: 12px;
  }

  /* Print Table for Door Notice */
  .p-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10pt;
    margin-bottom: 16px;
  }

  .p-table th,
  .p-table td {
    border: 1px solid #000;
    padding: 5px 6px;
    vertical-align: middle;
  }

  .p-table th {
    background-color: #f2f2f2 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    text-align: center;
    font-weight: 700;
  }

  .p-text-center { text-align: center; }
  .p-text-right { text-align: right; }
  .p-font-bold { font-weight: 700; }
  .p-sbd-font {
    font-family: 'Roboto Mono', monospace, 'Courier New' !important;
    font-weight: 700;
    font-size: 10.5pt;
  }

  /* Print Footer / Signatures */
  .p-footer-stats {
    font-size: 10pt;
    font-weight: 600;
    margin-bottom: 16px;
  }

  .p-signatures {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    page-break-inside: avoid;
  }

  .p-sign-col {
    text-align: center;
    width: 45%;
    font-size: 10pt;
  }

  .p-sign-role {
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 4px;
  }

  .p-sign-space {
    height: 60px;
  }

  /* Printable Seating Chart Layout */
  .p-chart-stage {
    border: 1px solid #000;
    padding: 8px;
    text-align: center;
    font-weight: 700;
    font-size: 10pt;
    background: #eee !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: 2px;
  }

  .p-chart-grid {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
  }

  .p-desk-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .p-col-label {
    text-align: center;
    font-weight: 700;
    font-size: 9.5pt;
    border-bottom: 1.5px solid #000;
    padding-bottom: 2px;
    margin-bottom: 4px;
  }

  .p-desk-box {
    border: 1.5px solid #000;
    padding: 5px 6px;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }

  .p-desk-box.empty {
    border: 1px dashed #888;
    background: #fafafa !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .p-desk-row-top {
    display: flex;
    justify-content: space-between;
    font-size: 8.5pt;
    font-weight: 700;
  }

  .p-desk-sbd {
    font-family: 'Roboto Mono', monospace, 'Courier New' !important;
    font-size: 10.5pt;
    font-weight: 800;
  }

  .p-desk-name {
    font-size: 9pt;
    font-weight: 700;
    line-height: 1.2;
    margin-top: 2px;
  }

  .p-desk-meta {
    font-size: 8pt;
    display: flex;
    justify-content: space-between;
    margin-top: 2px;
  }

  .p-guide-note {
    font-size: 8.5pt;
    font-style: italic;
    border: 1px solid #999;
    padding: 6px 10px;
    margin-top: 10px;
  }
}
