/* ============================================================
   Editor Page CSS
   ============================================================ */

body.editor-page {
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Editor Layout ---- */
.editor-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-page);
}

/* ---- Editor Topbar ---- */
.editor-topbar {
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-3);
  z-index: 50;
  flex-shrink: 0;
}

.editor-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  flex-shrink: 0;
  padding-right: var(--space-3);
  border-right: 1px solid var(--border-subtle);
}

.editor-title-group {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  flex: 1;
}

.editor-doc-title {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  border: none;
  background: none;
  outline: none;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  max-width: 280px;
  width: 100%;
  transition: background var(--transition-fast);
}

.editor-doc-title:hover { background: var(--bg-surface-2); }
.editor-doc-title:focus { background: var(--bg-surface-2); box-shadow: 0 0 0 2px var(--border-brand); }

.editor-save-status {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: 6px;
}

.save-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand-success);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.editor-topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
  flex-shrink: 0;
}

.topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--border-default);
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.topbar-btn:hover {
  background: var(--bg-surface-3);
  color: var(--text-primary);
}

.topbar-btn.primary {
  background: var(--gradient-brand);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(108,99,255,0.3);
}

.topbar-btn.primary:hover {
  box-shadow: 0 6px 20px rgba(108,99,255,0.4);
  transform: translateY(-1px);
}

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

/* ---- Main Editor Body ---- */
.editor-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---- Left Sidebar (Settings Panel) ---- */
.editor-sidebar {
  width: 280px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
  transition: transform var(--transition-base), width var(--transition-base);
}

.editor-sidebar.collapsed {
  width: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header h3 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-toggle {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-xs);
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1rem;
  transition: all var(--transition-fast);
}

.sidebar-toggle:hover { background: var(--bg-surface-2); color: var(--text-primary); }

.sidebar-section {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-3);
}

/* ---- Layout Presets ---- */
.layout-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.layout-preset {
  aspect-ratio: 3/4;
  border: 2px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface-2);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-2);
  transition: all var(--transition-fast);
  position: relative;
}

.layout-preset:hover { border-color: var(--brand-primary); }
.layout-preset.active { border-color: var(--brand-primary); background: rgba(108,99,255,0.06); }

.layout-preset-visual {
  width: 100%;
  flex: 1;
  display: flex;
  gap: 2px;
}

.lp-col { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.lp-line { height: 3px; background: var(--border-strong); border-radius: 1px; }
.lp-line.h { height: 5px; background: var(--brand-primary); opacity: 0.5; }

.layout-preset-name {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.layout-preset.active .layout-preset-name { color: var(--brand-primary); }

/* ---- Slider Rows ---- */
.slider-row {
  margin-bottom: var(--space-4);
}

.slider-row:last-child { margin-bottom: 0; }

.slider-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
}

.slider-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.slider-value {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--brand-primary);
  font-family: var(--font-mono);
  min-width: 36px;
  text-align: right;
}

/* ---- Template Picker ---- */
.template-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.template-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.template-item:hover { background: var(--bg-surface-2); }
.template-item.active { background: rgba(108,99,255,0.08); border-color: rgba(108,99,255,0.2); }

.ti-icon { font-size: 1rem; }
.ti-name { font-size: 0.82rem; font-weight: 600; color: var(--text-secondary); }
.template-item.active .ti-name { color: var(--brand-primary); }

/* ---- Color Picker ---- */
.density-display {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
}

.density-bar {
  flex: 1;
  height: 8px;
  background: var(--border-default);
  border-radius: 4px;
  overflow: hidden;
}

.density-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--gradient-brand);
  transition: width 0.5s ease;
}

.density-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--brand-primary);
  font-family: var(--font-mono);
  min-width: 32px;
}

/* ---- Editor Center Panel ---- */
.editor-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ---- Formatting Toolbar ---- */
.format-toolbar {
  height: 44px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-1);
  overflow-x: auto;
  flex-shrink: 0;
}

.format-toolbar::-webkit-scrollbar { display: none; }

.fmt-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.fmt-btn:hover { background: var(--bg-surface-2); color: var(--text-primary); }
.fmt-btn.active { background: rgba(108,99,255,0.1); color: var(--brand-primary); }

.fmt-sep {
  width: 1px;
  height: 20px;
  background: var(--border-default);
  margin: 0 var(--space-1);
  flex-shrink: 0;
}

.fmt-select {
  height: 28px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-default);
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

/* ---- Editor + Preview Split ---- */
.editor-split {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
}

.editor-split.preview-only {
  grid-template-columns: 0 1fr;
}

.editor-split.editor-only {
  grid-template-columns: 1fr 0;
}

/* ---- Text Editor Panel ---- */
.text-editor-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border-subtle);
}

.text-editor-area {
  flex: 1;
  padding: var(--space-8);
  overflow-y: auto;
  background: var(--bg-surface);
}

.rich-editor {
  min-height: 100%;
  outline: none;
  font-size: var(--editor-font-size, 14px);
  line-height: 1.8;
  color: var(--text-primary);
  caret-color: var(--brand-primary);
}

.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-placeholder);
  pointer-events: none;
}

.rich-editor p { margin-bottom: 0.5em; }
.rich-editor h1 { font-size: 1.4em; font-weight: 800; margin-bottom: 0.4em; }
.rich-editor h2 { font-size: 1.2em; font-weight: 700; margin-bottom: 0.3em; }
.rich-editor h3 { font-size: 1.05em; font-weight: 700; margin-bottom: 0.3em; }
.rich-editor ul, .rich-editor ol { padding-left: 1.5em; margin-bottom: 0.5em; }
.rich-editor li { margin-bottom: 0.2em; }
.rich-editor strong { font-weight: 700; }
.rich-editor em { font-style: italic; }
.rich-editor u { text-decoration: underline; }
.rich-editor mark { background: rgba(255,217,61,0.4); padding: 1px 2px; border-radius: 2px; }
.rich-editor code { font-family: var(--font-mono); background: var(--bg-surface-2); padding: 1px 4px; border-radius: 3px; font-size: 0.85em; }
.rich-editor table { border-collapse: collapse; width: 100%; margin-bottom: 0.5em; font-size: 0.85em; }
.rich-editor th, .rich-editor td { border: 1px solid var(--border-default); padding: 4px 8px; text-align: left; }
.rich-editor th { background: var(--bg-surface-2); font-weight: 700; }
.rich-editor hr.page-break { border: none; height: 2px; background: repeating-linear-gradient(90deg, var(--brand-primary) 0, var(--brand-primary) 10px, transparent 10px, transparent 20px); margin: var(--space-6) 0; opacity: 0.6; }

/* ---- Word Count Bar ---- */
.editor-status-bar {
  height: 32px;
  padding: 0 var(--space-4);
  background: var(--bg-surface-2);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.status-item { display: flex; align-items: center; gap: 4px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--brand-success); }

/* ---- Preview Panel ---- */
.preview-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface-2);
  overflow: hidden;
}

.preview-header {
  height: 44px;
  padding: 0 var(--space-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.preview-header-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex: 1;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.zoom-btn {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-xs);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-default);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.zoom-btn:hover { background: var(--bg-surface-3); color: var(--text-primary); }

.zoom-value {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  min-width: 38px;
  text-align: center;
  font-family: var(--font-mono);
}

.preview-scroll-area {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-6);
  gap: var(--space-6);
}

/* ---- A4 Paper ---- */
.a4-page {
  /* A4: 210mm × 297mm */
  width: 210mm;
  height: 297mm;
  background: white;
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(0,0,0,0.06);
  border-radius: 2px;
  transform-origin: top center;
  transition: transform var(--transition-base);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.a4-page-inner {
  position: static;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: var(--chit-margin-top, 8mm) var(--chit-margin-side, 6mm) var(--chit-margin-bottom, 8mm);
  overflow: hidden;
}

.a4-content {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  font-family: var(--font-sans);
  font-size: var(--chit-font-size, 7pt);
  line-height: var(--chit-line-height, 1.3);
  color: #000;
  column-count: var(--chit-columns, 3);
  column-gap: var(--chit-col-gap, 4mm);
  column-fill: auto;
  word-break: break-word;
  overflow-wrap: break-word;
}

.a4-column {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chit-heading {
  font-weight: 700;
  font-size: 1.1em;
  border-bottom: 0.5pt solid #000;
  padding-bottom: 1pt;
  margin-bottom: 2pt;
  letter-spacing: -0.01em;
}

.chit-subheading {
  font-weight: 600;
  font-size: 1em;
  margin-bottom: 1pt;
}

.chit-bullet-list {
  padding-left: 8pt;
  margin-bottom: 2pt;
}

.chit-bullet-list li { margin-bottom: 0.5pt; }

.chit-section-break {
  height: 0.5pt;
  background: #ccc;
  margin: 3pt 0;
}

/* Page number indicator */
.a4-page-num {
  position: absolute;
  bottom: 4mm;
  right: 6mm;
  font-size: 5pt;
  color: #999;
  font-family: var(--font-sans);
}

/* Overflow warning */
.overflow-warning {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--brand-accent);
  opacity: 0;
  transition: opacity var(--transition-base);
}

.a4-page.overflow .overflow-warning { opacity: 1; }

/* ---- Overflow Indicator ---- */
.overflow-banner {
  display: none;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: rgba(255,107,107,0.1);
  border: 1px solid rgba(255,107,107,0.3);
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  color: var(--brand-accent);
  font-weight: 600;
}

.overflow-banner.visible { display: flex; }

/* ---- Suggestions Panel ---- */
.suggestions-panel {
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.suggestions-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.suggestion-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: rgba(108,99,255,0.08);
  color: var(--brand-primary);
  border: 1px solid rgba(108,99,255,0.2);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.suggestion-chip:hover { background: rgba(108,99,255,0.16); }

/* ---- Mobile Bottom Nav ---- */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  z-index: 50;
  align-items: center;
  justify-content: space-around;
  backdrop-filter: blur(16px);
}

.mbn-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-2);
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  transition: color var(--transition-fast);
  border-radius: var(--radius-sm);
  min-width: 56px;
}

.mbn-btn.active { color: var(--brand-primary); }
.mbn-btn svg { flex-shrink: 0; }
.mbn-label { font-size: 0.65rem; font-weight: 600; }

/* ---- Command Palette ---- */
.cmd-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.cmd-palette-overlay.open {
  opacity: 1;
  visibility: visible;
}

.cmd-palette {
  width: 100%;
  max-width: 560px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  transform: scale(0.95) translateY(-10px);
  transition: transform var(--transition-spring);
}

.cmd-palette-overlay.open .cmd-palette {
  transform: scale(1) translateY(0);
}

.cmd-input-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.cmd-input-icon { font-size: 1rem; color: var(--text-muted); }

.cmd-input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-size: 1rem;
  color: var(--text-primary);
}

.cmd-input::placeholder { color: var(--text-placeholder); }

.cmd-results {
  max-height: 320px;
  overflow-y: auto;
  padding: var(--space-2);
}

.cmd-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.cmd-item:hover, .cmd-item.selected {
  background: var(--bg-surface-2);
}

.cmd-item-icon { font-size: 0.9rem; width: 20px; text-align: center; }
.cmd-item-name { font-size: 0.875rem; font-weight: 600; flex: 1; }
.cmd-item-shortcut { font-size: 0.72rem; color: var(--text-muted); display: flex; gap: 4px; }

.cmd-section-label {
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ---- Responsive Editor ---- */
@media (max-width: 1024px) {
  .editor-sidebar { width: 240px; }
}

@media (max-width: 768px) {
  .editor-sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 60px;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform var(--transition-base);
  }

  .editor-sidebar.mobile-open {
    transform: translateX(0);
  }

  .editor-split {
    grid-template-columns: 1fr !important;
  }

  .text-editor-panel {
    border-right: none;
  }

  .preview-panel {
    display: none;
  }

  .preview-panel.mobile-visible {
    display: flex;
    position: fixed;
    inset: 56px 0 60px 0;
    z-index: 30;
  }

  .mobile-bottom-nav { display: flex; }

  .editor-topbar-actions .topbar-btn:not(.primary) {
    display: none;
  }

  .editor-topbar-actions .topbar-btn.show-mobile {
    display: inline-flex;
  }

  .a4-page {
    width: 100%;
    min-height: auto;
  }
}

/* ============================================================
   Print Styles
   ============================================================ */
@media print {
  @page {
    margin: 0;
    size: A4 portrait;
  }

  body.editor-page {
    background: white !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* Hide entire UI except the preview container */
  .editor-topbar,
  .editor-sidebar,
  .text-editor-panel,
  .mobile-bottom-nav,
  .preview-header,
  .overflow-banner,
  .suggestions-panel,
  .cmd-palette-overlay,
  .toast-container,
  .modal-overlay {
    display: none !important;
  }

  .editor-layout,
  .editor-main,
  .editor-split,
  .preview-panel,
  .preview-scroll-area {
    display: block !important;
    position: static !important;
    height: auto !important;
    width: 100% !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 !important;
    background: none !important;
    border: none !important;
  }

  #previewContainer {
    display: block !important;
    position: static !important;
    width: 210mm !important;
    transform: none !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
  }

  .a4-page {
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    page-break-after: always;
    break-after: page;
    position: relative !important;
    transform: none !important;
    max-width: none !important;
    min-height: 297mm !important;
  }

  .a4-page-inner {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
