/* Jupus Document Generator — Redesign Prototype
   Production-faithful light theme (matches app.jupus.de). */

:root {
  /* Real Jupus tokens (sampled from production) */
  --purple: #9333EA;
  --purple-dark: #7E22CE;
  --purple-soft: #F3E8FF;
  --purple-tint: #FAF5FF;
  --green: #0CA678;
  --green-soft: #E6FAF3;
  --yellow: #F59E0B;
  --yellow-soft: #FEF3C7;
  --yellow-hl: #FDE68A;
  --red: #DC2626;
  --red-soft: #FEE2E2;

  --bg: #FFFFFF;
  --bg-subtle: #FAFAFB;
  --bg-rail: #F9FAFB;
  --text: #0F1729;
  --text-dim: #4B5563;
  --text-faint: #9099A8;
  --hairline: #E5E7EB;
  --hairline-strong: #D1D5DB;

  --radius-btn: 6px;
  --radius-card: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, 0.12);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --font: -apple-system, system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg-subtle);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }

/* ============================================================
   Jupus app shell — top nav + case header
   ============================================================ */
.jupus-nav {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--hairline);
  display: flex; align-items: center; gap: 30px;
  padding: 0 24px; height: 56px;
}
.jupus-wordmark {
  font-weight: 800; font-size: 21px; letter-spacing: -0.03em;
  color: var(--text);
}
.jupus-wordmark .dot { color: var(--purple); }
.nav-links { display: flex; gap: 26px; }
.nav-links a {
  font-size: 14px; font-weight: 500; color: var(--text-dim);
  text-decoration: none; padding: 18px 0; position: relative;
}
.nav-links a.active { color: var(--text); }
.nav-links a.active::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px; background: var(--purple);
}
.nav-badge {
  font-size: 10px; font-weight: 700; color: #fff; background: var(--purple);
  padding: 2px 6px; border-radius: 4px; margin-left: 6px; vertical-align: middle;
  letter-spacing: 0.02em;
}
.nav-spacer { flex: 1; }
.nav-icons { display: flex; align-items: center; gap: 18px; color: var(--text-faint); }
.nav-icons .ico { width: 20px; height: 20px; cursor: default; }
.nav-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--purple); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
}

/* Case header */
.case-wrap { max-width: 1400px; margin: 0 auto; padding: 26px 32px 80px; }
.case-head { margin-bottom: 4px; display: flex; align-items: center; gap: 12px; }
.case-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.pill-neu {
  font-size: 11px; font-weight: 700; color: #fff; background: #111827;
  padding: 3px 9px; border-radius: 5px; letter-spacing: 0.04em;
}
.case-meta { font-size: 13px; color: var(--text-faint); margin-bottom: 18px; }
.case-tabs {
  display: flex; gap: 26px; border-bottom: 1px solid var(--hairline);
  margin-bottom: 28px;
}
.case-tabs a {
  font-size: 14px; font-weight: 500; color: var(--text-dim);
  text-decoration: none; padding: 12px 0; position: relative;
}
.case-tabs a.active { color: var(--purple); }
.case-tabs a.active::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px; background: var(--purple);
}

/* ============================================================
   Stepper (production-style numbered pills)
   ============================================================ */
.stepper {
  display: flex; align-items: center; gap: 10px; margin-bottom: 26px;
  position: sticky; top: 56px; z-index: 30;
  background: rgba(250,250,251,0.92); backdrop-filter: saturate(180%) blur(8px);
  margin-left: clamp(-20px, -4vw, -32px); margin-right: clamp(-20px, -4vw, -32px);
  padding: 14px clamp(20px, 4vw, 32px);
  border-bottom: 1px solid var(--hairline);
}
.step { display: flex; align-items: center; gap: 9px; font-size: 14px; color: var(--text-faint); font-weight: 500; }
.step .num {
  width: 24px; height: 24px; border-radius: var(--radius-card);
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
  background: #F3F4F6; color: var(--text-faint);
  transition: all 0.3s var(--ease);
}
.step.active { color: var(--text); }
.step.active .num { background: var(--purple); color: #fff; }
.step.done { color: var(--text-dim); }
.step.done .num { background: var(--green-soft); color: var(--green); }
.stepper .sep { width: 26px; height: 1px; background: var(--hairline-strong); }

/* ============================================================
   Flow router
   ============================================================ */
.flow { display: none; }
.flow.active { display: block; animation: flow-in 0.45s var(--ease); }
/* opacity-only so no leftover transform creates a containing block for fixed children */
@keyframes flow-in { from { opacity: 0; } to { opacity: 1; } }

.flow-head { margin-bottom: 22px; }
.eyebrow {
  font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--purple); margin-bottom: 8px;
}
.flow-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
.flow-head p.sub { margin-top: 8px; font-size: 14px; color: var(--text-dim); line-height: 1.5; max-width: 680px; }

/* Info banner (matches production's soft purple notice) */
.info-banner {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--purple-tint); border: 1px solid #EBD9FB;
  border-radius: var(--radius-card); padding: 13px 16px;
  font-size: 13px; color: var(--text-dim); line-height: 1.5; margin-bottom: 22px;
}
.info-banner .ib-icon { color: var(--purple); flex-shrink: 0; margin-top: 1px; }

/* ============================================================
   Cards / buttons
   ============================================================ */
.card {
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
}

.btn {
  font-family: inherit; font-size: 14px; font-weight: 500;
  padding: 9px 16px; border-radius: var(--radius-btn);
  border: 1px solid var(--hairline-strong);
  background: var(--bg); color: var(--text);
  cursor: pointer; transition: all 0.15s var(--ease);
  display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { background: #F9FAFB; border-color: var(--text-faint); }
.btn.primary { background: var(--purple); border-color: var(--purple); color: #fff; }
.btn.primary:hover { background: var(--purple-dark); border-color: var(--purple-dark); }
.btn.ghost { border-color: var(--hairline); color: var(--text-dim); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .ki-chip {
  font-size: 10px; font-weight: 700; color: #fff; background: var(--purple);
  padding: 2px 5px; border-radius: 4px; letter-spacing: 0.02em;
}

/* ============================================================
   FLOW 0 — Documents overview (entry point)
   ============================================================ */
/* Prominent "generate document" hero — the AI feature, front & centre */
.gen-hero {
  border: 1px solid #E2CFFB;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #FAF5FF 0%, #F3E8FF 100%);
  box-shadow: 0 6px 28px rgba(147, 51, 234, 0.12);
  padding: 26px 28px;
  margin-bottom: 22px;
}
.gen-hero-main { display: flex; align-items: center; gap: 20px; }
.gen-hero-icon {
  width: 52px; height: 52px; flex-shrink: 0; border-radius: 14px;
  background: linear-gradient(135deg, var(--purple) 0%, #5b47cc 100%);
  display: grid; place-items: center; font-size: 24px;
  box-shadow: 0 6px 18px rgba(147, 51, 234, 0.35);
}
.gen-hero-text { flex: 1; }
.gen-hero-title { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }
.gen-hero-sub { font-size: 14px; color: var(--text-dim); margin-top: 4px; line-height: 1.45; max-width: 560px; }
.gen-hero-btn { font-size: 15px; padding: 12px 22px; flex-shrink: 0; box-shadow: 0 8px 24px rgba(147,51,234,0.3); }
.gen-hero-foot {
  margin-top: 18px; padding-top: 16px; border-top: 1px solid rgba(147,51,234,0.18);
  font-size: 13px; color: var(--purple-dark);
}
.gen-context { display: inline-flex; align-items: center; gap: 8px; }
.gen-context .gc-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.gen-context b { font-weight: 600; }

/* Documents list (secondary on this screen) */
.docs-card { padding: 0; overflow: hidden; }
.docs-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--hairline);
}
.docs-card-title { font-size: 14px; font-weight: 600; color: var(--text); }
.docs-secondary { display: flex; gap: 8px; }
.docs-table { width: 100%; border-collapse: collapse; }
.docs-table th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-faint);
  padding: 12px 20px; border-bottom: 1px solid var(--hairline);
}
.docs-table td { padding: 14px 20px; border-bottom: 1px solid var(--hairline); font-size: 14px; vertical-align: middle; }
.docs-table tr:last-child td { border-bottom: none; }
.docs-table tr:hover td { background: var(--bg-rail); }
.dt-name { display: flex; align-items: center; gap: 10px; color: var(--text); font-family: 'JetBrains Mono', monospace; font-size: 13px; }
.dt-thumb {
  width: 30px; height: 30px; border-radius: 6px; background: var(--bg-rail);
  border: 1px solid var(--hairline); display: grid; place-items: center; font-size: 14px; flex-shrink: 0;
}
.dt-date { color: var(--text-faint); font-size: 13px; }
.src-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; padding: 4px 10px; border-radius: 6px;
}
.src-pill.src-green { background: var(--green-soft); color: var(--green); }
.src-pill.src-grey { background: #F3F4F6; color: var(--text-dim); }
.src-pill.src-amber { background: var(--yellow-soft); color: #92400E; }

/* ============================================================
   FLOW 1 — Template selection
   ============================================================ */
.f1-layout { display: grid; grid-template-columns: 380px 1fr; gap: 22px; align-items: start; }
.f1-left { display: flex; flex-direction: column; gap: 14px; }
.f1-preview { position: sticky; top: 120px; }

.context-card { padding: 20px; }
.context-card .ctx-title {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-faint); margin-bottom: 14px;
}
.ctx-row { padding: 11px 0; border-bottom: 1px solid var(--hairline); }
.ctx-row:last-child { border-bottom: none; }
.ctx-row .k { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 3px; }
.ctx-row .v { font-size: 14px; color: var(--text); font-weight: 500; }
.ctx-row .v.accent { color: var(--purple); }

.template-list { display: flex; flex-direction: column; gap: 10px; }
.tpl {
  position: relative; padding: 18px 20px;
  border: 1px solid var(--hairline); border-radius: var(--radius-card);
  background: var(--bg); cursor: pointer; transition: all 0.2s var(--ease);
}
.tpl:hover:not(.disabled):not(.selected) { border-color: var(--hairline-strong); box-shadow: var(--shadow-sm); }
.tpl.disabled { opacity: 0.55; cursor: not-allowed; background: var(--bg-rail); }
.tpl.recommended { border-color: #E2CFFB; background: var(--purple-tint); }
.tpl.selected { border-color: var(--purple); box-shadow: 0 0 0 1px var(--purple), var(--shadow-md); }
.tpl .tpl-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; padding-right: 34px; }
.tpl .tpl-name { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.tpl .badge-rec {
  font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: #fff; background: var(--purple); padding: 3px 8px; border-radius: 5px;
}
.tpl .badge-jupus {
  font-size: 11px; font-weight: 500; color: var(--purple-dark);
  background: var(--purple-soft); padding: 2px 8px; border-radius: 5px;
}
.tpl .tpl-why { font-size: 13px; color: var(--purple-dark); display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.tpl .tpl-why::before { content: '✓'; font-weight: 700; }
.tpl .tpl-desc { font-size: 13px; color: var(--text-faint); margin-top: 5px; line-height: 1.45; }
.tpl .tpl-check {
  position: absolute; top: 18px; right: 20px;
  width: 20px; height: 20px; border-radius: 50%;
  border: 1.5px solid var(--hairline-strong);
  display: grid; place-items: center; font-size: 12px; color: transparent;
  transition: all 0.2s var(--ease);
}
.tpl.selected .tpl-check { background: var(--purple); border-color: var(--purple); color: #fff; }

.f1-footer { margin-top: 20px; display: flex; justify-content: flex-end; grid-column: 1 / -1; }

/* ============================================================
   FLOW 2 — Generation + traffic light
   ============================================================ */
.f2-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 22px; align-items: start; }

/* Loading (progressive disclosure) */
.loader { padding: 28px 26px; }
.loader h3 { font-size: 15px; font-weight: 600; margin-bottom: 20px; color: var(--text); }
.load-doc {
  display: flex; align-items: center; gap: 13px; padding: 13px 0;
  border-bottom: 1px solid var(--hairline); opacity: 0.4;
  transition: opacity 0.4s var(--ease);
}
.load-doc:last-of-type { border-bottom: none; }
.load-doc.activeLoad { opacity: 1; }
.load-doc.complete { opacity: 1; }
.load-doc .ld-icon {
  width: 34px; height: 34px; border-radius: var(--radius-btn);
  background: var(--purple-soft); display: grid; place-items: center; font-size: 15px; flex-shrink: 0;
}
.load-doc .ld-name { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--text); }
.load-doc .ld-status { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.load-doc.complete .ld-status { color: var(--green); }
.load-doc .ld-spinner {
  margin-left: auto; width: 16px; height: 16px;
  border: 2px solid var(--hairline-strong); border-top-color: var(--purple);
  border-radius: 50%; animation: spin 0.7s linear infinite; opacity: 0;
}
.load-doc.activeLoad .ld-spinner { opacity: 1; }
.load-doc.complete .ld-spinner { display: none; }
.load-doc .ld-check { margin-left: auto; color: var(--green); font-size: 17px; opacity: 0; }
.load-doc.complete .ld-check { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }
.load-final {
  margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--hairline-strong);
  font-size: 13px; color: var(--purple-dark); display: flex; align-items: center; gap: 8px;
  opacity: 0; transition: opacity 0.4s var(--ease);
}
.load-final.show { opacity: 1; }

/* Field list */
.fields-panel { padding: 20px 22px; }
.fields-panel .fp-title {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-faint); margin-bottom: 3px;
}
.fields-panel .fp-sub { font-size: 12px; color: var(--text-faint); margin-bottom: 16px; }
.field {
  display: grid; grid-template-columns: 1fr 116px; gap: 4px 14px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--hairline);
}
.field:last-of-type { border-bottom: none; }
.field .f-label { font-size: 13px; color: var(--text-dim); }
.field .f-value {
  font-size: 14px; font-weight: 600; color: var(--text);
  font-family: 'JetBrains Mono', monospace; grid-row: 2;
  border-radius: 5px; padding: 2px 6px; margin: -2px -6px;
  border: 1px solid transparent; outline: none;
  transition: border-color 0.15s, background 0.15s;
  min-width: 40px;
}
.field .f-value:hover { border-color: var(--hairline); background: var(--bg-rail); }
.field .f-value:focus { border-color: var(--purple); background: #fff; box-shadow: 0 0 0 3px rgba(147,51,234,0.12); }
.field .f-formula { font-size: 11px; color: var(--text-faint); grid-row: 3; grid-column: 1 / -1; font-family: 'JetBrains Mono', monospace; margin-top: 3px; }
.field .status {
  grid-column: 2; grid-row: 1 / 3; align-self: center; justify-self: stretch;
  justify-content: center;
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500;
  padding: 5px 10px; border-radius: 7px; white-space: nowrap; border: 1px solid transparent;
  width: 116px; /* equal length across all status badges */
}
.status .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.status.green  { color: var(--green); background: var(--green-soft); }
.status.red    { color: var(--red); background: var(--red-soft); }
.status .dot.green { background: var(--green); }
.status .dot.yellow { background: var(--yellow); }
.status .dot.red { background: var(--red); }

/* "Bitte prüfen" is an actionable button — make it clearly clickable
   vs. the passive "Geprüft" badge: stronger fill, border, pointer + caret. */
.status.yellow {
  color: #92400E; background: var(--yellow-soft);
  border-color: #FCD34D; cursor: pointer; font-weight: 600;
}
.status.yellow.clickable::after {
  content: '›'; font-size: 14px; line-height: 1; margin-left: 1px;
  transition: transform 0.15s var(--ease);
}
.status.yellow:hover {
  background: var(--yellow-hl); border-color: var(--yellow);
  box-shadow: 0 1px 3px rgba(245, 158, 11, 0.25);
}
.status.yellow:hover.clickable::after { transform: translateX(2px); }
.status.yellow:focus-visible { outline: 2px solid var(--yellow); outline-offset: 1px; }
.field.flip { animation: flip-green 0.55s var(--ease); }
@keyframes flip-green { 0% { background: var(--green-soft); } 100% { background: transparent; } }
.fields-foot {
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--hairline);
  font-size: 13px; font-style: italic; color: var(--purple-dark); line-height: 1.4;
}

/* Document preview (the letter) */
.doc-preview { padding: 0; overflow: hidden; position: sticky; top: 120px; }
.doc-toolbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 18px;
  border-bottom: 1px solid var(--hairline); font-size: 12px; color: var(--text-faint);
  background: var(--bg-rail);
}
.doc-toolbar .legend { display: inline-flex; align-items: center; gap: 6px; }
.doc-toolbar .legend .sw { width: 11px; height: 11px; border-radius: 3px; }
.doc-toolbar .legend .sw.filled { background: #C6F0E0; }
.doc-toolbar .legend .sw.open { background: var(--purple-soft); }
.doc-paper {
  background: #fff; color: #1a1a2e;
  font-family: 'Georgia', 'Times New Roman', serif; font-size: 14px; line-height: 1.7;
  padding: 34px 38px; max-height: 540px; overflow-y: auto;
}
.doc-paper h4 { font-size: 16px; margin-bottom: 14px; font-family: 'Georgia', serif; }
.doc-paper p { margin-bottom: 12px; }
.doc-paper .addr { color: #1a1a2e; margin-bottom: 36px; line-height: 1.5; }
/* right-aligned place + date, like the real letter */
.doc-paper .doc-date { text-align: right; margin-bottom: 28px; }
/* bold-label subject block */
.doc-paper .subj { line-height: 1.7; margin-bottom: 28px; }
.doc-paper .subj strong { font-weight: 700; }
/* indented damage-calculation block */
.doc-paper .calc { line-height: 1.8; margin: 4px 0 12px; }
.doc-paper .sig { margin-top: 36px; line-height: 1.5; }
/* Document value chips — appearance follows the field's status. */
.doc-paper .dv { border-radius: 3px; padding: 1px 5px; transition: background 0.2s var(--ease), box-shadow 0.2s var(--ease); }

/* Cross-highlight: hovering a value on one side rings its twin on the other */
.field.hl-link {
  background: var(--purple-tint);
  border-radius: 4px;
  /* pull the tint slightly outward + add the accent bar in the gutter so it
     never overlaps the label text */
  margin-left: -10px; margin-right: -10px;
  padding-left: 10px; padding-right: 10px;
  box-shadow: inset 3px 0 0 var(--purple);
}
.doc-paper .dv.hl-link {
  box-shadow: 0 0 0 2px var(--purple), 0 2px 10px rgba(147,51,234,0.28) !important;
  border-radius: 4px;
}
.doc-paper .dv-amount { font-weight: 700; }
.doc-paper .dv-filled { font-weight: 600; }
/* green = geprüft */
.doc-paper .dv-green { background: #D8F5E9; color: #0a6b48; }
.doc-paper .dv-green.dv-amount { background: #D8F5E9; color: #0a6b48; }
/* yellow = needs proof → clickable in the text */
.doc-paper .dv-yellow {
  background: var(--yellow-soft); color: #92400E; cursor: pointer;
  box-shadow: inset 0 -1px 0 #F0B429;
}
.doc-paper .dv-yellow::after { content: ' ⌕'; font-size: 0.85em; opacity: 0.7; }
.doc-paper .dv-yellow:hover { background: var(--yellow-hl); box-shadow: inset 0 -2px 0 var(--yellow); }
/* red = blocker (emptied value) */
.doc-paper .dv-red { background: var(--red-soft); color: var(--red); box-shadow: inset 0 -1px 0 #F87171; }
/* in preview mode all chips render as plain finished text */
.doc-editor[data-mode="preview"] .doc-paper .dv {
  background: transparent !important; color: inherit !important;
  box-shadow: none !important; padding: 0 !important; cursor: default;
}
.doc-editor[data-mode="preview"] .doc-paper .dv-yellow::after { content: ''; }
.fp-sub .dv-inline { color: #92400E; font-weight: 600; background: var(--yellow-soft); border-radius: 3px; padding: 0 4px; }
.doc-paper.editing { outline: 2px solid var(--purple); outline-offset: -2px; }
.doc-paper [data-body][contenteditable="true"] { background: #FCFBFF; border-radius: 4px; }

.edit-row {
  display: flex; align-items: center; gap: 11px; padding: 13px 18px;
  border-top: 1px solid var(--hairline); font-size: 13px; color: var(--text-dim);
  background: var(--bg-rail);
}
.toggle {
  position: relative; width: 40px; height: 23px; background: var(--hairline-strong);
  border-radius: 999px; cursor: pointer; transition: background 0.2s var(--ease); flex-shrink: 0;
}
.toggle::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform 0.2s var(--ease);
}
.toggle.on { background: var(--purple); }
.toggle.on::after { transform: translateX(17px); }
.edit-hint { font-size: 12px; color: var(--text-faint); margin-left: auto; }

/* Full-width bar, but actions stay aligned to the centered content column
   (1400px max) via large auto side-padding that matches the page gutter. */
.action-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  margin: 0;
  padding: 14px max(32px, calc((100% - 1400px) / 2 + 32px));
  display: flex; align-items: center; gap: 12px; justify-content: flex-end;
  background: #ffffff;
  border-top: 1px solid var(--hairline);
  box-shadow: 0 -4px 16px rgba(16, 24, 40, 0.06);
}
.action-bar .spacer { flex: 1; }
/* room so fixed footer never covers content */
.case-wrap { padding-bottom: 96px; }

/* ============================================================
   FLOW 3 — document-dominant layout (Word-like editing feel)
   ============================================================ */
.f3-layout { display: grid; grid-template-columns: 260px 1fr; gap: 22px; align-items: start; }
.fields-rail { padding: 20px 22px; position: sticky; top: 120px; }
/* Mini protected-value rows stack vertically in the narrow rail */
.fields-rail .field { display: block; padding: 11px 0; }
.fields-rail .field .f-label { font-size: 12px; color: var(--text-faint); margin-bottom: 4px; }
.fields-rail .field .f-value { font-size: 13px; padding: 0; margin: 0; border: none; }
.fields-rail .field .f-value:hover, .fields-rail .field .f-value:focus { background: transparent; box-shadow: none; }
.fields-rail .field .status {
  width: auto; min-width: 0; margin-top: 6px; padding: 3px 9px; font-size: 11px;
  grid-column: auto; grid-row: auto; align-self: auto; justify-self: start;
  display: inline-flex; float: none;
}
.fields-rail .field .f-value { grid-row: auto; display: block; }

.doc-editor { padding: 0; overflow: hidden; }
.viewmode { display: inline-flex; background: #EEF0F3; border-radius: var(--radius-btn); padding: 3px; gap: 2px; }
.vm-btn {
  font-family: inherit; font-size: 13px; font-weight: 500; color: var(--text-dim);
  background: transparent; border: none; cursor: pointer;
  padding: 6px 14px; border-radius: 5px; transition: all 0.15s var(--ease);
}
.vm-btn.active { background: #fff; color: var(--text); box-shadow: var(--shadow-sm); }

/* Fullscreen / focus toggle */
.fs-btn {
  display: inline-flex; align-items: center; gap: 7px; margin-left: 14px;
  font-family: inherit; font-size: 13px; font-weight: 500; color: var(--text-dim);
  background: transparent; border: 1px solid var(--hairline); border-radius: var(--radius-btn);
  padding: 6px 12px; cursor: pointer; transition: all 0.15s var(--ease);
}
.fs-btn:hover { background: #F9FAFB; border-color: var(--text-faint); color: var(--text); }
.fs-btn .fs-ico { font-size: 15px; line-height: 1; }

/* Fullscreen focus mode: the doc-editor becomes a fixed overlay filling the screen */
body.doc-fullscreen { overflow: hidden; }
/* the flow's leftover animation transform creates a containing block — clear it so
   position:fixed resolves against the viewport */
body.doc-fullscreen .flow.active { transform: none !important; animation: none !important; }
body.doc-fullscreen #docEditor {
  position: fixed; inset: 0; z-index: 300;
  margin: 0; border-radius: 0; border: none;
  display: flex; flex-direction: column;
  box-shadow: none; background: #E9EBEF;
  animation: fs-in 0.3s var(--ease);
}
@keyframes fs-in { from { opacity: 0; transform: scale(0.99); } to { opacity: 1; transform: none; } }
body.doc-fullscreen #docEditor .doc-toolbar { background: #fff; }
body.doc-fullscreen #docEditor .doc-canvas {
  flex: 1; max-height: none;
  padding: clamp(24px, 4vh, 56px) clamp(16px, 4vw, 80px);
}
body.doc-fullscreen #docEditor .doc-sheet { max-width: 820px; }
/* keep the send/export actions reachable above the fullscreen overlay — full width */
body.doc-fullscreen #f2Actions {
  position: fixed; z-index: 301;
  left: 0; right: 0; bottom: 0; width: 100%; margin: 0;
  padding: 14px clamp(20px, 4vw, 48px);
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(10px);
  border-top: 1px solid var(--hairline);
}
body.doc-fullscreen .fs-btn .fs-label::before { content: 'Verlassen'; }
body.doc-fullscreen .fs-btn .fs-label { font-size: 0; }
body.doc-fullscreen .fs-btn .fs-label::before { font-size: 13px; }
body.doc-fullscreen .fs-btn .fs-ico { transform: rotate(180deg); }

/* Formatting toolbar (Bold/Italic/Underline/List) */
.format-bar { display: inline-flex; align-items: center; gap: 2px; margin-left: 14px; }
.fmt-btn {
  width: 30px; height: 30px; border-radius: 5px;
  border: 1px solid transparent; background: transparent; color: var(--text-dim);
  font-size: 14px; cursor: pointer; display: grid; place-items: center;
  transition: all 0.12s var(--ease); font-family: 'Georgia', serif;
}
.fmt-btn:hover { background: #EEF0F3; color: var(--text); }
.fmt-btn.active { background: var(--purple-soft); color: var(--purple-dark); border-color: #E2CFFB; }
.fmt-sep { width: 1px; height: 18px; background: var(--hairline); margin: 0 4px; }
/* hide the format bar in preview mode */
.doc-editor[data-mode="preview"] .format-bar { display: none; }
/* protected value spans: not individually editable, subtly locked look on hover in edit mode */
.doc-sheet[contenteditable="true"] [data-doc-field] { cursor: default; }
.doc-sheet[contenteditable="true"] [data-doc-field][contenteditable="true"] { cursor: text; }

/* Grey "Word canvas" holding a white A4-ish sheet */
.doc-editor { position: sticky; top: 120px; }
.doc-canvas {
  background: #E9EBEF;
  padding: 28px clamp(14px, 2vw, 32px);
  max-height: 82vh; overflow-y: auto;
}
.doc-sheet {
  background: #fff;
  max-width: 940px; width: 100%; margin: 0 auto;
  min-height: 1000px;           /* page feel — fills more space */
  padding: 72px clamp(56px, 7%, 96px);
  box-shadow: 0 1px 3px rgba(16,24,40,0.10), 0 12px 36px rgba(16,24,40,0.12);
  border-radius: 2px;
  max-height: none;             /* override the .doc-paper cap inside a canvas */
  font-size: 15px;
}
.doc-canvas .doc-paper.editing { outline: none; }
.doc-editor[data-mode="edit"] .doc-sheet[contenteditable] { /* placeholder */ }

/* Preview mode: a clean final document (chip styling handled by the .dv rules above) */
.doc-editor[data-mode="preview"] .doc-sheet [data-body] { background: transparent !important; }
.doc-editor[data-mode="preview"] .doc-sheet { cursor: default; }

/* ============================================================
   Source modal
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 41, 0.45);
  display: none; align-items: center; justify-content: center; z-index: 400; padding: 24px;
  animation: fade 0.18s ease;
}
.modal-backdrop.show { display: flex; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 620px; background: var(--bg);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow-lg); animation: modal-in 0.25s var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--hairline); }
.modal-head .mh-title { font-size: 15px; font-weight: 600; }
.modal-head .mh-close { background: transparent; border: none; color: var(--text-faint); font-size: 22px; cursor: pointer; line-height: 1; padding: 0 4px; }
.modal-head .mh-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.faux-pdf {
  background: var(--bg-rail); color: #1a1a2e; border: 1px solid var(--hairline);
  font-family: 'Georgia', serif; font-size: 13px; line-height: 1.7;
  padding: 24px 26px; border-radius: var(--radius-card); max-height: 280px; overflow-y: auto;
}
.faux-pdf .hl { background: var(--yellow-hl); color: #7a5a00; padding: 2px 5px; border-radius: 3px; font-weight: 600; }
.modal-source { margin-top: 14px; display: flex; align-items: center; gap: 8px; font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--text-faint); flex-wrap: wrap; }
.modal-source .pin { color: var(--purple); }
.link-btn {
  margin-left: auto; background: transparent; border: none; cursor: pointer;
  font-family: inherit; font-size: 12px; font-weight: 600; color: var(--purple);
  padding: 2px 0; text-decoration: none;
}
.link-btn:hover { color: var(--purple-dark); text-decoration: underline; }

/* Editable value inside the check modal */
.modal-edit { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--hairline); }
.me-label { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 6px; }
.me-input {
  width: 100%; font-family: 'JetBrains Mono', monospace; font-size: 14px; font-weight: 600; color: var(--text);
  padding: 10px 12px; border: 1px solid var(--hairline-strong); border-radius: var(--radius-btn);
  background: #fff; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.me-input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(147,51,234,0.14); }
.me-hint { font-size: 12px; color: var(--text-faint); margin-top: 7px; }

.modal-foot { padding: 14px 20px; border-top: 1px solid var(--hairline); display: flex; justify-content: flex-end; gap: 12px; align-items: center; }
.modal-foot .confirm-hint { font-size: 12px; color: var(--text-faint); margin-right: auto; }

/* Large full-source document modal */
.modal.modal-lg { max-width: 820px; }
.src-meta { font-size: 11px; color: var(--text-faint); margin-bottom: 12px; letter-spacing: 0.02em; }
.faux-pdf-full {
  max-height: 64vh; padding: 36px 44px; font-size: 14px;
}
.faux-pdf-full p { margin-bottom: 13px; }
.faux-pdf-full strong { color: #0d1730; }
#srcBackdrop { z-index: 440; } /* above the check modal (400) and fullscreen (300) */

/* ============================================================
   Success state
   ============================================================ */
.success { display: none; text-align: center; padding: 70px 24px; animation: flow-in 0.5s var(--ease) both; }
.success.show { display: block; }
.success .check {
  width: 72px; height: 72px; margin: 0 auto 24px; border-radius: 50%;
  background: var(--green-soft); display: grid; place-items: center;
  font-size: 32px; color: var(--green); animation: pop 0.45s var(--ease) both;
}
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.1); } 100% { transform: scale(1); } }
.success h2 { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 10px; }
.success p { font-size: 15px; color: var(--text-dim); max-width: 460px; margin: 0 auto 24px; line-height: 1.55; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Responsive */
@media (max-width: 900px) {
  .f1-layout, .f2-layout { grid-template-columns: 1fr; }
  .doc-preview, .f1-preview, .doc-editor, .fields-rail { position: static; }
  .nav-links { display: none; }
  /* the mono filename is the one element that won't shrink — hide it on mobile */
  .doc-toolbar > span:last-child { display: none; }
  /* keep the document strictly inside the viewport */
  .doc-sheet { padding: 40px 24px; min-height: 0; }
  .doc-canvas { padding: 16px; max-height: none; }
  .case-wrap { padding: 20px 16px 80px; }
  .action-bar { margin: 18px -16px 0; padding: 14px 16px; flex-wrap: wrap; }
  .action-bar .btn { flex: 1 1 auto; justify-content: center; }
  /* case tabs scroll horizontally instead of overflowing the page */
  .case-tabs { overflow-x: auto; gap: 18px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .case-tabs::-webkit-scrollbar { display: none; }
  .case-tabs a { white-space: nowrap; flex-shrink: 0; }
  /* belt-and-suspenders: never let the page scroll sideways */
  html, body { overflow-x: hidden; }
}

/* ============================================================
   Global toast (warnings / confirmations)
   ============================================================ */
.app-toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(16px);
  max-width: 460px; width: max-content;
  background: #fff; color: var(--text);
  border: 1px solid var(--hairline-strong); border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 13px 18px; font-size: 13px; line-height: 1.45;
  display: flex; align-items: flex-start; gap: 10px;
  opacity: 0; pointer-events: none; z-index: 420;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}
.app-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.app-toast.warn { border-color: #FCD34D; border-left: 3px solid var(--yellow); }
.app-toast .t-ico { color: var(--yellow); font-size: 16px; line-height: 1.3; flex-shrink: 0; }
.app-toast b { font-weight: 600; }
