/* ---- Theme-Variablen ---------------------------------------------------- */
:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #f0ece1;
  --border: #e0d9c8;
  --text: #2c2823;
  --text-soft: #6b6459;
  --accent: #7c5cff;
  --accent-soft: #ece7ff;
  --family: #d97742;
  --relation: #2f9e8f;
  --danger: #c8503d;
  --ok: #4f9d4f;
  --shadow: 0 1px 2px rgba(60, 50, 30, 0.06), 0 6px 20px rgba(60, 50, 30, 0.06);
  --radius: 12px;
  --font-ui: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-prose: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
:root[data-theme="dark"] {
  --bg: #16151a;
  --surface: #201f27;
  --surface-2: #2a2933;
  --border: #35333f;
  --text: #ece9f0;
  --text-soft: #a29fb0;
  --accent: #a78bfa;
  --accent-soft: #2c2740;
  --family: #e08a54;
  --relation: #43b8a6;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout ------------------------------------------------------------- */
#app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; }
.brand-mark {
  width: 30px; height: 30px; display: grid; place-items: center;
  background: var(--accent); color: #fff; border-radius: 9px; font-size: 15px;
}
.brand-title { font-weight: 650; font-size: 15px; line-height: 1.15; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 9px;
  color: var(--text-soft); font-size: 14px; font-weight: 500;
  cursor: pointer; border: none; background: none; text-align: left; width: 100%;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ico { font-size: 16px; width: 18px; text-align: center; }
.nav-item .count { margin-left: auto; font-size: 12px; opacity: 0.7; font-variant-numeric: tabular-nums; }

.sidebar-foot { display: flex; gap: 6px; padding-top: 8px; border-top: 1px solid var(--border); }
.sidebar-foot .btn { flex: 1; font-size: 12px; padding: 7px 4px; }

.content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 640; }
.menu-toggle { display: none; }
.save-hint { margin-left: auto; font-size: 12px; color: var(--text-soft); }
.save-hint.show { animation: fade 1.6s ease; }
@keyframes fade { 0%,15% { opacity: 1; } 100% { opacity: 0; } }

.view { flex: 1; overflow-y: auto; padding: 24px; }

/* ---- Buttons / Inputs --------------------------------------------------- */
.btn {
  font-family: inherit; font-size: 14px; font-weight: 550;
  padding: 8px 14px; border-radius: 9px; border: 1px solid transparent;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface-2); color: var(--text);
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-sm { padding: 5px 9px; font-size: 12.5px; }

input, textarea, select {
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 11px; width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; line-height: 1.5; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-soft); margin: 0 0 5px; }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }

/* ---- Allgemeine Bausteine ---------------------------------------------- */
.view-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.view-head .lead { color: var(--text-soft); font-size: 14px; max-width: 620px; }
.spacer { flex: 1; }

.empty {
  text-align: center; padding: 60px 20px; color: var(--text-soft);
}
.empty .emoji { font-size: 34px; display: block; margin-bottom: 10px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 3px 9px; border-radius: 20px;
  background: var(--surface-2); color: var(--text-soft);
}
.tag { background: var(--accent-soft); color: var(--accent); }

/* ---- Projekt-Karten (Startseite) --------------------------------------- */
.project-card { padding: 18px; cursor: pointer; display: flex; flex-direction: column; gap: 7px; }
.project-card:hover { border-color: var(--accent); }
.project-top { display: flex; align-items: flex-start; gap: 8px; }
.project-title { font-weight: 680; font-size: 16px; flex: 1; line-height: 1.2; }
.project-author { font-size: 12.5px; color: var(--text-soft); }
.project-logline { font-size: 13px; color: var(--text-soft); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.project-stats { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--text-soft); margin-top: 4px; }
.project-modified { font-size: 11.5px; color: var(--text-soft); opacity: .8; }
.project-card:hover .node-actions { opacity: 1; }

/* ---- Charakter-Karten --------------------------------------------------- */
.char-card { padding: 16px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; }
.char-card:hover { border-color: var(--accent); }
.char-avatar {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 16px; flex-shrink: 0;
}
.char-top { display: flex; align-items: center; gap: 12px; }
.char-name { font-weight: 650; font-size: 15px; }
.char-role { font-size: 12.5px; color: var(--text-soft); }
.char-desc { font-size: 13px; color: var(--text-soft); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---- Beziehungsgraph ---------------------------------------------------- */
.graph-wrap { position: relative; height: calc(100vh - 150px); }
.graph-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.graph-legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-soft); }
.graph-legend span::before {
  content: ""; display: inline-block; width: 20px; height: 3px; border-radius: 2px;
  margin-right: 6px; vertical-align: middle;
}
.legend-family::before { background: var(--family); }
.legend-relation::before { background: var(--relation); }
.graph-canvas {
  width: 100%; height: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  touch-action: none; cursor: grab;
}
.graph-node { cursor: grab; }
.graph-node:active { cursor: grabbing; }
.graph-node circle { stroke: var(--surface); stroke-width: 3px; }
.graph-node text { font-size: 12px; font-weight: 600; fill: var(--text); pointer-events: none; }
.edge-line { stroke-width: 2px; fill: none; }
.edge-label { font-size: 10.5px; fill: var(--text-soft); pointer-events: none; }

/* ---- Outline ------------------------------------------------------------ */
.act { margin-bottom: 26px; }
.act-head, .chapter-head { display: flex; align-items: center; gap: 8px; }
.act-title { font-size: 17px; font-weight: 680; border: none; background: none; padding: 4px 2px; }
.chapter { margin: 12px 0 12px 14px; padding-left: 14px; border-left: 2px solid var(--border); }
.chapter-title { font-size: 14.5px; font-weight: 620; border: none; background: none; padding: 3px 2px; }
.scene-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-top: 10px; }
.scene-card { padding: 12px; cursor: pointer; }
.scene-card:hover { border-color: var(--accent); }
.scene-headline { font-weight: 600; font-size: 13.5px; margin-bottom: 4px; }
.scene-summary { font-size: 12.5px; color: var(--text-soft); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.scene-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; }
.status-idee { background: #b7afaa; }
.status-entwurf { background: var(--family); }
.status-fertig { background: var(--ok); }
.node-actions { margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.act-head:hover .node-actions, .chapter-head:hover .node-actions, .scene-card:hover .node-actions { opacity: 1; }
.icon-btn { border: none; background: none; cursor: pointer; color: var(--text-soft);
  padding: 3px 5px; border-radius: 6px; font-size: 13px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---- Manuskript --------------------------------------------------------- */
.manuscript { display: flex; gap: 20px; height: calc(100vh - 150px); }
.ms-list { width: 260px; flex-shrink: 0; overflow-y: auto; }
.ms-scene-list { display: flex; flex-direction: column; gap: 2px; }
.ms-scene { padding: 8px 9px; border-radius: 8px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; gap: 8px; }
.ms-scene:hover { background: var(--surface-2); }
.ms-scene.active { background: var(--accent-soft); color: var(--accent); }
.ms-scene-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ms-scene .meta { font-size: 11px; color: var(--text-soft); }
.ms-chapter-label { font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-soft); margin: 14px 0 4px; }
.ms-editor { flex: 1; display: flex; flex-direction: column; }
.ms-editor .ms-head { margin-bottom: 10px; }
.ms-textarea {
  flex: 1; font-family: var(--font-prose); font-size: 18px; line-height: 1.7;
  border: none; background: var(--surface); border-radius: var(--radius);
  padding: 28px 34px; box-shadow: var(--shadow); max-width: 46em;
}
.ms-wordcount { font-size: 12px; color: var(--text-soft); margin-top: 8px; }

/* ---- Ideen / Konflikte / Hintergrund ------------------------------------ */
.note-card { padding: 15px; display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.note-card:hover { border-color: var(--accent); }
.note-title { font-weight: 620; font-size: 14.5px; }
.note-body { font-size: 13px; color: var(--text-soft); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.note-tags { display: flex; gap: 5px; flex-wrap: wrap; }

/* ---- Modal -------------------------------------------------------------- */
.modal-root {
  position: fixed; inset: 0; background: rgba(20, 16, 10, 0.45);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
/* Wichtig: das hidden-Attribut muss das display der Klasse schlagen,
   sonst liegt das Overlay dauerhaft über der Seite und schluckt alle Klicks. */
.modal-root[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  width: min(640px, 100%); max-height: 90vh; overflow-y: auto; padding: 24px;
}
.modal-head { display: flex; align-items: center; margin-bottom: 18px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.modal-foot .spacer { flex: 1; }

/* ---- Tags --------------------------------------------------------------- */
.tag-chip {
  --tag: var(--accent);
  background: color-mix(in srgb, var(--tag) 16%, transparent);
  color: var(--tag); border: 1px solid transparent; font-weight: 550;
}
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
button.tag-chip { cursor: pointer; font-family: inherit; font-size: 12px; }
button.tag-chip.off { background: var(--surface-2); color: var(--text-soft); }
button.tag-chip.on { box-shadow: inset 0 0 0 1.5px var(--tag); }
.tag-new { width: auto; flex: 0 0 130px; padding: 5px 9px; font-size: 12px; }

/* ---- Kanban ------------------------------------------------------------- */
.kanban-board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.kanban-col { background: var(--surface-2); border-radius: 12px; padding: 10px;
  flex: 0 0 272px; display: flex; flex-direction: column; gap: 8px; }
.kanban-col-head { display: flex; align-items: center; gap: 4px; }
.kanban-col-title { font-weight: 640; font-size: 13.5px; background: none; border: none;
  padding: 4px 6px; flex: 1; border-radius: 6px; min-width: 0; }
.kanban-col-title:hover { background: var(--surface); }
.kanban-col-count { font-size: 11px; color: var(--text-soft); font-variant-numeric: tabular-nums; padding: 0 2px; }
.kanban-col-head .icon-btn { opacity: 0; }
.kanban-col:hover .kanban-col-head .icon-btn { opacity: 1; }
.kanban-col-body { display: flex; flex-direction: column; gap: 8px; min-height: 12px; }
.kanban-card { padding: 11px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.kanban-card:hover { border-color: var(--accent); }
.kanban-card-head { display: flex; align-items: center; gap: 6px; }
.kanban-card-head .note-title { margin: 0; font-size: 14px; }
.add-inline { align-self: flex-start; }

/* ---- Drag & Drop -------------------------------------------------------- */
.drag-handle {
  cursor: grab; touch-action: none; user-select: none; flex-shrink: 0;
  color: var(--text-soft); opacity: .45; font-size: 15px; line-height: 1;
  padding: 2px 3px; border-radius: 5px;
}
.drag-handle:hover { opacity: 1; background: var(--surface-2); }
.drag-handle:active { cursor: grabbing; }
.scene-card-head { display: flex; align-items: center; gap: 6px; }
.scene-card-head .scene-headline { margin: 0; }
.dnd-clone { box-shadow: var(--shadow); border-radius: var(--radius); cursor: grabbing; }
.dnd-placeholder {
  border: 2px dashed var(--accent); background: var(--accent-soft);
  border-radius: 8px; margin: 3px 0;
}
body.dnd-active { user-select: none; cursor: grabbing; }
/* Leere Zonen während des Ziehens abwerfbar machen. */
body.dnd-active .scene-row, body.dnd-active .chapter-list,
body.dnd-active .ms-scene-list, body.dnd-active .kanban-col-body { min-height: 42px; }
body.dnd-active .scene-row { outline: 1px dashed var(--border); outline-offset: 4px; border-radius: 8px; }

/* ---- Mobil -------------------------------------------------------------- */
@media (max-width: 820px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-flex; }
  .view { padding: 16px; }
  .manuscript, .ms-list { flex-direction: column; width: 100%; height: auto; }
  .manuscript { height: auto; }
  .ms-textarea { font-size: 17px; padding: 18px; }
}
