:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2229;
  --muted: #6b7682;
  --line: #e6e9ed;
  --accent: #16a085;
  --accent-d: #0e6655;
  --accent-bg: #e3f5f1;
  --danger: #d64545;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 40, .06), 0 4px 14px rgba(20, 30, 40, .06);
  --c-fruehstueck: #f4a73b;
  --c-mittag: #16a085;
  --c-abend: #5b6fd6;
  --c-snack: #d9608f;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161a;
    --card: #1b2127;
    --text: #e8ecef;
    --muted: #8d99a5;
    --line: #2a323a;
    --accent: #2bc4a5;
    --accent-d: #5fe0c5;
    --accent-bg: #173a33;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ---------- Buttons & Felder ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 11px 16px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.btn:active { filter: brightness(.92); }
.btn.ghost { background: var(--accent-bg); color: var(--accent-d); }
.btn.plain { background: transparent; color: var(--muted); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 12px; background: transparent;
  display: grid; place-items: center; color: var(--text); font-size: 20px; line-height: 1;
}
.icon-btn:active { background: var(--accent-bg); }
input[type=text], input[type=password], input[type=date], input[type=tel], select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px calc(24px + var(--safe-b)); }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card img { width: 72px; height: 72px; border-radius: 18px; }
.login-card h1 { font-size: 24px; margin: 14px 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 22px; }
.user-list { display: grid; gap: 10px; }
.user-tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; display: flex; align-items: center; gap: 12px; text-align: left; font-weight: 600;
  box-shadow: var(--shadow);
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent-bg); color: var(--accent-d);
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 20px 0 8px; min-height: 16px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent); }
.pin-dots i.on { background: var(--accent); }
.pin-err { color: var(--danger); min-height: 22px; font-size: 14px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 8px; }
.keypad button {
  height: 60px; border-radius: 16px; border: 1px solid var(--line); background: var(--card);
  font-size: 22px; font-weight: 600;
}
.keypad button:active { background: var(--accent-bg); }
.keypad .ok { background: var(--accent); color: #fff; border-color: var(--accent); }
.keypad .sec { font-size: 15px; color: var(--muted); font-weight: 500; }

/* ---------- App-Gerüst ---------- */
.shell { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 4px; padding: calc(8px + var(--safe-t)) 10px 8px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar .title { flex: 1; font-weight: 700; font-size: 17px; text-align: center; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px 4px; }
.seg { display: inline-flex; background: var(--line); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.spacer { flex: 1; }
.main { flex: 1; overflow: auto; padding: 8px 12px calc(88px + var(--safe-b)); -webkit-overflow-scrolling: touch; }

/* ---------- Monatsansicht ---------- */
.month-head, .month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.month-head div { text-align: center; font-size: 12px; color: var(--muted); padding: 6px 0; font-weight: 600; }
.mcell {
  background: var(--card); border-radius: 10px; min-height: 84px; padding: 4px; border: 1px solid transparent;
  display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); overflow: hidden;
}
.mcell.other { opacity: .45; }
.mcell.today { border-color: var(--accent); }
.mcell .dn {
  font-size: 12px; font-weight: 700; border: 0; background: transparent; text-align: left; padding: 1px 3px; border-radius: 6px;
  color: var(--text);
}
.mcell.today .dn { color: var(--accent-d); }
.mcell .chips { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.chip {
  display: flex; align-items: center; gap: 4px; font-size: 11px; line-height: 1.2; padding: 3px 5px; border-radius: 6px;
  background: color-mix(in srgb, var(--sc) 16%, var(--card)); border-left: 3px solid var(--sc);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; user-select: none; -webkit-user-select: none;
  touch-action: manipulation; -webkit-touch-callout: none;
}
.chip span { overflow: hidden; text-overflow: ellipsis; }
.more { font-size: 11px; color: var(--muted); padding: 0 4px; }

/* ---------- Wochenansicht ---------- */
.week { display: grid; gap: 10px; }
.day { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 12px 6px; border: 1px solid transparent; }
.day.today { border-color: var(--accent); }
.day h3 { margin: 0 0 6px; font-size: 15px; display: flex; align-items: baseline; gap: 8px; }
.day h3 small { color: var(--muted); font-weight: 500; font-size: 13px; }
.slot { display: flex; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); border-radius: 8px; }
.slot:first-of-type { border-top: 0; }
.slot .sl { width: 76px; flex: none; font-size: 12px; color: var(--muted); padding-top: 7px; display: flex; gap: 5px; align-items: flex-start; }
.slot .sl b { width: 8px; height: 8px; border-radius: 50%; background: var(--sc); margin-top: 5px; flex: none; }
.slot .items { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; min-height: 34px; }
.slot .chip { font-size: 14px; padding: 7px 9px; border-radius: 9px; }
.slot .add {
  align-self: flex-start; border: 1px dashed var(--line); background: transparent; color: var(--muted);
  border-radius: 9px; padding: 3px 10px; font-size: 13px;
}
.chip .by { margin-left: auto; font-size: 11px; color: var(--muted); flex: none; }
.drop-hot { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--accent-bg) !important; }

/* ---------- Gerichte-Schublade ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(16px + var(--safe-b)); z-index: 20;
  height: 52px; padding: 0 20px; border-radius: 26px; border: 0; background: var(--accent); color: #fff;
  font-weight: 700; box-shadow: 0 6px 18px rgba(22, 160, 133, .4); display: flex; align-items: center; gap: 8px;
}
.sheet-bg { position: fixed; inset: 0; background: rgba(10, 16, 22, .45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 88%; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + var(--safe-b));
  animation: up .18s ease-out;
}
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet h2 { margin: 0 0 4px; font-size: 18px; }
.sheet .sub { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { min-width: 0; }
.actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.actions .spacer { flex: 1; }
.dish-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.dish {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 12px; border-radius: 22px; background: var(--card);
  border: 1px solid var(--line); border-left: 4px solid var(--sc); font-size: 14px; user-select: none; -webkit-user-select: none;
  touch-action: manipulation; -webkit-touch-callout: none;
}
.dish button { border: 0; background: transparent; color: var(--muted); padding: 0 0 0 4px; font-size: 15px; }
.table { width: 100%; }
.urow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.urow:first-child { border-top: 0; }
.urow .nm { flex: 1; min-width: 0; font-weight: 600; }
.urow .nm small { display: block; color: var(--muted); font-weight: 400; }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 0; }

/* ---------- Drag ---------- */
.drag-ghost {
  position: fixed; z-index: 100; pointer-events: none; transform: translate(-50%, -60%) scale(1.05);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .28); opacity: .95; max-width: 70vw; width: auto !important;
}
.dragging { opacity: .35; }
body.is-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }
.drag-banner {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%); z-index: 90;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 22px; font-size: 14px; pointer-events: none;
}

#toast {
  position: fixed; left: 50%; top: calc(14px + var(--safe-t)); transform: translate(-50%, -80px); z-index: 200;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  transition: transform .25s; max-width: 90vw;
}
#toast.show { transform: translate(-50%, 0); }
#toast.err { background: var(--danger); color: #fff; }

/* ---------- Breite Bildschirme ---------- */
@media (min-width: 760px) {
  .main { padding-left: max(16px, calc((100vw - 1100px) / 2)); padding-right: max(16px, calc((100vw - 1100px) / 2)); }
  .toolbar { padding-left: max(16px, calc((100vw - 1100px) / 2)); padding-right: max(16px, calc((100vw - 1100px) / 2)); }
  .mcell { min-height: 112px; padding: 6px; }
  .chip { font-size: 12px; }
  .week { grid-template-columns: repeat(7, minmax(0, 1fr)); align-items: start; gap: 8px; }
  .week .slot { flex-direction: column; gap: 2px; }
  .week .slot .sl { width: auto; padding-top: 2px; }
  .week .day { padding: 10px 8px 6px; }
  .week .slot .chip { font-size: 12.5px; white-space: normal; }
}

/* ---------- Gerichte-Ablage ---------- */
.topbar .title { text-align: left; padding-left: 6px; }
.tray {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--card);
  border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; box-shadow: 0 -8px 28px rgba(0, 0, 0, .14);
  max-height: 42%; display: flex; flex-direction: column; padding: 10px 14px calc(12px + var(--safe-b));
  animation: up .18s ease-out;
}
.tray .dish-list { overflow: auto; flex: 1; align-content: flex-start; }
body.tray-open .main { padding-bottom: 46vh; }
@media (min-width: 760px) {
  .tray { left: 50%; right: auto; width: 640px; transform: translateX(-50%); }
  body.tray-open .main { padding-bottom: 40vh; }
}

/* Handy: Monatsansicht zeigt farbige Balken statt Text (Details in der Wochenansicht) */
@media (max-width: 759px) {
  .mcell { min-height: 74px; }
  .mcell .chip { height: 8px; padding: 0; border-left: 0; background: var(--sc); border-radius: 4px; }
  .mcell .chip span { display: none; }
}
