/* Layout: schmale App-Leiste, darunter zwei Spalten. Links der Ablauf als Zeitleiste (jeder Schritt sitzt mit seinem EPK-Symbol auf einer Linie),
   rechts die Zeichenflaeche mit Darstellung, Zoom und Export. Am Handy untereinander, Diagramm zuerst. */
:root {
  --bg: #f4f3f0;
  --surface: #ffffff;
  --sunken: #f7f6f3;
  --ink: #16161d;
  --ink-2: #3a3a46;
  --muted: #6c6b78;
  --line: #e3e1db;
  --line-strong: #cfccc4;
  --primary: #16161d;
  --primary-ink: #ffffff;
  --accent: #b8338c;
  --accent-soft: #f7e3f0;
  --focus: #b8338c;
  --ev: #b8338c;
  --ev-fill: #e9a6dc;
  --fn: #23874a;
  --fn-fill: #95d8a6;
  --org: #b08400;
  --info: #2f6fc4;
  --danger: #c0352b;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(22, 22, 29, .05);
  --shadow: 0 1px 2px rgba(22, 22, 29, .04), 0 8px 24px -8px rgba(22, 22, 29, .12);
  --ui: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f13; --surface: #17171d; --sunken: #121217; --ink: #f1f0ec; --ink-2: #cfcdd6; --muted: #9a98a6;
    --line: #26262f; --line-strong: #34343f; --primary: #f1f0ec; --primary-ink: #0f0f13;
    --accent: #ef8fd4; --accent-soft: #3a1c31; --focus: #ef8fd4;
    --ev: #ef8fd4; --fn: #74d69a; --org: #f2cf55; --info: #8ab8ff; --danger: #ff8f84;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 30px -10px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--ui); font-size: 15px; line-height: 1.45; min-height: 100vh; display: flex; flex-direction: column; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
svg.i { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* App-Leiste */
.appbar { background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); padding: calc(env(safe-area-inset-top, 0px) + 12px) 20px 12px; position: sticky; top: 0; z-index: 20; }
.appbar-inner { max-width: 1480px; margin: 0 auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: inherit; margin-right: auto; }
.brand svg { width: 36px; height: 36px; flex: none; }
.brand b { display: block; font-size: 1.12rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.brand small { display: block; font-size: .78rem; color: var(--muted); letter-spacing: .01em; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface); padding: 9px 14px; font-size: .9rem; font-weight: 600; line-height: 1.15; letter-spacing: -.005em; box-shadow: var(--shadow-sm); }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { opacity: .88; }
.btn.quiet { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink-2); }
.btn.quiet:hover { background: var(--surface); border-color: var(--line); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }

/* Arbeitsbereich */
main { flex: 1; width: 100%; max-width: 1480px; margin: 0 auto; padding: 22px 20px 32px; display: grid; gap: 22px; grid-template-columns: minmax(0, 500px) minmax(0, 1fr); align-items: start; }
@media (max-width: 980px) { main { grid-template-columns: minmax(0, 1fr); padding-inline: 14px; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.panel-head { padding: 18px 20px 14px; display: grid; gap: 6px; }
.eyebrow { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--accent); }
.panel-head h2 { margin: 0; font-size: 1.35rem; font-weight: 700; letter-spacing: -.025em; line-height: 1.15; text-wrap: balance; }
.panel-head p { margin: 0; color: var(--muted); font-size: .88rem; max-width: 60ch; }
.panel-head kbd { font-family: inherit; font-size: .8rem; background: var(--sunken); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }
.panel-body { padding: 4px 20px 18px; }
.panel-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--sunken); border-radius: 0 0 var(--radius) var(--radius); }

/* Ablauf als Zeitleiste */
.seq { position: relative; display: grid; gap: 10px; min-width: 0; padding-left: 30px; }
.seq::before { content: ""; position: absolute; left: 10px; top: 20px; bottom: 20px; width: 2px; border-radius: 2px; background: var(--line-strong); }
.item { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 8px 8px 10px; display: grid; gap: 7px; min-width: 0; box-shadow: var(--shadow-sm); }
.item:focus-within { border-color: var(--line-strong); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 10%, transparent); }
.row { display: flex; gap: 4px; align-items: center; min-width: 0; }
/* Der Typ steht als Symbol auf der Zeitleiste, der Text dient nur Screenreadern */
.badge { flex: none; width: 0; height: 0; overflow: visible; font-size: 0; color: transparent; }
.badge::before { content: ""; position: absolute; left: -33px; top: 19px; width: 22px; height: 14px; box-shadow: 0 0 0 4px var(--surface); }
.item.e { border-left: 3px solid var(--ev); }
.item.f { border-left: 3px solid var(--fn); }
.item.e > .row .badge { color: var(--ev); }
.item.e > .row .badge::before { background: var(--ev-fill); clip-path: polygon(24% 0, 76% 0, 100% 50%, 76% 100%, 24% 100%, 0 50%); box-shadow: none; outline: 0; }
.item.f > .row .badge { color: var(--fn); }
.item.f > .row .badge::before { background: var(--fn-fill); border-radius: 4px; border: 1.5px solid var(--fn); box-shadow: 0 0 0 3px var(--surface); }
.item.s > .row .badge::before { width: 16px; height: 16px; left: -30px; top: 18px; border-radius: 50%; background: var(--surface); border: 2px solid var(--ink-2); box-shadow: 0 0 0 3px var(--surface); }
input[type="text"], select { background: var(--sunken); border: 1px solid transparent; border-radius: 9px; padding: 8px 10px; min-width: 0; width: 100%; transition: border-color .12s, background-color .12s; }
input[type="text"]:hover, select:hover { border-color: var(--line); }
input[type="text"]::placeholder { color: var(--muted); opacity: .85; }
input[type="text"]:focus, select:focus { border-color: var(--accent); background: var(--surface); outline: none; }
.row > input[type="text"] { font-weight: 500; }
.extra { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding-right: 4px; }
.extra input { font-size: .84rem; padding: 6px 9px 6px 26px; background-repeat: no-repeat; background-position: 9px 50%; background-size: 11px 8px; }
.extra input:first-child { background-image: radial-gradient(ellipse at center, var(--org) 62%, transparent 66%); }
.extra input:last-child { background-image: linear-gradient(var(--info), var(--info)); }
@media (max-width: 560px) { .extra { padding: 0; grid-template-columns: 1fr; } }
.ic { flex: none; width: 34px; height: 34px; padding: 0; display: grid; place-items: center; cursor: pointer; border-radius: 9px; border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 1rem; line-height: 1; }
.ic:hover { background: var(--sunken); color: var(--ink); }
.ic.del:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.adds { display: flex; flex-wrap: wrap; gap: 6px; position: relative; }
.adds::before { content: ""; position: absolute; left: -24px; top: 50%; width: 10px; height: 10px; margin-top: -5px; border-radius: 50%; border: 2px dashed var(--line-strong); background: var(--surface); }
.adds button { cursor: pointer; border: 1px dashed var(--line-strong); background: transparent; border-radius: 9px; font-size: .82rem; padding: 6px 11px; font-weight: 600; color: var(--ink-2); }
.adds button:hover { border-style: solid; background: var(--surface); }
.adds .ae:hover { color: var(--ev); border-color: var(--ev); } .adds .af:hover { color: var(--fn); border-color: var(--fn); }
.opsel { width: auto !important; flex: 1; font-weight: 600; }
.branches { display: grid; gap: 10px; }
.branch { border: 1px solid var(--line); border-radius: 11px; padding: 10px 10px 12px 6px; display: grid; gap: 8px; background: var(--sunken); min-width: 0; }
.branch .item { box-shadow: none; }
.branch .badge::before, .branch .item.f > .row .badge::before, .branch .item.s > .row .badge::before { box-shadow: 0 0 0 3px var(--surface); }
.bhead { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; font-size: .84rem; padding-left: 8px; }
.bhead strong { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-2); }
.bhead label { display: inline-flex; gap: 7px; align-items: center; color: var(--muted); cursor: pointer; font-weight: 500; }
.bhead input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.addbranch { justify-self: start; cursor: pointer; border: 1px dashed var(--line-strong); background: transparent; border-radius: 9px; font-size: .82rem; padding: 6px 11px; font-weight: 600; color: var(--ink-2); }
.addbranch:hover { border-style: solid; }

/* Zeichenflaeche */
.stage { position: sticky; top: 84px; display: flex; flex-direction: column; max-height: calc(100vh - 106px); }
@media (max-width: 980px) { .stage { position: static; order: -1; max-height: none; } }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.tgroup { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--sunken); border: 1px solid var(--line); }
.seg button { cursor: pointer; border: 0; background: transparent; padding: 6px 11px; font-size: .82rem; font-weight: 600; border-radius: 7px; color: var(--muted); }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 1px var(--line); }
.zoom { display: inline-flex; align-items: center; gap: 2px; padding: 3px; border-radius: 10px; background: var(--sunken); border: 1px solid var(--line); }
.zoom button { cursor: pointer; border: 0; background: transparent; width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; color: var(--ink-2); }
.zoom button:hover { background: var(--surface); }
.zoom output { min-width: 50px; text-align: center; font-size: .82rem; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.spacer { flex: 1; }
.canvas-scroll { flex: 1; min-height: 0; overflow: auto; padding: 18px; background-color: var(--sunken); background-image: radial-gradient(color-mix(in srgb, var(--muted) 30%, transparent) 1px, transparent 1.2px); background-size: 20px 20px; }
@media (max-width: 980px) { .canvas-scroll { max-height: 72vh; } }
.canvas-wrap { position: relative; height: 480px; margin: 0 auto; border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); }
canvas { display: block; width: 100%; height: 100%; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; text-align: center; padding: 24px; color: var(--muted); }
.empty svg { width: 64px; height: 64px; opacity: .8; }
.empty b { color: var(--ink); font-size: 1.05rem; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 12px 16px; border-top: 1px solid var(--line); font-size: .8rem; color: var(--muted); background: var(--surface); border-radius: 0 0 var(--radius) var(--radius); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend svg { width: 24px; height: 15px; flex: none; }
#status { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 22px); transform: translateX(-50%); background: var(--primary); color: var(--primary-ink); padding: 11px 18px; border-radius: 12px; font-size: .9rem; font-weight: 600; box-shadow: var(--shadow); z-index: 30; max-width: calc(100% - 32px); margin: 0; }
#status:empty { display: none; }

/* Fuss */
footer { padding: 18px 20px calc(env(safe-area-inset-bottom, 0px) + 18px); color: var(--muted); font-size: .8rem; }
footer div { max-width: 1480px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 16px; }
footer svg { vertical-align: -3px; margin-right: 4px; }
footer a { color: inherit; text-underline-offset: 3px; }
footer a:hover { color: var(--accent); }

/* Bild-Fenster */
.overlay { position: fixed; inset: 0; background: rgba(10, 10, 14, .7); display: grid; place-items: center; padding: 16px; z-index: 40; }
.overlay .box { background: var(--surface); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; max-width: min(960px, 100%); max-height: 100%; overflow: auto; }
.overlay img { max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; }
.overlay p { margin: 0; }
/* Handy */
.show-sm, .mobnav { display: none; }
@media (max-width: 980px) {
  body { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 76px); }
  .mobnav { display: flex; position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 10px); z-index: 25; padding: 5px; gap: 4px; border-radius: 16px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid var(--line); box-shadow: var(--shadow); }
  .mobnav button { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; background: transparent; padding: 12px; border-radius: 12px; font-weight: 600; color: var(--muted); cursor: pointer; }
  .mobnav button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }
  body[data-view="edit"] #viewPanel, body[data-view="view"] #editPanel { display: none; }
  .stage { order: 0; }
  #status { bottom: calc(env(safe-area-inset-bottom, 0px) + 84px); }
  .canvas-scroll { max-height: none; height: calc(100dvh - 330px); min-height: 320px; }
}
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .show-sm { display: inline; }
  .appbar { position: static; padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px; }
  .brand small { display: none; }
  .appbar-inner { flex-wrap: nowrap; gap: 6px; }
  .brand { min-width: 0; }
  .brand b { font-size: 1.02rem; white-space: nowrap; }
  .brand svg { width: 32px; height: 32px; }
  .btn { padding: 8px 11px; }
  main { padding: 12px 10px 20px; gap: 12px; }
  .panel-head { padding: 16px 14px 12px; }
  .panel-head h2 { font-size: 1.15rem; }
  .panel-body { padding: 4px 10px 14px 8px; }
  .panel-foot { padding: 12px 14px; }
  /* Eingabefeld bekommt die ganze Breite, die Knoepfe rutschen klein darunter */
  .row { flex-wrap: wrap; row-gap: 2px; }
  .row > input[type="text"], .row > select { flex: 1 1 100%; }
  .row > .ic { width: 34px; height: 30px; }
  .row > .ic:first-of-type { margin-left: auto; }
  .row > .badge + input + .ic, .row > .badge + select + .ic { margin-left: auto; }
  /* weniger Einrueckung bei verschachtelten Wegen */
  .seq { padding-left: 24px; gap: 8px; }
  .seq::before { left: 8px; }
  .badge::before { left: -27px; }
  .item.s > .row .badge::before { left: -24px; }
  .adds::before { left: -20px; }
  .item { padding: 7px; }
  .branch { padding: 8px 6px 10px 2px; }
  .bhead { padding-left: 6px; }
  .toolbar { padding: 10px; gap: 8px; }
  .tgroup { gap: 6px; }
  .seg button { padding: 6px 9px; }
  .canvas-scroll { padding: 10px; }
  .legend { gap: 6px 12px; padding: 10px 12px; }
}

@media (prefers-reduced-motion: no-preference) { .btn, .ic, .seg button, .adds button, .zoom button { transition: background-color .12s, border-color .12s, color .12s, opacity .12s; } }

/* Umschalter zwischen den Werkzeugen */
.pagenav { display: inline-flex; padding: 3px; gap: 2px; border-radius: 11px; background: var(--sunken); border: 1px solid var(--line); margin-right: auto; }
.pagenav a { padding: 7px 14px; border-radius: 8px; font-size: .88rem; font-weight: 600; color: var(--muted); text-decoration: none; white-space: nowrap; }
.pagenav a:hover { color: var(--ink); }
.pagenav a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 1px var(--line); }
.brand { margin-right: 6px; }
@media (max-width: 640px) {
  .brand b { display: none; }
  .pagenav a { padding: 6px 10px; font-size: .84rem; }
}
