/* TheSpace – gemeinsame Gestaltung nach dem Design-Leitfaden (Weiß/Sand, Aktionsblau nur für Aktionen, Inter + Fraunces 400/500) */
:root {
  --bg: #FFFFFF; --panel: #F7F2EA; --card: #FFFFFF; --ink: #232A3A; --ink-soft: #3A4256; --muted: #61697B;
  --line: #EDE3D4; --accent: #1F3FCF; --accent-ink: #FFFFFF; --accent-soft: #EDF1FE; --accent-deep: #1B317F;
  --tinte: #16265C; --danger: #A33A2B; --stage: #FBF8F3; --paper: #FFFFFF; --grid: rgba(35, 42, 58, .07);
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mark: "Fraunces", Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #14171F; --panel: #1C202B; --card: #1C202B; --ink: #E8EAEF; --ink-soft: #C9CEDA; --muted: #A2A9B8; --line: #2A303E;
  --accent: #7C93F5; --accent-ink: #14171F; --accent-soft: #1A2340; --accent-deep: #B9C6FF; --tinte: #8FA3E8; --danger: #F0A496;
  --stage: #181C25; --paper: #F7F4EE; --grid: rgba(35, 42, 58, .08);
  color-scheme: dark;
} }
:root[data-theme="dark"] {
  --bg: #14171F; --panel: #1C202B; --card: #1C202B; --ink: #E8EAEF; --ink-soft: #C9CEDA; --muted: #A2A9B8; --line: #2A303E;
  --accent: #7C93F5; --accent-ink: #14171F; --accent-soft: #1A2340; --accent-deep: #B9C6FF; --tinte: #8FA3E8; --danger: #F0A496;
  --stage: #181C25; --paper: #F7F4EE; --grid: rgba(35, 42, 58, .08);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-ui); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wordmark { font-family: var(--font-mark); font-weight: 400; letter-spacing: -.012em; line-height: 1; white-space: nowrap; }
.wordmark i { font-style: italic; }

/* Werkzeug-Gerüst */
.app { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); }
header.top { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; padding: 10px 16px; }
.home { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; padding: 6px 8px 6px 4px; border-radius: 3px; min-height: 38px; }
.home:hover { background: var(--panel); }
.home svg { width: 18px; height: 18px; color: var(--muted); }
.home .wordmark { font-size: 21px; }
.top-sep { width: 1px; height: 28px; background: var(--line); flex: none; }
.app-pill { display: inline-flex; align-items: center; gap: 8px; background: var(--accent-soft); color: var(--accent-deep); font-size: 13.5px; padding: 6px 14px; border-radius: 999px; white-space: nowrap; }
.app-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.doc-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; background: transparent; font-family: var(--font-mark); font-size: 18px; padding: 6px 8px; border-radius: 3px; max-width: min(360px, 50vw); }
.doc-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-btn svg { width: 14px; height: 14px; color: var(--muted); flex: none; }
.doc-btn:hover { border-color: var(--line); }
.spacer { flex: 1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); border-radius: 3px; padding: 8px 12px; font-size: 13.5px; min-height: 38px; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.icon { padding: 8px 9px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 500; }
.btn.primary:hover:not(:disabled) { background: var(--accent-deep); border-color: var(--accent-deep); }
.btn.outline { background: transparent; border-color: var(--accent); color: var(--accent); font-weight: 500; }
.btn.danger { color: var(--danger); }
.btn.confirm { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-deep); border-color: var(--accent); }
.btn-group { display: flex; }
.btn-group .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.btn-group .btn + .btn { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }

main.work { display: grid; grid-template-columns: 96px minmax(0, 1fr) 290px; gap: 10px; min-height: 0; padding: 0 16px 12px; }
.rail { background: var(--panel); border-radius: 6px; padding: 8px 7px; display: flex; flex-direction: column; gap: 5px; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }
.rail h2 { margin: 6px 2px 2px; font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 500; text-align: center; }
.tile { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 5px; padding: 6px 2px 5px; color: var(--ink); touch-action: none; user-select: none; -webkit-user-select: none; }
.tile:hover { border-color: var(--accent); }
.tile[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-deep); }
.tile svg { width: 30px; height: 30px; pointer-events: none; }
.tile span { font-size: 11px; line-height: 1.15; text-align: center; pointer-events: none; }
.rail-sep { height: 1px; background: var(--line); margin: 5px 6px; flex: none; }

.stage { position: relative; min-width: 0; min-height: 0; border-radius: 6px; overflow: hidden; background: var(--stage); border: 1px solid var(--line); }
.stage svg.world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.viewbar { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; z-index: 3; }
.chip { position: absolute; left: 12px; bottom: 12px; max-width: calc(100% - 24px); background: var(--card); border: 1px solid var(--line); font-size: 12.5px; border-radius: 999px; padding: 5px 12px; pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; z-index: 3; }
.chip.act { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-deep); }
.toast { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 6; background: var(--ink); color: var(--bg); border-radius: 999px; padding: 6px 14px; font-size: 13px; pointer-events: none; white-space: nowrap; max-width: calc(100% - 24px); overflow: hidden; text-overflow: ellipsis; }

aside.side { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow: auto; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.panel h2, .sub-h { margin: 0; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.kind { margin: 0; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 500; }
.empty, .note { margin: 0; color: var(--muted); font-size: 12.5px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .lbl { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .text-input { flex: 1; min-width: 0; }
.text-input, textarea.text-input { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 3px; padding: 7px 10px; min-height: 38px; }
textarea.text-input { min-height: 84px; resize: vertical; line-height: 1.45; }
.chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.chips.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.chips button { border: 1px solid var(--line); background: var(--card); border-radius: 3px; padding: 6px 4px; font-size: 12px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 34px; justify-content: center; }
.chips button svg { width: 34px; height: 18px; }
.chips button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-deep); border-color: var(--accent); font-weight: 500; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); padding: 0; position: relative; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--accent); }
.switch { display: flex; align-items: center; gap: 10px; font-size: 13.5px; cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 38px; height: 22px; border-radius: 999px; background: var(--line); position: relative; margin: 0; cursor: pointer; flex: none; transition: background .15s; }
.switch input::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.legend { display: grid; gap: 6px; font-size: 12.5px; color: var(--ink-soft); }
.legend div { display: flex; align-items: center; gap: 8px; }
.legend svg { width: 40px; height: 18px; flex: none; }
.keys { margin: 0; padding: 0; list-style: none; display: grid; gap: 5px; color: var(--muted); font-size: 12.5px; }
.keys kbd { font-family: var(--font-ui); font-size: 11.5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--ink); background: var(--bg); }

/* Dialoge */
.shot { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(20, 23, 31, .55); padding: 16px; }
.dlg { background: var(--card); border-radius: 6px; padding: 18px; display: flex; flex-direction: column; gap: 14px; width: min(760px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dlg-head h2 { margin: 0; font-family: var(--font-mark); font-weight: 400; font-size: 24px; letter-spacing: -.012em; }
.exp-prev { background: var(--panel); border-radius: 4px; display: grid; place-items: center; padding: 10px; min-height: 160px; }
.exp-prev img { max-width: 100%; max-height: 46vh; display: block; box-shadow: 0 1px 4px rgba(35,42,58,.12); }
.doc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.doc-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px; }
.doc-item.current { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.doc-open { border: 0; background: transparent; text-align: left; padding: 0; min-width: 0; display: flex; flex-direction: column; }
.doc-open b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-open small { color: var(--muted); font-size: 12px; }

@media (max-width: 1100px) { .top-sep, .app-pill { display: none; } main.work { grid-template-columns: 84px minmax(0, 1fr) 260px; } }
@media (max-width: 820px) {
  html, body { height: auto; }
  .app { display: block; }
  main.work { display: flex; flex-direction: column; }
  .stage { order: -1; aspect-ratio: 4 / 3; }
  .rail { flex-direction: row; flex-wrap: wrap; }
  .rail .tile { width: 72px; }
  .rail h2, .rail-sep { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Leiste „Vorlage bearbeiten“ */
.tplbar { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 30; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; max-width: calc(100vw - 32px); background: var(--card); border: 1px solid var(--accent); border-radius: 6px; box-shadow: 0 10px 30px rgba(20, 23, 31, .18); padding: 10px 12px 10px 16px; font-size: 14px; }
.tplbar[hidden] { display: none; }
.tplbar .tb-txt { color: var(--ink-soft); min-width: 0; }
.tplbar b { color: var(--accent-deep); font-weight: 500; }

/* Klient:innen-Fenster: nur die Arbeitsfläche, nichts bearbeitbar */
body.klient header.top, body.klient .rail, body.klient aside.side, body.klient .viewbar, body.klient .chip, body.klient .tplbar { display: none !important; }
body.klient .app { grid-template-rows: minmax(0, 1fr); }
body.klient main.work { grid-template-columns: minmax(0, 1fr) !important; padding: 0; }
body.klient .stage { border-radius: 0; border: 0; }
body.klient .stage svg.world { pointer-events: none; }

/* Links in Knopf-Optik */
a.btn { text-decoration: none; color: var(--ink); }
a.btn.primary { color: var(--accent-ink); }

/* 2D-Methoden im Dunkelmodus: Fläche dunkel, Schrift und Linien hell. Zettel, Karten und Sprechblasen bleiben Papier; Export bleibt hell. */
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) svg.world #bg [fill="#FBF8F3"] { fill: var(--stage); }
:root:not([data-theme="light"]) svg.world #bg text[fill="#232A3A"] { fill: #ECEEF2; }
:root:not([data-theme="light"]) svg.world #bg text[fill="#61697B"], :root:not([data-theme="light"]) svg.world #bg text[fill="#8A8F9C"], :root:not([data-theme="light"]) svg.world #bg text[fill="#8A7A62"] { fill: #A9B0BE; }
:root:not([data-theme="light"]) svg.world #bg text[fill="#3A4256"] { fill: #C9CEDA; }
:root:not([data-theme="light"]) svg.world #bg [fill="#F3ECE0"] { fill: #232733; }
:root:not([data-theme="light"]) svg.world #bg [fill="#EFE6D6"] { fill: #282C38; }
:root:not([data-theme="light"]) svg.world #bg [fill="#EADFCB"] { fill: #2E323E; }
:root:not([data-theme="light"]) svg.world #bg [stroke="#DDD0B8"] { stroke: #474D5C; }
:root:not([data-theme="light"]) svg.world #bg [fill="#F2EADC"] { fill: #252935; }
:root:not([data-theme="light"]) svg.world #bg [stroke="#E2D5BF"] { stroke: #3F4452; }
:root:not([data-theme="light"]) svg.world #bg [stroke="#B9A88C"] { stroke: #707789; }
:root:not([data-theme="light"]) svg.world #bg [fill="#16265C"] { fill: #3A55C8; }
:root:not([data-theme="light"]) svg.world #bg [fill="#EEF4EC"] { fill: #1D2823; }
:root:not([data-theme="light"]) svg.world #bg [fill="#F8ECE9"] { fill: #2B2124; }
:root:not([data-theme="light"]) svg.world #bg [stroke="#232A3A"] { stroke: #C9CEDA; }
:root:not([data-theme="light"]) svg.world #bg path[fill="#232A3A"] { fill: #C9CEDA; }
:root:not([data-theme="light"]) svg.world #bg [stroke="#16265C"] { stroke: #8FA3E8; }
:root:not([data-theme="light"]) svg.world #bg text[fill="#2F5D33"] { fill: #79C985; }
:root:not([data-theme="light"]) svg.world #bg text[fill="#80281D"] { fill: #F0806F; }
:root:not([data-theme="light"]) svg.world #bg [fill="#E9DBC0"] { fill: #3A3128; }
:root:not([data-theme="light"]) svg.world #bg [fill="#F1E6D1"] { fill: #433A2F; }
:root:not([data-theme="light"]) svg.world #lay-items text[stroke="#FFFFFF"] { fill: #ECEEF2; stroke: var(--stage); }
}
:root[data-theme="dark"] svg.world #bg [fill="#FBF8F3"] { fill: var(--stage); }
:root[data-theme="dark"] svg.world #bg text[fill="#232A3A"] { fill: #ECEEF2; }
:root[data-theme="dark"] svg.world #bg text[fill="#61697B"], :root[data-theme="dark"] svg.world #bg text[fill="#8A8F9C"], :root[data-theme="dark"] svg.world #bg text[fill="#8A7A62"] { fill: #A9B0BE; }
:root[data-theme="dark"] svg.world #bg text[fill="#3A4256"] { fill: #C9CEDA; }
:root[data-theme="dark"] svg.world #bg [fill="#F3ECE0"] { fill: #232733; }
:root[data-theme="dark"] svg.world #bg [fill="#EFE6D6"] { fill: #282C38; }
:root[data-theme="dark"] svg.world #bg [fill="#EADFCB"] { fill: #2E323E; }
:root[data-theme="dark"] svg.world #bg [stroke="#DDD0B8"] { stroke: #474D5C; }
:root[data-theme="dark"] svg.world #bg [fill="#F2EADC"] { fill: #252935; }
:root[data-theme="dark"] svg.world #bg [stroke="#E2D5BF"] { stroke: #3F4452; }
:root[data-theme="dark"] svg.world #bg [stroke="#B9A88C"] { stroke: #707789; }
:root[data-theme="dark"] svg.world #bg [fill="#16265C"] { fill: #3A55C8; }
:root[data-theme="dark"] svg.world #bg [fill="#EEF4EC"] { fill: #1D2823; }
:root[data-theme="dark"] svg.world #bg [fill="#F8ECE9"] { fill: #2B2124; }
:root[data-theme="dark"] svg.world #bg [stroke="#232A3A"] { stroke: #C9CEDA; }
:root[data-theme="dark"] svg.world #bg path[fill="#232A3A"] { fill: #C9CEDA; }
:root[data-theme="dark"] svg.world #bg [stroke="#16265C"] { stroke: #8FA3E8; }
:root[data-theme="dark"] svg.world #bg text[fill="#2F5D33"] { fill: #79C985; }
:root[data-theme="dark"] svg.world #bg text[fill="#80281D"] { fill: #F0806F; }
:root[data-theme="dark"] svg.world #bg [fill="#E9DBC0"] { fill: #3A3128; }
:root[data-theme="dark"] svg.world #bg [fill="#F1E6D1"] { fill: #433A2F; }
:root[data-theme="dark"] svg.world #lay-items text[stroke="#FFFFFF"] { fill: #ECEEF2; stroke: var(--stage); }

/* Zwei Dokumente übereinander (Zeitstrahl) */
.pz-leg { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; }
.pz-leg span { display: flex; align-items: center; gap: 8px; }
.pz-leg i { width: 22px; height: 4px; border-radius: 2px; flex: none; }
.pz-leg small { color: var(--muted); font-size: 12px; }
.pz-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.pz-seg button { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 3px; padding: 6px 8px; font-size: 13px; cursor: pointer; min-height: 34px; }
.pz-seg button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-deep); }

/* Mehrere Lebenslinien (Zeitstrahl) */
.ln-list { list-style: none; margin: -4px 0 0; padding: 0; display: grid; gap: 4px; }
.ln-row { display: grid; grid-template-columns: auto 18px minmax(0, 1fr) 30px; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 4px; padding: 3px 4px 3px 8px; }
.ln-row.focus { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.ln-row input { margin: 0; accent-color: var(--accent); }
.ln-row i { width: 18px; height: 4px; border-radius: 2px; }
.ln-name { border: 0; background: transparent; text-align: left; padding: 5px 0; font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ln-name:disabled { color: var(--muted); cursor: default; }
.ln-name small { color: var(--muted); font-size: 11px; }
.ln-open { border: 1px solid var(--line); background: var(--card); border-radius: 3px; width: 28px; height: 28px; padding: 0; color: var(--ink-soft); }
.ln-open:hover { border-color: var(--accent); }
