/* fapla — Tokens, Bausteine, Handy-Layout. Tablet-Layout: tablet.css (greift nur unter
   body.layout-tablet). Struktur nach basis/CLAUDE.md §10, Primärfarbe Orange. */

:root {
  --brand: #ea580c;
  --brand-dark: #c2410c;
  --brand-light: #ffedd5;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --ink: #1f2937;
  --muted: #6b7280;
  --bg: #faf7f5;
  --card: #ffffff;
  --line: #e7e2de;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(31, 41, 55, 0.06), 0 4px 16px rgba(31, 41, 55, 0.06);
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100dvh; }
body.has-dialog { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--brand-dark); }
h1, h2, h3 { line-height: 1.2; }
code { background: #f3f0ed; padding: 1px 5px; border-radius: 6px; font-size: 0.9em; word-break: break-all; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }
.loading, .empty { color: var(--muted); text-align: center; padding: 24px 0; margin: 0; }

/* ---------- Handy-Rahmen (Basis §10) ---------- */

.shell { max-width: 480px; margin: 0 auto; min-height: 100dvh; }
@media (min-width: 640px) { body.layout-phone .shell, .login-card { zoom: 1.2; } }

.view {
  padding:
    calc(env(safe-area-inset-top) + 12px)
    calc(env(safe-area-inset-right) + 12px)
    calc(env(safe-area-inset-bottom) + 92px)
    calc(env(safe-area-inset-left) + 12px);
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  z-index: 20;
}

.tab {
  flex: 0 1 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: 0;
  padding: 6px 4px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.75rem;
}

.tab.active { color: var(--brand-dark); background: var(--brand-light); }
.tab-icon { font-size: 1.35rem; }

/* ---------- Karten, Abschnitte ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card h2 { margin: 0 0 12px; font-size: 1.1rem; }
.card h3 { margin: 18px 0 8px; font-size: 0.95rem; }
.card.hero { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff; border: 0; }
.card.hero h1 { margin: 0 0 6px; font-size: 1.5rem; }
.card.hero p { margin: 0; opacity: 0.92; }

.section { padding: 0; }
.section > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary h2 { margin: 0; font-size: 1.05rem; flex: 1; }
.section > summary::after { content: '›'; color: var(--muted); font-size: 1.4rem; transition: transform 0.15s; }
.section[open] > summary::after { transform: rotate(90deg); }
.sec-icon { font-size: 1.3rem; }
.sec-body { padding: 0 16px 16px; }
.card-inner { border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 10px 12px; margin-top: 10px; }
.card-inner > summary { cursor: pointer; font-weight: 600; color: var(--brand-dark); }

.hint { color: var(--muted); font-size: 0.9rem; margin: 6px 0 12px; }
.badge { display: inline-block; font-size: 0.72rem; padding: 1px 7px; border-radius: 999px; background: #f3f0ed; color: var(--muted); vertical-align: middle; }

.list { list-style: none; padding: 0; margin: 0 0 12px; }
.list > li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.status-ok { color: var(--green); }
.status-err { color: var(--red); }
.status-warn { color: var(--amber); }

/* ---------- Formulare ---------- */

label { display: block; font-size: 0.9rem; font-weight: 600; margin: 10px 0 4px; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 16px; /* iOS zoomt sonst beim Fokus */
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
input.num { width: 5.5em; display: inline-block; }
.code-input { text-transform: uppercase; letter-spacing: 0.25em; font-family: ui-monospace, Menlo, monospace; }
.code-input.big { font-size: 1.8rem; text-align: center; }

.switch { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.switch input { width: 22px; height: 22px; margin: 0; accent-color: var(--brand); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row > label { margin-top: 6px; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin: 8px 0; }
.inline-form > input, .inline-form > label { flex: 1 1 180px; margin: 0; }
.inline-form .form-error { flex-basis: 100%; }
.inline { display: flex; align-items: center; gap: 8px; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.form-error, .error { color: var(--red); font-size: 0.9rem; margin: 8px 0 0; }

fieldset.chips { border: 0; padding: 0; margin: 10px 0; display: flex; flex-wrap: wrap; gap: 6px; }
fieldset.chips legend { font-size: 0.9rem; font-weight: 600; margin-bottom: 6px; padding: 0; }
fieldset.chips small { flex-basis: 100%; }
.chip { margin: 0; font-weight: 500; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span {
  display: inline-block;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: #fff;
}
.chip input:checked + span { background: var(--pbg, var(--brand-light)); border-color: var(--pmain, var(--brand)); color: var(--pfg, var(--brand-dark)); }
.chip input:focus-visible + span { outline: 2px solid var(--brand); }

.color-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { margin: 0; }
.swatch input { position: absolute; opacity: 0; }
.swatch span { display: block; width: 32px; height: 32px; border-radius: 50%; background: var(--pmain); border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.swatch input:checked + span { box-shadow: 0 0 0 3px var(--ink); }
.swatch.taken span { opacity: 0.25; }
.emoji-row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.emoji-input { width: 4.5em; font-size: 1.4rem; text-align: center; padding: 4px; }
.emoji-btn { border: 0; background: #f6f3f0; border-radius: 8px; font-size: 1.2rem; padding: 4px 6px; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: #fff;
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
  min-height: 42px;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-dark); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 0.9rem; }
.btn.block { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: 0.55; }
.danger-text { color: var(--red) !important; }
.icon-btn { border: 0; background: #f3f0ed; border-radius: 999px; width: 40px; height: 40px; font-size: 1.3rem; line-height: 1; }
.icon-btn.small { width: 30px; height: 30px; font-size: 1rem; }
.link { border: 0; background: none; padding: 0; color: inherit; font-weight: inherit; text-align: left; }
.subtle-link { color: var(--muted); font-size: 0.9rem; }

.fab {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 18px);
  bottom: calc(env(safe-area-inset-bottom) + 80px);
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 0;
  background: var(--brand);
  color: #fff;
  font-size: 2rem;
  box-shadow: 0 6px 18px rgba(234, 88, 12, 0.4);
  z-index: 15;
}

/* ---------- Avatare, Personenfilter ---------- */

.avatar {
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--pbg);
  box-shadow: 0 0 0 2px var(--pmain);
  flex: 0 0 auto;
  line-height: 1;
}
.avatar-xs { width: 18px; height: 18px; font-size: 0.7rem; box-shadow: 0 0 0 1.5px var(--pmain); }
.avatar-sm { width: 28px; height: 28px; font-size: 1rem; }
.avatar-md { width: 38px; height: 38px; font-size: 1.3rem; }
.avatar-all { background: #f3f0ed; box-shadow: 0 0 0 2px #d6d0cb; }

.filter-row { overflow-x: auto; margin: 0 -12px 8px; padding: 2px 12px 6px; }
.pfilter { display: flex; gap: 6px; align-items: center; }
.pf, .pf-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 3px 10px 3px 3px;
  white-space: nowrap;
  font-size: 0.85rem;
}
.pf-all { padding: 6px 12px; }
.pf.active { background: var(--pbg); border-color: var(--pmain); color: var(--pfg); font-weight: 600; }
.pf-all.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- Kalender: Kopfleiste ---------- */

.cal-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-nav { display: flex; align-items: center; gap: 4px; }
.cal-title { margin: 0; font-size: 1.1rem; flex: 1 1 auto; text-align: right; }
.seg { display: flex; background: #f0ebe7; border-radius: 999px; padding: 3px; gap: 2px; flex-basis: 100%; }
.seg button { flex: 1; border: 0; background: none; border-radius: 999px; padding: 6px 8px; font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.seg button.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- Termin-Chips ---------- */

.occ {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  border: 0;
  border-left: 4px solid var(--pmain);
  border-image: var(--pstripe) 1;
  border-image-width: 0 0 0 4px;
  background: var(--pbg);
  color: var(--pfg);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 0.82rem;
  text-align: left;
  overflow: hidden;
  min-height: 24px;
}
.occ-time { font-weight: 700; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.occ-title { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.occ-avatars { display: inline-flex; gap: 2px; flex: 0 0 auto; }
.occ-holiday { background: #fef9c3; color: #854d0e; border-left-color: #eab308; font-style: italic; }
.occ-blurred {
  background: repeating-linear-gradient(135deg, #f1f5f9 0 6px, #e2e8f0 6px 12px);
  color: #475569;
  border-left-color: var(--pmain, #94a3b8);
}
.occ-source:not(.occ-blurred) { opacity: 0.95; }

/* ---------- Agenda (Handy) ---------- */

.agenda-day { margin-bottom: 14px; }
.agenda-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 2px 6px; font-size: 1rem; }
.agenda-head small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.agenda-day.is-today .agenda-head .link { color: var(--brand-dark); }
.agenda-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 6px;
  border-radius: var(--radius-sm);
  border: 0;
  border-left: 5px solid var(--pmain);
  font-size: 0.95rem;
  min-height: 52px;
}
.ai-time { flex: 0 0 76px; font-weight: 700; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.ai-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.ai-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.ai-sub { font-size: 0.8rem; opacity: 0.8; }
.ai-repeat { opacity: 0.6; }
.ai-avatars { display: flex; gap: 3px; }

/* ---------- Monat kompakt (Handy) ---------- */

.wd-row { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.month-compact .mgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.mday {
  aspect-ratio: 1 / 1.05;
  border: 0;
  border-radius: 10px;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 2px;
}
.mday.other { opacity: 0.4; }
.mday.today { background: var(--brand); color: #fff; font-weight: 700; }
.dots { display: flex; gap: 2px; min-height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: #9ca3af; }
.dot-holiday { background: #eab308; }

/* ---------- Dialoge, Toast ---------- */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 41, 55, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.dialog-backdrop.confirm { z-index: 60; align-items: center; }
.dialog {
  background: #fff;
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
}
.dialog-small { max-width: 380px; border-radius: 20px; margin: 16px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dialog-head h2 { margin: 0; font-size: 1.2rem; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.dialog details > summary { cursor: pointer; margin: 12px 0 4px; font-weight: 600; color: var(--brand-dark); }
.repeat-box { background: #faf7f5; border-radius: var(--radius-sm); padding: 4px 12px 10px; margin-top: 6px; }
.scope-list { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.confirm-text { font-size: 1.05rem; margin: 4px 0 8px; }
.detail-when { font-weight: 600; }
.detail-note { white-space: pre-wrap; }
.code-box { display: flex; align-items: center; gap: 10px; background: #faf7f5; border-radius: var(--radius-sm); padding: 10px 12px; }
.code-box.wrap { flex-wrap: wrap; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 1.5rem; letter-spacing: 0.2em; font-weight: 700; flex: 1; }
.feed-url { flex: 1; }
.pair-code { font-family: ui-monospace, Menlo, monospace; font-size: 3rem; letter-spacing: 0.25em; text-align: center; font-weight: 800; margin: 18px 0; color: var(--brand-dark); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 90px);
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 70;
  max-width: 90vw;
  box-shadow: var(--shadow);
}
.toast-error { background: var(--red); }
.offline-banner { position: fixed; top: env(safe-area-inset-top); left: 0; right: 0; background: var(--amber); color: #fff; text-align: center; font-size: 0.85rem; padding: 4px; z-index: 40; }

/* ---------- Einstellungen ---------- */

.role-select { width: auto; padding: 6px 8px; font-size: 0.9rem; }
.visibility-form { background: #faf7f5; border-radius: var(--radius-sm); padding: 4px 12px 10px; margin-top: 8px; }
.visibility-form .switch { font-size: 0.9rem; }

.profile-item, .source-item { border-bottom: 1px solid var(--line); padding: 8px 0; }
.profile-item > summary, .source-item > summary { display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none; }
.profile-item > summary::-webkit-details-marker, .source-item > summary::-webkit-details-marker { display: none; }

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

.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 24px; padding: 24px; box-shadow: var(--shadow); position: relative; }
.login-card h1 { text-align: center; margin: 6px 0 2px; }
.login-card .subtitle { text-align: center; color: var(--muted); margin: 0 0 16px; }
.logo { font-size: 3rem; text-align: center; }
.lang-switch { position: absolute; top: 14px; right: 14px; display: flex; gap: 2px; }
.lang-switch button { border: 0; background: none; color: var(--muted); font-size: 0.8rem; padding: 4px 6px; border-radius: 6px; }
.lang-switch button.active { background: var(--brand-light); color: var(--brand-dark); font-weight: 700; }
.banner { background: var(--brand-light); padding: 12px; border-radius: var(--radius-sm); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Aufgaben (Stufe 2) ---------- */

.task-toolbar .cal-title { text-align: left; }
.task-col { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.task-col-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.task-col-head .name { flex: 1 1 auto; font-weight: 700; font-size: 1.05rem; }
.coins-badge { font-weight: 700; color: var(--amber); white-space: nowrap; }
.ring { --p: 0%; width: 44px; height: 44px; border-radius: 50%; flex: 0 0 auto; display: grid; place-items: center;
  background: conic-gradient(var(--pmain, var(--brand)) var(--p), #ece7e3 0); }
.ring span { width: 34px; height: 34px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-size: 0.72rem; font-weight: 700; }
.slot-title { font-size: 0.85rem; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
.task-row { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.task-card { flex: 1 1 auto; display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 10px 12px; text-align: left;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: #fff; font: inherit; color: inherit; }
.task-card:active { transform: scale(0.98); }
.task-emoji { font-size: 1.6rem; line-height: 1; }
.task-title { flex: 1 1 auto; font-weight: 600; }
.task-coins { font-size: 0.85rem; color: var(--amber); font-weight: 700; white-space: nowrap; }
.task-check { width: 30px; height: 30px; flex: 0 0 auto; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-weight: 800; color: #fff; }
.task-card.done { background: var(--pbg, #f0fdf4); border-color: var(--pmain, var(--green)); }
.task-card.done .task-title { text-decoration: line-through; opacity: 0.7; }
.task-card.done .task-check { background: var(--pmain, var(--green)); border-color: var(--pmain, var(--green)); }
.task-all-done { text-align: center; color: var(--muted); padding: 12px 0; font-weight: 600; }
.task-form .weekdays .chip span { min-width: 44px; text-align: center; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 300; overflow: hidden; }
.confetti i { position: absolute; width: 8px; height: 12px; border-radius: 2px; animation: confetti-fly 1.1s ease-out forwards; }
@keyframes confetti-fly { to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; } }

/* ---------- Schätze (Stufe 2) ---------- */

.reward-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-bottom: 14px; }
.reward-head { display: flex; align-items: center; gap: 10px; }
.reward-head h2 { margin: 0; }
.avatar-lg { width: 52px; height: 52px; font-size: 1.8rem; }
.balance { font-size: 1.8rem; font-weight: 800; color: var(--amber); white-space: nowrap; }
.chests { display: flex; gap: 8px; margin: 12px 0 4px; }
.chest { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; font: inherit; font-weight: 600;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: #fff; color: inherit; }
.chest-icon { font-size: 2rem; line-height: 1.1; }
.chest-price { font-size: 0.85rem; color: var(--muted); }
.chest:disabled { opacity: 0.45; }
.won { list-style: none; padding: 0; margin: 0; }
.won li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.won li.redeemed { opacity: 0.55; }
.won-emoji { font-size: 1.4rem; }
.history .delta { min-width: 42px; font-weight: 700; }
.history .delta.plus { color: var(--green); }
.history .delta.minus { color: var(--muted); }
.prize { text-align: center; padding: 8px 0 4px; }
.prize-emoji { font-size: 4.5rem; line-height: 1.2; animation: prize-pop 0.6s ease-out; }
.prize-title { margin: 6px 0 14px; }
@keyframes prize-pop { from { transform: scale(0.3); } 60% { transform: scale(1.15); } to { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .prize-emoji { animation: none; } .confetti { display: none; } }
.task-page > .section { margin-top: 14px; }
