:root {
  --green: #22c55e;
  --green-tint: #f0fdf4;
  --green-text: #166534;
  --yellow: #eab308;
  --yellow-tint: #fefce8;
  --yellow-text: #854d0e;
  --red: #ef4444;
  --red-tint: #fef2f2;
  --red-text: #991b1b;
  --n-0: #ffffff;
  --n-50: #fafafa;
  --n-100: #f5f5f5;
  --n-200: #e5e5e5;
  --n-500: #737373;
  --n-900: #171717;
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-top: env(safe-area-inset-top);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--n-0);
  color: var(--n-900);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

#root {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
}

.loading {
  text-align: center;
  color: var(--n-500);
  margin-top: 4rem;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0s !important;
    transition-duration: 0s !important;
  }
}

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--n-50);
  border-top: 1px solid var(--n-200);
  padding-bottom: var(--safe-bottom);
  z-index: 10;
}
.tab {
  flex: 1;
  background: none;
  border: 0;
  padding: 14px 0;
  font: inherit;
  color: var(--n-500);
  min-height: 44px;
  cursor: pointer;
}
body[data-screen="week"]     .tab:nth-child(1),
body[data-screen="catalog"]  .tab:nth-child(2),
body[data-screen="settings"] .tab:nth-child(3) {
  color: var(--n-900);
  font-weight: 600;
}

#root { padding-bottom: calc(56px + var(--safe-bottom) + 16px); }

.stub { color: var(--n-500); padding: 1rem; }

/* ---------- Wochenansicht ---------- */
.wk-header {
  position: sticky;
  top: 0;
  background: var(--n-0);
  border-bottom: 1px solid var(--n-200);
  padding: 12px 16px calc(12px + var(--safe-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 5;
  min-height: calc(44px + var(--safe-top));
  box-sizing: border-box;
}
.wk-nav {
  background: none;
  border: 0;
  font-size: 18px;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
  color: var(--n-900);
}
.wk-title { font-weight: 600; font-size: 17px; }

.wk-summary {
  position: sticky;
  top: calc(44px + var(--safe-top));
  background: var(--n-0);
  border-bottom: 1px solid var(--n-200);
  padding: 12px 16px;
  z-index: 4;
}
.wk-bar {
  height: 12px;
  background: var(--n-100);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.wk-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green) 0%, var(--yellow) 70%, var(--red) 100%);
  transition: width 200ms ease-out;
}
.wk-bar.over .wk-bar-fill { background: var(--red); }
.wk-points {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 13px;
  color: var(--n-500);
}
.wk-points b { color: var(--n-900); }

.wk-stats {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--n-500);
}

.wk-mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 10px;
}
.wk-mini-day {
  background: var(--n-50);
  border: 1px solid var(--n-200);
  border-radius: 6px;
  padding: 6px 2px;
  text-align: center;
  font-size: 11px;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.wk-mini-day.active   { border: 2px solid var(--n-900); background: var(--n-0); }
.wk-mini-day.today    { border-color: var(--n-900); }
.wk-mini-day.past     { opacity: 0.6; }
.wk-mini-day .name    { font-weight: 600; }
.wk-mini-dots {
  display: flex;
  gap: 2px;
  min-height: 6px;
}
.wk-mini-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--n-200);
}
.wk-mini-dot.green  { background: var(--green); }
.wk-mini-dot.yellow { background: var(--yellow); }
.wk-mini-dot.red    { background: var(--red); }
.wk-mini-dot.empty  { background: var(--n-200); }

/* Day slots */
.wk-day {
  padding: 16px;
}
.wk-day-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}
.wk-day-header > div:first-child { font-weight: 600; font-size: 17px; }
.wk-day-points { color: var(--n-500); font-size: 13px; }
.wk-day-combo { font-size: 14px; }
.wk-slot {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--n-50);
  border: 1px solid var(--n-200);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  font: inherit;
  cursor: pointer;
  min-height: 44px;
}
.wk-slot.empty { color: var(--n-500); border-style: dashed; }
.wk-slot.filled.green  { background: var(--green-tint);  border-left: 4px solid var(--green); }
.wk-slot.filled.yellow { background: var(--yellow-tint); border-left: 4px solid var(--yellow); }
.wk-slot.filled.red    { background: var(--red-tint);    border-left: 4px solid var(--red); }
.wk-slot.warn { box-shadow: inset 0 0 0 1px var(--yellow); }
.wk-slot-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--n-500);
}
.wk-slot-name { font-weight: 500; margin-top: 2px; font-size: 15px; color: var(--n-900); }
.wk-slot-reason { font-size: 12px; color: var(--yellow-text); margin-top: 4px; }
.wk-slot-add { float: right; color: var(--n-500); }
.wk-day-warnings {
  text-align: center;
  font-size: 12px;
  color: var(--yellow-text);
  margin-top: 8px;
}

.picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}
.picker-sheet {
  background: var(--n-0);
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  border-radius: 16px 16px 0 0;
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}
.picker-handle {
  width: 40px;
  height: 4px;
  background: var(--n-200);
  border-radius: 2px;
  margin: 8px auto;
}
.picker-title { padding: 0 16px 8px; font-weight: 600; }
.picker-search {
  margin: 0 16px 12px;
  padding: 10px 12px;
  border: 1px solid var(--n-200);
  border-radius: 8px;
  font: inherit;
  min-height: 44px;
}
.picker-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 12px;
}
.picker-row {
  display: flex;
  width: 100%;
  text-align: left;
  background: var(--n-0);
  border: 1px solid var(--n-200);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 6px;
  gap: 10px;
  font: inherit;
  cursor: pointer;
  min-height: 44px;
}
.picker-row.green  { border-left: 3px solid var(--green); }
.picker-row.yellow { border-left: 3px solid var(--yellow); }
.picker-row.red    { border-left: 3px solid var(--red); }
.picker-row-name { font-weight: 500; }
.picker-row-pill {
  margin-left: 6px;
  font-size: 11px;
  background: var(--n-100);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--n-500);
}
.picker-row-verdict { font-size: 12px; margin-top: 2px; }
.picker-row-verdict.ok    { color: var(--green-text); }
.picker-row-verdict.warn  { color: var(--yellow-text); }
.picker-row-verdict.block { color: var(--red-text); }

.slot-detail-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 0 16px 8px;
}
.slot-detail-name { font-weight: 600; font-size: 17px; }
.slot-note {
  margin: 0 16px 12px;
  padding: 8px 10px;
  border: 1px solid var(--n-200);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
  min-height: 60px;
}
.slot-actions {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
  flex-wrap: wrap;
}
.slot-action {
  flex: 1;
  min-height: 44px;
  background: var(--n-50);
  border: 1px solid var(--n-200);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  cursor: pointer;
}
.slot-action.primary { background: var(--n-900); color: var(--n-0); border-color: var(--n-900); }
.slot-action.danger  { color: var(--red-text); border-color: var(--red); }

/* ── Catalog ─────────────────────────────────────────────────── */
.cat { padding: 16px; }
.cat-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cat-header h1 { margin: 0; font-size: 22px; }
.cat-add { width: auto; flex: none; padding: 8px 12px; }

.cat-filters { display: flex; gap: 6px; margin: 12px 0; flex-wrap: wrap; }
.cat-chip {
  background: var(--n-50);
  border: 1px solid var(--n-200);
  border-radius: 16px;
  padding: 6px 12px;
  min-height: 36px;
  font: inherit;
  cursor: pointer;
}
.cat-chip.on { background: var(--n-900); color: var(--n-0); border-color: var(--n-900); }

.cat-list { margin-top: 12px; }
.cat-row {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  background: var(--n-0);
  border: 1px solid var(--n-200);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 6px;
  gap: 10px;
  font: inherit;
  cursor: pointer;
  min-height: 44px;
}
.cat-row.green  { border-left: 3px solid var(--green); }
.cat-row.yellow { border-left: 3px solid var(--yellow); }
.cat-row.red    { border-left: 3px solid var(--red); }
.cat-row-body { flex: 1; }
.cat-row-name { font-weight: 500; }
.cat-row-meta { font-size: 12px; color: var(--n-500); }
.cat-row-arrow { color: var(--n-500); }

/* ── Dish form ───────────────────────────────────────────────── */
.df { padding: 0 16px 12px; display: flex; flex-direction: column; gap: 10px; }
.df-row { display: flex; flex-direction: column; gap: 4px; }
.df-row.df-checkbox { flex-direction: row; align-items: center; gap: 8px; }
.df-label { font-size: 12px; color: var(--n-500); }
.df-row input, .df-row select, .df-row textarea {
  padding: 10px 12px;
  border: 1px solid var(--n-200);
  border-radius: 8px;
  font: inherit;
  min-height: 44px;
  width: 100%;
}
.df-multi { display: flex; flex-wrap: wrap; gap: 6px; }
.df-chip { display: flex; gap: 4px; align-items: center; padding: 6px 10px; border: 1px solid var(--n-200); border-radius: 16px; cursor: pointer; }
.df-chip.on { background: var(--n-900); color: var(--n-0); border-color: var(--n-900); }
.df-chip input { display: none; }

/* ── Settings ────────────────────────────────────────────────── */
.set { padding: 16px; }
.set h1 { font-size: 22px; margin: 0 0 16px; }
.set h2 { font-size: 15px; margin: 0 0 8px; color: var(--n-500); font-weight: 600; }
.set-card { background: var(--n-50); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.set-slot-row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.set-slot-row select, .set-slot-row input { flex: 1; padding: 8px; border: 1px solid var(--n-200); border-radius: 6px; min-height: 44px; }
.set-slot-rm { background: none; border: 0; font-size: 16px; padding: 4px 8px; cursor: pointer; min-width: 44px; }

/* ---------- Polish ---------- */

/* Mini-grid dot fade-in */
@keyframes dot-pop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}
.wk-mini-dot:not(.empty) { animation: dot-pop 150ms ease-out; }

/* Point bar pulse on overflow */
@keyframes pulse-once {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
  50%      { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.3); }
}
.wk-bar.over { animation: pulse-once 600ms ease-out 1; }

/* Slot fade-in */
@keyframes slot-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.wk-slot { animation: slot-fade-in 120ms ease-out; }

/* Best-combo sparkle */
.wk-day-combo { animation: dot-pop 200ms ease-out; }

/* Logged badge */
.wk-slot-logged {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--n-900);
  color: var(--n-0);
  font-size: 10px;
  margin-left: 4px;
}

/* Focus rings */
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--n-900);
  outline-offset: 2px;
}
