:root {
  --bg: #f4ece0;
  --surface: #fffaf3;
  --surface-2: #efe4d4;
  --text: #2b2118;
  --muted: #7a6a5a;
  --line: #e2d4c0;
  --accent: #d9701e;
  --accent-ink: #ffffff;
  --accent-soft: #fbe2cb;
  --ok: #3f7d4e;
  --ok-soft: #dcecd9;
  --warn: #b83a26;
  --warn-soft: #f8d9d2;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 20px rgba(60, 40, 20, .06);
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1914;
    --surface: #27211b;
    --surface-2: #322a22;
    --text: #f3e9dc;
    --muted: #b3a291;
    --line: #3d342b;
    --accent: #f08a3a;
    --accent-ink: #1d1914;
    --accent-soft: #4a3220;
    --ok: #82c393;
    --ok-soft: #233a29;
    --warn: #ff8f7a;
    --warn-soft: #4a2420;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
[hidden] { display: none !important; }
h1, h2 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 0 14px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.3rem; letter-spacing: -.01em; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 55%;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 12px 6px 8px; font: inherit; font-size: .95rem; cursor: pointer;
}
.chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; background: var(--muted); }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 14px;
}

/* Status */
.status { display: grid; gap: 14px; }
.status-row { display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: start; }
.status-icon {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  font-size: 1.35rem; background: var(--surface-2);
}
.status-row.is-warn .status-icon { background: var(--warn-soft); }
.status-row.is-ok .status-icon { background: var(--ok-soft); }
.status-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.status-main { font-size: 1.25rem; font-weight: 700; letter-spacing: -.01em; }
.status-row.is-warn .status-main { color: var(--warn); }
.status-sub { color: var(--muted); font-size: .92rem; }
.status-sub .who { font-weight: 600; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--ok); border-radius: inherit; transition: width .4s ease; }
.bar.is-mid > span { background: var(--accent); }
.bar.is-warn > span { background: var(--warn); }
.status-note { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; font-size: .92rem; }

/* Buttons */
.btn {
  font: inherit; font-weight: 650; border: 0; border-radius: 14px; padding: 12px 16px; cursor: pointer;
  transition: transform .08s ease, filter .15s ease; color: var(--text); background: var(--surface-2);
  touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn:focus-visible, .chip:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-secondary { background: var(--surface); border: 1px solid var(--line); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-big { font-size: 1.15rem; padding: 18px; }
.btn.small { padding: 6px 10px; font-size: .875rem; }
.actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-bottom: 14px; }
.actions .btn-secondary { padding: 12px 14px; }

/* Zeitraum */
.period { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.period-dates { display: grid; gap: 2px; }
.period-dates b { font-weight: 650; }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 650; cursor: pointer; padding: 6px; }

.push-hint { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px dashed var(--accent); }
.push-hint p { margin: 2px 0 0; }

/* Verlauf */
.history h2 { margin: 22px 4px 10px; }
.day-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin: 16px 4px 8px; }
.entry {
  position: relative; display: grid; grid-template-columns: 54px 1fr auto; gap: 10px; align-items: center;
  background: var(--surface); border-radius: 14px; padding: 12px 8px 12px 16px; margin-bottom: 8px;
  box-shadow: var(--shadow); overflow: hidden;
}
.entry::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--c, var(--muted)); }
.entry-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.entry-who { font-weight: 650; display: flex; align-items: center; gap: 6px; }
.entry-who .dot { width: 10px; height: 10px; background: var(--c); }
.entry-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tag { font-size: .8rem; border-radius: 99px; padding: 2px 8px; background: var(--surface-2); color: var(--text); }
.tag.fed { background: var(--accent-soft); }
.entry-note { margin-top: 4px; font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; }
.entry-del {
  border: 0; background: transparent; color: var(--muted); width: 40px; height: 40px; border-radius: 12px;
  font-size: 1.1rem; cursor: pointer;
}
.entry-del:hover { background: var(--warn-soft); color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 24px 12px; }

/* Formulare */
.field { display: grid; gap: 6px; margin: 0 0 16px; border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { font-weight: 600; font-size: .92rem; padding: 0; margin-bottom: 6px; }
input[type="text"], input:not([type]), input[type="datetime-local"], textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; width: 100%; min-width: 0;
}
input[type="datetime-local"] { min-height: 48px; -webkit-appearance: none; appearance: none; }
textarea { resize: vertical; }
.checkline { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; font-weight: 600; }
.checkline input { width: 22px; height: 22px; accent-color: var(--accent); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; }
.segmented span {
  display: block; text-align: center; padding: 16px 8px; border-radius: 14px; border: 2px solid var(--line);
  font-weight: 650; background: var(--bg); cursor: pointer;
}
.segmented input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.segmented input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { position: relative; width: 40px; height: 40px; }
.swatch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.swatch span {
  display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--c);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.08); pointer-events: none;
}
.swatch input:checked + span { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--text); }
.swatch input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 4px; }
.swatch.custom span { background: conic-gradient(#e85d5d, #e8c35d, #6bc46d, #5db3e8, #9b6de8, #e85d5d); }
.swatch.custom input[type="color"] { width: 100%; height: 100%; padding: 0; border: 0; }

.form-error { color: var(--warn); font-weight: 600; min-height: 0; margin: 0 0 8px; }
.form-error:empty { display: none; }

/* Dialoge */
dialog.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); border-radius: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog.sheet::backdrop { background: rgba(30, 20, 10, .45); }
dialog.sheet form { padding: 22px 20px 18px; }
dialog.sheet h2 { margin-bottom: 18px; font-size: 1.3rem; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
@media (max-width: 600px) {
  dialog.sheet { margin: auto auto 0; width: 100vw; max-width: 100vw; border-radius: 22px 22px 0 0; }
  dialog.sheet form { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}
.push-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; border-radius: 14px; background: var(--bg); margin-bottom: 16px; }
.push-box p { margin: 2px 0 0; }
.push-buttons { display: grid; gap: 4px; justify-items: end; }

/* Onboarding */
.onboarding { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.onboarding-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 24px; padding: 28px 22px; box-shadow: var(--shadow); }
.onboarding-icon { display: block; margin-bottom: 12px; }
.onboarding-card h1 { font-size: 1.6rem; }
.onboarding-card > p { margin: 6px 0 22px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600;
  max-width: calc(100vw - 32px); z-index: 10; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
