:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #1b1f24;
  --ink-soft: #454c55;
  --muted: #6b7280;
  --line: #e3dfd6;
  --accent: #b4410f;
  --accent-ink: #ffffff;
  --accent-soft: #fbeee6;
  --focus: #2563eb;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--font); }
a { color: var(--accent); }
img { max-width: 100%; }
[hidden] { display: none !important; }

.wrap { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 28px; } }

/* Header */
.site-header { border-bottom: 1px solid var(--line); background: var(--bg); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.header-nav { display: flex; gap: 18px; font-size: .92rem; }
.header-nav a { color: var(--ink-soft); text-decoration: none; }
.header-nav a:hover { color: var(--accent); }
@media (max-width: 560px) { .header-nav { display: none; } }

/* Hero – bewusst kompakt, damit das Formular sofort sichtbar ist */
.hero { padding-top: 22px; padding-bottom: 18px; }
.hero h1 { font-size: clamp(1.35rem, 2.4vw, 1.9rem); line-height: 1.2; letter-spacing: -.015em; margin: 0 0 6px; }
.lead { font-size: 1rem; color: var(--ink-soft); max-width: 78ch; margin: 0 0 12px; }
.badges { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.badges li { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px 3px 26px; font-size: .82rem; position: relative; }
.badges li::before { content: ""; position: absolute; left: 10px; top: 50%; width: 9px; height: 5px; border-left: 2px solid var(--accent); border-bottom: 2px solid var(--accent); transform: translateY(-70%) rotate(-45deg); }
@media (max-width: 560px) {
  .hero { padding-top: 16px; padding-bottom: 14px; }
  .lead { font-size: .92rem; line-height: 1.45; margin-bottom: 10px; }
}

/* Tool layout */
.tool { display: grid; gap: 24px; padding-bottom: 56px; }
@media (min-width: 900px) { .tool { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); align-items: start; } }

.form { display: grid; gap: 16px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 20px; margin: 0; min-width: 0; }
.card legend { font-weight: 700; font-size: 1.02rem; padding: 0 6px; margin-left: -6px; display: flex; align-items: center; gap: 8px; }
.step { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: #fff; font-size: .8rem; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; margin-top: 12px; }
.grid .full, .card > .full { grid-column: 1 / -1; }
@media (max-width: 480px) { .grid { grid-template-columns: 1fr; } }

label { display: flex; flex-direction: column; gap: 4px; font-size: .86rem; font-weight: 600; color: var(--ink-soft); min-width: 0; }
.card > label.full { margin-top: 12px; }
.label-text { font-size: .86rem; font-weight: 600; color: var(--ink-soft); }
input, select, textarea {
  font: inherit; font-size: 1rem; font-weight: 400; color: var(--ink);
  background: #fff; border: 1px solid #cfcac0; border-radius: 8px; padding: 9px 11px; width: 100%; min-width: 0;
}
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
input::placeholder, textarea::placeholder { color: #a3a29d; }

.check { flex-direction: row; align-items: center; gap: 9px; font-weight: 600; margin-top: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

.hint { font-size: .84rem; color: var(--muted); font-weight: 400; margin: 8px 0 0; }
.hint:empty { display: none; }

.more { margin-top: 12px; }
.more summary { cursor: pointer; font-size: .9rem; font-weight: 600; color: var(--accent); }

/* Segmented controls */
.stages, .seg { display: grid; gap: 8px; margin-top: 10px; }
.stages { grid-template-columns: repeat(4, 1fr); }
.seg { grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .stages { grid-template-columns: 1fr 1fr; } }
.stages label, .seg label { position: relative; }
.stages input, .seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.stages span, .seg span {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 46px; padding: 6px 8px;
  border: 1px solid #cfcac0; border-radius: 8px; background: #fff; font-size: .9rem; font-weight: 600; color: var(--ink-soft); line-height: 1.2;
}
.stages input:checked + span, .seg input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.stages input:focus-visible + span, .seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

.logo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.logo-row .hint { margin: 0; }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-btn { position: relative; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: .95rem; border-radius: 8px; padding: 10px 16px; cursor: pointer; text-decoration: none; border: 1px solid transparent; line-height: 1.2; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #983609; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: #cfcac0; }
.btn-ghost:hover { border-color: var(--ink-soft); }
.btn-small { padding: 7px 12px; font-size: .88rem; flex-direction: row; }

/* Preview */
.preview-col { min-width: 0; align-self: stretch; }
.preview-sticky { position: sticky; top: 16px; }
@media (min-width: 900px) {
  /* Vorschau passt immer in den Bildschirm und bleibt beim Scrollen stehen; längere Briefe scrollen im Rahmen. */
  .preview-sticky { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
  .preview-sticky .paper-frame { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn-primary { flex: 1 1 auto; }
#action-msg { min-height: 1.3em; }
.paper-frame { margin-top: 10px; background: #e7e3da; border-radius: var(--radius); padding: 14px; overflow: hidden; overscroll-behavior: contain; }
.paper-sizer { overflow: hidden; }
.paper-frame .paper { transform-origin: top left; box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 8px 24px rgba(0,0,0,.08); }

/* The letter: DIN 5008 Form B, A4 */
.paper {
  position: relative; width: 210mm; min-height: 297mm; background: #fff; color: #111;
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 10.5pt; line-height: 1.4;
}
.fold { position: absolute; left: 0; width: 5mm; border-top: 0.3pt solid #9a9a9a; }
.fold-1 { top: 105mm; } .fold-2 { top: 210mm; } .fold-hole { top: 148.5mm; width: 7mm; }
.l-logo { position: absolute; top: 12mm; right: 20mm; max-width: 60mm; max-height: 25mm; object-fit: contain; }
.l-return { position: absolute; top: 45mm; left: 25mm; width: 85mm; font-size: 7pt; color: #444; border-bottom: 0.4pt solid #888; padding-bottom: 0.6mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.l-address { position: absolute; top: 50.5mm; left: 25mm; width: 85mm; height: 39mm; overflow: hidden; }
.l-address div { min-height: 1.4em; }
.l-info { position: absolute; top: 50mm; left: 125mm; right: 20mm; font-size: 9pt; }
.l-info .row { display: flex; gap: 3mm; }
.l-info .k { width: 27mm; color: #555; flex: none; }
.l-info .v { min-width: 0; overflow-wrap: anywhere; }
.l-body { padding: 103mm 20mm 42mm 25mm; }
.l-subject { font-weight: 700; font-size: 11pt; margin: 0 0 8mm; }
#l-text p { margin: 0 0 4mm; }
.l-table { width: 100%; border-collapse: collapse; margin: 1mm 0 5mm; font-size: 10pt; }
.l-table td { padding: 1.2mm 0; vertical-align: top; }
.l-table td.amt { text-align: right; white-space: nowrap; padding-left: 6mm; }
.l-table tr.sum td { border-top: 0.6pt solid #111; font-weight: 700; padding-top: 2mm; }
.l-table .sub { display: block; font-size: 8.5pt; color: #555; }
.l-sign { margin-top: 8mm; }
.l-sign .name { margin-top: 10mm; }
.l-footer {
  position: absolute; left: 25mm; right: 20mm; bottom: 12mm; border-top: 0.4pt solid #999; padding-top: 2.5mm;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4mm; font-size: 7.5pt; color: #444; line-height: 1.35;
}
.l-footer div { overflow-wrap: anywhere; }
.ph { color: #b0aca4; }

/* Content sections */
.content { padding-top: 36px; padding-bottom: 8px; }
.content > * { max-width: 860px; }
.content h2 { font-size: 1.55rem; letter-spacing: -.01em; margin: 0 0 12px; }
.content h3 { font-size: 1.15rem; margin: 22px 0 8px; }
.content p, .content li { color: var(--ink-soft); }
.steps-list { padding-left: 1.3em; }
.steps-list li { margin-bottom: 8px; }
.table-wrap { overflow-x: auto; }
.rates { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); font-size: .95rem; }
.rates th, .rates td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.rates th { font-size: .84rem; color: var(--muted); font-weight: 600; }
.rates tr:last-child td { border-bottom: 0; }
.faq { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 16px; margin-bottom: 8px; }
.faq summary { cursor: pointer; font-weight: 600; padding: 14px 0; }
.faq p { margin: 0 0 14px; }

/* Footer */
.site-footer { margin-top: 48px; border-top: 1px solid var(--line); padding: 24px 0 36px; font-size: .88rem; color: var(--muted); }
.disclaimer { max-width: 80ch; margin: 0 0 12px; }
.footer-links { display: flex; gap: 18px; margin: 0; }
.footer-links a { color: var(--ink-soft); }

/* Legal pages */
.legal { max-width: 760px; padding-top: 36px; padding-bottom: 24px; }
.legal h1 { font-size: 2rem; margin: 0 0 20px; }
.legal h2 { font-size: 1.2rem; margin: 26px 0 8px; }
.legal p, .legal li { color: var(--ink-soft); }

/* Print: only the letter */
@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; }
  .site-header, .hero, .form, .actions, #action-msg, .content, .site-footer { display: none !important; }
  .tool, .wrap { display: block; padding: 0; margin: 0; max-width: none; }
  .preview-sticky { position: static; }
  .paper-frame { background: none; padding: 0; margin: 0; border-radius: 0; overflow: visible !important; height: auto !important; }
  .paper-sizer { height: auto !important; overflow: visible; }
  .preview-sticky { max-height: none !important; display: block !important; }
  .paper-frame .paper { transform: none !important; box-shadow: none; }
  .ph { color: transparent; }
}

/* Zinsrechner */
.zr { display: grid; gap: 24px; padding-bottom: 40px; }
@media (min-width: 900px) { .zr { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); align-items: start; } }
.zr-total { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.zr-total span { font-weight: 600; color: var(--ink-soft); }
.zr-total strong { font-size: 2rem; letter-spacing: -.02em; }
.zr-sum { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: .95rem; }
.zr-sum td { padding: 6px 0; }
.zr-sum tr.sum td { border-top: 1px solid var(--ink); font-weight: 700; padding-top: 10px; }
.num { text-align: right !important; white-space: nowrap; }
.cta-box { margin-top: 16px; padding: 14px 16px; background: var(--accent-soft); border-radius: var(--radius); font-size: .95rem; }
.related { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 12px 0 0; }
.related a { display: inline-block; padding: 7px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--ink); font-size: .92rem; }
.related a:hover { border-color: var(--accent); color: var(--accent); }
.footer-nav { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0 0 14px; padding: 0; list-style: none; }
.footer-nav a { color: var(--ink-soft); }
.rates-history td:last-child, .rates-history th:last-child { text-align: right; }

/* Pflichtfelder & mobile Leiste */
.req-star { color: var(--accent); font-weight: 700; }
.req-note { margin: 0 0 4px; }
.mobile-bar { display: none; }
@media (max-width: 899px) {
  .mobile-bar { display: flex; position: fixed; left: 16px; right: 16px; bottom: 12px; z-index: 20;
    box-shadow: 0 6px 20px rgba(0,0,0,.18); padding: 13px 16px; transition: opacity .2s, transform .2s; }
  .mobile-bar.off { opacity: 0; transform: translateY(20px); pointer-events: none; }
}
@media print { .mobile-bar { display: none !important; } }

/* Brieftext direkt bearbeiten */
.l-body { outline: none; }
.l-body:hover { box-shadow: inset 0 0 0 1px rgba(180, 65, 15, .25); }
.l-body:focus { box-shadow: inset 0 0 0 2px rgba(180, 65, 15, .45); }
.ph-open { background: #fff3c4; }
.edit-banner { display: flex; align-items: center; gap: 12px; margin-top: 8px; padding: 10px 12px; background: #fff3c4;
  border: 1px solid #ecd27a; border-radius: 8px; font-size: .86rem; color: #5b4a12; }
.edit-banner span { flex: 1; }
#edit-hint { margin-top: 2px; }
@media print {
  .l-body, .l-body:hover, .l-body:focus { box-shadow: none !important; }
  .ph-open { background: none; }
  #edit-hint, .edit-banner { display: none !important; }
}

/* Tonfall */
.tone-label { display: block; margin-top: 14px; }
.seg3 { grid-template-columns: repeat(3, 1fr); margin-top: 6px; }

/* Dezente Scrollleiste im Vorschau-Rahmen */
.paper-frame { scrollbar-width: thin; scrollbar-color: #c9c2b4 transparent; }
.paper-frame::-webkit-scrollbar { width: 8px; }
.paper-frame::-webkit-scrollbar-track { background: transparent; }
.paper-frame::-webkit-scrollbar-thumb { background: #c9c2b4; border-radius: 8px; border: 2px solid #e7e3da; }
.paper-frame::-webkit-scrollbar-thumb:hover { background: #a9a092; }

/* Fußzeile mit Überschriften */
.l-footer strong { color: #222; }
.l-footer .lbl { color: #777; }

/* Datums-Plausibilität */
.warn-box { margin-top: 8px; padding: 10px 12px; background: #fff3c4; border: 1px solid #ecd27a; border-radius: 8px; font-size: .86rem; color: #5b4a12; }
.warn-box ul { margin: 4px 0 0; padding-left: 18px; }
@media print { .warn-box { display: none !important; } }

/* Briefkopf rechts */
.l-side { display: none; position: absolute; top: 45mm; left: 135mm; right: 20mm; font-size: 7.5pt; line-height: 1.35; color: #444; }
.l-side div + div { margin-top: 2.2mm; }
.l-side strong { color: #222; }
.l-side .lbl { color: #777; }
.paper.layout-right .l-side { display: block; }
.paper.layout-right .l-info, .paper.layout-right .l-footer { display: none; }
.paper.layout-right .l-body { padding-bottom: 20mm; }
.l-side .nw { white-space: nowrap; }

/* Hinweiszeile im Kopfbereich */
.notice { margin: 10px 0 0; padding: 8px 12px; background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 6px; font-size: .9rem; color: var(--ink); max-width: 78ch; }
@media (max-width: 560px) { .notice { font-size: .82rem; padding: 6px 10px; } }
