/* Korb – mobil zuerst, hell/dunkel nach Systemeinstellung */
:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #e9eeeb;
  --ink: #17201b;
  --ink-2: #4d5a53;
  --muted: #6b7871;
  --line: #d7dfda;
  --brand: #1a7a50;
  --brand-ink: #ffffff;
  --brand-soft: #dcefe5;
  --done: #e3e8e5;
  --done-ink: #3d4943;
  --danger: #b3261e;
  --danger-soft: #fbe3e1;
  --focus: #0b63ce;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 2px 8px rgb(0 0 0 / 0.05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101513;
    --surface: #18201c;
    --surface-2: #212b26;
    --ink: #e8efeb;
    --ink-2: #b9c6bf;
    --muted: #93a29a;
    --line: #2c3832;
    --brand: #2a9d68;
    --brand-ink: #04140c;
    --brand-soft: #193a2a;
    --done: #26302b;
    --done-ink: #c8d4ce;
    --danger: #ff8a80;
    --danger-soft: #3a1d1b;
    --focus: #7ab4ff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

#app { max-width: 720px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
.boot { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ---------- Kopfzeile ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 0 -16px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: var(--brand-ink);
}
.list-btn {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  background: none; border: 0; padding: 6px 4px; cursor: pointer; color: inherit;
  font-size: 1.3rem; font-weight: 700;
}
.list-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { font-size: 0.85em; opacity: 0.85; }
.top-actions { display: flex; gap: 4px; flex: none; }
.icon-btn {
  min-width: 44px; height: 44px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  background: transparent; border: 0; border-radius: 12px; cursor: pointer; color: inherit; font-size: 1.25rem;
}
.top .icon-btn:hover { background: rgb(255 255 255 / 0.14); }
.count { font-size: 0.85rem; font-weight: 700; }

.status {
  margin: 10px 0 0; padding: 8px 12px; border-radius: 10px;
  background: var(--brand-soft); color: var(--ink); font-size: 0.9rem;
}
.status--offline { background: #fff4d6; color: #4a3b00; }
@media (prefers-color-scheme: dark) { .status--offline { background: #3a3110; color: #f6e7b0; } }

/* ---------- Eingabe ---------- */
.add { display: flex; gap: 8px; margin: 14px 0 6px; }
.add input {
  flex: 1; min-width: 0; height: 50px; padding: 0 16px;
  border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--surface);
  font-size: 1.05rem;
}
.add input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.add-btn {
  width: 50px; height: 50px; flex: none; border: 0; border-radius: var(--radius); cursor: pointer;
  background: var(--brand); color: var(--brand-ink); font-size: 1.6rem; font-weight: 600;
}
.suggest { margin: 4px 0 10px; padding: 10px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }

/* ---------- Kacheln ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 8px; }
.tiles--small { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.tile {
  position: relative; min-height: 98px; padding: 10px 6px 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; border-radius: var(--radius); cursor: pointer; text-align: center;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
  transition: transform 0.08s ease;
}
.tile:active { transform: scale(0.96); }
.tile-emoji { font-size: 2rem; line-height: 1.1; }
.tile-name { font-weight: 650; font-size: 0.92rem; line-height: 1.2; overflow-wrap: break-word; hyphens: auto; max-width: 100%; }
.tile-spec { font-size: 0.78rem; opacity: 0.9; line-height: 1.2; overflow-wrap: break-word; hyphens: auto; max-width: 100%; }
.tile--open { background: var(--brand); color: var(--brand-ink); box-shadow: var(--shadow); }
.tile--done { background: var(--done); color: var(--done-ink); min-height: 84px; }
.tile--done .tile-emoji { font-size: 1.6rem; filter: saturate(0.6); }
.tile--sugg { background: var(--surface-2); color: var(--ink); }
.tile--sugg.is-on { outline: 2px solid var(--brand); outline-offset: -2px; }
.tile--sugg:first-child { background: var(--brand-soft); }
.tile-who {
  position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-size: 0.7rem; font-weight: 700;
  background: rgb(255 255 255 / 0.9); color: var(--brand);
}

.cat { margin-top: 14px; }
.cat-head { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; font-size: 0.85rem; font-weight: 650; color: var(--ink-2); text-transform: none; }
.cat-n { font-weight: 600; color: var(--muted); font-size: 0.85em; }

.empty { display: grid; justify-items: center; gap: 4px; padding: 28px 8px 18px; text-align: center; color: var(--ink-2); }
.empty-big { font-size: 2.6rem; }
.empty + .cat-head { margin-top: 8px; }

.recent { margin-top: 26px; }
.recent-head { margin: 0 0 8px; font-size: 1rem; }
.recent-head button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 0; background: none; border: 0; cursor: pointer; font-weight: 650; color: var(--ink-2); }
.recent-head .caret { margin-left: auto; }
.tip { margin-top: 20px; text-align: center; font-size: 0.85rem; color: var(--muted); }

/* ---------- Knöpfe & Formulare ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; cursor: pointer; text-decoration: none;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600;
}
.btn--primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn--danger.armed, .btn.armed { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.6; cursor: wait; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.stack { display: grid; gap: 8px; margin-top: 16px; }
.form { display: grid; gap: 12px; }
.form.inline { display: flex; gap: 8px; margin-top: 12px; }
.form.inline input { flex: 1; min-width: 0; }
.form label { display: grid; gap: 4px; font-weight: 600; font-size: 0.92rem; }
.form small { font-weight: 400; color: var(--muted); }
.form input, .form select, .link-input {
  height: 46px; padding: 0 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); width: 100%;
}
.muted { color: var(--muted); font-size: 0.88rem; }
.tag { padding: 1px 6px; border-radius: 6px; background: var(--brand-soft); color: var(--ink); font-size: 0.75rem; }

/* ---------- Sheet (Dialog von unten) ---------- */
.sheet {
  width: min(560px, 100%); max-height: 88dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0; background: var(--surface); color: var(--ink);
  box-shadow: 0 -8px 30px rgb(0 0 0 / 0.2);
}
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 18px; background: var(--surface); }
.sheet-head h2 { margin: 0; font-size: 1.15rem; }
.sheet-body { padding: 4px 18px calc(22px + env(safe-area-inset-bottom)); }
.sheet-body h3 { margin: 18px 0 8px; font-size: 0.95rem; }

.list-rows { display: grid; gap: 6px; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 52px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; text-align: left; }
.list-row.is-current { border-color: var(--brand); background: var(--brand-soft); }
.list-row-name { font-weight: 650; }
.list-row-meta { color: var(--muted); font-size: 0.88rem; white-space: nowrap; }

.members, .devices { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.member, .device { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.member-name { flex: 1; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: var(--brand-ink); font-weight: 700; flex: none; }

.menu { display: grid; }
.menu button, .menu a { display: block; padding: 14px 4px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer; color: var(--ink); text-decoration: none; font-size: 1rem; }
.menu a { color: var(--ink-2); font-size: 0.92rem; }
.menu .danger { color: var(--danger); }
.menu button.armed { background: var(--danger-soft); color: var(--danger); }

.linkbox { display: grid; gap: 8px; margin-top: 14px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(520px, calc(100% - 32px)); }
.toast { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 12px; background: #1d2722; color: #fff; box-shadow: 0 6px 20px rgb(0 0 0 / 0.25); }
.toast--error { background: #8c1d18; }
.toast-action { flex: none; background: none; border: 0; color: #9fe3bf; font-weight: 700; cursor: pointer; padding: 6px 4px; }

/* ---------- Einstieg ---------- */
.intro { max-width: 440px; margin: 0 auto; padding: 48px 4px; display: grid; gap: 12px; text-align: center; }
.intro h1 { margin: 0; }
.intro-logo { justify-self: center; border-radius: 18px; }
.intro .form { text-align: left; margin-top: 8px; }
.intro-label { font-weight: 600; }
.notice { padding: 12px; border-radius: 12px; background: var(--brand-soft); }
.notice--error { background: var(--danger-soft); color: var(--ink); }
.legal-links { margin-top: 24px; font-size: 0.85rem; color: var(--muted); }

/* ---------- Rechtliches ---------- */
.legal-page { max-width: 720px; margin: 0 auto; padding: 24px 16px 64px; }
.legal-page dt { font-weight: 700; margin-top: 10px; }
.legal-page dd { margin: 2px 0 0; }
.legal-missing { color: var(--danger); font-style: italic; }

@media (prefers-reduced-motion: reduce) { .tile { transition: none; } }
