:root {
  --bg: #e7ebf0;
  --panel: #ffffff;
  --line: #d7dee6;
  --text: #1d2733;
  --muted: #687789;
  --brand: #b3282d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Anmeldung ---------- */
.login { display: none; }
body.locked .app { display: none; }
body.locked .login {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px 16px;
  background: linear-gradient(160deg, #fff 0%, #f6eeee 55%, #fdf3e3 100%);
}
.login-card {
  width: 100%; max-width: 380px; margin: auto 0; padding: 32px 28px 28px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 40px rgba(60, 20, 20, .10); text-align: center;
}
.login-logo { height: 72px; margin-bottom: 10px; }
.login-card h1 { font-size: 20px; margin: 0; color: var(--brand); }
.login-sub { margin: 4px 0 22px; color: var(--muted); }
.login-card form { text-align: left; }
.login-card input { font-size: 18px !important; letter-spacing: .2em; text-align: center; }
.login-error { color: #b3282d; font-size: 13px; margin: -2px 0 10px; }
.login-btn { width: 100%; padding: 10px; font-size: 15px; }
.login-foot { margin-top: 24px; text-align: center; font-size: 12px; color: var(--muted); line-height: 1.7; }
.login-foot a { color: var(--text); text-decoration: none; white-space: nowrap; }
.login-foot a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: minmax(0, 1fr) 460px; height: 100vh; }
.preview-wrap { overflow: auto; padding: 32px 24px; }
.panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; }

/* Mobil-Umschalter zwischen Eingaben und Vorschau */
.mobile-tabs { display: none; }

@media screen and (max-width: 1100px) {
  .app { grid-template-columns: 1fr; height: auto; padding-bottom: 72px; }
  .panel { border-left: 0; }
  .preview-wrap { padding: 16px; }
  body[data-view="form"] .preview-wrap,
  body[data-view="preview"] .panel { display: none; }

  .mobile-tabs {
    display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0, 0, 0, .06);
  }
  body.locked .mobile-tabs { display: none; }
  .mobile-tabs .btn { padding: 10px 12px; font-weight: 600; }
  .mobile-tabs .btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }

  /* iOS zoomt bei Schriftgrößen unter 16px in Eingabefeldern */
  .field input, .field select, .field textarea, .add-topic input, .login-card input { font-size: 16px; }
}

@media screen and (max-width: 520px) {
  .subj-body .row.three { grid-template-columns: .8fr 1.5fr .8fr; gap: 6px; }
  .cost-table .c-mode { display: none; }
}

/* ---------- Panel ---------- */
.toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line);
}
.btn {
  font: inherit; padding: 7px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: #f5f7fa; color: var(--text);
}
.btn:hover { background: #eaeef3; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.link { font: inherit; font-size: 12px; background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; }
.link:hover { text-decoration: underline; }

details { border-bottom: 1px solid var(--line); padding: 0 16px; }
details[open] { padding-bottom: 14px; }
summary {
  cursor: pointer; padding: 14px 0; font-weight: 600; font-size: 15px;
  list-style: none; display: flex; align-items: center; gap: 8px;
}
summary::-webkit-details-marker { display: none; }
summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details[open] > summary::before { transform: rotate(90deg); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.three { grid-template-columns: repeat(3, 1fr); }
.row .narrow { max-width: 120px; }
.row:has(.narrow) { grid-template-columns: 110px 1fr; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
.field small { font-weight: normal; }
.field input, .field select, .field textarea, .add-topic input {
  font: inherit; font-size: 14px; color: var(--text);
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; width: 100%;
}
.field input[type="color"] { padding: 2px; height: 36px; }
.field input[type="file"] { padding: 5px; font-size: 12px; }
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .add-topic input:focus {
  outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand);
}
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; margin: 8px 0; cursor: pointer; }
.hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }

/* Fächer */
.subj { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; overflow: hidden; }
.subj.on { border-color: var(--brand); }
.subj-head { display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; }
.subj.on .subj-head { background: color-mix(in srgb, var(--brand) 8%, white); }
.subj-icon {
  display: inline-grid; place-items: center; min-width: 30px; height: 26px; padding: 0 4px;
  border-radius: 5px; background: #eef2f6; font-size: 11px; font-weight: 700; color: var(--brand);
}
.subj-name { font-weight: 600; flex: 1; }
.count { font-size: 12px; color: var(--muted); }
.subj-body { padding: 10px 12px 12px; }
.subj-body .field { margin-bottom: 6px; }
.topic-tools { display: flex; gap: 14px; margin: 4px 0 6px; }
.topics { display: flex; flex-direction: column; gap: 2px; }
.topic { display: flex; align-items: flex-start; gap: 8px; padding: 4px 6px; border-radius: 5px; cursor: pointer; font-size: 13px; }
.topic:hover { background: #f3f6f9; }
.topic span { flex: 1; }
.del { border: 0; background: none; color: #b33; font-size: 16px; line-height: 1; cursor: pointer; }
.add-topic { display: flex; gap: 6px; margin-top: 8px; }
.add-topic input { font-size: 13px; }

/* ---------- Angebot (A4) ---------- */
.sheet {
  --accent: #1d5c8c;
  --accent-soft: color-mix(in srgb, var(--accent) 9%, white);
  width: 210mm; min-height: 297mm; margin: 0 auto; padding: 16mm 18mm 14mm;
  background: #fff; color: #222; box-shadow: 0 6px 28px rgba(20, 35, 55, .16);
  font: 10pt/1.45 "Helvetica Neue", Arial, sans-serif;
}
.sheet p { margin: 0 0 8px; }
.sheet .muted { color: #888; font-style: italic; }
.sheet .small { font-size: 8.5pt; color: #555; margin-top: 6px; }

.doc-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2.5px solid var(--accent); padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { max-height: 52px; max-width: 140px; object-fit: contain; }
.brand-name { font-size: 17pt; font-weight: 700; color: var(--accent); line-height: 1.1; }
.brand-sub { font-size: 8.5pt; color: #777; margin-top: 3px; }
.doc-type { font-size: 20pt; font-weight: 300; letter-spacing: .18em; text-transform: uppercase; color: var(--accent); }

.addr-row { display: flex; justify-content: space-between; gap: 24px; margin: 22px 0 18px; }
.recipient { min-height: 30mm; font-size: 10.5pt; }
.sender-line { font-size: 7.5pt; color: #777; border-bottom: 1px solid #bbb; padding-bottom: 2px; margin-bottom: 6px; display: inline-block; }
.meta { font-size: 9pt; border-collapse: collapse; align-self: flex-start; }
.meta td { padding: 1.5px 0; }
.meta td:first-child { color: #777; padding-right: 14px; }
.meta td:last-child { font-weight: 600; text-align: right; }

.sheet h1 { font-size: 15pt; color: var(--accent); margin: 0 0 12px; }
.sheet h2 {
  font-size: 11pt; margin: 18px 0 8px; padding: 4px 0 4px 9px;
  border-left: 4px solid var(--accent); background: var(--accent-soft);
}
.sheet h2 small { font-weight: normal; color: #666; font-size: 8.5pt; }

.profile { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; }
.profile div { display: flex; gap: 8px; border-bottom: 1px dotted #ccc; padding: 2px 0; }
.lbl { color: #777; min-width: 32mm; font-size: 9pt; }
.goal { margin-top: 8px; }
.goal p { margin: 2px 0 0; }

.box {
  display: inline-grid; place-items: center; width: 12px; height: 12px; flex: none;
  border: 1.3px solid #555; border-radius: 2px; font-size: 9px; font-weight: 700; line-height: 1; vertical-align: -2px;
}
.box.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.overview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px 14px; }
.ov-item { display: flex; align-items: center; gap: 7px; }
.ov-item.off { color: #999; }

.subject-card { border: 1px solid #d5dbe2; border-radius: 6px; margin-bottom: 10px; overflow: hidden; break-inside: avoid; }
.subject-head { display: flex; align-items: center; gap: 9px; padding: 6px 10px; background: var(--accent-soft); border-bottom: 1px solid #d5dbe2; }
.subject-icon {
  display: inline-grid; place-items: center; min-width: 24px; height: 20px; padding: 0 3px; border-radius: 4px;
  background: var(--accent); color: #fff; font-size: 7.5pt; font-weight: 700;
}
.subject-meta { margin-left: auto; font-size: 8.5pt; color: #555; }
.subject-card > p { padding: 8px 10px; margin: 0; }

.check-table, .cost-table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
.check-table th { font-size: 7.5pt; text-transform: uppercase; letter-spacing: .04em; color: #777; font-weight: 600; text-align: left; padding: 5px 10px 3px; }
.check-table td { padding: 4px 10px; border-top: 1px solid #eceff3; }
.check-table tr.off td { color: #aaa; }
.c-nr { width: 9mm; color: #999; }
.c-box { width: 17mm; text-align: center !important; }
.c-date { width: 26mm; }
.line { display: block; border-bottom: 1px solid #999; height: 12px; }

.cost-table th { text-align: left; font-size: 8pt; color: #666; font-weight: 600; border-bottom: 1.5px solid #333; padding: 4px 6px; }
.cost-table td { padding: 4px 6px; border-bottom: 1px solid #e6e9ee; }
.cost-table tfoot td { border-bottom: 0; }
.cost-table tr.sum td { font-weight: 700; font-size: 10.5pt; border-top: 1.5px solid #333; background: var(--accent-soft); }
.r { text-align: right !important; }
.nowrap { white-space: nowrap; }
.note { font-size: 8.5pt; background: #f6f8fa; border-left: 3px solid var(--accent); padding: 6px 9px; margin-top: 8px; }

.doc-type.long { font-size: 13pt; letter-spacing: .12em; padding-top: 6px; }

.but-facts { margin-bottom: 8px; }
.docs { margin-top: 10px; border: 1px solid #d5dbe2; border-radius: 6px; padding: 8px 10px; }
.docs-title { font-weight: 600; font-size: 9.5pt; margin-bottom: 5px; }
.docs-item { display: flex; align-items: flex-start; gap: 8px; padding: 2.5px 0; font-size: 9.5pt; }
.docs-item .box { margin-top: 2px; }
.accept-text { font-size: 8.5pt; color: #444; margin: 4px 0 0; }

.terms { margin: 0 0 14px; padding-left: 18px; font-size: 9pt; }
.terms li { margin-bottom: 3px; }

.accept { margin-top: 18px; border: 1px solid #d5dbe2; border-radius: 6px; padding: 10px 12px 8px; }
.accept-title { font-weight: 600; font-size: 9.5pt; }
.signs { display: grid; grid-template-columns: 1fr 1.4fr; gap: 28px; margin-top: 26px; font-size: 8pt; color: #666; }
.signs .line { border-bottom-color: #333; margin-bottom: 3px; }

.doc-foot {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 22px; padding-top: 8px;
  border-top: 1px solid #ccc; font-size: 7.5pt; color: #666;
}

/* ---------- Angebot auf kleinen Bildschirmen: fließendes Layout statt fester A4-Breite ---------- */
@media screen and (max-width: 860px) {
  .preview-wrap { padding: 10px; }
  .sheet { width: 100%; min-height: 0; padding: 18px 14px; font-size: 9.5pt; }
  .doc-head { flex-direction: column-reverse; gap: 6px; }
  .doc-type, .doc-type.long { font-size: 12pt; padding-top: 0; }
  .brand-name { font-size: 14pt; }
  .logo { max-height: 40px; }
  .addr-row { flex-direction: column; gap: 14px; margin: 16px 0; }
  .recipient { min-height: 0; }
  .meta { align-self: stretch; }
  .sheet h1 { font-size: 13pt; }
  .profile { grid-template-columns: 1fr; }
  .lbl { min-width: 30mm; }
  .subject-head { flex-wrap: wrap; }
  .subject-meta { margin-left: 0; width: 100%; }
  .check-table td, .check-table th { padding-left: 6px; padding-right: 6px; }
  .c-nr { width: 22px; }
  .c-box { width: 46px; }
  .c-date { width: 56px; }
  .check-table th { font-size: 6.5pt; letter-spacing: 0; }
  .cost-table { font-size: 8.5pt; }
  .cost-table th, .cost-table td { padding: 4px 3px; }
  .signs { grid-template-columns: 1fr; gap: 22px; }
  .doc-foot { grid-template-columns: 1fr; gap: 8px; }
}

/* ---------- Druck ---------- */
@media print {
  @page { size: A4; margin: 12mm 14mm 14mm; }
  html, body { height: auto; background: #fff; }
  .panel { display: none !important; }
  .app { display: block; height: auto; }
  .preview-wrap { padding: 0; overflow: visible; }
  .sheet { width: auto; min-height: 0; margin: 0; padding: 0; box-shadow: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .avoid { break-inside: avoid; }
  .sheet h2 { break-after: avoid; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
}
