:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #16202b;
  --muted: #5d6b7a;
  --line: #e3e8ee;
  --brand: #1f4e79;
  --brand-soft: #e6eef6;
  --accent: #f5a623;
  --danger: #c8372d;
  --danger-soft: #fdecea;
  --warn-soft: #fff6e0;
  --ok: #2e8b57;
  --ok-soft: #e7f5ec;
  --anton: #2b6cb0;
  --carlotta: #b83280;
  --all: #5d6b7a;
  --radius: 14px;
  --tabbar-h: 58px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --card: #1a2129;
    --text: #e9eef3;
    --muted: #9aa8b6;
    --line: #2a333d;
    --brand: #6ea8dc;
    --brand-soft: #1d3246;
    --danger: #ff6b5f;
    --danger-soft: #3a1f1d;
    --warn-soft: #3a3120;
    --ok: #5cc98a;
    --ok-soft: #1d3326;
    --anton: #7fb3ec;
    --carlotta: #f08ac4;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ---------- Kopf ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.top h1 { font-size: 26px; margin: 2px 0 6px; letter-spacing: -0.02em; }
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: transparent; color: var(--brand); text-decoration: none; cursor: pointer;
}
.icon-btn:active { background: var(--brand-soft); }
.back { display: inline-flex; align-items: center; gap: 2px; color: var(--brand); text-decoration: none; border: 0; background: none; padding: 6px 0; font-size: 17px; cursor: pointer; }
.top-tools { display: flex; flex-direction: column; gap: 8px; }
.search { display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 0 10px; height: 38px; color: var(--muted); }
.search svg { width: 18px; height: 18px; }
.search input { border: 0; outline: 0; background: transparent; flex: 1; height: 100%; font-size: 16px; }
.segmented { display: flex; background: var(--line); border-radius: 10px; padding: 2px; }
.segmented button { flex: 1; border: 0; background: transparent; padding: 6px 4px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--muted); cursor: pointer; }
.segmented button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- Inhalt ---------- */
main { padding: 12px 16px 24px; outline: none; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 8px; display: flex; justify-content: space-between; align-items: center; }
.section-title.alert { color: var(--danger); }
.section-title.soon { color: var(--brand); }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.row { display: flex; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); align-items: flex-start; position: relative; background: var(--card); }
.row:first-child { border-top: 0; }
.row.link { cursor: pointer; }
.row.link:active { background: var(--brand-soft); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.row-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; }
.row-side { color: var(--muted); font-size: 13px; white-space: nowrap; text-align: right; }
.dot-new { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); position: absolute; left: 5px; top: 19px; }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.chip.anton { background: color-mix(in srgb, var(--anton) 15%, transparent); color: var(--anton); }
.chip.carlotta { background: color-mix(in srgb, var(--carlotta) 15%, transparent); color: var(--carlotta); }
.chip.all { background: var(--line); color: var(--muted); }
.chip.due { background: var(--line); color: var(--text); }
.chip.due.over { background: var(--danger-soft); color: var(--danger); }
.chip.due.soon { background: var(--warn-soft); color: #9a6200; }
.chip.optional { background: transparent; border: 1px dashed var(--muted); color: var(--muted); }
.chip.money { background: var(--ok-soft); color: var(--ok); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
@media (prefers-color-scheme: dark) { .chip.due.soon { color: #f5c26b; } .btn.primary { color: #0f1419; } }

/* Aufgaben-Haken */
.check { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--muted); background: transparent; display: grid; place-items: center; cursor: pointer; margin-top: 1px; padding: 0; }
.check svg { width: 16px; height: 16px; stroke-width: 3; opacity: 0; color: #fff; }
.check.done { background: var(--ok); border-color: var(--ok); }
.check.done svg { opacity: 1; }
.row.is-done .row-title { text-decoration: line-through; color: var(--muted); }

.task-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--brand); padding: 7px 12px; border-radius: 10px; font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer; min-height: 36px; }
.btn:active { background: var(--brand-soft); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.big { padding: 12px 20px; font-size: 17px; border-radius: 12px; width: 100%; }
.btn svg { width: 17px; height: 17px; }
.btn[disabled] { opacity: .5; }

/* Zahlungsdetails */
.pay { margin-top: 8px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.pay-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--line); }
.pay-row:first-child { border-top: 0; }
.pay-label { width: 78px; flex: none; color: var(--muted); font-size: 13px; }
.pay-value { flex: 1; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.pay-value.bad { color: var(--danger); }
.pay-warn { font-size: 12px; color: var(--danger); font-weight: 500; display: block; }
.copy { border: 0; background: var(--brand-soft); color: var(--brand); border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 600; cursor: pointer; }

/* Termine */
.date-box { flex: none; width: 48px; text-align: center; border-radius: 10px; background: var(--brand-soft); color: var(--brand); padding: 4px 0; }
.date-box .d { font-size: 20px; font-weight: 700; line-height: 1.1; }
.date-box .m { font-size: 11px; font-weight: 600; text-transform: uppercase; }
.date-box.child { background: var(--line); color: var(--muted); }

/* Anhänge */
.file-icon { flex: none; width: 40px; height: 48px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); display: grid; place-items: center; font-size: 11px; font-weight: 700; position: relative; }
.file-icon.photo { background: var(--brand-soft); color: var(--brand); }
.file-icon.filled { background: var(--ok-soft); color: var(--ok); }
.offline-dot { position: absolute; right: -3px; bottom: -3px; width: 14px; height: 14px; border-radius: 50%; background: var(--ok); border: 2px solid var(--card); }
.swipe-wrap { position: relative; overflow: hidden; border-top: 1px solid var(--line); }
.swipe-wrap:first-child { border-top: 0; }
.swipe-wrap .row { border-top: 0; transition: transform .2s ease; touch-action: pan-y; }
.swipe-action { position: absolute; right: 0; top: 0; bottom: 0; width: 110px; background: var(--danger); color: #fff; border: 0; font-weight: 600; font-size: 14px; cursor: pointer; }

/* Mail-Detail */
.detail-head { margin: 4px 0 12px; }
.detail-head h2 { font-size: 21px; margin: 0 0 6px; letter-spacing: -0.01em; }
.summary { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: 16px; }
.notice { background: var(--warn-soft); border-radius: 12px; padding: 10px 12px; margin-top: 10px; font-size: 14px; }
.notice b { display: block; margin-bottom: 2px; }
.packing { margin: 0; padding: 10px 14px 10px 32px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.packing li { margin: 3px 0; }
details.original { margin-top: 18px; }
details.original summary { color: var(--brand); cursor: pointer; font-weight: 600; font-size: 15px; }
details.original pre { white-space: pre-wrap; font: 14px/1.45 inherit; font-family: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty svg { width: 44px; height: 44px; stroke-width: 1.5; opacity: .6; }
.empty h3 { color: var(--text); margin: 10px 0 4px; font-size: 17px; }
.more { display: block; margin: 16px auto 0; }

/* Tab-Leiste */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 500; }
.tabbar a.active { color: var(--brand); }
.tabbar svg { width: 25px; height: 25px; }
.badge { position: absolute; top: 5px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

/* Sheets / Overlays */
.overlay { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .2s ease; }
.sheet h2 { margin: 4px 0 12px; font-size: 20px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.full { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; flex-direction: column; }
.full-head { display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 6px) 12px 8px; border-bottom: 1px solid var(--line); background: var(--card); }
.full-head .title { flex: 1; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.full-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 12px; }
.full-foot { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--card); display: flex; gap: 8px; }
.full-foot .btn { flex: 1; }
.pdf-page { display: block; width: 100%; height: auto; margin: 0 auto 12px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.2); border-radius: 4px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

/* Formulare */
.form-grid { display: grid; gap: 10px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; font-weight: 500; }
.field input, .field textarea, .field select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: var(--card); font-size: 16px; }
.field.check-field { display: flex; align-items: center; gap: 10px; }
.field.check-field input { width: 22px; height: 22px; }
.fieldset { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.fieldset h3 { margin: 0 0 10px; font-size: 15px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips-scroll { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--card); scrollbar-width: none; }
.chips-scroll::-webkit-scrollbar { display: none; }
.chips-scroll button { flex: none; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chips-scroll button.armed { background: var(--brand); color: #fff; border-color: var(--brand); }
.page-wrap { position: relative; margin: 0 auto 12px; }
.page-wrap .pdf-page { margin: 0; }
.placed { position: absolute; transform: translateY(-100%); color: #0a2a8a; font-family: Helvetica, Arial, sans-serif; white-space: nowrap; pointer-events: auto; cursor: pointer; background: rgba(245,166,35,.18); outline: 1px dashed rgba(245,166,35,.8); line-height: 1; }
.placed img { display: block; height: 100%; }
.placed-sig { transform: translateY(-100%); }
.form-hint { font-size: 13px; color: var(--muted); padding: 6px 12px; background: var(--warn-soft); }
.sig-pad { width: 100%; height: 200px; background: #fff; border: 1px solid var(--line); border-radius: 12px; touch-action: none; }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.thumbs figure { margin: 0; position: relative; }
.thumbs img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.thumbs button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.pick-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.file-input { position: relative; overflow: hidden; }
.file-input input { position: absolute; inset: 0; opacity: 0; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%) translateY(20px); background: #1e2833; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 90; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack > * + * { margin-top: 10px; }
.settings-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* Login */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card { max-width: 380px; text-align: center; }
.login-card img { border-radius: 20px; }
.login-card h1 { margin: 12px 0 4px; }
.login-card p { color: var(--muted); }
.login-card .hint { font-size: 13px; margin-top: 18px; }

/* Drucken: nur die PDF-Seiten */
@media print {
  body > *:not(#sheet-root) { display: none !important; }
  #sheet-root > *:not(:last-child), .overlay { display: none !important; }
  .full { position: static; }
  .full-head, .full-foot, .chips-scroll, .form-hint { display: none !important; }
  .full-body { overflow: visible; padding: 0; }
  .pdf-page { box-shadow: none; border-radius: 0; margin: 0; page-break-after: always; width: 100%; }
}
