/* Fehltage – Heft-Look: Papier, Tinte, roter Rand. */

:root {
  --bg: #f4f1ea;
  --flaeche: #fffdf8;
  --flaeche-2: #f9f6ef;
  --tinte: #1c2230;
  --leise: #6a7180;
  --linie: #e3ddd0;
  --linie-stark: #d3cbbb;
  --akzent: #2f4bd8;
  --akzent-tinte: #ffffff;
  --akzent-weich: #e7ebfc;
  --rot: #d0412b;
  --rot-weich: #fbe8e4;
  --gruen: #237a43;
  --gruen-weich: #e2f2e7;
  --heftlinie: rgba(47, 75, 216, 0.09);
  --rand: rgba(208, 65, 43, 0.45);
  --schatten: 0 1px 2px rgba(28, 34, 48, 0.06), 0 6px 20px rgba(28, 34, 48, 0.06);
  --schatten-gross: 0 10px 40px rgba(28, 34, 48, 0.18);
  --radius: 16px;
  --sicher-unten: env(safe-area-inset-bottom, 0px);
  --sicher-oben: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151c;
    --flaeche: #1b1f29;
    --flaeche-2: #171b24;
    --tinte: #eceef3;
    --leise: #98a0b0;
    --linie: #2a303c;
    --linie-stark: #394050;
    --akzent: #8196ff;
    --akzent-tinte: #0f1324;
    --akzent-weich: #222a4c;
    --rot: #ff7b67;
    --rot-weich: #3a221e;
    --gruen: #63c886;
    --gruen-weich: #1b3324;
    --heftlinie: rgba(129, 150, 255, 0.07);
    --rand: rgba(255, 123, 103, 0.35);
    --schatten: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    --schatten-gross: 0 10px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--tinte);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button, a, input, select, textarea, label { touch-action: manipulation; } /* kein Zoom bei schnellem Doppeltippen */
:focus-visible { outline: 2.5px solid var(--akzent); outline-offset: 2px; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--sicher-oben) + 8px) 16px calc(110px + var(--sicher-unten));
  min-height: 100dvh;
}

.laden { display: grid; place-items: center; min-height: 60dvh; }
.punkt { width: 10px; height: 10px; border-radius: 50%; background: var(--akzent); animation: puls 1s ease-in-out infinite; }
@keyframes puls { 50% { transform: scale(1.8); opacity: .4; } }

/* ------------------------------------------------ Kopf mit Heftlinien */

.kopf {
  position: relative;
  margin: 0 -16px 18px;
  padding: 18px 16px 18px 34px;
  background:
    linear-gradient(90deg, transparent 22px, var(--rand) 22px, var(--rand) 23.5px, transparent 23.5px),
    repeating-linear-gradient(180deg, transparent 0 27px, var(--heftlinie) 27px 28px);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.kopf h1 { margin: 0; font-size: 30px; line-height: 1.1; letter-spacing: -0.025em; font-weight: 780; }
.kopf .unter { margin: 4px 0 0; color: var(--leise); font-size: 14px; }

.rund {
  flex: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--linie);
  background: var(--flaeche);
  box-shadow: var(--schatten);
}
.rund svg { width: 22px; height: 22px; }

/* ------------------------------------------------ Zahlen */

.zahlen { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.zahl {
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: 14px;
  padding: 12px 12px 10px;
}
.zahl b { display: block; font-size: 26px; line-height: 1; font-weight: 760; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.zahl span { display: block; margin-top: 6px; font-size: 12.5px; color: var(--leise); }
.zahl.warn b { color: var(--rot); }
.zahl.gut b { color: var(--gruen); }

/* ------------------------------------------------ Karten */

.karte {
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  box-shadow: var(--schatten);
  padding: 16px;
  margin-bottom: 14px;
}
.karte h2 { margin: 0 0 4px; font-size: 18px; letter-spacing: -0.01em; }
.karte p { margin: 0 0 12px; color: var(--leise); font-size: 15px; }
.karte .marke { display: inline-block; font-size: 12px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--akzent); margin-bottom: 6px; }
.karte.woche { border-color: color-mix(in srgb, var(--akzent) 35%, var(--linie)); background: linear-gradient(180deg, var(--akzent-weich), var(--flaeche) 70%); }
.karte.leise { box-shadow: none; background: var(--flaeche-2); }
.karte .reihe { display: flex; gap: 8px; flex-wrap: wrap; }
.karte .reihe > * { flex: 1 1 140px; }
.hinweis { font-size: 14px; color: var(--leise); }
.hinweis ol { margin: 6px 0 0; padding-left: 20px; }
.hinweis li { margin: 3px 0; }

.erledigt-zeile {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 14px; padding: 10px 14px;
  border-radius: 12px; background: var(--gruen-weich); color: var(--gruen);
  font-size: 14.5px; font-weight: 600;
}
.erledigt-zeile svg { width: 18px; height: 18px; flex: none; }

/* ------------------------------------------------ Knöpfe */

.knopf {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--linie-stark);
  background: var(--flaeche);
  font-weight: 620; font-size: 15.5px;
  text-decoration: none;
  white-space: nowrap;
  transition: transform .12s ease, background-color .15s ease;
}
.knopf:active { transform: scale(.97); }
.knopf svg { width: 19px; height: 19px; flex: none; }
.knopf.haupt { background: var(--akzent); border-color: var(--akzent); color: var(--akzent-tinte); }
.knopf.gruen { background: var(--gruen-weich); border-color: transparent; color: var(--gruen); }
.knopf.gefahr { background: transparent; border-color: transparent; color: var(--rot); }
.knopf.klein { min-height: 38px; padding: 0 14px; font-size: 14px; }
.knopf.voll { width: 100%; }
.knopf[disabled] { opacity: .5; pointer-events: none; }

.neu-knopf {
  position: fixed;
  left: 50%; bottom: calc(18px + var(--sicher-unten));
  transform: translateX(-50%);
  z-index: 5;
  min-height: 56px; padding: 0 26px;
  font-size: 17px;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--akzent) 40%, transparent);
}
.neu-knopf:active { transform: translateX(-50%) scale(.97); }

/* ------------------------------------------------ Liste */

.abschnitt { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 2px 8px; }
.abschnitt h3 { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--leise); }
.abschnitt button { border: 0; background: none; color: var(--akzent); font-weight: 600; font-size: 14px; padding: 6px 0; }

.eintrag {
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.eintrag.offen { border-left: 4px solid var(--rot); }
.eintrag .oben {
  display: flex; gap: 12px; align-items: center;
  width: 100%; padding: 14px 14px 10px;
  border: 0; background: none; text-align: left;
}
.kalender {
  flex: none; width: 50px; text-align: center;
  border-radius: 10px; overflow: hidden;
  border: 1px solid var(--linie-stark);
  background: var(--flaeche);
}
.kalender small { display: block; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; background: var(--rot); color: #fff; padding: 2px 0; }
.kalender b { display: block; font-size: 21px; line-height: 1.25; font-weight: 750; font-variant-numeric: tabular-nums; padding: 2px 0 3px; }
.eintrag .text { flex: 1; min-width: 0; }
.eintrag .titel { display: block; font-weight: 650; font-size: 16px; }
.eintrag .info { display: block; color: var(--leise); font-size: 14px; margin-top: 2px; }
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  background: var(--flaeche-2); border: 1px solid var(--linie);
  font-size: 12.5px; font-weight: 600; color: var(--tinte); white-space: nowrap;
  flex: 0 1 auto; min-width: 0; max-width: 42%; overflow: hidden; text-overflow: ellipsis;
}
.eintrag .aktionen { display: flex; gap: 8px; padding: 0 14px 14px; }
.eintrag .aktionen .knopf { flex: 1; }
.eintrag.fertig { background: var(--flaeche-2); }
.eintrag.fertig .kalender small { background: var(--leise); }
.eintrag.fertig .aktionen { padding-top: 0; }

.leer {
  text-align: center; color: var(--leise);
  padding: 36px 20px; border: 1.5px dashed var(--linie-stark); border-radius: var(--radius);
}
.leer b { display: block; color: var(--tinte); font-size: 17px; margin-bottom: 4px; }

/* ------------------------------------------------ Anmelden */

.anmelden { min-height: 80dvh; display: grid; place-content: center; text-align: center; gap: 14px; }
.anmelden .logo { width: 76px; height: 76px; margin: 0 auto; border-radius: 20px; box-shadow: var(--schatten); }
.anmelden h1 { margin: 6px 0 0; font-size: 30px; letter-spacing: -0.025em; }
.anmelden p { margin: 0; color: var(--leise); }
.pin {
  width: 240px; margin: 8px auto 0;
  text-align: center; font-size: 30px; letter-spacing: .4em; padding: 12px 0 12px .4em;
  border-radius: 14px; border: 1.5px solid var(--linie-stark); background: var(--flaeche);
  font-variant-numeric: tabular-nums;
}
.fehler { color: var(--rot); font-size: 14.5px; min-height: 1.4em; }

/* ------------------------------------------------ Dialoge (Blätter) */

dialog.blattfenster {
  width: min(560px, 100%);
  max-width: 100%;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--flaeche);
  color: var(--tinte);
  box-shadow: var(--schatten-gross);
  overflow: hidden;
}
dialog.blattfenster.gross { height: 92dvh; }
dialog.blattfenster[open] { display: flex; flex-direction: column; animation: hoch .26s cubic-bezier(.2, .8, .2, 1); }
dialog::backdrop { background: rgba(10, 12, 18, .45); }
@keyframes hoch { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) {
  dialog.blattfenster { margin: auto; border-radius: 22px; max-height: 88dvh; }
  dialog.blattfenster.gross { height: 88dvh; }
}
@media (prefers-reduced-motion: reduce) {
  dialog.blattfenster[open] { animation: none; }
  .punkt { animation: none; }
}

.fenster-kopf {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--linie);
}
.fenster-kopf h2 { margin: 0; font-size: 18px; }
.fenster-kopf h2:focus { outline: none; } /* bekommt beim Öffnen den Fokus, damit kein Ring am X hängt */
.fenster-kopf .rund { width: 38px; height: 38px; box-shadow: none; }
.fenster-kopf .rund svg { width: 19px; height: 19px; }
/* flex-basis auto + min-height 0: Safari ließ den Inhalt bei "flex: 1" auf wenige Pixel zusammenfallen */
.fenster-inhalt {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 16px; -webkit-overflow-scrolling: touch;
}
html:has(dialog[open]) { overflow: hidden; } /* Seite dahinter scrollt nicht mit */
.fenster-fuss {
  flex: none;
  padding: 12px 16px calc(12px + var(--sicher-unten));
  border-top: 1px solid var(--linie);
  display: flex; gap: 8px; flex-wrap: wrap;
  background: var(--flaeche);
}
.fenster-fuss .knopf { flex: 1 1 160px; }

/* ------------------------------------------------ Formular */

.feld { margin-bottom: 16px; }
.feld > label, .feld > .label { display: block; font-size: 13.5px; font-weight: 650; color: var(--leise); margin-bottom: 6px; }
.feld input[type="text"], .feld input[type="date"], .feld input[type="password"], .feld select, .feld textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1.5px solid var(--linie-stark);
  background: var(--flaeche);
  font-size: 16px; /* verhindert Zoom auf dem iPhone */
}
.feld textarea { min-height: 76px; resize: vertical; }
/* iPhone: Datums- und Auswahlfelder sonst schmal/zentriert im Apple-Look */
.feld input[type="date"] { -webkit-appearance: none; appearance: none; display: block; text-align: left; }
.feld input[type="date"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
.feld select {
  -webkit-appearance: none; appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8f9c' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
}
.feld input:focus, .feld select:focus, .feld textarea:focus { outline: none; border-color: var(--akzent); }
.feld .klein { font-size: 13px; color: var(--leise); margin-top: 5px; }
.zwei { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.drei { display: grid; grid-template-columns: 110px 1fr; gap: 10px; }

.schnell { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.schnell button {
  border: 1px solid var(--linie-stark); background: var(--flaeche-2);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600;
}
.schnell button[aria-pressed="true"] { background: var(--akzent-weich); border-color: var(--akzent); color: var(--akzent); }

.segmente { display: flex; padding: 4px; gap: 4px; border-radius: 14px; background: var(--flaeche-2); border: 1px solid var(--linie); }
.segmente button {
  flex: 1; min-height: 42px; border: 0; border-radius: 10px; background: transparent;
  font-weight: 620; font-size: 15px; color: var(--leise);
}
.segmente button[aria-pressed="true"] { background: var(--flaeche); color: var(--tinte); box-shadow: var(--schatten); }

.gruende { display: flex; flex-wrap: wrap; gap: 8px; }
.gruende button {
  min-height: 42px; padding: 0 14px;
  border-radius: 999px; border: 1.5px solid var(--linie-stark); background: var(--flaeche);
  font-weight: 600; font-size: 15px;
}
.gruende button[aria-pressed="true"] { border-color: var(--akzent); background: var(--akzent-weich); color: var(--akzent); }

.schalter { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; }
.schalter input { appearance: none; -webkit-appearance: none; flex: none; width: 50px; height: 30px; border-radius: 999px; background: var(--linie-stark); position: relative; transition: background-color .2s; margin: 0; cursor: pointer; }
.schalter input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.schalter input:checked { background: var(--gruen); }
.schalter input:checked::after { transform: translateX(20px); }
.schalter span { flex: 1; font-size: 15.5px; }
.schalter small { display: block; color: var(--leise); font-size: 13px; }

.gruppe { margin: 4px 0 22px; }
.gruppe > h3 { margin: 0 0 10px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--leise); }
.gruppe .karte { box-shadow: none; }

.verborgen { display: none !important; }

/* ------------------------------------------------ Entschuldigung (Vorschau) */

.vorschau { background: var(--flaeche-2); }
.warnung {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; margin-bottom: 14px; border-radius: 12px;
  background: var(--rot-weich); color: var(--tinte); font-size: 14.5px;
}
.warnung button { border: 0; background: none; color: var(--rot); font-weight: 700; padding: 0; text-decoration: underline; }

.blatt-rahmen { container-type: inline-size; }
.blatt {
  /* A4, Maße in cqw: 100cqw = 210 mm */
  aspect-ratio: 210 / 297;
  background: #fff;
  color: #15171c;
  box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 8px 30px rgba(0,0,0,.10);
  border-radius: 3px;
  padding: 9.5cqw 9.5cqw 0 11.9cqw;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 1.85cqw;
  line-height: 1.45;
  position: relative;
  overflow: hidden;
}
.blatt p { margin: 0 0 1.1em; }
.b-absender { font-size: 1.68cqw; line-height: 1.3; min-height: 14cqw; }
.b-empfaenger { min-height: 21cqw; margin-top: 2cqw; line-height: 1.36; }
.b-datum { text-align: right; margin: 0 0 4.5cqw; padding-right: 0; }
.b-betreff { font-weight: 700; font-size: 1.93cqw; margin-bottom: 3cqw; }
.b-anrede { margin-bottom: 1.4em !important; }
.blatt table { width: 100%; border-collapse: collapse; font-size: 1.68cqw; margin: -0.2em 0 0.6em; }
.blatt th { text-align: left; border-bottom: 1px solid #8a8d95; padding: 0 0 .35em; }
.blatt td { padding: .45em 0 .2em; vertical-align: top; }
.blatt th:nth-child(1), .blatt td:nth-child(1) { width: 49%; }
.blatt th:nth-child(2), .blatt td:nth-child(2) { width: 22%; }
.blatt tbody tr:last-child td { border-bottom: 1px solid #8a8d95; padding-bottom: .5em; }
.b-summe { color: #6b6e75; font-size: 1.68cqw; }
.b-gruss { margin-top: .4em !important; }
.b-linie { width: 35.7cqw; border-top: 1px solid #15171c; margin-top: 8cqw; }
.b-name { font-size: 1.68cqw; margin-top: .5em; }
.b-zusatz { font-size: 1.35cqw; color: #6b6e75; }
.unterschreib-hier {
  position: absolute; left: 11.9cqw; width: 35.7cqw;
  font-size: 1.6cqw; color: var(--akzent);
}

/* ------------------------------------------------ Toast */

#toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--sicher-unten));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: 14px;
  background: var(--tinte); color: var(--bg);
  font-weight: 600; font-size: 15px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
  text-align: center;
}
#toast.da { opacity: 1; transform: translate(-50%, 0); }
