:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --text: #1c2523;
  --muted: #66736f;
  --line: #e1e6e3;
  --accent: #2f7d6d;
  --accent-soft: #e2f1ec;
  --on-accent: #ffffff;
  --overdue: #c0392b;
  --overdue-soft: #fbe7e4;
  --today: #b26a00;
  --today-soft: #fdf0d9;
  --radius: 14px;
  --tabbar-h: 62px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615;
    --surface: #1b2220;
    --text: #e7ecea;
    --muted: #93a19c;
    --line: #2b3431;
    --accent: #4fb39d;
    --accent-soft: #1d3530;
    --on-accent: #0d1513;
    --overdue: #ff8a7a;
    --overdue-soft: #3a1f1b;
    --today: #f2b75a;
    --today-soft: #3a2d17;
    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(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
input, select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 16px; /* below 16px iOS zooms into the field */
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
label { display: block; margin: 12px 0 4px; font-size: .9rem; color: var(--muted); }

/* --- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 0; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 600; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-quiet { background: transparent; color: var(--accent); }
.btn-danger { background: transparent; color: var(--overdue); }
.btn-block { width: 100%; margin-top: 18px; }
.btn-small { min-height: 34px; padding: 0 12px; font-size: .85rem; }
.btn:disabled { opacity: .6; }

.icon-btn {
  width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 50%; background: transparent;
  color: var(--muted); font-size: 1.4rem; line-height: 1;
}

/* --- Login --------------------------------------------------------------- */

.login {
  max-width: 380px; margin: 0 auto;
  padding: calc(48px + env(safe-area-inset-top)) 16px 32px;
  text-align: center;
}
.login img { border-radius: 18px; }
.login h1 { margin: 12px 0 20px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 8px 18px 20px; text-align: left; }
.form-error { color: var(--overdue); margin: 12px 0 0; }

/* --- Layout -------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.topbar h1 { margin: 0; font-size: 1.6rem; flex: 1; }
.user-btn { border: 0; background: none; color: var(--muted); font-size: .85rem; padding: 8px 0; }
.pill { padding: 2px 10px; border-radius: 99px; background: var(--today-soft); color: var(--today); font-size: .8rem; font-weight: 600; }

main {
  max-width: 640px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar button {
  position: relative; flex: 1;
  height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--muted); font-size: .75rem;
}
.tabbar button[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tab-icon { font-size: 1.35rem; line-height: 1; }
.badge-count {
  position: absolute; top: 6px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--overdue); color: #fff;
  font-size: .7rem; font-weight: 700; line-height: 18px; text-align: center;
}
#badge-shopping { background: var(--accent); color: var(--on-accent); }

.toolbar { display: flex; align-items: center; gap: 8px; margin: 8px 0 12px; flex-wrap: wrap; }
.toolbar-end { justify-content: flex-end; }
.toolbar .chips { flex: 1; }

/* --- Lists --------------------------------------------------------------- */

.list {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
}
.row {
  display: flex; align-items: center; gap: 10px;
  min-height: 56px; padding: 6px 6px 6px 14px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
  padding: 6px 0; cursor: pointer;
}
.title { overflow-wrap: anywhere; }
.row-inline { flex-direction: row; align-items: center; gap: 10px; }
.item-icon { flex: none; width: 1.6em; font-size: 1.15rem; text-align: center; }
.item-icon.is-generic { opacity: .3; filter: grayscale(1); }

.suggest { margin-bottom: 12px; border: 1px solid var(--accent); }
.suggest .row { min-height: 48px; }
.frequent { margin-bottom: 14px; }
.frequent .group-title { margin-top: 2px; }
.meta { font-size: .82rem; color: var(--muted); }
.area { font-size: .8rem; color: var(--muted); font-weight: 400; }
.empty { padding: 22px 16px; color: var(--muted); text-align: center; }
.is-done .title { text-decoration: line-through; color: var(--muted); }
.is-pending { opacity: .6; } /* added offline, not on the server yet */

/* Store sections inside the shopping list */
.section-title {
  padding: 10px 14px 4px;
  font-size: .75rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
  color: var(--muted); background: var(--bg);
}
.section-title:first-child { padding-top: 8px; }

/* Amount on a shopping item; "＋" when none is set yet */
.qty {
  flex: none; min-width: 36px; height: 30px; padding: 0 8px;
  border: 0; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent);
  font-size: .85rem; font-weight: 600; white-space: nowrap;
}
.qty.is-empty { background: transparent; color: var(--muted); opacity: .5; }
.is-done .qty { opacity: .5; }

/* Week view */
.day-date { margin-left: 6px; font-weight: 400; text-transform: none; letter-spacing: 0; }
.day-load { float: right; font-weight: 400; text-transform: none; letter-spacing: 0; }
.group-title.is-overdue { color: var(--overdue); }
.robot-line .title { font-size: .95rem; }

/* Action inside the toast, e.g. "Rückgängig" */
.toast { display: flex; align-items: center; gap: 14px; width: max-content; }
.toast[hidden] { display: none; }
.toast-action {
  border: 0; background: none; padding: 4px 0;
  color: var(--accent-soft); font-weight: 700; text-decoration: underline;
}

.check {
  position: relative; flex: none;
  width: 28px; height: 28px;
  border: 2px solid var(--line); border-radius: 50%;
  background: transparent;
}
.check::before { content: ""; position: absolute; inset: -8px; } /* larger touch target */
.check[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.check[aria-pressed="true"]::after {
  content: "✓"; position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--on-accent); font-size: .9rem; font-weight: 700;
}

.done-btn {
  flex: none; width: 46px; height: 46px;
  border: 0; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 1.3rem; font-weight: 700;
}
.done-btn:active { background: var(--accent); color: var(--on-accent); }

.due { font-weight: 600; color: var(--muted); }
.due.overdue { color: var(--overdue); }
.due.today { color: var(--today); }
.due.soon { color: var(--accent); }

.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.avatar.robot { background: var(--line); }

.group-title { margin: 18px 4px 6px; font-size: .85rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.group-title:first-child { margin-top: 6px; }

.add-row { display: flex; gap: 8px; margin: 8px 0 12px; }
.add-row .btn { width: 48px; padding: 0; font-size: 1.5rem; }

.done-section { margin-top: 16px; }
.done-section summary { padding: 10px 4px; color: var(--muted); cursor: pointer; }
.done-section .btn { margin-top: 8px; }

/* --- Chips & segmented control ------------------------------------------- */

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 99px;
  background: var(--surface); color: var(--text); font-size: .9rem;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.segmented {
  display: flex; padding: 3px; margin: 8px 0 4px;
  background: var(--line); border-radius: 12px;
}
.segmented > button, .segmented > label {
  flex: 1; margin: 0; min-height: 38px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 9px; background: transparent;
  color: var(--text); font-size: .9rem; text-align: center;
}
.segmented > button[aria-selected="true"],
.segmented > label:has(input:checked) { background: var(--surface); font-weight: 600; box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.segmented > label { position: relative; }
.segmented > label input, .weekdays input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.segmented-small { margin-top: 4px; }

/* --- Dialogs ------------------------------------------------------------- */

dialog {
  width: min(520px, calc(100% - 24px));
  max-height: calc(100dvh - 48px);
  padding: 20px 18px 16px;
  border: 0; border-radius: 18px;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dlg-small { width: min(360px, calc(100% - 24px)); }
.ask-text { margin: 4px 0 0; font-size: 1.05rem; }
dialog h2 { margin: 0 0 8px; font-size: 1.2rem; }
.hint { margin: 0 0 8px; color: var(--muted); }
fieldset.plain { border: 0; padding: 0; margin: 14px 0 0; }
fieldset.plain legend { padding: 0; font-size: .9rem; color: var(--muted); }

.dlg-actions { display: flex; align-items: center; gap: 6px; margin-top: 20px; flex-wrap: wrap; }
.spacer { flex: 1; }

.check-label { display: flex; align-items: center; gap: 10px; margin: 10px 0; color: var(--text); font-size: .95rem; }
.check-label input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.choice-list { background: var(--bg); border-radius: 12px; padding: 2px 12px; }

.weekdays { display: flex; gap: 4px; margin-top: 10px; }
.weekdays label { position: relative; flex: 1; margin: 0; }
.weekdays span {
  display: grid; place-items: center; height: 40px;
  border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); font-weight: 600;
}
.weekdays input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.weekdays input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

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

.toast {
  position: fixed; inset: auto; left: 50%; margin: 0; border: 0; z-index: 20;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg);
  font-size: .9rem; box-shadow: 0 6px 20px rgb(0 0 0 / .2);
}

/* --- Müllabfuhr ------------------------------------------------------------ */

.waste { margin-bottom: 18px; }
.waste .group-title { margin-top: 6px; }
.waste .row { min-height: 50px; }
.row.is-soon { background: var(--today-soft); }
.waste-manage summary { padding: 10px 4px 0; color: var(--muted); cursor: pointer; font-size: .9rem; }
.waste-manage .hint { margin: 8px 4px 0; font-size: .85rem; }
.file-btn { position: relative; overflow: hidden; cursor: pointer; margin: 0; color: var(--on-accent); font-size: inherit; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.waste-line .title { font-size: .95rem; }

/* --- Wer hat was gemacht ---------------------------------------------------- */

.stats-card { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.stats-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.stats-head span { font-size: .85rem; color: var(--muted); }
.share-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--line); margin-bottom: 8px; }
.share { flex: 0 0 auto; }
.share-0 { background: var(--accent); }
.share-1 { background: var(--today); }
.stats-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.stats-row .meta { margin-left: auto; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
