/* ==========================================================================
   Buchwerkstatt — Stylesheet
   Farben aus der Memoria-Tagebuch-App (Pergament-Thema).
   Kontraste geprüft auf WCAG 2.1 AA (Text ≥ 4.5:1, Bedienelemente ≥ 3:1).
   Gliederung: Variablen · Grundlagen · Kopfbereich · Buttons · IDML-Einstellungen ·
               Layout/Seitenleiste · Editor · Fußzeile/Status
   ========================================================================== */

/* ---------- Variablen (Farben, Schriften, Radien) ---------- */
:root {
  --bg: #F4EEE1;              /* Seitenhintergrund */
  --bg-elevated: #FFFDF8;     /* Felder, Karten */
  --bg-elevated-2: #EDE5D3;   /* Hover, Einstellungsleiste */
  --line: #d6cbb3;            /* dekorative Linien */
  --text: #2a2419;            /* Haupttext, 14:1 */
  --text-muted: #5c5648;      /* Nebentext, 6.6:1 */
  --accent: #8a5a1c;      /* 5.9:1 auf --bg-elevated */
  --accent-strong: #6e4712;
  --accent-text: #fff9ee;
  --danger: #a3261b;
  --focus: #1d4ed8;           /* Tastaturfokus, gut sichtbar auf Pergament */
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;
  --radius: 10px;
}

/* ---------- Grundlagen ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Sichtbarer Fokus für Tastaturbedienung (WCAG 2.4.7) */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Nur für Screenreader sichtbar (z. B. Labels, Datei-Inputs hinter Label-Buttons) */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* „Zum Editor springen“: erscheint erst bei Tastaturfokus */
.skip-link { position: absolute; left: -999px; top: 0; background: var(--bg-elevated); padding: .5rem 1rem; z-index: 10; }
.skip-link:focus { left: 1rem; }
.hidden { display: none !important; }

/* ---------- Kopfbereich: Buchtitel, Export, Sicherung ---------- */
.app-header {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--line); background: var(--bg-elevated);
}
/* App-Name „Buchwerkstatt“: ganze Breite, zurückhaltend, damit der Buchtitel die Hauptsache bleibt */
.app-name {
  flex: 1 0 100%; order: -1; margin: 0;
  font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent);
}
.book-meta { display: flex; flex-direction: column; gap: .15rem; flex: 1 1 320px; }
.book-meta input.book-title {
  font-family: var(--font-display); font-size: 1.8rem; font-weight: 700;
  border: 1px solid transparent; background: transparent; color: var(--text); padding: .1rem .3rem; border-radius: 6px;
}
.book-meta input.book-author { font-size: 1rem; color: var(--text-muted); border: 1px solid transparent; background: transparent; padding: .1rem .3rem; border-radius: 6px; }
.book-meta input:hover { border-color: var(--line); }
.header-actions { display: flex; flex-wrap: wrap; gap: .8rem; align-items: stretch; }
/* Gruppierte Aktionen mit sichtbarer Überschrift („Export als“, „Sicherung“) */
.action-group {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem .7rem .7rem; margin: 0;
}
.action-group legend { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); padding: 0 .3rem; }

/* ---------- Buttons (Mindesthöhe 44 px als Touch-Ziel) ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .3rem; cursor: pointer;
  font: 600 .92rem var(--font-sans); padding: .55rem .9rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg-elevated); color: var(--text);
  min-height: 44px;
}
.btn:hover { background: var(--bg-elevated-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-small { font-size: .85rem; padding: .35rem .7rem; min-height: 36px; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- IDML-Einstellungen (aufklappbare Leiste) ---------- */
.idml-settings { padding: .6rem 1.5rem; border-bottom: 1px solid var(--line); background: var(--bg-elevated-2); }
.idml-settings summary { cursor: pointer; font-weight: 600; font-size: .9rem; min-height: 32px; display: flex; align-items: center; }
.idml-settings .row { margin-top: .6rem; }

/* ---------- Layout: Seitenleiste + Editor, unter 800 px einspaltig ---------- */
.layout { display: grid; grid-template-columns: 280px 1fr; flex: 1; min-height: 0; }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } }

.sidebar { padding: 1rem; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: .6rem; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.sidebar h2 { font-family: var(--font-display); font-size: 1.25rem; margin: 0; }
.small-label { font-size: .8rem; color: var(--text-muted); }
select, input[type=text], input[type=url], textarea {
  font: inherit; color: var(--text); background: var(--bg-elevated);
  border: 1px solid #a99c80; border-radius: 8px; padding: .5rem .6rem; width: 100%;
}
.chapter-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
.chapter-list button {
  width: 100%; text-align: left; background: transparent; border: 1px solid transparent; border-radius: 8px;
  padding: .5rem .6rem; font: inherit; color: var(--text); cursor: pointer;
}
.chapter-list button:hover { background: var(--bg-elevated-2); }
.chapter-list button[aria-current="true"] { background: var(--bg-elevated); border-color: var(--accent); }
.chapter-list .num { color: var(--text-muted); font-size: .8rem; margin-right: .3rem; }
.chapter-list .cat { display: block; font-size: .75rem; color: var(--text-muted); }

/* ---------- Editor: Formularfelder des Kapitels ---------- */
.editor { padding: 1.5rem; max-width: 900px; width: 100%; }
.empty-hint { color: var(--text-muted); }
.chapter-form { display: flex; flex-direction: column; gap: 1.1rem; }
.row { display: flex; flex-wrap: wrap; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 200px; }
.field.grow { flex: 1 1 320px; }
label, .label, legend { font-weight: 600; font-size: .9rem; }
.hint { font-weight: 400; color: var(--text-muted); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem 1rem; margin: 0; }

/* Werkzeugleiste über dem Rich-Text */
.toolbar { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.toolbar button:not(.info-btn) {
  min-width: 44px; min-height: 36px; border: 1px solid var(--line); background: var(--bg-elevated);
  border-radius: 6px; cursor: pointer; font: 600 .9rem var(--font-sans); color: var(--text);
}
.toolbar button:not(.info-btn):hover { background: var(--bg-elevated-2); }
.toolbar button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
/* Bearbeitbarer Textbereich: Serifenschrift wie im späteren Buch */
.rich {
  min-height: 260px; padding: 1rem 1.1rem; background: var(--bg-elevated); border: 1px solid #a99c80;
  border-radius: var(--radius); font-family: Georgia, 'Times New Roman', serif; font-size: 1.08rem; line-height: 1.65;
}
.rich p { margin: 0 0 .8em; }
/* Absatzformate (gleiche Klassen im EPUB) */
.rich p.center { text-align: center; }
.rich p.vers { text-align: center; margin-left: 2.5em; margin-right: 2.5em; }
.rich p.zitat { margin-left: 2em; margin-right: 2em; padding-left: .8em; border-left: 3px solid var(--line); color: var(--text-muted); }
.rich a { color: var(--accent-strong); }
.link-panel { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .6rem; background: var(--bg-elevated-2); border-radius: 8px; }
.link-panel input { flex: 1 1 240px; width: auto; }

/* Listen für Links und Bilder (von app.js erzeugt) */
.links-list, .image-list { list-style: none; margin: 0 0 .6rem; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.links-list li { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: .5rem; align-items: center; }
@media (max-width: 600px) { .links-list li { grid-template-columns: 1fr; } }

/* Ablagefläche für Bilder; .over = Datei wird gerade darübergezogen */
.dropzone { border: 2px dashed #a99c80; border-radius: var(--radius); padding: 1rem; text-align: center; color: var(--text-muted); margin-bottom: .8rem; }
.dropzone.over { border-color: var(--accent); background: var(--bg-elevated); }
.dropzone p { margin: 0; }
.inline-link { color: var(--accent-strong); text-decoration: underline; cursor: pointer; }
.image-list li { display: grid; grid-template-columns: 96px 1fr auto; gap: .7rem; align-items: center; }
.image-list img { width: 96px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.image-list .img-actions { display: flex; gap: .3rem; }

.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; border-top: 1px solid var(--line); padding-top: 1rem; }

/* ---------- ⓘ-Hilfe: Symbol (24 px Touch-Ziel) und Sprechblase ---------- */
.info-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 24px; height: 24px; margin-left: .35rem; padding: 0; vertical-align: middle;
  border: 1.5px solid var(--accent-strong); border-radius: 50%; background: var(--bg-elevated);
  color: var(--accent-strong); font: italic 700 .8rem Georgia, serif; cursor: pointer; line-height: 1;
  text-transform: none; letter-spacing: 0;
}
.info-btn:hover, .info-btn[aria-expanded="true"] { background: var(--accent-strong); color: var(--accent-text); }
/* Element + ⓘ bleiben zusammen; bei Feldern füllt das Feld die Breite */
.info-wrap { display: inline-flex; align-items: center; }
.info-wrap-field { display: flex; width: 100%; }
.book-meta .info-wrap-field { width: 100%; max-width: 40rem; }
.info-wrap-field > input, .info-wrap-field > select, .info-wrap-field > textarea { flex: 1; min-width: 0; }
.info-bubble {
  position: absolute; z-index: 50; padding: .7rem .9rem; border-radius: 8px;
  background: var(--text); color: var(--bg-elevated); font-size: .88rem; line-height: 1.45;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}

/* ---------- Sonderteile in der Seitenleiste ---------- */
.extra-parts { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; padding: .5rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.extra-parts .small-label { width: 100%; display: flex; align-items: center; }
.chapter-list button.special { font-style: italic; }

/* ---------- Anmeldung: Vollbild-Dialog; bis zur Anmeldung ist alles andere unsichtbar ---------- */
body.locked > :not(#lock):not(.status):not(script) { visibility: hidden; }
.lock { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 1rem; overflow: auto; }
.lock-box { width: min(420px, 100%); display: flex; flex-direction: column; gap: .9rem; background: var(--bg-elevated); border: 1px solid var(--line); border-radius: 14px; padding: 1.6rem; box-shadow: 0 10px 40px rgba(42,36,25,.12); }
.lock-title { font-family: var(--font-display); font-size: 1.6rem; margin: 0; }
.lock-intro { margin: 0; color: var(--text-muted); font-size: .95rem; }
.lock-error { margin: 0; min-height: 1.3em; color: var(--danger); font-weight: 600; font-size: .9rem; }
.lock-note { margin: 0; font-size: .78rem; color: var(--text-muted); }
.lock-note a { color: var(--accent-strong); }
input[type=email], input[type=password] { font: inherit; color: var(--text); background: var(--bg-elevated); border: 1px solid #a99c80; border-radius: 8px; padding: .5rem .6rem; width: 100%; }
.btn-lock { margin-left: auto; order: 3; }
.btn-passkey { order: 3; }
/* Mit ⓘ steckt der Knopf in einem .info-wrap: dann muss die Hülle verschoben werden */
.app-header > .info-wrap:has(> .btn-lock) { order: 3; margin-left: auto; }
.app-header > .info-wrap:has(> .btn-passkey) { order: 3; }

/* ---------- Titelbild-Dialog vor dem EPUB-Export ---------- */
.epub-dialog { border: 1px solid var(--line); border-radius: 14px; padding: 1.4rem; max-width: min(440px, 92vw); background: var(--bg-elevated); color: var(--text); }
.epub-dialog::backdrop { background: rgba(42,36,25,.55); }
.epub-dialog h2 { font-family: var(--font-display); margin: 0 0 .8rem; font-size: 1.3rem; }
.epub-cover-preview { display: block; width: 220px; aspect-ratio: 5 / 8; object-fit: cover; margin: 0 auto; border: 1px solid var(--line); box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.epub-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; margin-top: .8rem; }

/* ---------- Fußzeile: Export- und Sicherungsfelder ---------- */
.footer-actions { display: flex; flex-wrap: wrap; gap: .8rem; margin-bottom: .8rem; }
.app-footer .idml-settings { padding: .4rem 0 .8rem; border-bottom: 0; background: transparent; color: var(--text); }

/* ---------- Fußzeile und Statusmeldung (unten rechts, blendet aus) ---------- */
.app-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--line); font-size: .85rem; color: var(--text-muted); }
.app-footer p { margin: .2rem 0; }
.app-footer a { color: var(--accent-strong); }
.status {
  position: fixed; bottom: 1rem; right: 1rem; background: var(--text); color: var(--bg-elevated);
  padding: .6rem 1rem; border-radius: 8px; font-size: .9rem; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.status.show { opacity: 1; }

/* Keine Animationen, wenn das System reduzierte Bewegung wünscht */
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
