/* ==========================================================================
   Teachers Pet - Editor Screen Layout Styling
   ========================================================================== */

.editor-container {
  display: grid;
  grid-template-columns: 380px 1fr;
  min-height: calc(100vh - 73px);
  background: var(--bg-app);
}

/* Editor Controls Panel (Left) */
.editor-controls {
  background: var(--bg-card);
  border-right: 1px solid var(--border-glass);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 73px);
  position: sticky;
  top: 73px;
  overflow-y: auto;
  backdrop-filter: blur(10px);
}

.editor-controls-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.btn-back {
  background: var(--bg-hover);
  border: 1px solid var(--border-glass);
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  transition: var(--transition-smooth);
}
.btn-back:hover {
  background: var(--color-primary-light);
  color: var(--text-main);
}

.editor-controls-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Tabs Navigation */
.control-tabs {
  display: flex;
  background: var(--bg-surface);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  border: 1px solid var(--border-glass);
}

.ctrl-tab {
  flex: 1;
  background: transparent;
  border: none;
  font-family: var(--font-sans);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.5rem;
  border-radius: calc(var(--radius-md) - 4px);
  cursor: pointer;
  transition: var(--transition-smooth);
}
.ctrl-tab.active {
  background: var(--color-primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

/* Tab Panes */
.tab-pane {
  display: none;
}
.tab-pane.active {
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.2s ease-out;
}

/* Custom Checkbox Slider Switch */
.color-system-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.switch-container {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
  flex-shrink: 0;
}

.switch-container input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: .3s;
  border-radius: 22px;
  border: 1px solid var(--border-glass);
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--color-primary);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

.toggle-label-text {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-main);
}

/* Template Picker Cards */
.template-selector-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.tpl-option {
  cursor: pointer;
}

.tpl-option input {
  display: none;
}

.tpl-card {
  height: 54px;
  border: 2px solid var(--border-glass);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  transition: var(--transition-smooth);
  background: var(--bg-surface);
  text-transform: capitalize;
}

.tpl-option input:checked + .tpl-card {
  border-color: var(--color-primary);
  background: rgba(99, 102, 241, 0.15);
  color: white;
}

/* Mini borders for template cards */
.classic-preview { border-style: double; }
.modern-preview { border-style: solid; border-width: 3px; }
.playful-preview { border-style: dotted; }

/* Print Layout Sizing Cards */
.print-size-selector {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.size-option {
  flex: 1;
  cursor: pointer;
}

.size-option input {
  display: none;
}

.size-card {
  background: var(--bg-surface);
  border: 2px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  text-align: center;
  transition: var(--transition-smooth);
}

.size-card span {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
}

.size-option input:checked + .size-card {
  border-color: var(--color-primary);
  background: rgba(99, 102, 241, 0.1);
}
.size-option input:checked + .size-card span {
  color: var(--text-main);
}

.mini-page {
  width: 48px;
  height: 34px;
  background: var(--bg-hover);
  border: 1px solid var(--border-glass);
  border-radius: 2px;
  position: relative;
}

.full-page::before {
  content: "";
  position: absolute;
  top: 4px; left: 4px; right: 4px; bottom: 4px;
  border: 1px solid var(--border-main);
}

.half-page::before, .half-page::after {
  content: "";
  position: absolute;
  left: 4px; right: 4px;
  height: 11px;
  border: 1px solid var(--border-main);
}
.half-page::before { top: 4px; }
.half-page::after { bottom: 4px; }

/* Print Instructions Panel */
.print-instructions {
  background: rgba(245, 158, 11, 0.06);
  border: 1px solid rgba(245, 158, 11, 0.15);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-top: 1rem;
}

.print-instructions h4 {
  font-size: 0.8rem;
  font-weight: 700;
  color: #f59e0b;
  margin-bottom: 0.5rem;
}

.print-instructions ul {
  list-style: none;
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* Actions Footer Inside Sidebar */
.editor-actions,
.editor-actions-consolidated {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 0.75rem;
  margin-top: auto;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-glass);
}

.btn-editor-action {
  padding: 0.75rem;
  font-size: 0.85rem;
}

.btn-save {
  background: var(--bg-hover);
  border: 1px solid var(--border-main);
  color: var(--text-main);
}
.btn-save:hover {
  background: var(--color-primary-light);
}

/* Dropdown Container */
.export-dropdown-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Toggle Button */
.btn-export-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  background: var(--bg-hover);
  border: 1px solid var(--border-main);
  color: var(--text-main);
  padding: 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-smooth);
}

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

.btn-export-toggle .chevron {
  font-size: 0.7rem;
  transition: transform 0.2s ease;
  color: var(--text-muted);
}

.export-dropdown-wrapper.open .btn-export-toggle .chevron {
  transform: rotate(180deg);
}

/* Menu Dropdown - Opens upward due to scroll container bottom position */
.export-dropdown-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 0.5rem;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  z-index: 100;
  flex-direction: column;
  gap: 0.35rem;
  animation: slideUpFade 0.2s ease-out;
}

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

.export-dropdown-menu.show {
  display: flex;
}

/* Individual dropdown menu items */
.export-dropdown-menu .dropdown-item {
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  text-align: left;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition-smooth);
}

/* Dropdown items styled premium based on their theme color */
.export-dropdown-menu .dropdown-item.btn-print {
  background: transparent;
  color: var(--text-main);
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.export-dropdown-menu .dropdown-item.btn-print:hover {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.6);
  transform: translateY(-1px);
}

.export-dropdown-menu .dropdown-item.btn-pdf {
  background: transparent;
  color: var(--text-main);
  border: 1px solid rgba(99, 102, 241, 0.3);
}
.export-dropdown-menu .dropdown-item.btn-pdf:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.6);
  transform: translateY(-1px);
}

.export-dropdown-menu .dropdown-item.btn-docx {
  background: transparent;
  color: var(--text-main);
  border: 1px solid rgba(43, 87, 154, 0.3);
}
.export-dropdown-menu .dropdown-item.btn-docx:hover {
  background: rgba(43, 87, 154, 0.15);
  border-color: rgba(43, 87, 154, 0.6);
  transform: translateY(-1px);
}

.export-dropdown-menu .dropdown-item.btn-quiz {
  background: transparent;
  color: var(--text-main);
  border: 1px solid rgba(236, 72, 153, 0.3);
}
.export-dropdown-menu .dropdown-item.btn-quiz:hover {
  background: rgba(236, 72, 153, 0.15);
  border-color: rgba(236, 72, 153, 0.6);
  transform: translateY(-1px);
}

/* Editor Preview Pane (Right) */
.editor-preview-pane {
  background-color: var(--bg-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 2rem;
  overflow-y: auto;
  height: calc(100vh - 73px);
  position: relative;
  background-image: 
    radial-gradient(var(--border-main) 1px, transparent 0),
    radial-gradient(var(--border-main) 1px, transparent 0);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 900px;
  margin-bottom: 1.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.preview-badge {
  background: var(--bg-hover);
  border: 1px solid var(--border-glass);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-weight: 600;
}

/* The physical paper sheet simulation */
.print-sheet {
  background: white;
  width: 900px; /* Scaled aspect ratio of landscape A4 (approx 1.414) */
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  transition: var(--transition-smooth);
  color: #1f2937;
  overflow: hidden;
  position: relative;
  aspect-ratio: 297/210; /* Perfect A4 Landscape ratio */
}

/* A4 Half sheet mode layout changes */
.layout-half {
  aspect-ratio: 210/297; /* Vertically stacked landscape cards fits A4 portrait best, OR Landscape layout with side-by-side. 
  Let's stack two Landscape certificates on a single Portrait sheet! That is extremely standard:
  Portrait A4 contains Certificate 1 (Landscape) on the top half, Certificate 2 (Landscape) on the bottom half.
  Perfect cutting option! */
  width: 636px; /* Scaled portrait sheet size: 636px wide x 900px high (210/297) */
}

.layout-full {
  aspect-ratio: 297/210;
  width: 900px;
}

/* Scissors Cut line between certificates */
.print-cut-line {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  border-top: 1.5px dashed #94a3b8;
  border-bottom: 1.5px dashed #94a3b8;
  background: #f1f5f9;
  font-size: 0.7rem;
  font-weight: 700;
  color: #475569;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  user-select: none;
  z-index: 10;
}

/* Scale animation for preview switching */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1024px) {
  .editor-container {
    display: flex;
    flex-direction: column;
  }
  .editor-controls {
    order: 2;
    height: auto;
    position: relative;
    top: 0;
    border-right: none;
    border-top: 1px solid var(--border-glass);
    overflow-y: visible;
  }
  .editor-preview-pane {
    order: 1;
    height: auto;
    min-height: 250px;
    padding: 1rem;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: flex-start;
  }
  .print-sheet {
    transform-origin: top center;
  }
}

/* Accordion Styles & Question Collapsing */
.accordion-header {
  display: none !important;
}

#view-worksheet-editor .editor-preview-pane,
#view-assessment .editor-preview-pane {
  overflow-x: hidden;
  overflow-y: auto;
  align-items: flex-start;
}

.q-card {
  background: var(--bg-hover);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
}

.q-card-body {
  display: flex !important;
  flex-direction: column;
  gap: 0.5rem;
}

.q-chevron {
  display: none !important;
}

/* Mobile-only Tab Navigation and Toolbar Styles */
.mobile-editor-tabs {
  display: none !important;
}

.mobile-preview-toolbar {
  display: none !important;
}

@media (max-width: 768px) {
  .mobile-editor-tabbar {
    display: none !important;
  }

  .editor-container {
    height: calc(100vh - 73px) !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .editor-preview-pane {
    height: 45% !important;
    flex: 0 0 45% !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
    padding: 1rem 0.5rem !important;
    border-bottom: 2px solid var(--border-glass) !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important; /* Centered preview sheet placement on split screen */
    background-color: var(--bg-surface) !important;
  }

  .editor-controls {
    height: 55% !important;
    flex: 0 0 55% !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 1.25rem 1rem !important;
    background: var(--bg-card) !important;
    border-top: none !important;
  }

  /* Fit print sheet to viewport width */
  .print-sheet {
    transform-origin: center center !important;
    margin-bottom: 0;
  }

  /* Editor layout refinements */
  .editor-controls-header {
    margin-bottom: 1rem;
    gap: 0.5rem;
  }
  .editor-controls-header h2 {
    font-size: 1rem;
  }
  .control-tabs {
    display: none !important; /* Hide desktop tab bar on mobile */
  }
  .form-group {
    margin-bottom: 0.75rem;
  }
  .form-group label {
    margin-bottom: 0.2rem;
    font-size: 0.75rem;
  }
  .form-group input, .form-group select, .form-group textarea {
    padding: 0.45rem 0.6rem;
    font-size: 0.8rem;
  }
  .template-selector-grid {
    gap: 0.35rem;
  }
  .tpl-card {
    height: 44px;
    font-size: 0.7rem;
  }
  .size-card {
    padding: 0.5rem;
    gap: 0.25rem;
  }
  .size-card span {
    font-size: 0.65rem;
  }
  .mini-page {
    width: 36px;
    height: 25px;
  }
  .editor-actions,
  .editor-actions-consolidated {
    padding-top: 1rem;
    gap: 0.5rem;
  }
  .btn-editor-action,
  .btn-export-toggle {
    padding: 0.6rem;
    font-size: 0.8rem;
  }

  /* Accordion Headers on Mobile */
  .accordion-header {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background: var(--bg-hover);
    border: 1px solid var(--border-glass);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 0.5rem;
    margin-top: 0.5rem;
    text-align: left;
    transition: var(--transition-smooth);
  }
  .accordion-header:hover {
    background: var(--color-primary-light);
  }
  .accordion-header .chevron {
    transition: transform 0.3s ease;
    font-size: 0.8rem;
    color: var(--text-muted);
  }
  .accordion-section.active > .accordion-header .chevron {
    transform: rotate(180deg);
  }
  
  /* Accordion Contents on Mobile */
  .accordion-section .accordion-content,
  .accordion-section .tab-pane {
    display: none !important;
  }
  .accordion-section.active .accordion-content,
  .accordion-section.active .tab-pane {
    display: block !important;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-glass);
  }

  /* Worksheet Question Cards (Accordion style on Mobile) */
  .q-card-header {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    user-select: none;
  }
  .q-chevron {
    display: inline-block !important; /* Show chevron on mobile */
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: transform 0.3s ease;
  }
  .q-card.expanded .q-chevron {
    transform: rotate(180deg);
  }
  .q-card .q-card-body {
    display: none !important;
  }
  .q-card.expanded .q-card-body {
    display: flex !important;
    flex-direction: column;
    gap: 0.5rem;
  }
}

/* Recommended badge overlays */
.tpl-option {
  position: relative;
}
.tpl-option.recommended::after {
  content: "★ REC";
  position: absolute;
  top: -8px;
  right: -5px;
  background: var(--color-warning);
  color: var(--text-inverse);
  font-size: 0.6rem;
  font-weight: 800;
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-sm);
  letter-spacing: 0.5px;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  z-index: 5;
}

/* ==========================================================================
   DOCUMENT BUILDER STYLING
   ========================================================================== */

/* Word Document Paper Simulation */
.word-paper-page {
  background: #ffffff;
  color: #1e293b;
  width: 100%;
  max-width: 800px;
  min-height: auto;
  margin: 0 auto;
  padding: 3rem 4rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  border-radius: 4px;
  box-sizing: border-box;
  text-align: left;
}

/* Multi-page worksheet / assessment preview */
.worksheet-pages-host,
#assessment-preview {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.worksheet-pages-host .doc-pages-root,
#assessment-preview .doc-pages-root {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 794px;
  max-width: 100%;
}

.doc-page {
  page-break-after: always;
  break-after: page;
}

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

.ws-question-block,
.doc-page-block {
  break-inside: avoid;
  page-break-inside: avoid;
}
.word-paper-page h1, .word-paper-page h2, .word-paper-page h3, .word-paper-page p {
  color: #1e293b;
  margin-top: 0;
  outline: none;
}
.word-paper-page h1 { font-size: 2.2rem; font-weight: 800; border-bottom: 2px solid #cbd5e1; padding-bottom: 0.5rem; margin-bottom: 1.5rem; }
.word-paper-page h2 { font-size: 1.6rem; font-weight: 700; margin-top: 1.5rem; margin-bottom: 0.8rem; }
.word-paper-page h3 { font-size: 1.25rem; font-weight: 600; margin-top: 1.25rem; margin-bottom: 0.6rem; }
.word-paper-page p { font-size: 1rem; line-height: 1.6; margin-bottom: 1rem; min-height: 1.6em; }
.word-paper-page table { width: 100%; border-collapse: collapse; margin-bottom: 1.25rem; }
.word-paper-page th, .word-paper-page td { border: 1px solid #cbd5e1; padding: 8px 12px; font-size: 0.95rem; text-align: left; outline: none; }
.word-paper-page th { background: #f1f5f9; font-weight: bold; }

/* Google Sheets Layout Simulation */
.sheets-editor-viewport {
  background: #0f172a;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  overflow: auto;
  max-height: calc(100vh - 200px);
  position: relative;
  box-shadow: var(--shadow-md);
}

.sheets-grid-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.825rem;
  background: #ffffff;
  color: #334155;
  width: 100%;
}

.sheets-grid-table th, .sheets-grid-table td {
  border-right: 1px solid #e2e8f0;
  border-bottom: 1px solid #e2e8f0;
  padding: 0;
  height: 25px;
  min-height: 25px;
  position: relative;
}

/* Row & Column Headers */
.sheets-grid-table th {
  background: #f8fafc;
  font-weight: 600;
  text-align: center;
  color: #64748b;
  user-select: none;
  font-size: 0.72rem;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 2px solid #cbd5e1;
}

.sheets-grid-table th.col-header {
  border-top: 1px solid #cbd5e1;
}

.sheets-grid-table td.row-num-header {
  background: #f8fafc;
  font-weight: 600;
  text-align: center;
  color: #64748b;
  user-select: none;
  font-size: 0.72rem;
  position: sticky;
  left: 0;
  z-index: 9;
  border-right: 2px solid #cbd5e1;
  width: 40px;
  max-width: 40px;
}

.sheets-grid-table td.row-num-header.active, .sheets-grid-table th.col-header.active {
  background: #e2e8f0;
  color: var(--color-primary);
}

/* Input Cell styling */
.sheet-cell-input {
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  padding: 0 4px;
  font-size: 0.8rem;
  background: transparent;
  color: inherit;
  font-weight: inherit;
  font-style: inherit;
}

.sheet-cell-input:focus {
  background: #f0fdf4 !important;
  box-shadow: inset 0 0 0 2px var(--color-primary);
  color: #0f172a;
}

/* Sheets Bottom Tab Bar */
.sheets-tab-bar {
  display: flex;
  background: #1e293b;
  border-top: 1px solid var(--border-glass);
  padding: 4px 8px;
  align-items: center;
  gap: 8px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.sheets-tab-item {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border: 1px solid var(--border-glass);
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.sheets-tab-item.active {
  background: var(--color-primary);
  color: #ffffff;
  border-color: var(--color-primary);
}


