/* ==========================================================================
   Project Cover Template - Stylesheet
   Faithfully calibrated to match ปก(template).docx (100% exact A4 proportions)
   Calibrated to match ปก(template).docx (100% exact A4 proportions)
   UI: 100% Zero-Scroll Full-Screen Interface
   ========================================================================== */

/* Official Thai Government & Vocational Font (TH Sarabun New) */
@font-face {
  font-family: 'TH Sarabun New';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('assets/fonts/THSarabunNew.ttf') format('truetype');
}

@font-face {
  font-family: 'TH Sarabun New';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('assets/fonts/THSarabunNew-Bold.ttf') format('truetype');
}

/* CSS Variables */
:root {
  --font-doc: 'TH Sarabun New';
  --font-ui: 'TH Sarabun New';
  
  --bg-app: #0b1329;
  --bg-sidebar: #131d38;
  --bg-card: #1e294b;
  --bg-input: #0b1329;
  --border-color: #2b3964;
  --border-focus: #38bdf8;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-hover: #15803d;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.3), 0 8px 10px -6px rgb(0 0 0 / 0.3);
  --shadow-paper: 0 12px 35px rgba(0, 0, 0, 0.45);

  /* A4 Dimensions (ISO 216 standard) */
  --a4-width: 210mm;
  --a4-height: 297mm;
  
  /* Exact Docx Margins from Word document.xml */
  /* Top: 3969 twips = 70.0mm; Bottom: 1418 twips = 25.0mm; Left: 1418 = 25.0mm; Right: 1701 = 30.0mm */
  --margin-top: 77.4mm; /* 70mm top margin + 7.4mm empty line (P00) */
  --margin-bottom: 25mm;
  --margin-left: 25mm;
  --margin-right: 30mm;
  
  /* Logo exact docx size & position */
  /* Logo exact docx size & position (Fixed Official Template) */
  --logo-width: 46mm;
  --logo-height: 35.8mm;
  --logo-top: 34.3mm;
  --logo-gap: 8mm;
}

/* Base Reset */
/* Base Reset - 100% Zero-Scroll Viewport Lock */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100vw;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

body {
  font-family: var(--font-ui);
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top Navigation Bar */
.navbar {
  height: 60px;
  height: 48px;
  min-height: 48px;
  max-height: 48px;
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  padding: 0 18px;
  z-index: 50;
  flex-shrink: 0;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  width: 30px;
  height: 30px;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  border-radius: 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  font-size: 17px;
  color: white;
  box-shadow: 0 2px 8px rgba(14, 165, 233, 0.4);
  box-shadow: 0 2px 6px rgba(14, 165, 233, 0.4);
}

.brand-title {
  font-size: 15px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: -0.2px;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 12px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.1;
}

.server-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 9999px;
  margin-left: 10px;
  transition: all 0.25s ease;
  user-select: none;
}

.server-status-pill.online {
  background: rgba(22, 163, 74, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #4ade80;
}

.server-status-pill.online .status-indicator-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 6px #22c55e;
  animation: pulse-dot 2s infinite ease-in-out;
}

.server-status-pill.offline {
  background: rgba(234, 179, 8, 0.15);
  border: 1px solid rgba(234, 179, 8, 0.35);
  color: #facc15;
}

.server-status-pill.offline .status-indicator-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #eab308;
}

@keyframes pulse-dot {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; filter: drop-shadow(0 0 3px #22c55e); }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  gap: 8px;
}

/* Action Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13.5px;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  text-decoration: none;
  font-family: var(--font-ui);
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
  transform: translateY(-1px);
}

.btn-success {
  background: linear-gradient(135deg, #16a34a, #15803d);
  color: white;
  box-shadow: 0 2px 6px rgba(22, 163, 74, 0.3);
}
.btn-success:hover {
  background: linear-gradient(135deg, #15803d, #166534);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background-color: #2b3964;
  color: white;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  padding: 3px 8px;
  font-size: 11.5px;
}

.btn-icon {
  padding: 8px;
  padding: 6px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
}
.btn-icon:hover {
  color: var(--text-main);
  background: #2b3964;
}

/* Main Layout */
/* Main Layout (Locked Viewport) */
.app-container {
  display: flex;
  flex: 1;
  height: calc(100vh - 60px);
  height: calc(100vh - 48px);
  max-height: calc(100vh - 48px);
  overflow: hidden;
}

/* Sidebar Editor Panel */
.sidebar-panel {
  width: 440px;
  min-width: 360px;
  min-width: 380px;
  max-width: 460px;
  height: 100%;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow: hidden;
  z-index: 20;
  flex-shrink: 0;
}

.sidebar-content {
  padding: 18px;
}

/* Segmented Tabs Header */
.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px;
  background: rgba(11, 19, 41, 0.7);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.tab-btn {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-ui);
  transition: all 0.15s ease-in-out;
  user-select: none;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.35);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  font-weight: 600;
}

.tab-btn svg {
  flex-shrink: 0;
}

/* Sidebar Content Panels */
.sidebar-tab-panels {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

/* Custom Scrollbar for Edge-case screen sizes */
.sidebar-tab-panels::-webkit-scrollbar {
  width: 5px;
}
.sidebar-tab-panels::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-tab-panels::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
.sidebar-tab-panels::-webkit-scrollbar-thumb:hover {
  background: #3b4e80;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: tabFadeIn 0.15s ease-out;
}

@keyframes tabFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-section {
  background-color: rgba(30, 41, 75, 0.5);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 14px;
  padding: 12px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  margin-bottom: 10px;
}

.section-title {
  font-size: 13.5px;
  font-size: 13px;
  font-weight: 600;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-badge {
  font-size: 10.5px;
  background: rgba(56, 189, 248, 0.12);
  color: #38bdf8;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(56, 189, 248, 0.2);
}

/* Form Controls & Grid Rows */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Form Controls */
.form-group {
  margin-bottom: 12px;
  margin-bottom: 8px;
}
.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 12px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 5px;
  margin-bottom: 4px;
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  padding: 6px 9px;
  font-size: 12.5px;
  font-family: var(--font-ui);
  background-color: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.form-textarea {
  resize: vertical;
  min-height: 56px;
  min-height: 52px;
  line-height: 1.35;
}

.form-tip {
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.6);
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  margin-top: 8px;
  line-height: 1.4;
}

/* Dynamic Members List */
.members-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
  margin-bottom: 6px;
  max-height: 380px;
  overflow-y: auto;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 8px;
  gap: 6px;
  background-color: var(--bg-input);
  padding: 5px 8px;
  padding: 4px 7px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.member-drag-handle {
  color: var(--text-muted);
  font-size: 12px;
  font-size: 11.5px;
  font-weight: 600;
  min-width: 18px;
  min-width: 16px;
  user-select: none;
}

.member-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-ui);
  font-size: 13px;
  font-size: 12.5px;
  outline: none;
}

.btn-remove-member {
  background: transparent;
  border: none;
  color: #f87171;
  cursor: pointer;
  padding: 4px;
  padding: 3px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s;
}
.btn-remove-member:hover {
  background-color: rgba(239, 68, 68, 0.2);
}
.btn-remove-member:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background-color: transparent;
}

/* Range Sliders */
.range-group {
  display: flex;
  align-items: center;
  gap: 12px;
  gap: 8px;
}

.range-input {
  flex: 1;
  width: 100%;
  accent-color: #38bdf8;
  height: 6px;
  height: 5px;
  cursor: pointer;
}

.range-val {
  font-size: 12px;
  font-size: 11.5px;
  font-weight: 600;
  color: #38bdf8;
  min-width: 44px;
  text-align: right;
}

/* Preview Canvas Workspace */
/* ==========================================================================
   PREVIEW WORKSPACE - 100% ZERO-SCROLL AUTO-FIT VIEWPORT
   ========================================================================== */

.preview-workspace {
  flex: 1;
  height: 100%;
  max-height: 100%;
  background-color: #070c18;
  background-image: 
    radial-gradient(circle at 1px 1px, rgba(255,255,255,0.06) 1px, transparent 0);
  background-size: 24px 24px;
  overflow: auto !important;
  display: flex;
  flex-direction: column;
  align-items: safe center;
  justify-content: flex-start !important;
  padding: 56px 40px 140px 40px;
  position: relative;
  scroll-behavior: smooth;
}

/* Unit 2 preview uses the neutral paper desk seen in Word's Print Layout. */
body.unit2-mode .preview-workspace,
body.unit3-mode .preview-workspace {
  background: #eef1f5;
  background-image: none;
}

/* Pan Mode Cursors */
.preview-workspace.pan-mode {
  cursor: grab !important;
}
.preview-workspace.pan-mode * {
  cursor: grab !important;
}
.preview-workspace.is-panning,
.preview-workspace.is-panning * {
  cursor: grabbing !important;
  user-select: none !important;
}

/* Floating Zoom & Canvas Toolbar */
.preview-toolbar {
  position: sticky;
  top: 12px;
  z-index: 50;
  display: flex;
  justify-content: center;
  pointer-events: none;
  width: 100%;
  margin-bottom: 24px;
}

.zoom-controls {
  pointer-events: auto;
  background-color: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 9999px;
  padding: 4px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  user-select: none;
}

.zoom-btn {
  background: transparent;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  padding: 0;
}
.zoom-btn:hover {
  background-color: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}
.zoom-btn:active {
  transform: scale(0.94);
}

.zoom-divider {
  width: 1px;
  height: 18px;
  background-color: rgba(255, 255, 255, 0.14);
  margin: 0 2px;
}

/* Smooth Zoom Range Slider */
.zoom-slider-container {
  display: flex;
  align-items: center;
  width: 100px;
  padding: 0 4px;
}
.zoom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.2);
  outline: none;
  cursor: pointer;
  transition: background 0.15s ease;
}
.zoom-slider:hover {
  background: rgba(255, 255, 255, 0.3);
}
.zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #38bdf8;
  cursor: pointer;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
  transition: transform 0.12s ease;
}
.zoom-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}
.zoom-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #38bdf8;
  cursor: pointer;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

/* Zoom Dropdown & Preset Menu */
.zoom-dropdown-wrap {
  position: relative;
}
.zoom-level-badge {
  background: transparent;
  border: none;
  font-size: 12px;
  font-weight: 600;
  color: #38bdf8;
  padding: 3px 6px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
  transition: all 0.15s ease;
}
.zoom-level-badge:hover {
  background-color: rgba(56, 189, 248, 0.12);
}
.zoom-text {
  font-size: 12px;
  font-weight: 600;
  min-width: 40px;
  text-align: center;
  color: #38bdf8;
}

.zoom-preset-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background-color: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.65);
  padding: 4px;
  z-index: 100;
  min-width: 140px;
}
.zoom-preset-menu.open {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.zoom-preset-item {
  background: transparent;
  border: none;
  color: #cbd5e1;
  text-align: left;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.zoom-preset-item:hover {
  background-color: #1e293b;
  color: #38bdf8;
}
.zoom-menu-divider {
  height: 1px;
  background-color: rgba(255, 255, 255, 0.1);
  margin: 4px 0;
}

/* Quick Action Buttons (100%, พอดีหน้าจอ, พอดีกว้าง) */
.zoom-quick-btn {
  background-color: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  font-size: 11.5px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.zoom-quick-btn:hover {
  background-color: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.25);
}
.zoom-quick-btn:active {
  transform: scale(0.96);
}

/* ==========================================================================
   A4 SHEET - PIXEL-PERFECT WORD REPLICA
   ========================================================================== */

.page-wrapper {
  transform-origin: top center;
  transition: transform 0.15s ease-out;
  margin-bottom: 30px;
  width: 794px;
  height: 1123px;
  flex-shrink: 0;
  display: block;
  position: relative;
  box-shadow: var(--shadow-paper);
  border-radius: 2px;
  transition: transform 0.12s ease-out;
}

.page-a4 {
  width: var(--a4-width);
  height: var(--a4-height);
  min-height: var(--a4-height);
  max-height: var(--a4-height);
  background-color: #ffffff;
  color: #000000;
  box-shadow: var(--shadow-paper);
  position: relative;
  box-sizing: border-box;
  transform-origin: top left;
  transition: transform 0.12s ease-out;
  
  /* Font specifications from ปก(template).docx */
  font-family: var(--font-doc);
  font-size: 16pt;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  
  /* Margins: Top 77.4mm (70mm + empty line P00), Bottom 25mm, Left 25mm, Right 30mm */
  padding-top: var(--margin-top);
  padding-bottom: var(--margin-bottom);
  padding-left: var(--margin-left);
  padding-right: var(--margin-right);
  
  /* Flex layout to balance sections */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* Logo positioned exactly inside the top margin area, horizontally aligned with text margins */
.cover-logo-wrapper {
  position: absolute;
  top: var(--logo-top, 34.3mm);
  left: var(--margin-left, 25mm);
  right: var(--margin-right, 30mm);
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}

.cover-logo-img {
  width: var(--logo-width, 46mm);
  max-width: var(--logo-width, 46mm);
  height: var(--logo-height, 35.8mm);
  max-height: var(--logo-height, 35.8mm);
  object-fit: contain;
  pointer-events: none;
  border-radius: 2px;
}

/* Sections */
.cover-section-top {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: var(--logo-gap, 8mm);
}

.cover-title-th {
  font-size: inherit;
  font-weight: 700;
  color: #000000;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.25;
}

.cover-title-en {
  font-size: inherit;
  font-weight: 700;
  color: #000000;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.25;
}

.cover-section-middle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0;
  margin: auto 0; /* Auto center between top and bottom */
}

.cover-author-item {
  font-size: inherit;
  font-weight: 700;
  color: #000000;
  line-height: 1.25;
}

.cover-section-bottom {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.cover-bottom-line {
  font-size: inherit;
  font-weight: 700;
  color: #000000;
  line-height: 1.25;
  white-space: pre-wrap;
}

/* Single line curriculum row */
#view-curriculum-line {
  letter-spacing: -0.2px;
  white-space: nowrap;
}

/* Mode: Word Exact Spacers (when user prefers exact blank line count) */
/* Mode: Word Exact Spacers (matching ปก(template).docx 100%) */
.page-a4.mode-word-exact {
  justify-content: flex-start;
}

.page-a4.mode-word-exact .spacer-line {
  height: calc(16pt * 1.2);
  height: 1.15em;
  min-height: 1.15em;
  line-height: 1.15;
  display: block;
}

.page-a4.mode-word-exact .cover-section-middle {
  margin: 0;
}

/* Contenteditable inline editing style */
[contenteditable="true"] {
  outline: none;
  transition: background-color 0.2s, box-shadow 0.2s;
  border-radius: 2px;
  padding: 0 2px;
}

[contenteditable="true"]:hover {
  background-color: rgba(56, 189, 248, 0.08);
  outline: 1px dashed rgba(56, 189, 248, 0.5);
  cursor: text;
}

[contenteditable="true"]:focus {
  background-color: rgba(56, 189, 248, 0.15);
  outline: 1.5px solid #0284c7;
}

/* Print Guidelines / Watermark (hidden when printing) */
.page-guidelines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  border: 1px dashed rgba(0, 0, 0, 0.06);
}

/* Badge & Notifications */
.toast-msg {
  position: fixed;
  bottom: 24px;
  right: 24px;
  bottom: 20px;
  right: 20px;
  background-color: #1e293b;
  color: #f8fafc;
  padding: 12px 20px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-xl);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  gap: 8px;
  font-size: 13px;
  z-index: 100;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Guide Modal / Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.active,
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 90%;
  max-width: 540px;
  padding: 24px;
  max-width: 520px;
  padding: 22px;
  box-shadow: var(--shadow-xl);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  margin-bottom: 14px;
}

.modal-title {
  font-size: 18px;
  font-size: 17px;
  font-weight: 600;
  color: #38bdf8;
}

.modal-body {
  font-size: 14px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-muted);
}

.modal-body ol {
  margin-left: 20px;
  margin-top: 10px;
  margin-left: 18px;
  margin-top: 8px;
}

.modal-body li {
  margin-bottom: 8px;
  margin-bottom: 6px;
}

.modal-footer {
  margin-top: 20px;
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
}

/* ==========================================================================
   PRINT MEDIA - 100% EXACT A4 REPRODUCTION
   ========================================================================== */

@page {
  size: A4 portrait;
  margin: 0; /* Zero margin because .page-a4 handles exact margins via padding */
}

@media print {
  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .navbar,
  .sidebar-panel,
  .zoom-controls,
  .toast-msg,
  .modal-overlay,
  .page-guidelines,
  .btn-remove-member {
    display: none !important;
  }

  .app-container {
    display: block !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .preview-workspace {
    background: none !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
    overflow: visible !important;
  }

  .page-wrapper {
    transform: none !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 210mm !important;
    height: auto !important;
    box-shadow: none !important;
    display: block !important;
  }

  .page-a4 {
    transform: none !important;
    box-shadow: none !important;
    border: none !important;
    margin: 0 !important;
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  [contenteditable="true"]:hover,
  [contenteditable="true"]:focus {
    background-color: transparent !important;
    outline: none !important;
  }
}

/* ==========================================================================
   Template Switcher in Navbar
   ========================================================================== */
.template-switcher {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  margin-left: 14px;
}

.template-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.template-switch-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.template-switch-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.4);
}

/* ==========================================================================
   Certificate Document (ProjectCertificate.docx) A4 Page Layout
   Exact Margins: Top 35mm (1985 twips), Left 35mm (1985 twips),
                  Bottom 30mm (1701 twips), Right 25mm (1418 twips)
   ========================================================================== */
.page-cert {
  box-sizing: border-box !important;
  width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  padding: 35mm 25mm 30mm 35mm !important;
  background-color: #ffffff !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  font-size: 15pt !important;
  line-height: 1.25 !important;
  text-align: left !important;
  position: relative !important;
  display: block !important;
  overflow: hidden !important;
}

/* Logo Box */
.cert-logo-box {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  margin-top: -5mm !important;
  margin-bottom: 7mm !important;
  width: 100% !important;
}

.cert-logo-box img,
.cert-logo-img {
  height: 32mm !important;
  max-height: 32mm !important;
  width: auto !important;
  max-width: 46mm !important;
  object-fit: contain !important;
  display: block !important;
}

/* Document Header Titles (18pt Bold Centered) */
.cert-header-title1 {
  font-size: 18pt !important;
  font-weight: bold !important;
  text-align: center !important;
  margin: 0 0 2px 0 !important;
  line-height: 1.2 !important;
  color: #000000 !important;
}

.cert-header-title2 {
  font-size: 18pt !important;
  font-weight: bold !important;
  text-align: center !important;
  margin: 0 0 8px 0 !important;
  line-height: 1.2 !important;
  color: #000000 !important;
}

/* Project & Authors Info Block */
.cert-info-table {
  display: flex !important;
  flex-direction: column !important;
  gap: 2px !important;
  margin-bottom: 12px !important;
  width: 100% !important;
}

.cert-info-row {
  display: flex !important;
  align-items: baseline !important;
  font-size: 15pt !important;
  line-height: 1.35 !important;
  min-height: 20pt !important;
  color: #000000 !important;
}

.cert-info-label {
  display: inline-block !important;
  width: 23mm !important;
  min-width: 23mm !important;
  max-width: 23mm !important;
  flex-shrink: 0 !important;
  box-sizing: border-box !important;
  color: #000000 !important;
}

.cert-info-value {
  flex-grow: 1 !important;
  color: #000000 !important;
}

/* Approval Paragraph (First-line indent 12.7mm) */
.cert-approval-paragraph {
  text-indent: 12.7mm !important;
  font-size: 15pt !important;
  line-height: 1.35 !important;
  text-align: left !important;
  margin-top: 14px !important;
  margin-bottom: 16px !important;
  color: #000000 !important;
}

/* Department Head Signature Block (Centered under underline) */
.cert-head-container {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  margin-left: 39mm !important;
  margin-top: 14px !important;
  margin-bottom: 20px !important;
  font-size: 15pt !important;
  line-height: 1.35 !important;
  color: #000000 !important;
}

.cert-head-sign-row {
  display: flex !important;
  align-items: baseline !important;
  white-space: nowrap !important;
}

.cert-head-sign-line {
  display: inline-block !important;
  width: 41mm !important;
  letter-spacing: -0.5px !important;
  color: #000000 !important;
}

.cert-head-role {
  margin-left: 4px !important;
  color: #000000 !important;
  white-space: nowrap !important;
}

.cert-head-name-row {
  width: 41mm !important;
  text-align: center !important;
  margin-top: 2px !important;
  white-space: nowrap !important;
  color: #000000 !important;
}

.cert-head-date-row {
  margin-top: 4px !important;
  margin-left: -12mm !important;
  white-space: nowrap !important;
  color: #000000 !important;
}

/* Examination Committee Section */
.cert-comm-section {
  width: 100% !important;
  color: #000000 !important;
}

.cert-comm-heading {
  font-size: 15pt !important;
  font-weight: normal !important;
  margin-bottom: 10px !important;
  line-height: 1.3 !important;
  color: #000000 !important;
}

.cert-comm-list {
  display: flex !important;
  flex-direction: column !important;
  gap: 10px !important;
}

.cert-comm-item {
  display: flex !important;
  flex-direction: column !important;
  font-size: 15pt !important;
  line-height: 1.3 !important;
  color: #000000 !important;
}

.cert-comm-sign-row {
  display: flex !important;
  align-items: baseline !important;
  white-space: nowrap !important;
}

.cert-comm-underline {
  display: inline-block !important;
  width: 78.5mm !important;
  letter-spacing: -0.5px !important;
  color: #000000 !important;
}

.cert-comm-role {
  margin-left: 6px !important;
  color: #000000 !important;
}

.cert-comm-name-row {
  width: 78.5mm !important;
  text-align: center !important;
  margin-top: 2px !important;
  color: #000000 !important;
}

/* ==========================================================================
   Abstract Page (บทคัดย่อ) Styles - 100% Calibrated to Abstract.docx
   Web preview/print padding: Top 15mm, Bottom 10mm, Left 25mm, Right 25mm
   Tab stop: 40mm (2268 twips)
   Font: TH Sarabun New (16pt body, 18pt bold heading)
   Flow: Natural top-to-bottom block layout (NOT flex space-between)
   ========================================================================== */

.page-abstract,
.abstract-paper {
  width: var(--a4-width);
  height: var(--a4-height);
  max-height: var(--a4-height);
  padding: 10mm 25mm 10mm 25mm !important;
  background-color: #ffffff;
  color: #000000;
  font-family: var(--font-doc);
  box-shadow: var(--shadow-paper);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  box-sizing: border-box !important;
  width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  padding: 15mm 25mm 10mm 25mm !important;
  background-color: #ffffff !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  font-size: 16pt !important;
  font-weight: 400 !important;
  line-height: 1.15 !important;
  text-align: left !important;
  position: relative !important;
  display: block !important;
  overflow: hidden !important;
  box-shadow: var(--shadow-paper) !important;
}

/* Abstract Metadata Section (Tab Stop 40mm) */
.abstract-meta-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  display: block !important;
  width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
}

.abstract-meta-row {
  display: flex;
  align-items: baseline;
  font-size: 16pt;
  line-height: 1.15;
  color: #000000;
  font-family: var(--font-doc);
  margin: 0 0 2.2mm 0;
  padding: 0;
  min-height: 1.15em;
}

.abstract-meta-row[style*="display: none"],
.abstract-meta-row.hidden {
  display: none !important;
}

.abstract-meta-label {
  width: 40mm;
  min-width: 40mm;
  max-width: 40mm;
  flex-shrink: 0;
  color: #000000;
  font-family: var(--font-doc);
  width: 40mm !important;
  min-width: 40mm !important;
  max-width: 40mm !important;
  flex-shrink: 0 !important;
  color: #000000 !important;
  font-weight: 400 !important;
  font-family: var(--font-doc) !important;
}

.abstract-meta-value {
  flex: 1;
  color: #000000;
  word-break: break-word;
  font-family: var(--font-doc);
  flex: 1 !important;
  color: #000000 !important;
  font-weight: 400 !important;
  font-family: var(--font-doc) !important;
  word-break: break-word !important;
}

/* Horizontal Divider (Border bottom 1.5pt solid) */
.abstract-divider {
  width: 100%;
  border: none;
  border-bottom: 1.5pt solid #000000;
  margin-top: 16px;
  margin-bottom: 20px;
  width: 100% !important;
  border: none !important;
  border-bottom: 1.5pt solid #000000 !important;
  margin-top: 9mm !important;
  margin-bottom: 0 !important;
  display: block !important;
}

/* Spacers matching empty paragraphs P[9] and P[11] in Abstract.docx */
.abstract-spacer {
  height: 6.5mm !important;
  display: block !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* Abstract Title Heading: 18pt Bold Centered */
.abstract-heading {
  font-size: 18pt;
  font-weight: 700;
  text-align: center;
  color: #000000;
  font-family: var(--font-doc);
  margin-bottom: 20px;
  line-height: 1.2;
  font-size: 18pt !important;
  font-weight: 700 !important;
  text-align: center !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  line-height: 1.15 !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
}

/* Abstract Body Content: 16pt Justified (Thai Distribute), Indented 1 Tab (12.5mm) */
/* Abstract Body Content: 16pt Justified (Thai Distribute), Indented 1 Tab (12.7mm) */
.abstract-body-content {
  font-size: 16pt;
  line-height: 1.35;
  text-align: justify;
  text-justify: inter-cluster;
  color: #000000;
  font-family: var(--font-doc);
  word-break: break-word;
  font-size: 16pt !important;
  font-weight: 400 !important;
  line-height: 1.25 !important;
  text-align: justify !important;
  text-justify: inter-cluster !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  word-break: break-word !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
}

.abstract-paragraph {
  text-indent: 12.5mm;
  margin-bottom: 0.5em;
  text-align: justify;
  text-justify: inter-cluster;
  line-height: 1.35;
  font-size: 16pt;
  font-family: var(--font-doc);
  text-indent: 12.7mm !important;
  margin-bottom: 0 !important;
  text-align: justify !important;
  text-justify: inter-cluster !important;
  line-height: 1.25 !important;
  font-size: 16pt !important;
  font-weight: 400 !important;
  font-family: var(--font-doc) !important;
  display: block !important;
}

.abstract-paragraph:last-child {
  margin-bottom: 0;
}
.abstract-paragraph + .abstract-paragraph {
  margin-top: 0.4em !important;
}

/* Quick Delete Button for Co-Advisor on Paper Preview */
.quick-del-btn {
  position: absolute;
  right: -55px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: inherit;
  color: #ef4444;
  cursor: pointer;
  opacity: 0;
  white-space: nowrap;
  transition: opacity 0.2s, background 0.2s, transform 0.15s;
}

#view-co-advisor-row:hover .quick-del-btn {
  opacity: 0.85;
}

.quick-del-btn:hover {
  opacity: 1 !important;
  background: rgba(239, 68, 68, 0.25) !important;
  transform: translateY(-50%) scale(1.05);
}

/* Abstract Specific Sidebar Form Tweaks */
.char-counter-badge {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: normal;
  margin-left: auto;
}

/* Page Number Footer (Centered Bottom) */
.abstract-footer-page {
  position: absolute;
  bottom: 12.7mm;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-doc);
  font-size: 16pt;
  line-height: 1;
  color: #000000;
  z-index: 10;
}

.abstract-footer-page span[contenteditable="true"] {
  outline: none;
  cursor: text;
  display: inline-block;
  min-width: 20px;
  padding: 1px 4px;
  border-radius: 2px;
  transition: background 0.2s;
}

.abstract-footer-page span[contenteditable="true"]:hover {
  background: rgba(56, 189, 248, 0.15);
}

.abstract-footer-page span[contenteditable="true"]:focus {
  background: rgba(56, 189, 248, 0.25);
}

/* Print Setup for Abstract Page */
@media print {
  body.abstract-print-mode .page-abstract,
  body.abstract-print-mode .abstract-paper {
    width: 210mm !important;
    height: 297mm !important;
    max-height: 297mm !important;
    padding: 15mm 25mm 10mm 25mm !important;
    box-shadow: none !important;
    margin: 0 !important;
    display: block !important;
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.abstract-print-mode .abstract-footer-page {
    position: absolute !important;
    bottom: 12.7mm !important;
    left: 0 !important;
    right: 0 !important;
    text-align: center !important;
  }

  .abstract-footer-page #view-page-number {
    visibility: hidden !important;
  }
}

/* ==========================================================================
   Acknowledgements Page (กิตติกรรมประกาศ)
   Calibrated to match templates/Acknowledgements.docx
   Margins: top=35mm, right=25mm, bottom=30mm, left=35mm
   ========================================================================== */

.page-acknowledgements {
  box-sizing: border-box !important;
  width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  padding: 35mm 25mm 25mm 35mm !important;
  background-color: #ffffff !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  font-size: 16pt !important;
  font-weight: 400 !important;
  line-height: 1.15 !important;
  text-align: left !important;
  position: relative !important;
  display: block !important;
  overflow: hidden !important;
  box-shadow: var(--shadow-paper) !important;
}

/* Heading: กิตติกรรมประกาศ (Heading1 = 18pt Bold Centered) */
.ack-heading {
  font-size: 18pt !important;
  font-weight: 700 !important;
  text-align: center !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  line-height: 1.15 !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
}

/* Spacer matching empty paragraphs in Acknowledgements.docx */
.ack-spacer {
  height: 6.5mm !important;
  display: block !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* Body Content: 16pt Thai Distribute, Tab Indent 12.7mm */
.ack-body-content {
  font-size: 16pt !important;
  font-weight: 400 !important;
  line-height: 1.25 !important;
  text-align: justify !important;
  text-justify: inter-cluster !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  word-break: break-word !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
}

.ack-paragraph {
  text-indent: 12.7mm !important;
  margin-bottom: 0 !important;
  text-align: justify !important;
  text-justify: inter-cluster !important;
  line-height: 1.25 !important;
  font-size: 16pt !important;
  font-weight: 400 !important;
  font-family: var(--font-doc) !important;
  display: block !important;
}

.ack-paragraph + .ack-paragraph {
  margin-top: 0.4em !important;
}

/* Signoff Section: Right-aligned (คณะผู้จัดทำ + author names) */
.ack-signoff {
  text-align: right !important;
  font-size: 16pt !important;
  font-weight: 400 !important;
  line-height: 1.25 !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  margin-top: 7mm !important;
}

.ack-signoff-label {
  font-size: 16pt !important;
  font-weight: 400 !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  margin-bottom: 0 !important;
}

.ack-signoff-name {
  font-size: 16pt !important;
  font-weight: 400 !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
}

.ack-signoff-name[contenteditable="true"] {
  outline: none;
  cursor: text;
  min-width: 40px;
  display: block;
}

.ack-signoff-name[contenteditable="true"]:hover {
  background: rgba(56, 189, 248, 0.08);
  border-radius: 2px;
}

.ack-signoff-name[contenteditable="true"]:focus {
  background: rgba(56, 189, 248, 0.15);
  border-radius: 2px;
}

/* Page Number Footer (Centered Bottom) */
.ack-footer-page {
  position: absolute;
  bottom: 12.7mm;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-doc);
  font-size: 16pt;
  line-height: 1;
  color: #000000;
  z-index: 10;
}

.ack-footer-page span[contenteditable="true"] {
  outline: none;
  cursor: text;
  display: inline-block;
  min-width: 20px;
  padding: 1px 4px;
  border-radius: 2px;
  transition: background 0.2s;
}

.ack-footer-page span[contenteditable="true"]:hover {
  background: rgba(56, 189, 248, 0.15);
}

.ack-footer-page span[contenteditable="true"]:focus {
  background: rgba(56, 189, 248, 0.25);
}

/* Print Setup for Acknowledgements Page */
@media print {
  body.acknowledgements-print-mode .page-acknowledgements {
    width: 210mm !important;
    height: 297mm !important;
    max-height: 297mm !important;
    padding: 35mm 25mm 25mm 35mm !important;
    box-shadow: none !important;
    margin: 0 !important;
    display: block !important;
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.acknowledgements-print-mode .ack-footer-page {
    position: absolute !important;
    bottom: 12.7mm !important;
    left: 0 !important;
    right: 0 !important;
    text-align: center !important;
  }

  .ack-footer-page #view-page-number {
    visibility: hidden !important;
  }
}

/* ==========================================================================
   Chapter 1 (Unit 1: บทนำ) - Calibrated to match templates/Unit1.docx
   ========================================================================== */

/* A4 Paper Dimensions & Margins */
/* Margins: Top 35mm, Right 25mm, Bottom 30mm, Left 35mm */
.page-unit1 {
  width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  padding: 35mm 25mm 30mm 35mm !important;
  background-color: #ffffff !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  font-size: 16pt !important;
  font-weight: 400 !important;
  line-height: 1.15 !important;
  text-align: left !important;
  position: relative !important;
  display: block !important;
  overflow: hidden !important;
  box-shadow: var(--shadow-paper) !important;
}

/* Unit 1 Chapter Heading: 18pt Bold Centered */
.unit1-heading {
  font-size: 18pt !important;
  font-weight: 700 !important;
  text-align: center !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  line-height: 1.15 !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
}

.unit1-heading[contenteditable="true"] {
  outline: none;
  cursor: text;
}
.unit1-heading[contenteditable="true"]:hover {
  background: rgba(56, 189, 248, 0.06);
}
.unit1-heading[contenteditable="true"]:focus {
  background: rgba(56, 189, 248, 0.12);
}

/* Spacer matching empty paragraphs in Unit1.docx */
.unit1-spacer {
  height: 5mm !important;
  display: block !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* Subheading: 16pt Bold Left-aligned */
.unit1-subheading {
  font-size: 16pt !important;
  font-weight: 700 !important;
  text-align: left !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  line-height: 1.25 !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
}

.unit1-subheading[contenteditable="true"] {
  outline: none;
  cursor: text;
}
.unit1-subheading[contenteditable="true"]:hover {
  background: rgba(56, 189, 248, 0.06);
}
.unit1-subheading[contenteditable="true"]:focus {
  background: rgba(56, 189, 248, 0.12);
}

/* Body Content: 16pt Thai Distribute, Tab Indent 12.7mm */
.unit1-body-content {
  font-size: 16pt !important;
  font-weight: 400 !important;
  line-height: 1.25 !important;
  text-align: justify !important;
  text-justify: inter-cluster !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  word-break: break-word !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
}

.unit1-paragraph {
  text-indent: 12.7mm !important;
  margin-bottom: 0 !important;
  text-align: justify !important;
  text-justify: inter-cluster !important;
  line-height: 1.25 !important;
  font-size: 16pt !important;
  font-weight: 400 !important;
  font-family: var(--font-doc) !important;
  display: block !important;
}

.unit1-paragraph[contenteditable="true"] {
  outline: none;
  cursor: text;
  min-height: 1.2em;
}
.unit1-paragraph[contenteditable="true"]:hover {
  background: rgba(56, 189, 248, 0.06);
}
.unit1-paragraph[contenteditable="true"]:focus {
  background: rgba(56, 189, 248, 0.12);
}

.unit1-paragraph + .unit1-paragraph {
  margin-top: 0.15em !important;
}

/* Print Setup for Unit 1 Page */
@media print {
  body.unit1-print-mode .page-unit1 {
    width: 210mm !important;
    height: 297mm !important;
    max-height: 297mm !important;
    padding: 35mm 25mm 30mm 35mm !important;
    box-shadow: none !important;
    margin: 0 !important;
    display: block !important;
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* ==========================================================================
   Chapter 2 (Unit 2: ทฤษฎีและงานวิจัยที่เกี่ยวข้อง) - templates/Unit2.docx
   ========================================================================== */

/* A4 Paper Dimensions & Margins */
/* Margins: Top 35mm, Right 25mm, Bottom 30mm, Left 35mm */
.page-unit2 {
  width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  padding: 35mm 25mm 30mm 35mm !important;
  background-color: #ffffff !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  font-size: 16pt !important;
  font-weight: 400 !important;
  line-height: 1.15 !important;
  text-align: left !important;
  position: relative !important;
  display: block !important;
  overflow: hidden !important;
  box-shadow: var(--shadow-paper) !important;
}

/* Page Number Header (Top Right: Top 12.7mm, Right 25mm) */
.unit2-header-page {
  position: absolute !important;
  top: 12.7mm !important;
  right: 25mm !important;
  text-align: right !important;
  font-family: var(--font-doc) !important;
  font-size: 16pt !important;
  line-height: 1 !important;
  color: #000000 !important;
  z-index: 10 !important;
}

.unit2-header-page span[contenteditable="true"] {
  outline: none;
  cursor: text;
  display: inline-block;
  min-width: 20px;
  padding: 1px 4px;
  border-radius: 2px;
  transition: background 0.2s;
}

.unit2-header-page span[contenteditable="true"]:hover {
  background: rgba(56, 189, 248, 0.15);
}

.unit2-header-page span[contenteditable="true"]:focus {
  background: rgba(56, 189, 248, 0.25);
}

/* Unit 2 Chapter Heading: 18pt Bold Centered */
.unit2-heading {
  font-size: 18pt !important;
  font-weight: 700 !important;
  text-align: center !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  line-height: 1.15 !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
}

.unit2-heading[contenteditable="true"] {
  outline: none;
  cursor: text;
}
.unit2-heading[contenteditable="true"]:hover {
  background: rgba(56, 189, 248, 0.06);
}
.unit2-heading[contenteditable="true"]:focus {
  background: rgba(56, 189, 248, 0.12);
}

/* Spacer matching empty paragraphs in Unit2.docx */
.unit2-spacer {
  height: 5.5mm !important;
  display: block !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* Subheading: 16pt Bold Left-aligned */
.unit2-subheading {
  font-size: 16pt !important;
  font-weight: 700 !important;
  text-align: left !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  line-height: 1.25 !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
}

.unit2-subheading[contenteditable="true"] {
  outline: none;
  cursor: text;
}
.unit2-subheading[contenteditable="true"]:hover {
  background: rgba(56, 189, 248, 0.06);
}
.unit2-subheading[contenteditable="true"]:focus {
  background: rgba(56, 189, 248, 0.12);
}

/* Body Content: 16pt Thai Distribute, Tab Indent 12.7mm */
.unit2-body-content {
  font-size: 16pt !important;
  font-weight: 400 !important;
  line-height: 1.25 !important;
  text-align: justify !important;
  text-justify: inter-cluster !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  word-break: normal !important;
  overflow-wrap: normal !important;
  line-break: loose !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
}

.unit2-paragraph {
  text-indent: 12.7mm !important;
  margin-bottom: 0 !important;
  text-align: justify !important;
  text-justify: inter-cluster !important;
  line-height: 1.36 !important;
  font-size: 16pt !important;
  font-weight: 400 !important;
  font-family: var(--font-doc) !important;
  word-break: normal !important;
  overflow-wrap: normal !important;
  line-break: loose !important;
  display: block !important;

  white-space: pre-wrap !important;
}

.unit2-paragraph[contenteditable="true"] {
  outline: none;
  cursor: text;
  min-height: 1.2em;
}
.unit2-paragraph[contenteditable="true"]:hover {
  background: rgba(56, 189, 248, 0.06);
}
.unit2-paragraph[contenteditable="true"]:focus {
  background: rgba(56, 189, 248, 0.12);
}

.unit2-paragraph + .unit2-paragraph {
  margin-top: 0.25em !important;
}

/* Unit 2 Multi-page Stack Styles */
.unit2-mode .page-wrapper,
.unit3-mode .page-wrapper {
  box-shadow: none !important;
  background: transparent !important;
  position: relative !important;
  margin: 0 auto 30px auto !important;
}

.pages-scaler {
  position: absolute;
  top: 0;
  left: 0;
  width: 794px;
  transform-origin: top left;
  transition: transform 0.12s ease-out;
  display: flex;
  flex-direction: column;
}

.unit2-page-sheet {
  width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  padding: 35mm 25mm 30mm 35mm !important;
  background-color: #ffffff !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  font-size: 16pt !important;
  font-weight: 400 !important;
  line-height: 1.36 !important;
  text-align: left !important;
  position: relative !important;
  display: block !important;
  box-sizing: border-box !important;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.18) !important;
  overflow: hidden !important;
}

.unit2-page-sheet + .unit2-page-sheet {
  margin-top: 28px !important;
}

.unit2-header-space {
  height: 0;
}

.unit2-page-header {
  position: absolute !important;
  top: 12.7mm !important;
  right: 25mm !important;
  text-align: right !important;
  font-family: var(--font-doc) !important;
  font-size: 16pt !important;
  line-height: 1 !important;
  color: #000000 !important;
  z-index: 10 !important;
}

.unit2-header-pagenum {
  outline: none;
  cursor: text;
  display: inline-block;
  min-width: 20px;
  padding: 1px 4px;
  border-radius: 2px;
  transition: background 0.2s;
}

.unit2-header-pagenum:hover {
  background: rgba(56, 189, 248, 0.15);
}

.unit2-header-pagenum:focus {
  background: rgba(56, 189, 248, 0.25);
}

.unit2-page-body {
  display: block !important;
  height: auto !important;
  min-height: 0 !important;
  box-sizing: border-box !important;
  position: relative !important;
}

.unit2-title-block {
  text-align: center !important;
  margin-bottom: 0 !important;
}

.chapter-title-spacer {
  height: 5.5mm !important;
}

.unit2-chapter {
  font-size: 18pt !important;
  font-weight: 700 !important;
  text-align: center !important;
  color: #000000 !important;
  line-height: 1.15 !important;
}

.unit2-title {
  font-size: 18pt !important;
  font-weight: 700 !important;
  text-align: center !important;
  color: #000000 !important;
  line-height: 1.15 !important;
}

/* Appendix title pages: title centered on the sheet (Word section vAlign="center") */
.unit2-page-sheet.chapter-page-centered .unit2-page-body {
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  align-items: stretch !important;
  height: 100% !important;
}

.unit2-page-sheet.chapter-page-centered .unit2-subheading,
.unit2-page-sheet.chapter-page-centered .unit2-title {
  text-align: center !important;
}

/* Appendix content: "ก.1 ..." lines are bold subheadings without first-line indent */
.unit2-paragraph.chapter-appendix-subheading {
  font-weight: 700 !important;
  text-indent: 0 !important;
  text-align: left !important;
}

/* Chapter sub-headings "2.1.1 ..." keep their own line, not bold, one tab per level
   (as 3.5.1 in templates/Unit3.docx); the text under them keeps the same indent. */
.unit2-paragraph.chapter-subsubheading,
.unit2-paragraph.chapter-under-subheading {
  text-indent: calc(var(--indent-tabs, 2) * 12.7mm) !important;
}

.unit2-paragraph[data-placeholder]:empty::before {
  content: attr(data-placeholder);
  color: #9ca3af;
}

@media print {
  .unit2-paragraph[data-placeholder]:empty::before {
    content: none;
  }
}

/* Bibliography: matches templates/Bibliography.docx */
.unit2-subheading.chapter-bib-title {
  font-size: 18pt !important;
  text-align: center !important;
  line-height: 1.36 !important;
}

.chapter-bib-blank {
  height: calc(16pt * 1.36) !important;
}

.unit2-paragraph.chapter-bib-entry {
  padding-left: 12.7mm !important;
  text-indent: -12.7mm !important;
  line-height: 2.04 !important; /* Word 1.5 lines = 1.5 x single (1.36) */
  margin-top: 0 !important;
  margin-bottom: 8pt !important;
}

/* Print Setup for Unit 2 Multi-page */
/* Print Setup for Unit 2 Multi-page */
@media print {
  body.unit2-mode .page-wrapper,
  body.unit3-mode .page-wrapper,
  body.unit2-print-mode .page-wrapper {
    height: auto !important;
    width: 210mm !important;
    transform: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
  }

  body.unit2-mode .pages-scaler,
  body.unit3-mode .pages-scaler,
  body.unit2-print-mode .pages-scaler {
    position: static !important;
    width: 210mm !important;
    height: auto !important;
    transform: none !important;
    display: block !important;
  }

  body.unit2-mode .unit2-page-sheet,
  body.unit3-mode .unit2-page-sheet,
  body.unit2-print-mode .unit2-page-sheet {
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    padding: 35mm 25mm 30mm 35mm !important;
    box-shadow: none !important;
    margin: 0 !important;
    display: flex !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.unit2-mode .unit2-page-sheet:last-child,
  body.unit3-mode .unit2-page-sheet:last-child,
  body.unit2-print-mode .unit2-page-sheet:last-child {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  body.unit2-mode .unit2-page-sheet + .unit2-page-sheet,
  body.unit3-mode .unit2-page-sheet + .unit2-page-sheet,
  body.unit2-print-mode .unit2-page-sheet + .unit2-page-sheet {
    margin-top: 0 !important;
  }

  body.unit2-mode .unit2-page-header,
  body.unit3-mode .unit2-page-header,
  body.unit2-print-mode .unit2-page-header {
    position: absolute !important;
    top: 12.7mm !important;
    right: 25mm !important;
    text-align: right !important;
  }
}

/* Figure Dataset & Caption Styles (Unit 2 & Modular) */
.figure-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

.figure-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.figure-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-add-figure {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px dashed rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-top: 8px;
}

.btn-add-figure:hover {
  background: rgba(56, 189, 248, 0.16);
  border-color: #38bdf8;
  color: #ffffff;
  transform: translateY(-1px);
}

.figure-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.figure-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  position: relative;
  transition: all var(--transition-fast);
}

.figure-card:hover {
  border-color: rgba(56, 189, 248, 0.3);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.figure-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.figure-badge {
  font-size: 11px;
  font-weight: 600;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.2px;
}

.figure-card-actions {
  display: flex;
  gap: 4px;
}

.btn-figure-del {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-figure-del:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

.figure-upload-area {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.figure-dropzone {
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.02);
  transition: all var(--transition-fast);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.figure-dropzone:hover {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.04);
}

.figure-dropzone-text {
  font-size: 11px;
  color: var(--text-secondary);
}

.figure-thumb-wrapper {
  position: relative;
  width: 100%;
  height: 90px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.figure-thumb-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.figure-thumb-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 23, 42, 0.85);
  color: #cbd5e1;
  font-size: 10.5px;
  padding: 4px 6px;
  text-align: center;
  backdrop-filter: blur(4px);
  pointer-events: none;
  transition: all var(--transition-fast);
}

.figure-dropzone:hover .figure-thumb-overlay {
  background: rgba(30, 58, 138, 0.95);
  color: #38bdf8;
}

.btn-thumb-action:hover {
  background: #38bdf8;
  color: #0f172a;
}

.figure-caption-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.figure-caption-label {
  font-size: 11px;
  color: var(--text-muted);
}

.figure-caption-input {
  width: 100%;
  font-size: 12px;
  padding: 6px 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  box-sizing: border-box;
}

.figure-caption-input:focus {
  border-color: #38bdf8;
  outline: none;
}

/* A4 Paper Figure Block (Exact Academic Print & Preview Layout) */
.unit2-figure-block {
  margin: 4.5mm auto 3.5mm auto !important;
  text-align: center !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  page-break-inside: avoid !important;
  break-inside: avoid !important;
}

.unit2-figure-img-wrapper {
  display: inline-block !important;
  text-align: center !important;
  max-width: 100% !important;
}

.unit2-figure-img {
  max-width: 120mm !important;
  max-height: 75mm !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain !important;
  display: block !important;
  margin: 0 auto !important;
  border: 1px solid #cbd5e1;
  background-color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.unit2-figure-caption {
  font-size: 16pt !important;
  font-weight: 400 !important;
  line-height: 1.25 !important;
  color: #000000 !important;
  font-family: var(--font-doc) !important;
  text-align: center !important;
  margin-top: 2.2mm !important;
  display: block !important;
  word-break: break-word !important;
}

.unit2-figure-label {
  font-weight: 700 !important;
  margin-right: 2mm !important;
}

.unit2-figure-caption-text {
  font-weight: 400 !important;
}

/* Table Dataset & A4 Preview Styles */
.table-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

.table-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.table-empty-hint {
  color: var(--text-muted);
  font-size: 12px;
  padding: 8px 0;
}

.table-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px;
}

.table-card-header,
.table-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.table-card-header {
  margin-bottom: 6px;
}

.table-label-input {
  flex: 1;
  font-size: 12px;
  padding: 5px 7px;
}

.table-caption-input {
  width: 100%;
  font-size: 12px;
  padding: 5px 7px;
  margin-bottom: 8px;
}

.table-style-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.table-style-controls label {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--text-secondary);
  font-size: 11px;
  white-space: nowrap;
}

.table-style-controls input[type="number"] {
  width: 52px;
  padding: 3px 4px;
  font-size: 11px;
}

.table-style-controls input[type="color"] {
  width: 28px;
  height: 24px;
  padding: 1px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}

.btn-table-delete,
.btn-table-action {
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  padding: 4px 7px;
}

.btn-table-delete:hover {
  color: #f87171;
  border-color: #f87171;
}

.btn-table-action:hover {
  color: #38bdf8;
  border-color: #38bdf8;
}

.table-editor-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
}

.table-editor {
  width: 100%;
  /* Wide tables keep usable cells and scroll sideways inside .table-editor-wrap */
  min-width: max(280px, calc(var(--editor-cols, 3) * 76px));
  border-collapse: collapse;
  table-layout: fixed;
}

.table-editor td {
  border: 1px solid var(--border-subtle);
  padding: 3px;
  vertical-align: middle;
}

.table-editor td.is-header {
  background: rgba(56, 189, 248, 0.1);
}

.table-cell-input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 11px;
  padding: 4px;
  box-sizing: border-box;
}

.table-editor-cell {
  display: flex;
  align-items: center;
  gap: 3px;
}

.table-cell-select {
  flex: 0 0 auto;
  margin: 0;
  accent-color: #38bdf8;
  cursor: pointer;
}

.table-card-actions {
  flex-wrap: wrap;
  margin-top: 8px;
}

.btn-add-table {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  margin-top: 8px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px dashed rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
}

.btn-add-table:hover {
  background: rgba(56, 189, 248, 0.16);
  border-color: #38bdf8;
  color: #ffffff;
}

.unit2-table-block {
  margin: 5mm auto 4mm auto !important;
  text-align: center !important;
  page-break-inside: avoid !important;
  break-inside: avoid !important;
  width: 100%;
}

.unit2-table-caption {
  font-family: var(--font-doc) !important;
  font-size: 16pt !important;
  line-height: 1.25 !important;
  text-align: center !important;
  margin-top: 2.5mm !important;
  color: #000000 !important;
}

.unit2-table-label {
  font-weight: 700 !important;
  margin-right: 2mm;
}

.unit2-table-caption-text {
  font-weight: 400 !important;
}

.unit2-preview-table {
  width: var(--table-width, 100%);
  margin-left: auto;
  margin-right: auto;
  border-collapse: collapse;
  table-layout: fixed;
  font-family: var(--font-doc) !important;
  font-size: var(--table-font-size, 16pt) !important;
  line-height: 1.25 !important;
  color: #000000 !important;
  text-align: center !important;
}

/* Layout options used by tables imported from the ตารางประเมิน page */
.unit2-preview-table .is-left {
  text-align: left;
}

.unit2-preview-table .is-bold {
  font-weight: 700;
}

.unit2-preview-table.is-compact th,
.unit2-preview-table.is-compact td {
  padding: 0.4mm 1mm;
}

.unit2-preview-table th,
.unit2-preview-table td {
  border: 1px solid var(--table-border-color, #808080);
  padding: 2.5mm 2mm;
  height: var(--table-row-height, 8mm);
  vertical-align: middle;
  word-break: normal;
  overflow-wrap: anywhere;
}

.unit2-preview-table th {
  background: var(--table-header-color, #d9eaf7);
  font-weight: 700;
}

.unit2-preview-table td {
  font-weight: 400;
}

.unit2-table-label[contenteditable="true"],
.unit2-table-caption-text[contenteditable="true"],
.unit2-preview-table [contenteditable="true"] {
  outline: none;
}

@media print {
  .table-section,
  .table-card,
  .btn-add-table {
    display: none !important;
  }

  .unit2-table-block {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .unit2-preview-table {
    font-size: var(--table-font-size, 16pt) !important;
  }
}

.unit2-figure-caption[contenteditable="true"] {
  outline: none;
  cursor: text;
  border-radius: 2px;
  padding: 1px 4px;
}

.unit2-figure-caption[contenteditable="true"]:hover {
  background: rgba(56, 189, 248, 0.08);
}

.unit2-figure-caption[contenteditable="true"]:focus {
  background: rgba(56, 189, 248, 0.15);
}

/* Print Rules for Figures */
@media print {
  .unit2-figure-block {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin: 4mm auto 3mm auto !important;
  }
  .unit2-figure-img {
    box-shadow: none !important;
    border: 1px solid #000000 !important;
    max-width: 120mm !important;
    max-height: 75mm !important;
  }
  .unit2-figure-caption {
    font-size: 16pt !important;
    color: #000000 !important;
    line-height: 1.25 !important;
  }
}

/* Unit 2 Sidebar Action Bar & Element Controls */
.sidebar-action-bar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-surface-alt, #0f172a);
  border-bottom: 1px solid var(--border-color);
  align-items: center;
}

.sidebar-action-bar .btn-action {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.28);
  color: #38bdf8;
}

.sidebar-action-bar .btn-action:hover {
  background: rgba(56, 189, 248, 0.18);
  border-color: #38bdf8;
  color: #ffffff;
  transform: translateY(-1px);
}

.sidebar-action-bar .btn-action-primary {
  background: #2563eb;
  border-color: #3b82f6;
  color: #ffffff;
}

.sidebar-action-bar .btn-action-primary:hover {
  background: #1d4ed8;
}

.section-title-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.section-title-input {
  flex: 1;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.section-title-input:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.15);
}

.btn-section-delete {
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #ef4444;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all var(--transition-fast);
}

.btn-section-delete:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: #ef4444;
}

.content-helper-buttons {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.btn-content-helper {
  flex: 1;
  font-size: 11.5px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: var(--bg-surface-alt, #1e293b);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-content-helper:hover {
  background: rgba(56, 189, 248, 0.1);
  border-color: rgba(56, 189, 248, 0.3);
  color: #38bdf8;
}

.tab-btn-add {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px 9px;
  background: transparent;
  border: 1px dashed rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  font-size: 14px;
  font-weight: 700;
  border-radius: 4px;
  cursor: pointer;
  margin: 4px 4px;
  transition: all var(--transition-fast);
}

.tab-btn-add:hover {
  background: rgba(56, 189, 248, 0.15);
  border-color: #38bdf8;
}

.unit2-subheading-nested,
.chapter-subheading-nested {
  margin-left: 0 !important;
  font-size: 16pt !important;
  font-weight: 400 !important;
  text-indent: 12.7mm !important;
}

body.unit2-mode .sidebar-tabs,
body.unit3-mode .sidebar-tabs,
body.chapter-mode .sidebar-tabs {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  padding: 6px 8px !important;
  gap: 4px !important;
  align-items: center !important;
}

body.unit2-mode .sidebar-tabs .tab-btn,
body.unit3-mode .sidebar-tabs .tab-btn,
body.chapter-mode .sidebar-tabs .tab-btn {
  flex: 0 0 auto !important;
  min-width: 65px !important;
  padding: 5px 8px !important;
}

body.unit2-mode .tab-btn-add,
body.unit3-mode .tab-btn-add,
body.chapter-mode .tab-btn-add {
  flex: 0 0 auto !important;
  width: 26px !important;
  height: 26px !important;
  min-width: 26px !important;
  max-width: 26px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  margin: 0 2px !important;
  border: 1px dashed #38bdf8 !important;
  color: #38bdf8 !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  border-radius: 4px !important;
  cursor: pointer !important;
  background: transparent !important;
  line-height: 1 !important;
}

body.unit2-mode .tab-btn-add:hover,
body.unit3-mode .tab-btn-add:hover,
body.chapter-mode .tab-btn-add:hover {
  background: rgba(56, 189, 248, 0.15) !important;
}

/* Aligned Rows for Rating Scales & Structured Lists */
.unit-aligned-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: baseline !important;
  text-indent: 0 !important;
  padding-left: 25.4mm !important; /* 1 inch left indent matching Word w:ind w:left="1440" */
  text-align: left !important;
  margin-top: 0.1em !important;
  margin-bottom: 0.1em !important;
  line-height: 1.36 !important;
  white-space: pre-wrap !important;
}

.unit-aligned-row .aligned-col-left {
  display: inline-block !important;
  width: 58mm !important;
  min-width: 58mm !important;
  max-width: 58mm !important;
  flex-shrink: 0 !important;
  font-family: inherit !important;
  font-size: inherit !important;
  text-align: left !important;
}

.unit-aligned-row .aligned-col-right {
  display: inline-block !important;
  flex-grow: 1 !important;
  font-family: inherit !important;
  font-size: inherit !important;
  text-align: left !important;
}

/* Aligned Rows for Statistical Formula Definitions */
.unit-aligned-def-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: baseline !important;
  text-indent: 0 !important;
  padding-left: 25.4mm !important;
  text-align: left !important;
  margin-top: 0.1em !important;
  margin-bottom: 0.1em !important;
  line-height: 1.36 !important;
  white-space: pre-wrap !important;
}

.unit-aligned-def-row .aligned-def-prefix {
  display: inline-block !important;
  width: 14mm !important;
  min-width: 14mm !important;
  flex-shrink: 0 !important;
  font-family: inherit !important;
  font-size: inherit !important;
}

.unit-aligned-def-row .aligned-def-sym {
  display: inline-block !important;
  width: 22mm !important;
  min-width: 22mm !important;
  flex-shrink: 0 !important;
  font-family: "Cambria Math", var(--font-doc), serif !important;
  font-size: inherit !important;
}

.unit-aligned-def-row .aligned-def-desc {
  display: inline-block !important;
  flex-grow: 1 !important;
  font-family: inherit !important;
  font-size: inherit !important;
  text-align: left !important;
}

.unit-formula-row {
  text-indent: 0 !important;
  padding-left: 25.4mm !important;
  margin-top: 0.25em !important;
  margin-bottom: 0.25em !important;
  font-family: "Cambria Math", var(--font-doc), serif !important;
}

/* Teacher picker under advisor / examiner inputs (teacher-picker.js) */
.teacher-select {
  margin-top: 6px;
  font-size: 13px;
}
