:root {
  --bg: #1b1d23;
  --bg-elev: #242730;
  --bg-elev-2: #2d313c;
  --border: #3a3f4b;
  --text: #e6e8ec;
  --text-dim: #a0a6b0;
  --accent: #6ea8fe;
  --accent-strong: #3b82f6;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 8px;
  --gap: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

main { height: 100vh; }

button {
  font: inherit;
  cursor: pointer;
  color: var(--text);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
}
button:hover { background: var(--border); }
button.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
button.primary:hover { filter: brightness(1.1); }
button.danger { color: var(--danger); }
button:disabled { opacity: 0.5; cursor: default; }

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  width: 100%;
}
textarea { resize: vertical; }
label { color: var(--text-dim); font-size: 0.85rem; display: block; margin-bottom: 4px; }

/* ---------- Login ---------- */
.login-container {
  max-width: 360px;
  margin: 12vh auto 0;
  padding: 28px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-align: center;
}
.login-container h1 { margin: 0 0 18px; font-size: 1.6rem; letter-spacing: 0.5px; }
.login-container form { display: flex; flex-direction: column; gap: 12px; }
.login-remember { display: flex; align-items: center; gap: 8px; color: var(--text-dim); }
.login-remember input { width: auto; }
.login-error { color: var(--danger); margin-top: 12px; }

/* ---------- Project list ---------- */
.projects {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px;
}
.projects-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.projects-header h1 { margin: 0; font-size: 1.4rem; }
.projects-header .user { color: var(--text-dim); }
.project-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; margin-bottom: 10px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
}
.project-card .meta { display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
.project-card .title { font-weight: 600; }
.project-card .sub { color: var(--text-dim); font-size: 0.82rem; }
.project-new { display: flex; gap: 10px; margin-top: 18px; }

/* ---------- Editor shell ---------- */
.editor-shell {
  display: grid;
  grid-template-columns: minmax(150px, 0.8fr) 3fr minmax(180px, 1fr) 56px;
  /* Graph-Zeile per --graph-h steuerbar (Default 30vh → ~30/70). Splitter-Zeile
     dazwischen, Editor nimmt den Rest (1fr), Footer auto. Der Hook EditorSplitter
     überschreibt --graph-h per Drag und persistiert es in localStorage. */
  grid-template-rows: var(--graph-h, 30vh) 8px minmax(140px, 1fr) auto;
  grid-template-areas:
    "left   graph  right  tools"
    "split  split  split  tools"
    "editor editor editor tools"
    "footer footer footer tools";
  /* Nimmt den Rest der app-root-Spalte (100vh minus ggf. Kaskaden-Banner) statt
     fix 100vh — so verkleinert das Banner den Editor, statt ihn zu überdecken. */
  flex: 1 1 auto;
  min-height: 0;
  gap: 1px;
  background: var(--border);
}
.editor-splitter {
  grid-area: split;
  background: var(--bg-elev);
  cursor: row-resize;
  touch-action: none;
  display: flex; align-items: center; justify-content: center;
}
.editor-splitter:hover { background: var(--border); }
.splitter-grip { width: 44px; height: 3px; border-radius: 2px; background: var(--text-dim); opacity: 0.5; }
.editor-splitter:hover .splitter-grip { opacity: 0.9; }
body.splitter-dragging { cursor: row-resize; user-select: none; }
.pane { background: var(--bg); overflow: auto; }
.side-pane { padding: 10px; }
.side-left { grid-area: left; }
.side-right { grid-area: right; }
.graph-pane { grid-area: graph; padding: 8px; display: flex; flex-direction: column; overflow: hidden; }
.graph-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.graph-head .pane-title { margin: 0; }
.graph-head button { padding: 4px 10px; font-size: 0.8rem; }
/* Beim horizontalen Zoom wird das SVG breiter als der Rahmen → Scrollbalken
   unten verschiebt den Ausschnitt. Vertikal bleibt es fix. */
.graph-board { flex: 1; min-height: 0; overflow-x: auto; overflow-y: hidden; }
.graph-board::-webkit-scrollbar { height: 10px; }
.graph-board::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
.graph-board::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
.footer-pane { grid-area: footer; padding: 8px 12px; border-top: 1px solid var(--border); }
.editor-pane { grid-area: editor; padding: 14px; display: flex; flex-direction: column; }
.tools-pane {
  grid-area: tools; background: var(--bg-elev);
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 6px;
}
.tools-pane button { width: 40px; height: 40px; padding: 0; font-size: 1.1rem; }

/* Mic-Button (Diktat). Push-to-talk: rot+pulsierend während der Aufnahme,
   bernsteinfarben während der Transkription. touch-action:none, damit Halten
   auf Touch nicht scrollt/zoomt. */
.tool-mic { touch-action: none; margin-top: auto; }
.tool-mic.recording {
  background: var(--danger); border-color: var(--danger); color: #fff;
  animation: mic-pulse 1s ease-in-out infinite;
}
.tool-mic.transcribing {
  background: #b45309; border-color: #b45309; color: #fff;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.pane-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin: 0 0 8px; }

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-list.vertical { flex-direction: column; align-items: stretch; }
.chip-list.vertical .chip { justify-content: space-between; }

/* ---------- SVG-Graph ---------- */
.graph-svg {
  width: 100%; height: 100%; display: block;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  touch-action: none; user-select: none; cursor: grab;
}
/* Während des Hintergrund-Pans: überall Greif-Cursor. */
body.graph-panning, body.graph-panning .graph-svg, body.graph-panning .graph-svg * {
  cursor: grabbing !important;
}
.plot-line { fill: none; stroke-width: 2; opacity: 0.9; cursor: pointer; }
.plot-line:hover { opacity: 1; }
.plot-line.selected { stroke-width: 4; }
.plot-line.orientation { stroke-dasharray: 7 5; opacity: 0.55; }

.tp-line { stroke: var(--text-dim); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.45; cursor: pointer; }
.tp-line:hover { opacity: 0.8; }
.tp-line.selected { stroke: var(--accent); opacity: 1; stroke-width: 1.5; }

.tp-node-main { stroke: #fff; stroke-width: 1.5; cursor: pointer; }
.tp-node-shift { fill: var(--bg-elev); stroke-width: 2; cursor: pointer; }
.tp-node-main.selected, .tp-node-shift.selected { stroke: var(--accent); stroke-width: 2.5; }
/* Geerbte Intensität (intensity=nil): hohl + gestrichelt → folgt dem Vorgänger. */
.tp-node-main.inherited { fill: var(--bg-elev); stroke-width: 2; stroke-dasharray: 3 2; }

/* Top-Handle: jeder Wendepunkt ist oben (halb sichtbar) per x greifbar. */
.tp-handle { fill: var(--text-dim); stroke: var(--bg); stroke-width: 1.5; cursor: ew-resize; }
.tp-handle:hover { fill: var(--accent); }
.tp-handle.selected { fill: var(--accent); }

/* Gridlines (ganzzahlige Zeiten; T=0 betont). */
.grid-line { stroke: var(--border); stroke-width: 1; opacity: 0.3; }
.grid-line.major { stroke: var(--text-dim); stroke-width: 1.5; opacity: 0.7; }
.grid-label { fill: var(--text-dim); font-size: 11px; opacity: 0.7; }
.grid-label.major { fill: var(--text); opacity: 1; }

.chapter-band { fill: var(--accent-strong); fill-opacity: 0.22; stroke: var(--accent-strong); stroke-width: 1; cursor: grab; }
.chapter-band:hover { fill-opacity: 0.32; }
.chapter-band.selected { fill-opacity: 0.45; stroke: var(--accent); }
/* Als fertig markierte Kapitel grün statt blau (Auswahl bleibt über die höhere
   Deckkraft erkennbar). Nach .selected, damit die Farbe auch bei Auswahl greift. */
.chapter-band.finalized { fill: var(--ok); stroke: var(--ok); }
/* Kanten-Handles: unsichtbar, aber greifbar (Länge ändern wie Kalender-Termin). */
.chapter-handle { fill: transparent; pointer-events: all; cursor: ew-resize; }
.chapter-handle:hover { fill: var(--accent); fill-opacity: 0.5; }
.lane-bg { fill: var(--bg); opacity: 0.35; }
.lane-sep { stroke: var(--border); stroke-width: 1; }
.graph-hint { fill: var(--text-dim); font-size: 18px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  cursor: pointer; font-size: 0.85rem;
}
.chip.selected { border-color: var(--accent); color: var(--accent); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.chip .kind-mark { font-size: 0.9em; line-height: 1; }
.chip .del { color: var(--text-dim); }

/* Wendepunkt ↔ Handlungsebenen-Knoten */
.node-section { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.node-row {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.node-row .node-line { display: inline-flex; align-items: center; gap: 6px; min-width: 130px; font-size: 0.9rem; }
.node-row .node-line .dot { width: 10px; height: 10px; border-radius: 50%; }
.node-field { display: flex; flex-direction: column; gap: 2px; }
.node-field label { margin: 0; }
.node-field input { width: 110px; }
.intensity-cell { display: flex; gap: 4px; }
.intensity-cell button { width: 32px; padding: 0; }
.node-del { margin-left: auto; padding: 6px 10px; }
.node-add { display: flex; gap: 8px; margin-top: 10px; }
.node-add select { width: auto; flex: 1; }

/* Wendepunkt ↔ Element-Verknüpfung */
.entity-link-form { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.entity-checks { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.entity-check {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text); font-size: 0.88rem; margin: 0;
}
.entity-check input { width: auto; }
.entity-check .kind-mark { font-size: 0.9em; }

/* Kapitel: enthaltene Wendepunkte (aus Zeitfenster abgeleitet) */
.chapter-tps { margin-bottom: 12px; }
.chapter-tps .chip-list { margin-top: 4px; }
.chapter-tps p { margin: 4px 0 0; }

.chapter-strip { display: flex; gap: 8px; align-items: stretch; }
.chapter-pill {
  min-width: 90px; padding: 8px 10px; border-radius: var(--radius);
  background: var(--bg-elev-2); border: 1px solid var(--border); cursor: grab; font-size: 0.82rem;
  user-select: none; touch-action: none;
}
.chapter-pill.selected { border-color: var(--accent); }
.chapter-pill.drag-source { opacity: 0.3; }

/* Ghost hängt am <body> → Pill-Styles explizit wiederholen (keine Vererbung). */
.chapter-pill-ghost {
  position: fixed; z-index: 1000; pointer-events: none;
  min-width: 90px; padding: 8px 10px; border-radius: var(--radius);
  background: var(--bg-elev-2); border: 1px solid var(--accent); font-size: 0.82rem;
  color: var(--text); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); opacity: 0.95;
}
body.dragging-active { cursor: grabbing; user-select: none; }

/* Graph-Drag-Ghosts (am <body>, eigene Styles — keine SVG-Vererbung). */
.graph-ghost-dot {
  position: fixed; z-index: 1000; pointer-events: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
/* Herausziehen (neuer Punkt) — grün abgesetzt vom Verschieben (blau). */
.graph-ghost-dot.create { background: var(--ok); }
.graph-ghost-line {
  position: fixed; z-index: 1000; pointer-events: none;
  width: 0; border-left: 2px dashed var(--accent);
  transform: translateX(-1px);
}
/* Kapitel-Band-Ghost (verschieben/Länge/aufziehen) — horizontaler Termin-Look. */
.graph-ghost-band {
  position: fixed; z-index: 1000; pointer-events: none;
  background: var(--accent-strong); opacity: 0.4;
  border: 1px solid var(--accent); border-radius: 3px;
}
.graph-ghost-band.create { background: var(--ok); }

.editor-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 10px; }
.editor-head .field-label { font-weight: 600; }
.editor-head > input { flex: 1; min-width: 0; }

/* Vor/zurück durch die Wendepunkte (auch bei gleichem Zeitpunkt) */
.tp-nav { display: flex; gap: 4px; flex: none; }
.tp-nav button { padding: 4px 9px; line-height: 1; font-size: 16px; }

/* Kaskaden-Leiste ("Mach den Rest") oben im Projekt-Panel */
.cascade-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cascade-bar button.primary { width: auto; }

/* Globales Kaskaden-Banner: bleibt sichtbar, egal welcher Editor gewählt ist,
   damit man die Kaskade jederzeit abbrechen kann. Liegt im Layout-Fluss (erste
   Zeile der app-root-Flex-Spalte) und verkleinert den Editor darunter, statt ihn
   zu überdecken. */
.cascade-banner {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--accent);
  font-size: 0.9rem;
}
.cascade-banner-status { flex: 1; color: var(--text); }
.cascade-banner button.secondary { width: auto; }
.cascade-spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: cascade-spin 0.8s linear infinite;
}
@keyframes cascade-spin { to { transform: rotate(360deg); } }

button.secondary { border-color: var(--accent); color: var(--accent); }

/* Kaskade läuft: alles gesperrt außer der Editor-Auswahl (Chips/Pills/Graph-Klick).
   Der Editor wird sichtbar abgeblendet und nicht bedienbar; Lösch-× in den Chips
   und die Drag-Cursor verlieren ihre Bedienbarkeit. */
.cascade-locked .editor-pane { pointer-events: none; opacity: 0.55; }
.cascade-locked .del { pointer-events: none; opacity: 0.35; }
.cascade-locked .chapter-pill,
.cascade-locked .chapter-band,
.cascade-locked .chapter-handle { cursor: pointer; }

/* Anweisungs-Dialog vor jedem Generierungsstart: zentriertes Overlay mit einem
   Textfeld für eine optionale Sonder-Anweisung an den Generator. */
.gen-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.55);
}
.gen-modal {
  width: min(560px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  padding: 16px;
}
.gen-modal label { display: block; margin-bottom: 6px; }
.gen-modal-hint { margin: 0 0 10px; font-size: 0.85rem; }
.gen-modal textarea { width: 100%; resize: vertical; }
.gen-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}
.gen-modal-actions button { width: auto; }
.editor-body { flex: 1; }
.editor-body textarea { height: 100%; min-height: 200px; }

/* Feld-Kopf mit Generieren-Button (LLM-Feldgenerierung) */
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field-head label { margin: 0; }
.gen-btn { font-size: 0.78rem; padding: 3px 10px; width: auto; height: auto; color: var(--accent); white-space: nowrap; }
.gen-btn:hover:not(:disabled) { border-color: var(--accent); }

.row { display: flex; gap: 10px; margin-bottom: 10px; }
.row > * { flex: 1; }
.muted { color: var(--text-dim); }
.toolbar-sep { width: 70%; height: 1px; background: var(--border); margin: 6px 0; }

/* ---------- Mobile ---------- */
.editor-shell.mobile {
  grid-template-columns: 1fr;
  grid-template-rows: 50vh auto auto auto auto auto;
  grid-template-areas:
    "graph"
    "left"
    "right"
    "editor"
    "footer"
    "tools";
}
/* Splitter nur im Desktop-Grid sinnvoll; im Mobile-Stack ausblenden (sonst
   würde grid-area:split mangels Bereich implizit platziert). */
.editor-shell.mobile .editor-splitter { display: none; }
.editor-shell.mobile .tools-pane { flex-direction: row; justify-content: center; }
/* In der horizontalen Mobile-Leiste den Mic stattdessen nach rechts in die
   Ecke drücken (margin-top:auto greift nur in der Spalte). */
.editor-shell.mobile .tool-mic { margin-top: 0; margin-left: auto; }
.editor-shell.mobile .graph-pane { overflow: hidden; }

/* ---------- Graph-Vollbild ---------- */
/* Knopf rechts in der Graph-Kopfzeile; gedrückt (aria-pressed) = Vollbild aktiv. */
.graph-full-btn { font-size: 1rem; line-height: 1; }
.graph-full-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* Vollbild: nur Graph + Kapitelleiste. Sidebars, Splitter, Editor und Werkzeug-
   leiste sind ausgeblendet, der Graph füllt die Höhe (statt --graph-h). Rein
   client-seitig (localStorage) wie der Splitter: die Klasse setzt der
   GraphFullscreen-Hook, das Re-Apply nach LiveView-Patches macht der Viewport-Hook.
   Gleiche Spezifität wie .editor-shell.mobile, steht aber danach → gewinnt in
   beiden Viewports. */
.editor-shell.graph-full .side-pane,
.editor-shell.graph-full .editor-splitter,
.editor-shell.graph-full .editor-pane,
.editor-shell.graph-full .tools-pane { display: none; }
.editor-shell.graph-full {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "graph"
    "footer";
}
