/* ==========================================================================
   PROTOCOLO LIBRE | FACTORY SUITE - CORE & PRINT STYLES
   Architecture: Serverless 100% Client-Side (Cloudflare Pages Ready)
   Design System: Dark Mode SaaS Premium (Slate 950/900 + Indigo/Emerald accents)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&family=Playfair+Display:ital,wght@0,600;0,700;0,800;1,600&family=Plus+Jakarta+Sans:wght@500;600;700;800&display=swap');

:root {
  --color-slate-950: #020617;
  --color-slate-900: #0f172a;
  --color-slate-800: #1e293b;
  --color-indigo-500: #6366f1;
  --color-emerald-500: #10b981;
}

/* ==========================================================================
   BASELINE RESET & STANDALONE DARK MODE FALLBACK
   Guarantees dark aesthetic & correct typography regardless of Tailwind CDN
   ========================================================================== */
html {
  background-color: #020617;
  color: #f1f5f9;
  color-scheme: dark;
}

body {
  background-color: #020617;
  color: #f1f5f9;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

/* Essential Utility Fallbacks */
.bg-slate-950 { background-color: #020617; }
.bg-slate-900 { background-color: #0f172a; }
.bg-slate-900\/80 { background-color: rgba(15, 23, 42, 0.8); }
.bg-slate-950\/80 { background-color: rgba(2, 6, 23, 0.8); }
.bg-slate-800 { background-color: #1e293b; }
.bg-slate-800\/80 { background-color: rgba(30, 41, 59, 0.8); }
.bg-slate-800\/50 { background-color: rgba(30, 41, 59, 0.5); }
.text-slate-100 { color: #f1f5f9; }
.text-slate-200 { color: #e2e8f0; }
.text-slate-300 { color: #cbd5e1; }
.text-slate-400 { color: #94a3b8; }
.text-slate-500 { color: #64748b; }
.text-white { color: #ffffff; }
.text-emerald-400 { color: #34d399; }
.text-indigo-400 { color: #818cf8; }
.border-slate-800 { border-color: #1e293b; }
.border-slate-800\/80 { border-color: rgba(30, 41, 59, 0.8); }
.border-slate-700 { border-color: #334155; }
.font-sans { font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.font-mono { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

/* Custom Base Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #090d16;
}

::-webkit-scrollbar-thumb {
  background: #1e293b;
  border-radius: 9999px;
}

::-webkit-scrollbar-thumb:hover {
  background: #334155;
}

/* Scrollbar utility for horizontal navigation */
.scrollbar-none::-webkit-scrollbar {
  display: none;
}
.scrollbar-none {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Premium Subtle Background Grids & Glows */
.bg-grid-pattern {
  background-size: 32px 32px;
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
}

.glow-indigo {
  box-shadow: 0 0 25px -5px rgba(99, 102, 241, 0.25);
}

.glow-emerald {
  box-shadow: 0 0 25px -5px rgba(16, 185, 129, 0.25);
}

/* Transitions and Module Visibility */
.module-view {
  display: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.25s ease-out, transform 0.25s ease-out;
}

.module-view.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

/* Modal Animations */
.modal-backdrop {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-in-out;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-panel {
  transform: scale(0.96) translateY(8px);
  opacity: 0;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease-in-out;
}

.modal-backdrop.open .modal-panel {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Glassmorphism Accents */
.glass-panel {
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(51, 65, 85, 0.5);
}

/* ==========================================================================
   EBOOK & PDF STUDIO: A4 PREVIEW CANVASES & THEMES
   ========================================================================== */

/* ==========================================================================
   EBOOK, MICRO-APP & SANDBOX WORKSTATIONS
   Unified Sticky Container & Solid Header Architecture
   ========================================================================== */

#pdf-viewer-workstation,
#microapp-viewer-workstation,
#sandbox-viewer-workstation {
  position: sticky;
  top: 5rem;
  z-index: 20;
}

#canvas-action-toolbar,
#microapp-action-toolbar,
#sandbox-action-toolbar {
  position: relative;
  z-index: 20;
  background-color: #0f172a !important; /* Solid Slate 900 */
  border-bottom: 1px solid #1e293b !important;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
  margin-bottom: 0 !important;
}

#pdf-preview-wrapper,
#microapp-preview-viewport,
#sandbox-preview-viewport {
  position: relative;
  z-index: 10;
  background-color: #0b0f19;
  background-image: radial-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px);
  background-size: 20px 20px;
  scroll-behavior: smooth;
  scroll-padding-top: 2rem;
}

/* Realistic A4 Simulation in Screen */
#pdf-preview-canvas {
  width: 100%;
  max-width: 820px;
  min-height: 1100px;
  margin: 0 auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  transition: background-color 0.2s ease, color 0.2s ease;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.7;
  overflow-wrap: break-word;
  word-break: break-word;
}

.editorial-body,
.editorial-cover {
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Page Break Divider in Screen Mode */
.page-break-screen-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 2rem -1rem;
  padding: 0.75rem;
  background: #090d16;
  border-top: 1px dashed #334155;
  border-bottom: 1px dashed #334155;
  color: #94a3b8;
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  user-select: none;
}
@media (min-width: 640px) {
  .page-break-screen-indicator {
    margin: 3rem -2rem;
    gap: 1rem;
  }
}
@media (min-width: 1024px) {
  .page-break-screen-indicator {
    margin: 3rem -3rem;
  }
}

/* ==========================================================================
   UNIVERSAL COVER TITLE & TYPOGRAPHY CONTRAST ENFORCEMENT
   Guarantees 100% Pure White (#ffffff) text over all dark cover gradients
   ========================================================================== */
.editorial-cover,
.theme-modern-corporate .editorial-cover,
.theme-high-ticket-dark .editorial-cover,
.theme-wealth-emerald .editorial-cover,
.theme-minimalist-warm .editorial-cover {
  color: #ffffff !important;
}

.editorial-cover h1,
.editorial-cover h2,
.editorial-cover h3,
.editorial-cover .cover-title,
.theme-modern-corporate .editorial-cover h1,
.theme-high-ticket-dark .editorial-cover h1,
.theme-wealth-emerald .editorial-cover h1,
.theme-minimalist-warm .editorial-cover h1 {
  color: #ffffff !important;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.editorial-cover p,
.editorial-cover .cover-subtitle,
.theme-modern-corporate .editorial-cover p,
.theme-high-ticket-dark .editorial-cover p,
.theme-wealth-emerald .editorial-cover p,
.theme-minimalist-warm .editorial-cover p {
  color: rgba(255, 255, 255, 0.92) !important;
}

.editorial-cover strong,
.editorial-cover span,
.editorial-cover div,
.theme-modern-corporate .editorial-cover strong,
.theme-high-ticket-dark .editorial-cover strong,
.theme-wealth-emerald .editorial-cover strong,
.theme-minimalist-warm .editorial-cover strong {
  color: inherit;
}

.editorial-cover .cover-badge {
  color: #ffffff !important;
  background-color: rgba(255, 255, 255, 0.15) !important;
  border-color: rgba(255, 255, 255, 0.25) !important;
}

/* 1. Theme: Modern Corporate (Default - Crisp High-Contrast Editorial) */
.theme-modern-corporate {
  background-color: #ffffff !important;
  color: #0f172a !important;
}
.theme-modern-corporate p,
.theme-modern-corporate li {
  color: #1e293b !important;
}
.theme-modern-corporate .editorial-cover {
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 60%, #312e81 100%);
  color: #ffffff !important;
}
.theme-modern-corporate .editorial-accent {
  color: #4338ca !important;
}
.theme-modern-corporate h1, 
.theme-modern-corporate h2,
.theme-modern-corporate h3,
.theme-modern-corporate h4 {
  color: #020617 !important;
  border-color: #cbd5e1 !important;
}
.theme-modern-corporate blockquote {
  color: #1e293b !important;
  border-left-color: #4f46e5 !important;
  background-color: #f8fafc !important;
}
.theme-modern-corporate table {
  border-color: #cbd5e1 !important;
}
.theme-modern-corporate th {
  background-color: #f1f5f9 !important;
  color: #0f172a !important;
}
.theme-modern-corporate td {
  color: #1e293b !important;
  border-color: #e2e8f0 !important;
}
.theme-modern-corporate .editorial-callout-tip {
  background: #eff6ff !important;
  border-left: 4px solid #2563eb !important;
  color: #1e3a8a !important;
}
.theme-modern-corporate .editorial-callout-alert {
  background: #fef2f2 !important;
  border-left: 4px solid #dc2626 !important;
  color: #7f1d1d !important;
}
.theme-modern-corporate .editorial-callout-note {
  background: #f8fafc !important;
  border-left: 4px solid #475569 !important;
  color: #0f172a !important;
}
.theme-modern-corporate .editorial-cta-box {
  background: linear-gradient(135deg, #f8fafc 0%, #eef2ff 100%) !important;
  border: 1px solid #818cf8 !important;
}
.theme-modern-corporate .editorial-cta-box h3 {
  color: #0f172a !important;
}
.theme-modern-corporate .editorial-cta-box p {
  color: #334155 !important;
}

/* 2. Theme: High-Ticket Dark (Luminous OLED Contrast) */
.theme-high-ticket-dark {
  background-color: #030712 !important;
  color: #f1f5f9 !important;
}
.theme-high-ticket-dark p,
.theme-high-ticket-dark li {
  color: #cbd5e1 !important;
}
.theme-high-ticket-dark .editorial-cover {
  background: radial-gradient(circle at top right, #1e1b4b 0%, #030712 70%);
  color: #ffffff !important;
  border: 1px solid #334155 !important;
}
.theme-high-ticket-dark .editorial-accent {
  color: #a5b4fc !important;
}
.theme-high-ticket-dark h1, 
.theme-high-ticket-dark h2,
.theme-high-ticket-dark h3,
.theme-high-ticket-dark h4 {
  color: #ffffff !important;
  border-color: #334155 !important;
}
.theme-high-ticket-dark blockquote {
  color: #f1f5f9 !important;
  border-left-color: #818cf8 !important;
  background-color: rgba(30, 41, 59, 0.6) !important;
}
.theme-high-ticket-dark table {
  border-color: #334155 !important;
}
.theme-high-ticket-dark th {
  background-color: #1e293b !important;
  color: #ffffff !important;
}
.theme-high-ticket-dark td {
  color: #cbd5e1 !important;
  border-color: #1e293b !important;
}
.theme-high-ticket-dark .editorial-callout-tip {
  background: rgba(99, 102, 241, 0.15) !important;
  border-left: 4px solid #818cf8 !important;
  color: #e0e7ff !important;
}
.theme-high-ticket-dark .editorial-callout-alert {
  background: rgba(239, 68, 68, 0.15) !important;
  border-left: 4px solid #f87171 !important;
  color: #fecaca !important;
}
.theme-high-ticket-dark .editorial-callout-note {
  background: rgba(30, 41, 59, 0.7) !important;
  border-left: 4px solid #94a3b8 !important;
  color: #f1f5f9 !important;
}
.theme-high-ticket-dark .editorial-cta-box {
  background: linear-gradient(135deg, #090d16 0%, #1e1b4b 100%) !important;
  border: 1px solid #4f46e5 !important;
}
.theme-high-ticket-dark .editorial-cta-box h3 {
  color: #ffffff !important;
}
.theme-high-ticket-dark .editorial-cta-box p {
  color: #cbd5e1 !important;
}

/* 3. Theme: Wealth Emerald (Deep Forest High-Contrast) */
.theme-wealth-emerald {
  background-color: #fcfbf7 !important;
  color: #022017 !important;
}
.theme-wealth-emerald p,
.theme-wealth-emerald li {
  color: #063728 !important;
}
.theme-wealth-emerald .editorial-cover {
  background: linear-gradient(140deg, #022c22 0%, #064e3b 50%, #065f46 100%);
  color: #f0fdf4 !important;
}
.theme-wealth-emerald .editorial-accent {
  color: #047857 !important;
}
.theme-wealth-emerald h1, 
.theme-wealth-emerald h2,
.theme-wealth-emerald h3,
.theme-wealth-emerald h4 {
  color: #022017 !important;
  border-color: #a7f3d0 !important;
}
.theme-wealth-emerald blockquote {
  color: #064e3b !important;
  border-left-color: #059669 !important;
  background-color: #ecfdf5 !important;
}
.theme-wealth-emerald table {
  border-color: #a7f3d0 !important;
}
.theme-wealth-emerald th {
  background-color: #d1fae5 !important;
  color: #064e3b !important;
}
.theme-wealth-emerald td {
  color: #063728 !important;
  border-color: #e6e2d3 !important;
}
.theme-wealth-emerald .editorial-callout-tip {
  background: #ecfdf5 !important;
  border-left: 4px solid #059669 !important;
  color: #064e3b !important;
}
.theme-wealth-emerald .editorial-callout-alert {
  background: #fffbeb !important;
  border-left: 4px solid #d97706 !important;
  color: #78350f !important;
}
.theme-wealth-emerald .editorial-callout-note {
  background: #f4f1ea !important;
  border-left: 4px solid #059669 !important;
  color: #022c22 !important;
}
.theme-wealth-emerald .editorial-cta-box {
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%) !important;
  border: 1px solid #34d399 !important;
}
.theme-wealth-emerald .editorial-cta-box h3 {
  color: #022c22 !important;
}
.theme-wealth-emerald .editorial-cta-box p {
  color: #064e3b !important;
}

/* 4. Theme: Minimalist Warm (Classic Book Editorial) */
.theme-minimalist-warm {
  background-color: #faf7f2 !important;
  color: #1c1917 !important;
  font-family: 'Georgia', 'Playfair Display', serif;
}
.theme-minimalist-warm p,
.theme-minimalist-warm li {
  color: #292524 !important;
}
.theme-minimalist-warm .editorial-cover {
  background: #292524;
  color: #faf7f2 !important;
}
.theme-minimalist-warm .editorial-accent {
  color: #b45309 !important;
}
.theme-minimalist-warm h1, 
.theme-minimalist-warm h2,
.theme-minimalist-warm h3,
.theme-minimalist-warm h4 {
  color: #0c0a09 !important;
  font-family: 'Playfair Display', 'Georgia', serif;
  border-color: #d6d3d1 !important;
}
.theme-minimalist-warm blockquote {
  color: #292524 !important;
  border-left-color: #d97706 !important;
  background-color: #f5f5f4 !important;
}
.theme-minimalist-warm table {
  border-color: #d6d3d1 !important;
}
.theme-minimalist-warm th {
  background-color: #e7e5e4 !important;
  color: #1c1917 !important;
}
.theme-minimalist-warm td {
  color: #292524 !important;
  border-color: #e7e5e4 !important;
}
.theme-minimalist-warm .editorial-callout-tip {
  background: #fef3c7 !important;
  border-left: 4px solid #b45309 !important;
  color: #78350f !important;
  font-family: 'Inter', sans-serif;
}
.theme-minimalist-warm .editorial-callout-alert {
  background: #fee2e2 !important;
  border-left: 4px solid #b91c1c !important;
  color: #7f1d1d !important;
  font-family: 'Inter', sans-serif;
}
.theme-minimalist-warm .editorial-callout-note {
  background: #f5f5f4 !important;
  border-left: 4px solid #57534e !important;
  color: #1c1917 !important;
  font-family: 'Inter', sans-serif;
}
.theme-minimalist-warm .editorial-cta-box {
  background: #f5f5f4 !important;
  border: 1px solid #78716c !important;
}
.theme-minimalist-warm .editorial-cta-box h3 {
  color: #0c0a09 !important;
}
.theme-minimalist-warm .editorial-cta-box p {
  color: #44403c !important;
}

/* Editorial Components Styling */
.editorial-checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0.6rem 0;
}
.editorial-checklist-item .chk-box {
  margin-top: 0.2rem;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 4px;
  border: 2px solid #6366f1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.editorial-checklist-item.checked .chk-box {
  background: #6366f1;
  color: #ffffff;
}

/* ==========================================================================
   PRINT ENGINE STYLES (@media print)
   Optimized for high-fidelity eBook & PDF Generation in Client-Side Engine
   ========================================================================== */
@media print {
  /* Set exact print size to A4 */
  @page {
    size: A4 portrait;
    margin: 15mm 15mm 15mm 15mm;
  }

  /* Force background colors and gradients to print accurately */
  *, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Completely isolate and display ONLY the preview canvas */
  body * {
    visibility: hidden;
  }

  #pdf-preview-canvas, 
  #pdf-preview-canvas * {
    visibility: visible;
  }

  #pdf-preview-canvas {
    position: absolute;
    left: 0;
    top: 0;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
  }

  /* Hide UI elements, headers, sidebars, indicator dividers */
  aside,
  header,
  nav,
  #license-simulator-wrapper,
  #toast-container,
  .no-print,
  .sidebar,
  .top-header,
  .action-buttons-toolbar,
  .page-break-screen-indicator,
  #pdf-editor-column,
  #canvas-action-toolbar,
  #microapp-action-toolbar,
  #sandbox-action-toolbar {
    display: none !important;
  }

  #pdf-viewer-workstation,
  #pdf-preview-wrapper,
  #microapp-viewer-workstation,
  #microapp-preview-viewport,
  #sandbox-viewer-workstation,
  #sandbox-preview-viewport {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    max-height: none !important;
    padding: 0 !important;
    margin: 0 !important;
    position: static !important;
  }

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

  html, body {
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    width: 100% !important;
  }

  /* Page Break Utilities */
  .page-break {
    page-break-before: always !important;
    break-before: page !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    display: block !important;
  }

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

  h1, h2, h3 {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  .editorial-callout-tip,
  .editorial-callout-alert,
  .editorial-callout-note,
  .editorial-cta-box,
  .editorial-cover {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}
