:root {
  --bg: #f7f1ee;
  --surface: #ffffff;
  --surface-2: #f2e9e5;
  --ink: #2a2023;
  --muted: #7d6e72;
  --line: #e7dcd8;
  --accent: #8c3b5e;
  --accent-2: #e9926b;
  --accent-ink: #ffffff;
  --ok: #3f8a6b;
  --warn-bg: #fff3e6;
  --warn-ink: #8a4b12;
  --err: #b3263e;
  --c-menstrual: #d24a68;
  --c-follicular: #3e9a8a;
  --c-ovulatory: #e3a33a;
  --c-luteal: #8a6cc6;
  --c-pill: #4e83cf;
  --c-pause: #c27b9b;
  --c-psy: #6a55b8;
  --crisis-bg: #fdecee;
  --crisis-ink: #8c1d32;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(60, 30, 40, .06), 0 6px 24px rgba(60, 30, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1517; --surface: #251d20; --surface-2: #30262a; --ink: #f3ebee; --muted: #b3a2a8;
    --line: #3d3135; --accent: #e07aa4; --accent-2: #f0a27f; --accent-ink: #1b1517;
    --ok: #6cc59e; --warn-bg: #3a2a1a; --warn-ink: #f2c08a; --err: #ff7d92;
    --c-psy: #a592f0; --crisis-bg: #3d1a22; --crisis-ink: #ffc2cc;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 .7em; }
ul { margin: 0 0 .8em; padding-left: 1.2em; }
li { margin-bottom: .35em; }
.muted { color: var(--muted); font-weight: 400; }
.center { text-align: center; }
.note { color: var(--muted); font-size: .86rem; }
.warn { background: var(--warn-bg); color: var(--warn-ink); padding: .65em .8em; border-radius: 12px; font-size: .9rem; }
.err { color: var(--err); min-height: 1.2em; font-size: .9rem; }
.ok-line { color: var(--ok); font-weight: 600; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 6px; }

/* ---------- Buttons ---------- */
button, .btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: .6em 1em; cursor: pointer; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .4em;
}
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
button:disabled { opacity: .6; cursor: progress; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.ghost { background: transparent; }
.light { background: rgba(255, 255, 255, .9); color: #2a2023; border-color: transparent; font-weight: 600; }
.link { border: 0; background: none; color: var(--accent); padding: 0; min-height: 0; font-weight: 600; }
.wide { width: 100%; }
.small { min-height: 36px; padding: .35em .8em; font-size: .9rem; }
.btns { display: grid; gap: .6em; margin-bottom: .8em; }

/* ---------- Gate ---------- */
.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 24px; padding: 28px 22px; box-shadow: var(--shadow); }
.gate-card h1 { font-size: 1.6rem; text-align: center; }
.logo { width: 64px; height: 64px; margin: 0 auto 10px; color: var(--accent); }
.stack { display: grid; gap: .8em; }
label { display: grid; gap: .3em; font-size: .92rem; font-weight: 550; }
input[type=password], input[type=number], input[type=date], input[type=time], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: .6em .75em; min-height: 44px;
}
textarea { resize: vertical; }

/* ---------- Layout ---------- */
#app { max-width: 640px; margin: 0 auto; padding: 0 16px calc(90px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; justify-content: space-between; padding: calc(12px + env(safe-area-inset-top)) 2px 10px; }
.brand { font-weight: 750; letter-spacing: .02em; color: var(--accent); }
.sync { font-size: .78rem; color: var(--muted); display: inline-flex; align-items: center; gap: .4em; }
.sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync.ok::before { background: var(--ok); }
.sync.sync::before { background: var(--accent-2); }
.sync.err::before { background: var(--err); }
.sync.err { color: var(--err); }

.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card.pill.done { outline: 2px solid color-mix(in srgb, var(--ok) 40%, transparent); }

.hero {
  border-radius: 24px; padding: 22px 20px; margin-bottom: 14px; color: #fff;
  background: linear-gradient(140deg, #8c3b5e, #c0607a 60%, #e9926b);
}
.hero.ph-menstrual { background: linear-gradient(140deg, #a3324f, #d24a68 60%, #ec8a7c); }
.hero.ph-follicular { background: linear-gradient(140deg, #2a7a6d, #3e9a8a 60%, #8cc7a4); }
.hero.ph-ovulatory { background: linear-gradient(140deg, #b9731f, #e3a33a 60%, #f0c46a); }
.hero.ph-luteal { background: linear-gradient(140deg, #5b449a, #8a6cc6 60%, #c096c9); }
.hero.ph-pill { background: linear-gradient(140deg, #2f5d9f, #4e83cf 60%, #8ab3e6); }
.hero.ph-dng { background: linear-gradient(140deg, #3d4f9a, #5b6fc6 60%, #9a9fdc); }
.hero.ph-pause { background: linear-gradient(140deg, #8f4c6b, #c27b9b 60%, #e2a9b9); }
.hero p { margin: 0 0 .3em; }
.hero .eyebrow { opacity: .85; font-size: .88rem; }
.hero .big { font-size: 2.1rem; font-weight: 750; letter-spacing: -.01em; margin-bottom: .15em; }
.hero .sub { opacity: .92; font-size: .92rem; }
.hero button { margin-top: .6em; }

/* ---------- Editor ---------- */
.editor { display: grid; gap: 14px; }
.field > label { margin-bottom: .4em; }
.field.inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field.inline label { margin: 0; }
.field.inline input { max-width: 110px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg button { padding: .45em .3em; min-height: 42px; font-size: .9rem; background: var(--surface-2); border-color: transparent; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg[data-f=mood] button { font-size: 1.25rem; }
.seg[data-f=flow] button.on { background: var(--c-menstrual); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { min-height: 36px; padding: .3em .75em; border-radius: 999px; font-size: .88rem; background: var(--surface-2); border-color: transparent; }
.chips button.on { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ---------- Kalender ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-head h2 { font-size: 1.1rem; margin: 0; }
.cal-head button { font-size: 1.4rem; width: 44px; padding: 0; border: 0; }
.cal-dow, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { margin: 10px 0 4px; font-size: .75rem; color: var(--muted); text-align: center; }
.cell { aspect-ratio: 1; min-height: 0; padding: 0; border-radius: 12px; border: 0; background: var(--surface-2); flex-direction: column; gap: 0; position: relative; font-size: .92rem; }
.cell.empty { background: transparent; }
.cell.future { color: var(--muted); }
.cell.flow { background: var(--c-menstrual); color: #fff; }
.cell.flow.f1 { background: color-mix(in srgb, var(--c-menstrual) 55%, var(--surface)); color: var(--ink); }
.cell.pred { background: transparent; box-shadow: inset 0 0 0 2px var(--c-menstrual); }
.cell.fertile { background: color-mix(in srgb, var(--c-ovulatory) 22%, var(--surface)); }
.cell.ov { box-shadow: inset 0 0 0 2px var(--c-ovulatory); font-weight: 700; }
.cell.today .n { background: var(--ink); color: var(--bg); border-radius: 999px; padding: 0 .45em; font-weight: 700; }
.dots { display: flex; gap: 3px; height: 6px; margin-top: 3px; }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.dot.pill { background: var(--c-pill); }
.dot.miss { background: transparent; box-shadow: inset 0 0 0 1.5px var(--err); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 14px 0 6px; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .4em; }
.lg { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.lg.flow { background: var(--c-menstrual); }
.lg.pred { box-shadow: inset 0 0 0 2px var(--c-menstrual); }
.lg.fertile { background: color-mix(in srgb, var(--c-ovulatory) 30%, var(--surface)); }
.lg.ov { box-shadow: inset 0 0 0 2px var(--c-ovulatory); }

/* ---------- Diagramme ---------- */
.chart { width: 100%; height: auto; display: block; margin: 8px 0; }
.chart .bar { fill: var(--accent); }
.chart .b-menstrual { fill: var(--c-menstrual); } .chart .b-follicular { fill: var(--c-follicular); }
.chart .b-ovulatory { fill: var(--c-ovulatory); } .chart .b-luteal { fill: var(--c-luteal); }
.chart .b-pill { fill: var(--c-pill); } .chart .b-pause { fill: var(--c-pause); }
.chart text { font-size: 10px; fill: var(--muted); }
.chart .val { fill: var(--ink); font-weight: 600; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .pt { fill: var(--accent); }
.chart .grid { stroke: var(--line); stroke-dasharray: 3 3; }
.axis-row { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 6px; }
.stats div { background: var(--surface-2); border-radius: 12px; padding: 10px; }
.stats b { display: block; font-size: 1.3rem; }
.stats span { font-size: .78rem; color: var(--muted); }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .86rem; }
.tbl th { font-weight: 600; color: var(--muted); font-size: .78rem; text-align: center; padding: 4px; }
.tbl td { padding: 5px 4px; border-top: 1px solid var(--line); }
.tbl td:not(:first-child) { text-align: center; }
.heat { display: inline-block; min-width: 3.2em; padding: .1em .3em; border-radius: 6px; background: color-mix(in srgb, var(--accent) calc(var(--p) * .6%), transparent); }

.ph-card { border-left: 5px solid var(--accent); }
.ph-card.ph-menstrual { border-color: var(--c-menstrual); } .ph-card.ph-follicular { border-color: var(--c-follicular); }
.ph-card.ph-ovulatory { border-color: var(--c-ovulatory); } .ph-card.ph-luteal { border-color: var(--c-luteal); }
.ph-card.ph-pill, .ph-card.ph-dng { border-color: var(--c-pill); } .ph-card.ph-pause { border-color: var(--c-pause); }

/* ---------- Einstellungen ---------- */
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: .7em; font-weight: 500; }
.row > span { flex: 1; }
.row select, .row input[type=number], .row input[type=date], .row input[type=time] { width: auto; max-width: 58%; }
.row input[type=number] { max-width: 90px; }
input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); }
.card form { margin-bottom: .8em; }

/* ---------- Navigation ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
}
.tabs button { border: 0; background: none; flex-direction: column; gap: 2px; font-size: .7rem; color: var(--muted); min-height: 52px; padding: 4px 0; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs svg .fill { fill: currentColor; }
.tabs button.on { color: var(--accent); font-weight: 650; }
@media (min-width: 700px) { .tabs { max-width: 640px; margin: 0 auto 12px; border-radius: 20px; border: 1px solid var(--line); bottom: 0; } }

/* ---------- Dialog ---------- */
dialog {
  border: 0; padding: 0; width: min(560px, 100%); max-height: 92vh; max-height: 92dvh; border-radius: 24px 24px 0 0;
  background: var(--surface); color: var(--ink); margin: auto auto 0; box-shadow: 0 -8px 40px rgba(0, 0, 0, .2);
}
@media (min-width: 700px) { dialog { border-radius: 24px; margin: auto; } }
dialog::backdrop { background: rgba(20, 10, 15, .45); }
#dlg-body { padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: inherit; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.dlg-head h2 { font-size: 1.05rem; margin: 0; }
.x { border: 0; background: var(--surface-2); width: 40px; min-height: 40px; padding: 0; border-radius: 50%; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 50; background: var(--ink); color: var(--bg); padding: .7em 1em; border-radius: 12px; max-width: calc(100% - 32px); font-size: .9rem; box-shadow: var(--shadow); }

/* ---------- Bericht ---------- */
body.report-open #app { display: none; }
.report { max-width: 800px; margin: 0 auto; padding: 16px; }
.report-bar { position: sticky; top: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--bg); padding: calc(8px + env(safe-area-inset-top)) 0 12px; }
.report-bar .chk { display: inline-flex; align-items: center; gap: .4em; grid-auto-flow: column; }
.report-body { background: #fff; color: #222; padding: 24px; border-radius: 12px; font-size: 14px; }
.report-body h1 { font-size: 1.4rem; }
.report-body h2 { font-size: 1.05rem; margin-top: 1.4em; border-bottom: 1px solid #ddd; padding-bottom: .2em; }
.report-body table { width: 100%; border-collapse: collapse; margin-bottom: 1em; }
.report-body th, .report-body td { border: 1px solid #ddd; padding: 4px 6px; text-align: left; vertical-align: top; }
.report-body .meta { color: #666; font-size: 12px; }
.report-body .nowrap { white-space: nowrap; }
@media print {
  body { background: #fff; }
  .no-print, #app, #gate, .tabs, .toast, dialog { display: none !important; }
  .report { padding: 0; max-width: none; }
  .report-body { padding: 0; border-radius: 0; }
}

/* ---------- Version 2: Symptomgruppen, Intensität, Kurven, Zusammenfassung ---------- */
.mini { font-size: .78rem; color: var(--muted); margin: .6em 0 .3em; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.quick { margin-bottom: 8px; }
.area { margin: 14px 0 4px; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.area-psyche { color: var(--c-psy); }
.area-crisis { color: var(--crisis-ink); }
.grp { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 6px; background: var(--surface); }
.grp > summary { cursor: pointer; padding: .6em .8em; font-weight: 600; font-size: .93rem; list-style: none; display: flex; align-items: center; gap: .5em; min-height: 44px; }
.grp > summary::-webkit-details-marker { display: none; }
.grp > summary::after { content: "›"; margin-left: auto; transition: transform .15s; color: var(--muted); font-size: 1.2rem; }
.grp[open] > summary::after { transform: rotate(90deg); }
.grp > .chips { padding: 0 .6em .7em; }
.grp-crisis { border-color: color-mix(in srgb, var(--crisis-ink) 35%, var(--line)); }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: .72rem; padding: .05em .55em; font-weight: 700; }

.chips button.sx { gap: .35em; }
.chips button.sx .lvl { font-size: .5rem; letter-spacing: 1px; line-height: 1; }
.chips button.sx.i1 { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--ink); }
.chips button.sx.i2 { background: color-mix(in srgb, var(--accent) 30%, var(--surface)); border-color: var(--accent); color: var(--ink); font-weight: 600; }
.chips button.sx.i3 { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.chips button.crisis-chip.i1, .chips button.crisis-chip.i2, .chips button.crisis-chip.i3 { background: var(--crisis-ink); border-color: var(--crisis-ink); color: #fff; }

.card.crisis { background: var(--crisis-bg); color: var(--crisis-ink); border: 2px solid color-mix(in srgb, var(--crisis-ink) 40%, transparent); }
.card.crisis a { color: inherit; font-weight: 700; white-space: nowrap; }
.card.crisis ul { margin-bottom: 0; }
.cell.crisis-day { box-shadow: inset 0 0 0 2px var(--crisis-ink); }

.sum-btn { margin-bottom: 12px; }
.subtabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 14px; margin-bottom: 14px; }
.subtabs button { border: 0; background: transparent; min-height: 40px; font-weight: 600; color: var(--muted); }
.subtabs button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg.mode { margin-bottom: 10px; }
.seg.mode button:disabled { opacity: .4; }

.flag-line { margin: 0 0 .3em; padding-left: .7em; border-left: 4px solid var(--warn-ink); }
.flag-line.lvl-crisis { border-color: var(--crisis-ink); }
.flag-line.lvl-urgent { border-color: var(--err); }

/* Kurven */
.chart .band { opacity: .13; }
.chart .band-menstrual { fill: var(--c-menstrual); } .chart .band-follicular { fill: var(--c-follicular); }
.chart .band-ovulatory { fill: var(--c-ovulatory); } .chart .band-luteal { fill: var(--c-luteal); }
.chart .line.s-p { stroke: var(--c-psy); } .chart .pt.s-p { fill: var(--c-psy); }
.chart .line.s-c { stroke: var(--c-menstrual); } .chart .pt.s-c { fill: var(--c-menstrual); }
.chart .line.s-d { stroke: var(--c-pill); } .chart .pt.s-d { fill: var(--c-pill); }
.chart .line.s-mood { stroke: var(--accent); } .chart .pt.s-mood { fill: var(--accent); }
.chart .line.s-sym { stroke-width: 2.2; }
.lg.s-p { background: var(--c-psy); height: 4px; } .lg.s-c { background: var(--c-menstrual); height: 4px; } .lg.s-d { background: var(--c-pill); height: 4px; }
.curve-group { margin: 16px 0 6px; font-size: .9rem; }
.curve-group:first-child { margin-top: 0; }
.curves { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 560px) { .curves { grid-template-columns: 1fr 1fr; } }
.curve { background: var(--surface-2); border-radius: 12px; padding: 8px 10px 2px; }
.curve.crisis-curve { background: var(--crisis-bg); }
.curve-title { font-size: .85rem; font-weight: 600; margin: 0; }
.curve .chart { margin: 2px 0; }
.small-t { font-size: .8rem; margin: .3em 0 .6em; }

/* Zusammenfassung (auch im Bericht) */
.tboxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: .4em 0 .8em; }
.tbox { border-radius: 12px; padding: 10px 12px; background: #f3f0ee; border-left: 5px solid #999; }
.tbox .tl { display: block; font-size: 12px; color: #666; }
.tbox b { display: block; font-size: 1.05rem; }
.tbox .tv { font-size: 12px; color: #444; }
.tbox.worse { border-color: #c0392b; background: #fdeeec; }
.tbox.better { border-color: #2e8b57; background: #ebf7f0; }
.tbox.same { border-color: #8a8a8a; }
.tbox.na { opacity: .7; }
.flags { list-style: none; padding: 0; }
.flags li { border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: #fff7e8; border-left: 5px solid #d08a1e; }
.flags li.lvl-urgent { background: #fdeeec; border-color: #c0392b; }
.flags li.lvl-crisis { background: #fbe3e8; border-color: #8c1d32; }
.lvl-tag { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; color: #7a4a0c; }
.lvl-crisis .lvl-tag { color: #8c1d32; } .lvl-urgent .lvl-tag { color: #a5281b; }
.report-body .ok-line { color: #2e7d55; }
.report-body .card.crisis { background: #fbe3e8; color: #8c1d32; box-shadow: none; }
.report-body ul { padding-left: 1.2em; }
.report-body .muted { color: #777; }
.report-body .mini { color: #666; }
@media print { .tbox, .flags li { break-inside: avoid; -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
