@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

/* ==========================================================================
   CSS Variables & Multi-Theme System
   ========================================================================== */
:root {
  --font-heading: 'Outfit', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;
  --bg-app: #f0f3f8;
  --panel-bg: rgba(255, 255, 255, 0.88);
  --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.08);
  --shadow-sheet: 0 12px 40px rgba(0, 0, 0, 0.15);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  /* Theme Defaults (Festive) */
  --primary: #8b1e2e;
  --secondary: #b5621d;
  --accent: #2d6a38;
  --text-dark: #222222;
  --sheet-bg: #ffffff;
  --card-bg: #faf6f2;
  --callout-bg: #edf7ee;
  --border-color: #e5d8cc;
  --th-bg: var(--primary);
  --th-color: #ffffff;
}

/* Theme 1: Festive / Weihnachtlich & Gemütlich */
body.theme-festive {
  --primary: #8b1e2e;
  --secondary: #b5621d;
  --accent: #2d6a38;
  --card-bg: #faf6f2;
  --callout-bg: #edf7ee;
  --border-color: #e5d8cc;
  --th-bg: #8b1e2e;
  --th-color: #ffffff;
}

/* Theme 2: Warm / Pizza, Grillen, Sommer, Kochen */
body.theme-warm {
  --primary: #c2410c;
  --secondary: #d97706;
  --accent: #b45309;
  --card-bg: #fffbf5;
  --callout-bg: #fef3c7;
  --border-color: #fed7aa;
  --th-bg: #c2410c;
  --th-color: #ffffff;
}

/* Theme 3: Green / Natur, Vital, Garten, Ausflug */
body.theme-green {
  --primary: #1e592f;
  --secondary: #43763c;
  --accent: #15803d;
  --card-bg: #f4f9f4;
  --callout-bg: #e6f4ea;
  --border-color: #c7e5cc;
  --th-bg: #1e592f;
  --th-color: #ffffff;
}

/* Theme 4: Modern / Schiefer, Film, Technik, Neutral */
body.theme-modern {
  --primary: #1e3a8a;
  --secondary: #3b82f6;
  --accent: #0284c7;
  --card-bg: #f8fafc;
  --callout-bg: #e0f2fe;
  --border-color: #cbd5e1;
  --th-bg: #1e3a8a;
  --th-color: #ffffff;
}

/* Theme 5: Clean / Schlicht Büro */
body.theme-clean {
  --primary: #222222;
  --secondary: #444444;
  --accent: #333333;
  --card-bg: #f9f9f9;
  --callout-bg: #f3f3f3;
  --border-color: #cccccc;
  --th-bg: #333333;
  --th-color: #ffffff;
}

/* ==========================================================================
   TONER-SPAREND (Keine dunklen Vollflächen, dünne Ränder)
   ========================================================================== */
body.toner-saver {
  --card-bg: #ffffff !important;
  --callout-bg: #ffffff !important;
  --border-color: #cccccc !important;
  --th-bg: #ffffff !important;
  --th-color: var(--primary) !important;
}

body.toner-saver .sheet-info-card {
  background: #ffffff !important;
  border: 1.5px solid var(--primary) !important;
}

body.toner-saver .sheet-callout {
  background: #ffffff !important;
  border: 1.5px dashed var(--accent) !important;
}

body.toner-saver .sheet-table th {
  background: #ffffff !important;
  color: var(--primary) !important;
  border: 1.5px solid var(--primary) !important;
}

body.toner-saver .sheet-table tr:nth-child(even) td {
  background: #ffffff !important;
}

/* ==========================================================================
   SCHWARZ-WEISS (S/W) MODUS (Monochrom, hohe Kontraste)
   ========================================================================== */
body.bw-mode {
  --primary: #111111 !important;
  --secondary: #333333 !important;
  --accent: #222222 !important;
  --border-color: #888888 !important;
  --th-bg: #111111 !important;
  --th-color: #ffffff !important;
}

body.bw-mode.toner-saver {
  --th-bg: #ffffff !important;
  --th-color: #111111 !important;
  --border-color: #666666 !important;
}

body.bw-mode .sheet-divider {
  background: #666666 !important;
}

body.bw-mode .sheet-callout p {
  color: #222222 !important;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg-app);
  color: var(--text-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Header / Liquid Glass Navigation
   ========================================================================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.90);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

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

.brand-icon {
  font-size: 1.8rem;
  line-height: 1;
}

.brand-text h1 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-badge {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 700;
}

.brand-text p {
  font-size: 0.78rem;
  color: #666;
}

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

/* Format Toggle: Hoch / Quer */
.toggle-group {
  display: flex;
  background: #e2e8f0;
  padding: 3px;
  border-radius: var(--radius-sm);
  gap: 3px;
}

.format-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  color: #475569;
  transition: all 0.15s ease;
}

.format-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Print Options Wrap (Toner-sparend & S/W) */
.print-options-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.03);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.check-opt {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.check-opt input {
  cursor: pointer;
}

.theme-select-wrap select {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid #ccc;
  background: #fff;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

/* Mobile Tabs */
.mobile-tabs {
  display: none;
  background: #e2e8f0;
  padding: 3px;
  border-radius: var(--radius-sm);
  gap: 3px;
}

.tab-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
}

.tab-btn.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Buttons */
.btn {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background: #fff;
  color: #333;
  border: 1px solid #d1d5db;
}
.btn-secondary:hover {
  background: #f8fafc;
}

.btn-print {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.btn-sm {
  padding: 4px 9px;
  font-size: 0.78rem;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #fff;
  cursor: pointer;
}
.btn-sm:hover {
  background: #f3f4f6;
}

.btn-danger {
  color: #dc2626;
  border-color: #fca5a5;
}
.btn-danger:hover {
  background: #fee2e2;
}

/* ==========================================================================
   Main Layout: Split Screen
   ========================================================================== */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 65px);
}

/* Left: Editor Panel */
.editor-panel {
  width: 480px;
  min-width: 420px;
  background: var(--panel-bg);
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.editor-card {
  background: #ffffff;
  border-radius: var(--radius-md);
  padding: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #666;
}

.card-header-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Presets Chips */
.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 5px 10px;
  border-radius: 16px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  font-size: 0.8rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  transform: translateY(-1px);
}

/* KI Card */
.ai-card {
  background: linear-gradient(135deg, #fdf4ff 0%, #f0fdf4 100%);
  border: 1px solid #e9d5ff;
}

.ai-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ai-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.92rem;
  color: #6b21a8;
}

.ai-pill {
  background: #e9d5ff;
  color: #6b21a8;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
}

.ai-desc {
  font-size: 0.78rem;
  color: #555;
  line-height: 1.4;
}

.ai-input-wrap {
  display: flex;
  gap: 8px;
}

.ai-input-wrap input {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid #d8b4fe;
  font-family: var(--font-body);
  font-size: 0.85rem;
  outline: none;
}
.ai-input-wrap input:focus {
  border-color: #9333ea;
  box-shadow: 0 0 0 3px rgba(147, 51, 234, 0.15);
}

.btn-ai {
  background: linear-gradient(135deg, #7e22ce, #9333ea);
  color: #fff;
  white-space: nowrap;
}

/* Fields & Form Elements */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #555;
}

.field-group input,
.field-group textarea,
.field-group select {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid #d1d5db;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: #222;
  outline: none;
}

.field-group input:focus,
.field-group textarea:focus,
.field-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

.field-row {
  display: flex;
  gap: 10px;
}

.icon-field {
  width: 60px;
}
.icon-field input {
  text-align: center;
  font-size: 1.15rem;
}

.flex-1 {
  flex: 1;
}

.info-item-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}

.info-item-label {
  width: 85px;
}

.info-item-val {
  flex: 1;
}

.switch-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

/* ==========================================================================
   Right: Live DIN A4 Canvas
   ========================================================================== */
.preview-panel {
  flex: 1;
  background: #dfe5ec;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.canvas-zoom-bar {
  width: 210mm;
  max-width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
  transition: width 0.2s ease;
}

body.format-landscape .canvas-zoom-bar {
  width: 297mm;
}

.canvas-badge-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

.status-badge {
  background: #ffffff;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #334155;
  border: 1px solid #cbd5e1;
}

.toner-badge {
  background: #ecfdf5;
  color: #065f46;
  border-color: #a7f3d0;
}

.bw-badge {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #94a3b8;
}

.hint-pill {
  background: rgba(255, 255, 255, 0.8);
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  color: #334155;
}

/* ==========================================================================
   DIN A4 Page Sizing (Portrait vs Landscape)
   ========================================================================== */
.a4-sheet-container {
  display: flex;
  justify-content: center;
}

/* Default: DIN A4 Hochformat (210mm x 297mm) */
.a4-page {
  width: 210mm;
  min-height: 297mm;
  background: var(--sheet-bg);
  box-shadow: var(--shadow-sheet);
  border-radius: 4px;
  padding: 16mm 18mm;
  display: flex;
  flex-direction: column;
  position: relative;
  box-sizing: border-box;
  color: var(--text-dark);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* DIN A4 Querformat (297mm x 210mm) */
body.format-landscape .a4-page {
  width: 297mm;
  min-height: 210mm;
  padding: 14mm 18mm;
}

/* Landscape 2-Column Upper Grid Layout */
body.format-landscape .sheet-upper-grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 16px;
  align-items: stretch;
  margin-bottom: 12px;
}

body.format-landscape .sheet-lead-text {
  text-align: left;
  margin-bottom: 0;
  display: flex;
  align-items: center;
}

body.format-landscape .sheet-info-card {
  margin-bottom: 0;
}

/* ==========================================================================
   A4 Sheet Typography & Components
   ========================================================================== */
.sheet-title-banner {
  text-align: center;
  margin-bottom: 10px;
}

.sheet-title-banner h2 {
  font-family: var(--font-heading);
  font-size: 24pt;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 0.5px;
  line-height: 1.2;
  outline: none;
}

body.format-landscape .sheet-title-banner h2 {
  font-size: 26pt;
}

.sheet-title-banner h2:focus,
.sheet-subtitle:focus,
.sheet-lead-text:focus,
.sheet-callout h3:focus,
.sheet-callout p:focus,
.sheet-footer-note:focus {
  background: rgba(254, 240, 138, 0.35);
  border-radius: 4px;
}

.sheet-subtitle {
  font-family: var(--font-heading);
  font-size: 13pt;
  font-weight: 600;
  color: var(--secondary);
  margin-top: 3px;
  outline: none;
}

.sheet-divider {
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--secondary), transparent);
  margin: 8px 0 14px 0;
}

.sheet-lead-text {
  font-size: 10.5pt;
  line-height: 1.5;
  text-align: center;
  color: #333333;
  margin-bottom: 14px;
  white-space: pre-line;
  outline: none;
}

/* Info Cards (Wann, Wo, Was) */
.sheet-info-card {
  background: var(--card-bg);
  border: 2px solid var(--primary);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 14px;
}

.sheet-info-row {
  display: flex;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-color);
}
.sheet-info-row:last-child {
  border-bottom: none;
}

.sheet-info-label {
  width: 95px;
  font-weight: 700;
  color: var(--primary);
  font-size: 10.5pt;
}

.sheet-info-val {
  flex: 1;
  font-size: 10pt;
  line-height: 1.4;
  outline: none;
}

/* Callout Box (Kein Zwang) */
.sheet-callout {
  background: var(--callout-bg);
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 12px 16px;
  text-align: center;
  margin-bottom: 14px;
}

.sheet-callout h3 {
  font-size: 11.5pt;
  color: var(--accent);
  margin-bottom: 4px;
  font-weight: 700;
  outline: none;
}

.sheet-callout p {
  font-size: 9.8pt;
  line-height: 1.4;
  color: #1a4023;
  outline: none;
}

/* Table Section */
.sheet-table-section {
  margin-top: 8px;
  margin-bottom: 12px;
  flex: 1;
}

.sheet-table-title {
  font-family: var(--font-heading);
  font-size: 11.5pt;
  font-weight: 700;
  color: var(--secondary);
  margin-bottom: 5px;
  outline: none;
}

.sheet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 9.5pt;
}

.sheet-table th {
  background: var(--th-bg);
  color: var(--th-color);
  padding: 7px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 9.5pt;
  border: 1px solid var(--primary);
}

.sheet-table th.center,
.sheet-table td.center {
  text-align: center;
}

.sheet-table td {
  padding: 7px 8px;
  border: 1px solid var(--border-color);
  vertical-align: middle;
  outline: none;
}

.sheet-table tr:nth-child(even) td {
  background: var(--card-bg);
}

.check-square {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 1.5px solid #888;
  border-radius: 3px;
}

/* Footer */
.sheet-footer-note {
  text-align: center;
  font-size: 9.5pt;
  color: #555555;
  line-height: 1.4;
  margin-top: auto;
  padding-top: 8px;
  outline: none;
}

/* ==========================================================================
   Modal Dialog
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: none;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal-backdrop.active {
  display: flex;
}

.modal-card {
  background: #fff;
  width: 580px;
  max-width: 100%;
  max-height: 85vh;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  color: var(--primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: #888;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: flex-end;
}

.archive-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}
.archive-item:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.archive-info h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e293b;
}

.archive-info p {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 2px;
}

.archive-actions {
  display: flex;
  gap: 6px;
}

/* ==========================================================================
   Mobile Responsive Rules
   ========================================================================== */
@media (max-width: 900px) {
  .app-header {
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
    padding: 10px 12px;
  }

  .header-actions {
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .mobile-tabs {
    display: flex;
    justify-content: center;
  }

  .main-layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .editor-panel {
    width: 100%;
    min-width: 100%;
    height: auto;
    border-right: none;
  }

  .preview-panel {
    width: 100%;
    padding: 12px 6px;
    overflow-x: auto;
  }

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

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

  body.view-editor .preview-panel {
    display: none;
  }
  body.view-preview .editor-panel {
    display: none;
  }
}

/* ==========================================================================
   PRINT STYLES (DIN A4 Strict Vector Output)
   ========================================================================== */
@media print {
  html, body {
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
    height: 100% !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .no-print,
  .app-header,
  .editor-panel,
  .canvas-zoom-bar,
  .modal-backdrop {
    display: none !important;
  }

  .main-layout,
  .preview-panel,
  .a4-sheet-container {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: #ffffff !important;
  }

  .a4-page {
    box-shadow: none !important;
    border-radius: 0 !important;
    width: 100% !important;
    min-height: 100vh !important;
    padding: 12mm 14mm !important;
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
  }
}
