:root {
  --color-background: #1f2121;
  --color-surface: #262828;
  --color-text: #ffffff;
  --color-text-secondary: rgba(255, 255, 255, 0.7);
  --color-text-muted: rgba(255, 255, 255, 0.5);
  --color-primary: #50b8c6;
  --color-primary-hover: #32b8c6;
  --color-border: rgba(255, 255, 255, 0.15);
  --color-secondary: rgba(255, 255, 255, 0.1);
  --color-error: #ff5459;
  --color-success: #4ade80;
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
  --radius-base: 8px;
  --space-16: 16px;
  --space-8: 8px;
  --transition-fast: 0.2s ease;
  --transition-medium: 0.3s ease;
  --font-family-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-family-serif: Georgia, 'Times New Roman', serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: var(--font-family-sans);
  background: var(--color-background);
  color: var(--color-text);
  line-height: 1.6;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

/* ===== LAYOUT SYSTEM ===== */

.page {
  display: none;
  min-height: 100vh;
}

.page.active {
  display: block;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ===== MODAL SYSTEM ===== */

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--color-surface);
  border-radius: var(--radius-base);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 450px;
  border: 1px solid var(--color-border);
  max-height: 90vh;
  overflow-y: auto;
  animation: modalSlideIn var(--transition-medium);
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-base) var(--radius-base) 0 0;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--color-text);
}

.modal-close {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: var(--transition-fast);
}

.modal-close:hover {
  background: var(--color-secondary);
  color: var(--color-text);
  transform: scale(1.1);
}

.modal-actions {
  padding: 1.5rem;
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 0 0 var(--radius-base) var(--radius-base);
}

/* ===== BUTTON SYSTEM ===== */

.btn {
  padding: var(--space-8) var(--space-16);
  border-radius: var(--radius-base);
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: var(--transition-fast);
  color: var(--color-text);
  font-size: 0.875rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: inherit;
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn--primary {
  background: var(--color-primary);
  color: #1f2121;
  font-weight: 600;
}

.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(80, 184, 198, 0.3);
}

.btn--secondary {
  background: var(--color-secondary);
  border: 1px solid var(--color-border);
}

.btn--secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--color-primary);
}

.btn--outline {
  background: transparent;
  border: 1px solid var(--color-border);
}

.btn--outline:hover:not(:disabled) {
  background: var(--color-secondary);
  border-color: var(--color-primary);
}

.btn--danger {
  background: var(--color-error);
  color: white;
}

.btn--danger:hover:not(:disabled) {
  background: #e53e3e;
  transform: translateY(-1px);
}

.btn--lg {
  padding: 12px 24px;
  font-size: 1rem;
}

.btn--sm {
  padding: 6px 12px;
  font-size: 0.75rem;
}

.btn--full-width {
  width: 100%;
  justify-content: center;
}

/* ===== FORM SYSTEM ===== */

.form-group {
  margin-bottom: 1.5rem;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--color-text);
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  color: var(--color-text);
  font-size: 1rem;
  transition: var(--transition-fast);
  font-family: inherit;
}

.form-control:focus {
  border-color: var(--color-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(80, 184, 198, 0.1);
}

.form-control::placeholder {
  color: var(--color-text-muted);
}

textarea.form-control {
  resize: vertical;
  min-height: 100px;
}

/* ===== HEADER SYSTEM ===== */

.header {
  background: linear-gradient(135deg, var(--color-primary), #2980b9);
  color: white;
  padding: 2rem;
  border-radius: 12px;
  margin-bottom: 2rem;
  margin-bottom: 2rem;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.header h1 {
  font-size: 2.5rem;
  margin: 0;
  font-weight: 700;
}

.subtitle {
  color: rgba(255, 255, 255, 0.9);
  font-size: 1.1rem;
  margin: 0.5rem 0 0 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-info {
  background: rgba(255, 255, 255, 0.1);
  padding: 0.5rem 1rem;
  border-radius: 50px;
  font-size: 0.875rem;
  backdrop-filter: blur(10px);
}

/* ===== DASHBOARD SYSTEM ===== */

.dashboard-actions {
  margin-bottom: 2rem;
  text-align: center;
}

.books-section h2 {
  margin-bottom: 1.5rem;
  color: var(--color-text);
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
}

.book-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  padding: 1.5rem;
  transition: var(--transition-medium);
  position: relative;
  cursor: pointer;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--color-primary);
}

.book-card h3 {
  margin: 0 0 0.5rem 0;
  color: var(--color-text);
  font-size: 1.25rem;
  line-height: 1.3;
}

.book-card p {
  margin: 0 0 1rem 0;
  color: var(--color-text-secondary);
  line-height: 1.5;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.book-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.book-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: space-between;
}

/* ===== EDITOR SYSTEM ===== */

.editor-main {
  display: flex;
  height: calc(100vh - 120px);
  background: var(--color-surface);
  border-radius: var(--radius-base);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border);
}

.sidebar {
  width: 300px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 10;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--color-text);
}

.chapters-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  max-height: calc(100vh - 200px);
  scroll-behavior: smooth;
}

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

.chapter-header {
  padding: 1rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  gap: 1rem;
  align-items: center;
  background: var(--color-surface);
}

.chapter-title-input {
  flex: 1;
  background: transparent;
  border: 2px solid transparent;
  color: var(--color-text);
  font-size: 1.25rem;
  font-weight: 600;
  padding: 0.5rem;
  border-radius: var(--radius-base);
  transition: var(--transition-fast);
  font-family: inherit;
}

.chapter-title-input:focus {
  background: var(--color-secondary);
  outline: none;
  border-color: var(--color-primary);
}

.chapter-title-input:hover {
  background: var(--color-secondary);
}

.editor-wrapper {
  flex: 1;
  padding: 1rem;
  display: flex;
  min-height: 0;
}

.chapter-editor {
  width: 100%;
  height: 100%;
  border: none;
  padding: 1.5rem;
  font-family: var(--font-family-serif);
  font-size: 16px;
  line-height: 1.8;
  background: var(--color-background);
  color: var(--color-text);
  outline: none;
  resize: none;
  border-radius: var(--radius-base);
  border: 1px solid var(--color-border);
  transition: var(--transition-fast);
}

.chapter-editor:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(80, 184, 198, 0.1);
}

.editor-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 0;
}

.editor-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
  gap: 1rem;
}

.book-info h1 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--color-text);
}

.save-status {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  margin-top: 0.25rem;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.word-count {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  padding: 0.5rem 0.75rem;
  background: var(--color-secondary);
  border-radius: var(--radius-base);
  border: 1px solid var(--color-border);
  font-family: monospace;
}

/* ===== KAPITEL-MANAGEMENT ===== */

.chapter-item {
  display: flex;
  align-items: center;
  margin-bottom: 0.25rem;
  padding: 0.25rem;
  border-radius: var(--radius-base);
  transition: var(--transition-fast);
  position: relative;
}

.chapter-item:hover {
  background: var(--color-secondary);
}

.chapter-item.active {
  background: var(--color-primary);
  color: var(--color-background);
}

.chapter-item.active .chapter-btn {
  color: var(--color-background);
  font-weight: 600;
}

.chapter-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: var(--color-primary);
  transition: height var(--transition-fast);
  border-radius: 0 2px 2px 0;
}

.chapter-item.active::before {
  height: 70%;
  background: var(--color-background);
}

.chapter-controls {
  display: flex;
  flex-direction: column;
  margin-right: 0.5rem;
  gap: 2px;
}

.chapter-move-btn {
  background: var(--color-secondary);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  width: 20px;
  height: 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  padding: 0;
}

.chapter-move-btn:hover:not(.disabled) {
  background: var(--color-primary);
  color: var(--color-background);
  transform: translateY(-1px);
}

.chapter-move-btn.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  background: transparent;
}

.chapter-btn {
  background: none;
  border: none;
  color: var(--color-text);
  text-align: left;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  width: 100%;
  border-radius: var(--radius-base);
  font-size: 0.875rem;
  transition: var(--transition-fast);
  font-family: inherit;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-btn:hover {
  background: var(--color-secondary);
}

.chapter-item.active .chapter-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ===== VOLLBILD-MODUS ===== */

.editor-fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 9999 !important;
  background: var(--color-background) !important;
  border-radius: 0 !important;
}

.editor-fullscreen .sidebar {
  display: none;
}

.editor-fullscreen .editor-content {
  width: 100%;
}

/* ===== TOAST-SYSTEM ===== */

.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--color-success);
  color: white;
  padding: 1rem 1.5rem;
  border-radius: var(--radius-base);
  box-shadow: var(--shadow-lg);
  z-index: 1001;
  transform: translateX(100%);
  transition: transform var(--transition-medium);
  font-weight: 500;
  max-width: 400px;
  word-wrap: break-word;
}

.toast.show {
  transform: translateX(0);
}

.toast.error {
  background: var(--color-error);
}

/* ===== UTILITY STATES ===== */

.loading {
  text-align: center;
  padding: 2rem;
  color: var(--color-text-secondary);
}

.loading::after {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-text-muted);
  border-top: 2px solid var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-left: 10px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-secondary);
}

.empty-state h3 {
  margin-bottom: 0.5rem;
  color: var(--color-text);
}

.pro-hint {
  background: var(--color-secondary);
  padding: 1rem;
  border-radius: var(--radius-base);
  margin-top: 1rem;
  border-left: 4px solid var(--color-primary);
  font-size: 0.875rem;
}

/* ===== AUTH SYSTEM ===== */

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
}

.auth-tab {
  flex: 1;
  padding: 1rem;
  background: none;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
  font-weight: 500;
  font-family: inherit;
}

.auth-tab.active {
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-primary);
  background: rgba(80, 184, 198, 0.05);
}

.auth-tab:hover {
  background: var(--color-secondary);
}

.auth-form {
  padding: 2rem;
}

.auth-form h2 {
  margin: 0 0 0.5rem 0;
  text-align: center;
  color: var(--color-text);
}

.auth-form .subtitle {
  text-align: center;
  margin-bottom: 2rem;
  color: var(--color-text-secondary);
}

.error-message {
  color: var(--color-error);
  font-size: 0.875rem;
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: rgba(255, 84, 89, 0.1);
  border: 1px solid rgba(255, 84, 89, 0.3);
  border-radius: var(--radius-base);
  display: none;
}

.error-message.show {
  display: block;
}

/* ===== UTILITY CLASSES ===== */

.hidden {
  display: none !important;
}

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

/* ===== THEME SWITCH BUTTON ===== */

.theme-switch-btn {
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-lg);
  transition: var(--transition-medium);
}

.theme-switch-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5);
}

/* ===== SCROLLBARS ===== */

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--color-surface);
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

/* ===== RESPONSIVE DESIGN ===== */

@media (max-width: 1024px) {
  .header h1 {
    font-size: 2.25rem;
  }

  .books-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

@media (max-width: 768px) {
  .header h1 {
    font-size: 2rem;
  }

  .header-content {
    text-align: center;
    flex-direction: column;
  }

  .books-grid {
    grid-template-columns: 1fr;
  }

  .editor-main {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 120px);
  }

  .sidebar {
    width: 100%;
    max-height: 200px;
    order: 2;
  }

  .editor-content {
    order: 1;
    min-height: 400px;
  }

  .editor-nav {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }

  .editor-actions {
    flex-wrap: wrap;
    justify-content: center;
  }

  .book-actions {
    flex-direction: column;
  }

  .chapter-controls {
    margin-right: 0.25rem;
  }

  .chapter-move-btn {
    width: 18px;
    height: 18px;
    font-size: 9px;
  }

  .chapter-btn {
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
  }

  .modal-content {
    width: 95%;
    max-width: none;
    margin: 1rem;
  }

  .modal-actions {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 0.75rem;
  }

  .header {
    padding: 1.5rem 0;
    margin-bottom: 1.5rem;
  }

  .header h1 {
    font-size: 1.75rem;
  }

  .book-card {
    padding: 1rem;
  }

  .editor-wrapper {
    padding: 0.5rem;
  }

  .chapter-editor {
    padding: 1rem;
    font-size: 15px;
  }
}

/* ===== PRINT STYLES ===== */

@media print {
  .theme-switch-btn,
  .toast,
  .modal,
  .sidebar,
  .editor-header,
  .chapter-header,
  .book-actions {
    display: none !important;
  }

  .editor-content {
    width: 100% !important;
  }

  .chapter-editor {
    border: none !important;
    box-shadow: none !important;
    background: white !important;
    color: black !important;
  }
}

/* ===== ACCESSIBILITY ===== */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Focus styles for better accessibility */
.btn:focus,
.form-control:focus,
.chapter-btn:focus,
.chapter-move-btn:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --color-border: rgba(255, 255, 255, 0.3);
    --color-secondary: rgba(255, 255, 255, 0.2);
  }
}

/* ANKER:PDF-PRINT-STYLES-START */
@media print {
  /* Modale & Overlays im Druck ausblenden */
  .modal, #toast { display: none !important; }

  /* Seitenränder und saubere Typografie */
  @page { margin: 18mm; }
  body { color: #000 !important; }

  /* Kapitel-Titel und Buch-Titel hübsch */
  .pdf-print h1, .pdf-print h2 { page-break-after: avoid; }
  .pdf-print h1 { font-size: 22pt; margin-bottom: 6pt; }
  .pdf-print h2 { font-size: 16pt; margin: 16pt 0 8pt; }
  .pdf-print p { font-size: 11pt; line-height: 1.5; }

  /* Absatz-Abstände */
  .pdf-print p + p { margin-top: 6pt; }

  /* Seitenumbruch-Helfer falls genutzt */
  .page-break { page-break-before: always; }
}
/* ANKER:PDF-PRINT-STYLES-END */


/* ANKER:PDF-PRINT-STYLES-START */
@media print {
  .modal, #toast { display: none !important; }
  @page { margin: 18mm; }
  body { color: #000 !important; }
  .pdf-doc h1 { font-size: 22pt; margin: 0 0 8pt 0; }
  .pdf-doc h2 { font-size: 16pt; margin: 16pt 0 8pt 0; }
  .pdf-doc p  { font-size: 11pt; line-height: 1.5; margin: 8pt 0 0 0; }
  .page-break { page-break-before: always; }
}
/* ANKER:PDF-PRINT-STYLES-END */

/* ANKER:PDF-PRINT-BASE-START */
@media print {
  .modal, #toast { display: none !important; }
  @page { margin: 18mm; }
  body { color: #000 !important; }
  .page-break { page-break-before: always; }
}
/* ANKER:PDF-PRINT-BASE-END */
