/* ==========================================================================
   Générateur de Chevalets — Institut de France
   Design System & Layout Styles (Light Minimal Sage Palette)
   ========================================================================== */

/* --- CSS Variables & Design System --- */
:root {
  /* UI Editor Colors (Light Mode) */
  --bg-editor: #ffffff;
  --bg-editor-sub: #f3f6f4;
  --text-editor: #1e293b;
  --text-editor-muted: #64748b;
  --accent-color: #658778; /* Sage Green - Institut de France */
  --accent-color-hover: #536f62;
  --border-editor: #cbdcd3;
  --input-bg: #f5f8f6;
  
  /* UI Preview Colors (Luminous Sage Canvas Backdrop) */
  --bg-preview: #dfeae3;
  
  /* Print/Sheet Colors */
  --sheet-bg: #ffffff;
  --card-text: #000000;
  --card-text-muted: #000000;
}

/* --- Custom Local Fonts --- */
@font-face {
  font-family: 'InstitutDeFrance';
  src: url('InstitutDeFrance-Regular.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
}
@font-face {
  font-family: 'Institut';
  src: url('InstitutDeFrance-Regular.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'Graphie';
  src: url('Graphie-Regular.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
}
@font-face {
  font-family: 'Graphie';
  src: url('Graphie-SemiBold.otf') format('opentype');
  font-weight: 600;
  font-style: normal;
}

/* --- Base Reset & Typography --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-preview);
  color: var(--text-editor);
  min-height: 100vh;
  overflow: hidden;
}

/* --- App Layout (Main Editor Left 70%, Compact Miniatures Sidebar Right 30%) --- */
.app-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ==========================================================================
   LEFT PANEL: Spacious Primary Workspace
   ========================================================================== */
.editor-workspace {
  background-color: var(--bg-editor);
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
  overflow: hidden;
  border-right: 1px solid var(--border-editor);
}

.app-header {
  padding: 24px 32px 16px 32px;
}

.app-header h1 {
  font-family: 'Outfit', sans-serif;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #3b5047; /* Prestigious Deep Sage */
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-tagline {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-color);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 4px;
}

/* --- Top Options Toolbar --- */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 16px 32px;
  background-color: var(--bg-editor-sub);
  border-top: 1px solid var(--border-editor);
  border-bottom: 1px solid var(--border-editor);
  box-sizing: border-box;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.toolbar-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-editor-muted);
  letter-spacing: 0.08em;
}

/* Visually Intuitive Segmented Control (Grand / Mini size switch) */
.segmented-control {
  display: flex;
  gap: 4px;
  background-color: var(--bg-editor);
  border: 1px solid var(--border-editor);
  border-radius: 8px;
  padding: 3px;
}

.segment-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid transparent;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-editor-muted);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}

.segment-btn:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

.segment-btn .segment-title {
  font-family: 'Outfit', sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-editor);
  transition: color 0.15s ease;
}

.segment-btn .segment-title-light {
  font-weight: 400;
  opacity: 0.7;
  font-size: 11px;
}

.segment-btn.active {
  background: linear-gradient(135deg, #78998a 0%, #658778 100%);
  box-shadow: 0 4px 12px rgba(101, 135, 120, 0.25);
  border-color: rgba(255, 255, 255, 0.1);
}

.segment-btn.active .segment-title {
  color: #ffffff !important;
}

/* Sliders layout inside Toolbar */
.sliders-group {
  display: flex;
  gap: 32px;
  flex: 1;
  justify-content: center;
}

.toolbar-slider-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 220px;
}

.toolbar-slider-item label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-editor-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  width: 85px;
}

.slider-val {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-color);
  background-color: rgba(101, 135, 120, 0.15);
  padding: 1px 4px;
  border-radius: 3px;
}

.form-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  border-radius: 3px;
  background: var(--input-bg);
  outline: none;
  border: 1px solid var(--border-editor);
}

.form-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
  border: 2px solid var(--bg-editor);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: transform 0.1s ease;
}

.form-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

/* --- Spacious List Table section --- */
.editor-table-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 24px 32px 16px 32px;
}

.table-container {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border-editor);
  border-radius: 8px;
  background-color: var(--bg-editor);
  margin-bottom: 16px;
  min-height: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.02);
}

.participants-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.participants-table th {
  background-color: var(--bg-editor-sub);
  color: var(--text-editor);
  padding: 12px 16px;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border-editor);
  z-index: 2;
}

.participants-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-editor);
  vertical-align: middle;
}

.table-input, .table-textarea {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-editor);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  transition: all 0.15s ease;
  font-family: inherit;
}

.table-input:focus, .table-textarea:focus {
  outline: none;
  background-color: var(--input-bg);
  border-color: var(--border-editor);
  box-shadow: 0 0 0 2px rgba(101, 135, 120, 0.1);
}

.table-textarea {
  height: 60px; /* Lock height to exactly 3 lines of text */
  resize: none; /* Disable manual resizing entirely */
  line-height: 1.4;
  overflow-y: auto; /* Allow internal scrolling if content exceeds 3 lines */
}

.btn-delete-row {
  background: none;
  border: none;
  color: #ef4444;
  opacity: 0.5;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.btn-delete-row:hover {
  opacity: 1;
  background-color: rgba(239, 68, 68, 0.08);
}

.actions-row {
  display: flex;
  justify-content: flex-start;
  padding: 16px;
}

/* --- Clear Button --- */
.btn-clear {
  background-color: var(--bg-editor);
  color: #ef4444;
  border: 1px solid #fca5a5;
  padding: 8px 14px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
  transition: all 0.15s ease;
}

.btn-clear:hover {
  background-color: #fee2e2;
  border-color: #ef4444;
}

/* --- Primary / Secondary Action Buttons --- */
.btn-secondary {
  width: auto;
  background-color: var(--bg-editor);
  color: var(--text-editor);
  border: 1px solid var(--border-editor);
  padding: 10px 20px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
  transition: all 0.15s ease;
}

.btn-secondary:hover {
  background-color: var(--bg-editor-sub);
  border-color: var(--accent-color);
}

.btn-primary {
  width: 240px;
  background: linear-gradient(135deg, #78998a 0%, #658778 100%);
  color: white;
  border: none;
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(101, 135, 120, 0.3);
  transition: all 0.2s ease;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(101, 135, 120, 0.4);
}

/* --- Preview Sidebar Action Footer (Positioned at the very bottom right) --- */
.preview-footer {
  padding: 16px 24px 24px 24px;
  border-top: 1px solid var(--border-editor);
  background-color: rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  z-index: 5;
  box-sizing: border-box;
  width: 100%;
}

.preview-footer .btn-primary {
  width: 100%; /* Spans full width of the sidebar for standard visual alignment */
}

/* ==========================================================================
   RIGHT PANEL: Compact Miniature Preview Sidebar
   ========================================================================== */
.preview-sidebar {
  background-color: var(--bg-preview);
  width: 380px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-sidebar-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-editor);
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(10px);
}

.preview-status {
  background-color: var(--bg-editor);
  border: 1px solid var(--border-editor);
  color: var(--text-editor);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: 0 2px 6px rgba(101, 135, 120, 0.05);
}

/* --- Miniature Deck Scroll Container --- */
.miniatures-container {
  flex: 1;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  overflow-y: auto;
}

/* ==========================================================================
   Miniature Card Rendering (HTML Page scaling via 0.3414 Transform)
   ========================================================================== */
.sheet-miniature-wrapper {
  width: 280px;
  height: 198px; /* Mathematical aspect ratio equivalent to 280 * 210 / 297 */
  overflow: hidden;
  position: relative;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(101, 135, 120, 0.12);
  border: 1px solid rgba(101, 135, 120, 0.2);
  background-color: #ffffff;
  flex-shrink: 0;
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.22s ease;
}

.sheet-miniature-wrapper:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(101, 135, 120, 0.2);
}

/* Miniature A4 Canvas target: Rendered full-scale at 820px, visually scaled to 0.3414 */
.sheet-miniature-wrapper .sheet-page {
  width: 820px !important;
  height: 580px !important;
  transform: scale(0.34146); /* Mathematically perfect scale down (280/820) */
  transform-origin: top left;
  box-shadow: none !important;
  border: none !important;
  pointer-events: none; /* Ignore internal clicks inside scaling */
}

/* --- Temporarily strip miniature constraints during PDF compile --- */
body.printing-pdf .miniatures-container {
  padding: 0 !important;
  margin: 0 !important;
  gap: 0 !important;
  display: block !important;
  background: none !important;
  width: 297mm !important;
  height: auto !important;
}

body.printing-pdf .sheet-miniature-wrapper {
  width: 297mm !important;
  height: 209.5mm !important; /* Slightly reduced (99.7%) to absorb browser sub-pixel rounding errors and eliminate intermediate blank pages */
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  border: none !important;
  box-shadow: none !important;
  transform: none !important;
  border-radius: 0 !important;
  background: #ffffff !important;
  transition: none !important;
  page-break-after: always !important;
  page-break-inside: avoid !important;
  display: block !important;
}

body.printing-pdf .sheet-miniature-wrapper:last-child {
  page-break-after: avoid !important; /* Prevents trailing blank page at the end of the PDF */
}

body.printing-pdf .sheet-miniature-wrapper .sheet-page {
  transform: none !important;
  width: 297mm !important;
  height: 209.5mm !important;
  box-shadow: none !important;
  border: none !important;
  pointer-events: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  background-color: #ffffff !important;
}

/* ==========================================================================
   Sheet interiors (Unchanged base dimensions for perfect PDF export)
   ========================================================================== */
.sheet-page {
  background-color: var(--sheet-bg);
  position: relative;
  box-sizing: border-box;
  overflow: hidden;
  width: 820px;
  aspect-ratio: 297/210;
}

/* --- Grand Layout: Card Sides (1 per sheet) --- */
.sheet-grand .card-face {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  overflow: hidden;
  left: 0;
  right: 0;
  height: 50%;
  padding: 40px;
}

.sheet-grand .card-face-top {
  top: 0;
  transform: rotate(180deg);
}

.sheet-grand .card-face-bottom {
  bottom: 0;
}

/* --- Mini Layout (4 per sheet) Grid System --- */
.sheet-mini {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.sheet-mini .mini-quadrant {
  position: relative;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  border-right: 1px dashed rgba(0, 0, 0, 0.12);
  border-bottom: 1px dashed rgba(0, 0, 0, 0.12);
}

.sheet-mini .mini-quadrant:nth-child(2n) {
  border-right: none;
}

.sheet-mini .mini-quadrant:nth-child(3),
.sheet-mini .mini-quadrant:nth-child(4) {
  border-bottom: none;
}

.mini-quadrant .card-face {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  overflow: hidden;
  left: 0;
  right: 0;
  height: 50%;
  padding: 16px;
}

.mini-quadrant .card-face-top {
  top: 0;
  transform: rotate(180deg);
}

.mini-quadrant .card-face-bottom {
  bottom: 0;
}

/* --- Card Typography & Layout --- */
.text-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.card-name {
  font-family: 'InstitutDeFrance', 'Institut', Georgia, serif;
  font-weight: normal;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--card-text);
  word-wrap: break-word;
  max-width: 100%;
  margin-bottom: 8px;
  transition: font-size 0.2s ease;
}

.card-title {
  font-family: 'Graphie', 'Avenir Next', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.35;
  color: var(--card-text-muted);
  max-width: 90%;
  white-space: pre-wrap; 
  word-wrap: break-word;
  transition: font-size 0.2s ease;
}

/* ==========================================================================
   PRINT STYLES (@media print)
   This disables miniatures and transforms, forcing precise vector A4 output.
   ========================================================================== */
@media print {
  body, html {
    background-color: #ffffff !important;
    color: #000000 !important;
    overflow: visible !important;
    height: auto !important;
    min-height: auto !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  .app-layout {
    display: block !important;
    height: auto !important;
    width: 100% !important;
  }
  
  .editor-workspace, .preview-sidebar, .editor-toolbar, .editor-footer {
    display: none !important;
  }
  
  .preview-sidebar {
    background: none !important;
    overflow: visible !important;
    height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
  }
  
  .miniatures-container {
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
    display: block !important;
    overflow: visible !important;
  }
  
  /* Disable Miniature Wrappers and scales to restore exact physical dimensions */
  .sheet-miniature-wrapper {
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    border: none !important;
    box-shadow: none !important;
    transform: none !important;
    background: none !important;
    display: block !important;
  }
  
  .sheet-miniature-wrapper .sheet-page {
    width: 297mm !important;
    height: 210mm !important;
    transform: none !important;
    display: block !important;
    page-break-after: always !important;
    page-break-inside: avoid !important;
    background-color: #ffffff !important;
  }

  .sheet-miniature-wrapper:last-child .sheet-page {
    page-break-after: avoid !important;
  }
  
  body.print-landscape {
    width: 297mm !important;
    height: 210mm !important;
  }

  .sheet-mini .mini-quadrant {
    border-right-color: rgba(0, 0, 0, 0.15) !important;
    border-bottom-color: rgba(0, 0, 0, 0.15) !important;
  }
  
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
