/* Dunkles Theme mit violetten Akzenten – bewusst unabhängig von der Systemeinstellung */
:root {
  --bg: #15121c;
  --surface: #1f1a29;
  --surface-2: #2a2337;
  --ink: #ece8f4;
  --muted: #9d94ae;
  --line: #342c44;
  --accent: #a78bfa;
  --accent-strong: #8b5cf6;
  --accent-ink: #1a1028;
  --accent-soft: rgb(167 139 250 / 16%);
  --today: #241b38;
  --danger: #f87171;
  --ok: #4fbf8a;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 20px rgb(0 0 0 / 25%);
  --radius: 16px;
  --tap: 44px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 Nunito, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Kopfzeile ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.clock { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
.date { color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs button {
  position: relative;
  display: flex; align-items: center; gap: 6px;
  min-height: var(--tap); padding: 0 14px;
  border: 0; border-radius: 999px; background: transparent;
  font-weight: 700; color: var(--muted);
}
.tabs button.active { background: var(--accent); color: var(--accent-ink); }
.sync-dot {
  width: 14px; height: 14px; padding: 0; border-radius: 50%;
  border: 0; background: var(--muted); opacity: .5; flex: none;
}
.sync-dot.ok { background: var(--ok); opacity: 1; }
.sync-dot.error { background: var(--danger); opacity: 1; }

/* Handy: Navigation unten */
@media (max-width: 760px) {
  /* backdrop-filter würde die fixierte Tab-Leiste an die Kopfzeile binden */
  .topbar { padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); backdrop-filter: none; background: var(--bg); }
  .clock { font-size: 20px; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    justify-content: space-around; gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .tabs button { flex-direction: column; gap: 0; padding: 4px 6px; border-radius: 12px; font-size: 12px; min-width: 60px; }
  .tabs button .ico { font-size: 20px; }
  .tabs button.active { background: var(--accent-soft); color: var(--accent); }
  .sync-dot { margin-left: auto; }
  main { padding-bottom: calc(90px + env(safe-area-inset-bottom)) !important; }
}

main { padding: 20px; max-width: 1800px; margin: 0 auto; }
@media (max-width: 760px) { main { padding: 12px 16px; } }

/* ---------- Bausteine ---------- */

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar h1 { font-size: 22px; margin: 0 8px 0 0; }
.btn {
  min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); font-weight: 700;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.round { width: var(--tap); padding: 0; border-radius: 50%; font-size: 20px; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.spacer { flex: 1; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }

input[type=text], input[type=url], input[type=password], input[type=date], input[type=time], input:not([type]), select, textarea {
  width: 100%; min-height: var(--tap); padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: 14px;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; background: var(--c); }
.chip.off { color: var(--muted); text-decoration: line-through; opacity: .6; }
.chip.off .dot { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }
.cal-filter { margin: -4px 0 14px; }
@media (max-width: 760px) {
  .cal-filter { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .cal-filter .chip { flex: none; }
}
.settings hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.check {
  flex: none; width: 26px; height: 26px; padding: 0;
  border: 2px solid var(--c, var(--muted)); border-radius: 50%; background: transparent;
  display: grid; place-items: center; color: transparent; font-size: 14px; font-weight: 800;
}
.done > .check { background: var(--c, var(--muted)); color: #fff; }
.done > .title { text-decoration: line-through; color: var(--muted); }

/* ---------- Woche ---------- */

.week { display: grid; gap: 12px; }
@media (min-width: 1000px) { .week { grid-template-columns: repeat(7, minmax(0, 1fr)); } }

.day {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; display: flex; flex-direction: column; gap: 8px; min-height: 120px;
}
@media (min-width: 1000px) { .day { min-height: calc(100dvh - 180px); } }
.day.today { background: var(--today); outline: 2px solid var(--accent); box-shadow: 0 0 0 6px var(--accent-soft), var(--shadow); }
.day.past { opacity: .7; }
@media (max-width: 999px) { .week.current .day.past { display: none; } }
.meals { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 6px; }
.day-head { display: flex; align-items: center; gap: 8px; }
.day-head .dow { font-weight: 800; font-size: 18px; }
.day-head .dnum { color: var(--muted); font-weight: 700; }
.dow .short { display: none; }
@media (min-width: 1000px) and (max-width: 1999px) {
  .dow .long { display: none; }
  .dow .short { display: inline; }
}
.day-head .btn { margin-left: auto; min-height: 34px; width: 34px; font-size: 18px; }

.meal {
  display: flex; flex-direction: column; width: 100%;
  padding: 6px 10px; border: 0; border-radius: 10px; background: var(--surface-2); text-align: left;
}
.meal .slot { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; flex: none; }
.meal .what { font-weight: 600; min-width: 0; overflow-wrap: break-word; }

.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.event {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 6px 8px 6px 10px; border-radius: 10px; cursor: pointer;
  background: color-mix(in srgb, var(--c) 16%, var(--surface));
  border-left: 4px solid var(--c);
}
.event .time { font-weight: 800; font-size: 14px; flex: none; font-variant-numeric: tabular-nums; }
.event .title { font-weight: 600; min-width: 0; overflow-wrap: break-word; }
.event .loc { display: block; font-size: 13px; color: var(--muted); }

.task { display: flex; gap: 8px; align-items: center; padding: 4px 2px; }
.task .title { flex: 1; min-width: 0; cursor: pointer; overflow-wrap: break-word; font-weight: 600; }
.task .meta { display: flex; gap: 4px; align-items: center; flex: none; }
.tag { font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: color-mix(in srgb, var(--c) 25%, var(--surface)); }
.avatar {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c); color: #fff; font-size: 12px; font-weight: 800;
}
.day .tag { display: none; }
.day .title, .meal .what { hyphens: auto; }
@media (min-width: 1000px) {
  .day .event { flex-direction: column; gap: 0; }
  .day .task { align-items: flex-start; }
  .day .task .meta { flex-direction: column-reverse; align-items: flex-end; gap: 2px; }
}
.task.overdue .title::after { content: " · überfällig"; color: var(--danger); font-size: 12px; font-weight: 700; }
.recur { font-size: 12px; color: var(--muted); }

/* ---------- Allgemein ---------- */

.icon-btn { border: 0; background: transparent; color: var(--muted); width: 36px; height: 36px; border-radius: 50%; font-size: 18px; }
.icon-btn:hover { background: var(--surface-2); }
details > summary { cursor: pointer; font-weight: 700; color: var(--muted); padding: 6px 0; }

/* ---------- Essen ---------- */

.meal-grid { display: grid; gap: 10px; }
.meal-row { display: grid; grid-template-columns: 110px repeat(var(--slots), minmax(0, 1fr)); gap: 10px; align-items: center; }
.meal-row.today { background: var(--today); border-radius: 12px; padding: 6px; margin: -6px; }
.meal-row .day-label { font-weight: 800; }
.meal-row .day-label small { display: block; color: var(--muted); font-weight: 600; }
.meal-cell { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px; min-width: 0; }
.meal-sub { grid-column: 1 / -1; display: flex; gap: 8px; font-size: 13px; padding: 0 4px; cursor: pointer; }
@media (max-width: 760px) {
  .meal-row { grid-template-columns: 1fr; }
}
.essen-tabs { max-width: 420px; margin: 0 auto 16px; }
.note { color: var(--muted); font-weight: 600; font-style: italic; }
.stars-s { color: #e9a23b; letter-spacing: 1px; white-space: nowrap; }
.stars { display: flex; gap: 2px; }
.star { border: 0; background: transparent; font-size: 30px; line-height: 1; padding: 2px 4px; color: var(--line); }
.star.on { color: #e9a23b; }
.dish { display: flex; gap: 8px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.dish:last-child { border-bottom: 0; }
.dish .title { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: break-word; }
.dish .loc { display: block; font-size: 13px; color: var(--muted); font-weight: 500; }
.dish .meta { display: flex; gap: 4px; align-items: center; flex: none; }
.dish .tag { --c: var(--muted); }
@media (max-width: 500px) { .dish .tag { display: none; } }
[hidden] { display: none !important; }
.archive-week .toolbar { margin-bottom: 8px; }
.archive-week h2 { margin: 0; font-size: 18px; }
.arch { width: 100%; border-collapse: collapse; }
.arch th, .arch td { text-align: left; padding: 6px 8px 6px 0; border-top: 1px solid var(--line); vertical-align: top; }
.arch thead th { border-top: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.arch tbody th { white-space: nowrap; color: var(--muted); font-weight: 700; width: 1%; }
.arch .link { cursor: pointer; font-weight: 600; }
.served { margin: 4px 0 0; padding-left: 20px; color: var(--muted); }

/* ---------- Aufgaben ---------- */

.task-wrap { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.group h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 0 0 6px; }
.group .task { border-bottom: 1px solid var(--line); padding: 8px 4px; }
.group .task:last-child { border-bottom: 0; }
.task .when { font-size: 13px; color: var(--muted); font-weight: 700; flex: none; }
.quick-add { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.quick-add .opts { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.quick-add .opts > * { width: auto; flex: 1 1 140px; }

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

.settings { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.settings h2 { margin: 0 0 12px; font-size: 19px; }
.settings p { margin: 0 0 10px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 14px; font-weight: 700; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.row input[type=color] { width: 48px; height: var(--tap); padding: 2px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); flex: none; }
.cal-row { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.cal-row:last-child { border-bottom: 0; }
.cal-row label { flex: 1; display: flex; gap: 10px; align-items: center; }
.cal-row input[type=checkbox] { width: 22px; height: 22px; }
.status-line { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.steps { padding-left: 20px; margin: 0 0 12px; }
.steps li { margin-bottom: 6px; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 14px; overflow-wrap: break-word; }

/* ---------- Dialog ---------- */

dialog {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  border: 0; border-radius: 20px; padding: 0;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
}
dialog::backdrop { background: rgb(8 4 16 / 65%); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; font-size: 20px; }
dialog .two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
dialog .actions { display: flex; gap: 8px; margin-top: 4px; }
dialog .checkline { display: flex; gap: 8px; align-items: center; font-weight: 700; }
dialog .checkline input { width: 22px; height: 22px; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.seg button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; font-weight: 700; color: var(--muted); }
.seg button.active { background: var(--accent-soft); color: var(--accent); box-shadow: var(--shadow); }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 760px) { #toast { bottom: calc(90px + env(safe-area-inset-bottom)); } }

.login { max-width: 360px; margin: 15vh auto 0; text-align: center; display: flex; flex-direction: column; gap: 12px; }
.login input { text-align: center; font-size: 24px; letter-spacing: 6px; }
.plan-row { flex-wrap: wrap; }
.plan-row input, .plan-row select { flex: 1 1 130px; min-width: 0; }

/* ---------- Rezepte ---------- */

.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
a.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; color: inherit; }
.recipe-mark { font-size: 13px; }
.recipe-btn { border: 0; background: transparent; color: var(--accent); font-weight: 700; font-size: 13px; padding: 0; margin-left: auto; }
.sources { display: flex; flex-direction: column; gap: 6px; }
.src-link { display: flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 2px 4px 2px 10px; }
.src-link a { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: center; color: inherit; font-weight: 600; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.thumb { position: relative; aspect-ratio: 1; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; display: block; }
.thumb-del {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: rgb(0 0 0 / 55%); color: #fff; font-size: 16px; line-height: 1;
}
.src-add { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; }
.src-add .btn { padding: 0 14px; }
.photo-btn { position: relative; display: flex; align-items: center; justify-content: center; cursor: pointer; }

.cook { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.cook-head { margin-bottom: 0; }
.cook-head .btn.round { flex: none; }
.cook-head h1 { order: 5; flex-basis: 100%; margin: 4px 0 0; font-size: 26px; hyphens: auto; }
.cook-notes { font-size: 20px; line-height: 1.5; white-space: pre-wrap; }
.cook-links { display: flex; flex-wrap: wrap; gap: 10px; }
.cook-link { font-size: 18px; min-height: 56px; padding: 0 20px; }
.cook-photo img { width: 100%; display: block; border-radius: var(--radius); box-shadow: var(--shadow); }
