/* ---------------------------------------------------------------------------
   Kapsel — Design-Tokens
   Richtung: „Hausapotheke, freundlich“ — Porzellanweiß, Flaschengrün,
   Mohnrot nur für Fälliges, Minze fürs Abhaken. Signatur: die Kapsel.
--------------------------------------------------------------------------- */

@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/fonts/bricolage-grotesque-var.woff2") format("woff2");
  font-weight: 300 800;
  font-stretch: 100%;
  font-display: swap;
}

:root {
  --bg: #EFF3EE;
  --card: #FFFFFF;
  --ink: #1C332B;
  --ink-soft: #5F7268;
  --line: #DDE6DE;
  --line-soft: #E9EFE9;
  --mohn: #D94F28;
  --mohn-soft: #FBEAE3;
  --minze: #2E8464;
  --minze-soft: #E3F0E9;
  --shadow: 0 1px 2px rgba(28, 51, 43, 0.06), 0 4px 16px rgba(28, 51, 43, 0.05);

  --font-display: "Bricolage Grotesque", -apple-system, system-ui, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --radius: 18px;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1915;
    --card: #17251E;
    --ink: #EAF1EC;
    --ink-soft: #94A99C;
    --line: #2A3B31;
    --line-soft: #1F2E26;
    --mohn: #F0693F;
    --mohn-soft: #37211A;
    --minze: #4EB388;
    --minze-soft: #1C3128;
    --shadow: none;
  }
}

/* ---------- Grundgerüst ---------- */

* { box-sizing: border-box; }

/* hidden muss immer gewinnen — auch gegen display-Regeln von Klassen */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--minze);
  outline-offset: 2px;
  border-radius: 6px;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px calc(96px + env(safe-area-inset-bottom));
}

.view[hidden] { display: none; }

/* ---------- Kopf ---------- */

.eyebrow {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.greeting {
  margin: 0;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.1;
}

.day-header { margin: 8px 0 24px; }

/* Tages-Zitat */
.daily-quote {
  margin: 12px 0 0;
  padding-left: 12px;
  border-left: 2.5px solid var(--minze);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-soft);
}

.daily-quote .author {
  display: block;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Fortschritt: eine Mini-Kapsel pro geplanter Einnahme */
.progress { margin-top: 16px; }

.progress-capsules {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.progress-capsules i {
  width: 22px;
  height: 9px;
  border-radius: 5px;
  background: var(--line);
  transition: background 0.3s ease;
}

.progress-capsules i.done { background: var(--minze); }
.progress-capsules i.due  { background: var(--mohn); }

.progress-label {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

/* ---------- Abschnitte (Morgens / Mittags / Abends / Zur Nacht) ---------- */

.section-label {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 26px 0 10px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.section-label::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--line);
}

.section-label .count {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

/* ---------- Karten & Einnahme-Zeilen ---------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.intake {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: var(--tap);
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
}

.intake:last-child { border-bottom: none; }

.intake .time {
  font-family: var(--font-mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  min-width: 44px;
}

.intake .what { flex: 1; min-width: 0; }

.intake .name {
  margin: 0;
  font-weight: 600;
  font-size: 16px;
}

.intake .meta {
  margin: 1px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Zustand: fällig */
.intake.is-due .time { color: var(--mohn); font-weight: 600; }
.intake.is-due .name::after {
  content: "fällig";
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--mohn-soft);
  color: var(--mohn);
  font-size: 11px;
  font-weight: 600;
  vertical-align: 2px;
}

/* Zustand: genommen */
.intake.is-taken .name,
.intake.is-taken .time { color: var(--ink-soft); }
.intake.is-taken .name { font-weight: 500; }

/* Zustand: ausgelassen */
.intake.is-skipped .name { color: var(--ink-soft); text-decoration: line-through; }

/* ---------- Die Kapsel (Signatur-Element) ---------- */

.capsule {
  position: relative;
  flex: none;
  width: 54px;
  height: 28px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: transparent;
  transition: background 0.25s ease, border-color 0.25s ease, transform 0.15s ease;
}

/* linke Hälfte + Naht: eine leere Zweifarbkapsel */
.capsule::before {
  content: "";
  position: absolute;
  inset: 3px 50% 3px 3px;
  border-radius: 10px 0 0 10px;
  background: var(--line-soft);
  transition: background 0.25s ease, opacity 0.2s ease;
}

.capsule::after {
  content: "";
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 50%;
  border-left: 2px solid var(--line);
  transition: opacity 0.2s ease;
}

.capsule svg {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  stroke: #fff;
  stroke-width: 3;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 22;
  stroke-dashoffset: 22;
  transition: stroke-dashoffset 0.3s ease 0.05s;
}

.intake.is-due .capsule { border-color: var(--mohn); }
.intake.is-due .capsule::before { background: var(--mohn-soft); }
.intake.is-due .capsule::after { border-color: var(--mohn); }

.intake.is-taken .capsule {
  border-color: var(--minze);
  background: var(--minze);
}
.intake.is-taken .capsule::before,
.intake.is-taken .capsule::after { opacity: 0; }
.intake.is-taken .capsule svg { stroke-dashoffset: 0; }

.capsule:active { transform: scale(0.92); }

@keyframes capsule-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.capsule.just-taken { animation: capsule-pop 0.35s ease; }

/* ---------- Swipe-to-Delete ---------- */

.swipe {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--line-soft);
}
.swipe:last-child { border-bottom: none; }

.swipe .intake,
.swipe .history-item { border-bottom: none; }

.swipe-row {
  position: relative;
  z-index: 1;
  background: var(--card);
  transition: transform 0.22s ease;
  touch-action: pan-y;
  will-change: transform;
}

.swipe.dragging .swipe-row { transition: none; }

.swipe-action {
  position: absolute;
  inset: 0 0 0 auto;
  width: 84px;
  background: var(--mohn);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.swipe-action svg { width: 22px; height: 22px; fill: currentColor; }

/* ---------- Detail-Zeile (aufgeklappt) ---------- */

.intake-detail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--line-soft);
}
.intake-detail:last-child { border-bottom: none; }

.intake-detail p {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
}

/* ---------- Leere & fertige Zustände ---------- */

.all-done {
  margin-top: 26px;
  padding: 28px 20px;
  text-align: center;
  border-radius: var(--radius);
  background: var(--minze-soft);
  color: var(--minze);
}

.all-done .big {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 650;
}

.all-done p { margin: 0; font-size: 14px; }

.empty {
  margin-top: 26px;
  padding: 28px 20px;
  text-align: center;
  border-radius: var(--radius);
  border: 1.5px dashed var(--line);
  color: var(--ink-soft);
  font-size: 14px;
}

/* ---------- Verlauf ---------- */

.range-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.range-chip {
  padding: 7px 13px;
  border-radius: 99px;
  border: 1.5px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.range-chip.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.range-summary {
  margin: 12px 0 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.streak {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--minze);
  font-weight: 600;
}

.history-day { margin-bottom: 22px; }

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0 2px 8px;
}

.history-date {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
}

.history-score {
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.history-score.full { color: var(--minze); }

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 14px;
}
.history-item:last-child { border-bottom: none; }

.history-item .time {
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  min-width: 40px;
}

.history-item .dot {
  flex: none;
  width: 16px;
  height: 8px;
  border-radius: 4px;
}
.history-item .dot.taken { background: var(--minze); }
.history-item .dot.skipped { background: var(--line); }
.history-item .dot.missed { background: var(--mohn); }

.history-item .h-name { flex: 1; }
.history-item .h-status { font-size: 12px; color: var(--ink-soft); }

/* ---------- Plan / Verwaltung ---------- */

.med-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
}
.med-row:last-child { border-bottom: none; }

.med-row .what { flex: 1; }

.med-row .times {
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.med-row .chevron {
  color: var(--ink-soft);
  font-size: 18px;
  line-height: 1;
}

.settings { margin-top: 34px; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.settings-row:last-child { border-bottom: none; }

.settings-title { margin: 0; font-weight: 600; font-size: 15px; }
.settings-sub { margin: 2px 0 0; font-size: 13px; color: var(--ink-soft); }

.install-hint {
  margin: 14px 2px 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--mohn-soft);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: 14px;
  font-weight: 600;
  font-size: 15px;
  transition: transform 0.12s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--ink); color: var(--bg); }
.btn-ghost { color: var(--ink-soft); }
.btn-danger { color: var(--mohn); }
.btn-wide { width: 100%; margin-top: 14px; }
.btn-small { min-height: 36px; padding: 6px 14px; font-size: 14px; background: var(--minze-soft); color: var(--minze); border-radius: 99px; flex: none; }

/* ---------- Tab-Leiste ---------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 20px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line-soft);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  max-width: 110px;
  padding: 6px 0;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
}

.tab svg { width: 22px; height: 22px; fill: currentColor; }

.tab.is-active { color: var(--ink); }

/* ---------- Sheet (Dialog) ---------- */

.sheet {
  width: min(480px, 100vw);
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
  border: none;
  border-radius: 22px 22px 0 0;
  background: var(--card);
  color: var(--ink);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet::backdrop { background: rgba(14, 25, 21, 0.45); }

.sheet-title {
  margin: 0 0 18px;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 650;
}

.field { display: block; margin-bottom: 16px; }

.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}

.field > span em { font-style: normal; font-weight: 400; }

.field-hint {
  margin: -2px 0 8px;
  font-size: 12px;
  color: var(--ink-soft);
}

.field input[type="text"],
.field input[type="time"],
#login-code {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}

.field input:focus, #login-code:focus {
  outline: none;
  border-color: var(--minze);
}

.time-chips, .day-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.time-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 99px;
  background: var(--minze-soft);
  color: var(--minze);
  font-family: var(--font-mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.time-chip b { font-weight: 700; font-size: 15px; line-height: 1; }

.day-chip {
  min-width: 40px;
  min-height: 36px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}

.day-chip.on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.time-add { display: flex; gap: 8px; margin-top: 10px; }
.time-add input { flex: 1; }

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
}
.sheet-actions .btn-danger { margin-right: auto; }

/* ---------- Login ---------- */

.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 24px;
  z-index: 10;
}

.login-inner { width: 100%; max-width: 320px; text-align: center; }

.wordmark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}

.wordmark-capsule {
  display: inline-block;
  width: 34px;
  height: 18px;
  border-radius: 9px;
  background: linear-gradient(90deg, var(--minze) 50%, var(--minze-soft) 50%);
  border: 2px solid var(--minze);
  transform: rotate(-12deg);
}

.login-hint { color: var(--ink-soft); font-size: 14px; margin: 0 0 20px; }

#login-form { display: grid; gap: 10px; }

.login-error {
  color: var(--mohn);
  font-size: 14px;
  font-weight: 600;
  margin: 4px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--mohn-soft);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: calc(92px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 99px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 20;
}

/* ---------- Bewegung reduzieren ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
