/* ============================================================
   Kalorien-Tracker · Oberflächen-Stylesheet
   Lokal, offline, ohne externe Abhängigkeiten.
   Alle Klassennamen sind kompatibel zu den bestehenden Templates.
   ============================================================ */

/* ---------- Design-Token / Farbsystem ---------- */
:root {
  /* Flächen & Text */
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-soft: #f6f8fb;
  --surface-2: #eef2f7;
  --border: #e4e8ef;
  --border-strong: #d6dce6;
  --text: #1b2230;
  --text-soft: #3c4658;
  --muted: #6b7384;
  --muted-2: #8b93a3;

  /* Akzente */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #e8effd;
  --primary-tint: #f2f6fe;
  --success: #15a34a;
  --success-soft: #e6f6ec;
  --warning: #d97706;
  --warning-soft: #fcf1e1;
  --danger: #dc2626;
  --danger-soft: #fdeaea;
  --info: #2563eb;
  --info-soft: #e8effd;

  /* Form */
  --radius: 14px;
  --radius-lg: 18px;
  --radius-sm: 10px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 20px -12px rgba(16, 24, 40, .18);
  --shadow-pop: 0 10px 30px -8px rgba(16, 24, 40, .28);

  --ring: 0 0 0 3px rgba(37, 99, 235, .22);

  --sidebar-w: 264px;
  --content-max: none;
}

/* ---------- Dark Mode (vorbereitet, sauber umgesetzt) ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #0f141d;
    --surface: #18202d;
    --surface-soft: #1d2735;
    --surface-2: #232e3e;
    --border: #2a3546;
    --border-strong: #36435a;
    --text: #eef2f9;
    --text-soft: #c4ccda;
    --muted: #97a1b4;
    --muted-2: #7a8499;
    --primary: #5b8def;
    --primary-hover: #74a0f5;
    --primary-soft: #1f2c44;
    --primary-tint: #1a2336;
    --success: #34c46f;
    --success-soft: #16301f;
    --warning: #e3a046;
    --warning-soft: #322618;
    --danger: #ef5959;
    --danger-soft: #341c1c;
    --info: #5b8def;
    --info-soft: #1f2c44;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 2px 6px rgba(0, 0, 0, .4);
    --shadow-pop: 0 16px 40px rgba(0, 0, 0, .55);
    --ring: 0 0 0 3px rgba(91, 141, 239, .3);
  }
}
html[data-theme=dark] {
  --bg: #0f141d;
  --surface: #18202d;
  --surface-soft: #1d2735;
  --surface-2: #232e3e;
  --border: #2a3546;
  --border-strong: #36435a;
  --text: #eef2f9;
  --text-soft: #c4ccda;
  --muted: #97a1b4;
  --muted-2: #7a8499;
  --primary: #5b8def;
  --primary-hover: #74a0f5;
  --primary-soft: #1f2c44;
  --primary-tint: #1a2336;
  --success: #34c46f;
  --success-soft: #16301f;
  --warning: #e3a046;
  --warning-soft: #322618;
  --danger: #ef5959;
  --danger-soft: #341c1c;
  --info: #5b8def;
  --info-soft: #1f2c44;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 2px 6px rgba(0, 0, 0, .4);
  --shadow-pop: 0 16px 40px rgba(0, 0, 0, .55);
  --ring: 0 0 0 3px rgba(91, 141, 239, .3);
}

/* ---------- Basis ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { color: var(--text); letter-spacing: -.01em; }
small, .hint { display: block; color: var(--muted); font-size: .85rem; line-height: 1.5; }
::selection { background: var(--primary-soft); }

/* ---------- Sidebar / Navigation ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  padding: 18px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 30;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 40px; height: 40px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(140deg, var(--primary), var(--primary-hover));
  color: #fff; font-weight: 800; font-size: 1.15rem;
  box-shadow: var(--shadow-sm);
}
.brand strong { display: block; font-size: 1.02rem; letter-spacing: -.01em; }
.brand small { margin-top: 1px; color: var(--muted-2); font-size: .76rem; }

.sidebar nav { display: grid; gap: 3px; align-content: start; }
.sidebar nav a {
  display: flex; align-items: center;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 550;
  font-size: .92rem;
  transition: background .12s ease, color .12s ease;
}
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar nav a.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 650;
}

/* ---------- Hauptbereich ---------- */
.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  padding: 26px 30px 60px;
}
.main > * { max-width: var(--content-max); }

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 22px;
}
.topbar > div { flex: 1 1 auto; min-width: 0; }
.topbar h1 { margin: 0; font-size: 1.6rem; font-weight: 700; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: .92rem; }
.top-actions { display: flex; gap: 10px; flex: 0 0 auto; }

.menu-button {
  display: none;
  width: 42px; height: 42px;
  padding: 0; font-size: 1.2rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  flex: 0 0 auto;
}
.menu-button:hover { background: var(--surface-2); }

/* ---------- Karten ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
  margin-bottom: 18px;
}
.card > h2, .card > h3 { margin: 0 0 16px; font-size: 1.06rem; font-weight: 650; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.card-header h2, .card-header h3 { margin: 0; font-size: 1.06rem; font-weight: 650; }

.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }

/* ---------- KPI- / Statuskarten ---------- */
.stat {
  position: relative;
  padding: 16px 18px;
  display: grid;
  gap: 2px;
  align-content: start;
  overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute; inset: 0 auto 0 0;
  width: 3px; background: var(--border-strong);
  border-radius: 3px;
}
.stat > span { color: var(--muted); font-size: .82rem; font-weight: 600; }
.stat > strong {
  display: block;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -.02em;
  margin: 3px 0 1px;
  font-variant-numeric: tabular-nums;
}
.stat > small { color: var(--muted-2); }
.small-stats .stat > strong { font-size: 1.35rem; }

.stat.ok::before   { background: var(--success); }
.stat.near::before { background: var(--warning); }
.stat.over::before { background: var(--danger); }
.stat.low::before  { background: var(--primary); }
.stat.ok   { background: linear-gradient(180deg, var(--success-soft), var(--surface) 60%); }
.stat.near { background: linear-gradient(180deg, var(--warning-soft), var(--surface) 60%); }
.stat.over { background: linear-gradient(180deg, var(--danger-soft), var(--surface) 60%); }
.stat.low  { background: linear-gradient(180deg, var(--primary-tint), var(--surface) 60%); }

/* ---------- Werkzeugleisten / Aktionsreihen ---------- */
.toolbar, .quick-actions, .actions, .inline-form {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
}
.toolbar { margin-bottom: 18px; }
.toolbar > strong {
  padding: 0 6px; font-size: 1.02rem; font-variant-numeric: tabular-nums;
}
.inline-form { gap: 8px; }
.actions { gap: 6px; }

/* Eingaben in Werkzeugleisten kompakt halten (nicht volle Breite) */
.toolbar input, .toolbar select, .inline-form input, .inline-form select { width: auto; }
.toolbar input[type=date], .inline-form input[type=date] { min-width: 150px; }
.toolbar input[name=q] { flex: 1 1 240px; min-width: 200px; }
.toolbar select[name=category] { min-width: 150px; }

/* ---------- Buttons ---------- */
.button, button,
input[type=file]::file-selector-button {
  appearance: none;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font: inherit;
  font-weight: 600;
  font-size: .92rem;
  line-height: 1.2;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease, transform .04s ease;
}
.button:hover, button:hover,
input[type=file]::file-selector-button:hover { background: var(--primary-hover); }
.button:active, button:active { transform: translateY(1px); }
.button:focus-visible, button:focus-visible,
a.button:focus-visible { outline: none; box-shadow: var(--ring); }

/* Sekundär / neutral */
button.ghost, .button.ghost,
button.secondary, .button.secondary {
  background: var(--surface);
  color: var(--text-soft);
  border-color: var(--border-strong);
}
button.ghost:hover, .button.ghost:hover,
button.secondary:hover, .button.secondary:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* Gefahr / Löschen */
button.danger, .button.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 38%, var(--border));
}
button.danger:hover, .button.danger:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* Erfolg */
button.success, .button.success {
  background: var(--success); color: #fff;
}
button.success:hover, .button.success:hover {
  background: color-mix(in srgb, var(--success) 85%, #000);
}

/* Größen */
.small, button.small, .button.small {
  padding: 6px 11px;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 600;
}
.primary { width: max-content; }

/* ---------- Formulare ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px 16px;
  align-items: end;
}
.form-grid.wide { grid-template-columns: repeat(5, minmax(140px, 1fr)); }
.stack { display: grid; gap: 14px; }
.span-2 { grid-column: span 2; }

label {
  display: grid;
  gap: 6px;
  color: var(--text-soft);
  font-weight: 600;
  font-size: .85rem;
}
label.check, .checks label {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-weight: 500;
  font-size: .92rem;
  padding: 7px 0;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 9px 12px;
  font: inherit;
  font-size: .92rem;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--primary) 35%, var(--border-strong)); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
textarea { resize: vertical; min-height: 64px; line-height: 1.5; }

/* Checkbox / Radio: nicht auf volle Breite ziehen */
input[type=checkbox], input[type=radio] {
  width: 17px; height: 17px;
  flex: 0 0 auto;
  accent-color: var(--primary);
  cursor: pointer;
  padding: 0;
}

/* Select mit eigenem Pfeil (lokales SVG, keine externe Ressource) */
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7384' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}

input[type=date] { cursor: text; }
input[type=file] { padding: 7px 10px; cursor: pointer; }
input[type=file]::file-selector-button {
  margin-right: 12px; padding: 7px 12px; font-size: .85rem;
  background: var(--surface); color: var(--text-soft);
  border: 1px solid var(--border-strong);
}

/* ---------- Tabellen ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  font-variant-numeric: tabular-nums;
}
th, td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 650;
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody td { vertical-align: middle; }
tbody tr { transition: background .1s ease; }
tbody tr:hover td { background: var(--surface-soft); }
td strong { font-weight: 650; }
td small { margin-top: 3px; color: var(--muted-2); }
/* Aktionsspalte: echte Tabellenzelle (kein Flex) -> vertikal mittig zentrierbar */
td.actions {
  display: table-cell;
  vertical-align: middle;
  white-space: nowrap;
}
td.actions > * { vertical-align: middle; }
td.actions > * + * { margin-left: 6px; }
td.actions form, .actions form { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
td.actions form + form, td.actions form + button, td.actions button + form { margin-left: 6px; }
td.actions input, .actions input {
  width: auto;
  min-width: 0;
  padding: 6px 10px;
  font-size: .85rem;
}
td.actions input[type=date], .actions input[type=date] { width: 132px; }

/* ---------- Badges / Pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 11px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-soft);
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--radius-pill);
  font-size: .78rem; font-weight: 650;
  background: var(--surface-2); color: var(--text-soft);
  border: 1px solid var(--border);
}
.badge-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.badge-danger  { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.badge-muted   { background: var(--surface-2); color: var(--muted); }

/* Dezente, farblich codierte Mahlzeit-Badges (per JS gesetzt) */
.pill.meal-fruehstueck { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 26%, transparent); color: color-mix(in srgb, var(--warning) 78%, #000); }
.pill.meal-mittagessen { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 26%, transparent); color: color-mix(in srgb, var(--success) 78%, #000); }
.pill.meal-abendessen  { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 26%, transparent); color: var(--primary-hover); }
.pill.meal-snack       { background: #f3eafc; border-color: #e2cdf5; color: #7c3aed; }
.pill.meal-sonstiges   { background: var(--surface-2); border-color: var(--border); color: var(--muted); }

/* ---------- Hinweise / Alerts ---------- */
.alert {
  border-radius: var(--radius);
  padding: 13px 16px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  font-size: .92rem;
  font-weight: 500;
}
.alert.success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 35%, transparent); color: color-mix(in srgb, var(--success) 80%, #000); }
.alert.error   { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: color-mix(in srgb, var(--danger) 80%, #000); }
.alert.warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 35%, transparent); color: color-mix(in srgb, var(--warning) 80%, #000); }
.alert.info    { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); color: var(--primary-hover); }

.empty {
  color: var(--muted);
  padding: 18px 4px;
  text-align: center;
  font-size: .92rem;
}

/* ---------- Listen ---------- */
.list { display: grid; gap: 0; }
.list div {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.list div:last-child { border-bottom: 0; }
.list div span { color: var(--muted); }
.list div strong { font-variant-numeric: tabular-nums; }

/* ---------- Balken / Fortschritt ---------- */
.bars { display: grid; gap: 4px; }
.bar-row {
  display: grid;
  grid-template-columns: 44px 1fr 74px;
  gap: 12px; align-items: center;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  transition: background .1s ease;
}
.bar-row:hover { background: var(--surface-soft); }
.bar-row span { color: var(--muted); font-size: .85rem; }
.bar-row b { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }
.bar-row div, .progress {
  height: 8px; border-radius: var(--radius-pill);
  background: var(--surface-2);
  overflow: hidden;
}
.bar-row i, .progress i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-hover));
  border-radius: var(--radius-pill);
  transition: width .3s ease;
}

/* ---------- Kalender ---------- */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.calendar-grid.header {
  margin-bottom: 8px; color: var(--muted); font-weight: 650;
  text-align: center; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em;
}
.calendar-day {
  min-height: 96px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 11px;
  background: var(--surface);
  display: grid;
  align-content: space-between;
  transition: box-shadow .12s ease, transform .04s ease, border-color .12s ease;
}
a.calendar-day:hover { box-shadow: var(--shadow); border-color: var(--border-strong); }
a.calendar-day:active { transform: translateY(1px); }
.calendar-day strong { font-size: 1rem; font-weight: 650; }
.calendar-day span { color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }

/* dezenter Zielstatus: getönter Rand + linker Akzent */
.calendar-day.ok   { border-color: color-mix(in srgb, var(--success) 40%, var(--border)); box-shadow: inset 3px 0 0 var(--success); }
.calendar-day.near { border-color: color-mix(in srgb, var(--warning) 45%, var(--border)); box-shadow: inset 3px 0 0 var(--warning); }
.calendar-day.over { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); box-shadow: inset 3px 0 0 var(--danger); }
.calendar-day.low  { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); box-shadow: inset 3px 0 0 var(--primary); }
.calendar-day.empty { opacity: .8; }
.calendar-day.muted { opacity: 0; border: 0; background: transparent; pointer-events: none; }

.legend {
  display: flex; gap: 16px; flex-wrap: wrap;
  color: var(--muted); margin: 14px 2px 0; font-size: .85rem; align-items: center;
}
.legend .dot { margin-right: 4px; }
.dot { width: 10px; height: 10px; border-radius: var(--radius-pill); display: inline-block; background: var(--border-strong); }
.dot.ok { background: var(--success); }
.dot.near { background: var(--warning); }
.dot.over { background: var(--danger); }
.dot.low { background: var(--primary); }
.dot.empty { background: var(--border-strong); }

/* ---------- Berechnungs-Vorschau ---------- */
.preview {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text-soft);
  background: var(--primary-tint);
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Zutaten ---------- */
.ingredients-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface-soft);
}
.ingredient-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 150px auto;
  gap: 10px; align-items: center;
  margin-bottom: 10px;
}
.ingredient-row:last-of-type { margin-bottom: 0; }

/* ---------- Dialoge ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-pop);
  max-width: 95vw;
  width: min(620px, 95vw);
}
dialog::backdrop { background: rgba(15, 23, 42, .42); backdrop-filter: blur(2px); }
.dialog-form { display: grid; gap: 13px; }
.dialog-form h2, .dialog-form h3 { margin: 0 0 2px; font-size: 1.15rem; font-weight: 650; }
.dialog-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 6px; padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* ---------- Module / Sonstiges ---------- */
.checks {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 4px 18px;
}
code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: .88em;
  font-family: ui-monospace, "SFMono-Regular", "Cascadia Code", Menlo, Consolas, monospace;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .form-grid, .form-grid.wide { grid-template-columns: 1fr 1fr; }
  .span-2 { grid-column: span 2; }
  .main { padding: 22px 20px 48px; }
}

@media (max-width: 820px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-pop);
  }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; padding: 18px 16px 48px; }
  .menu-button { display: inline-flex; }
  .topbar { align-items: center; }
  .topbar h1 { font-size: 1.35rem; }
  .grid.stats, .grid.two, .form-grid, .form-grid.wide, .checks { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .calendar-grid { gap: 5px; }
  .calendar-day { min-height: 74px; padding: 7px 8px; border-radius: 10px; }
  .calendar-day span { font-size: .74rem; }
  .ingredient-row { grid-template-columns: 1fr; }
  .actions { align-items: stretch; }
  .card { padding: 16px 16px; }
}

@media (max-width: 600px) {
  .form-grid, .form-grid.wide { grid-template-columns: 1fr; }
  .calendar-grid { gap: 4px; }
  dialog { padding: 18px; }
}

/* Sidebar-Overlay auf Mobil */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .4);
  z-index: 25;
}
.sidebar-backdrop.show { display: block; }

@media print {
  .sidebar, .topbar, .toolbar, .menu-button { display: none !important; }
  .main { margin: 0; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* ============================================================
   Authentifizierung: Login, Setup, Account, Benutzerverwaltung
   ============================================================ */

.auth-page {
  display: block;
  background: var(--bg);
  min-height: 100vh;
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px 18px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-pop);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.auth-logo .brand-mark { width: 40px; height: 40px; }

.auth-logo strong { display: block; font-size: 1.05rem; }
.auth-logo small { display: block; color: var(--muted); font-size: .8rem; }

.auth-title {
  margin: 0 0 6px;
  font-size: 1.4rem;
  font-weight: 680;
}

.auth-subtitle {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.45;
}

.auth-hint {
  margin: 2px 0 6px;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.4;
}

.auth-card .form-grid { grid-template-columns: 1fr; gap: 12px; }
.auth-card .button { width: 100%; justify-content: center; }

.checkbox-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  font-size: .9rem;
  color: var(--text-soft);
}
.checkbox-row input { width: auto; }

.login-footer {
  color: var(--muted-2);
  font-size: .8rem;
  text-align: center;
  margin: 0;
}

.form-error { color: var(--danger); font-size: .85rem; margin: 4px 0 0; }
.form-success { color: var(--success); font-size: .85rem; margin: 4px 0 0; }

/* Benutzer-Menü in der Sidebar */
.user-menu {
  margin-top: auto;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  display: grid;
  gap: 4px;
}
.user-menu small { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; }
.user-menu strong { font-size: .95rem; }
.user-menu-actions { display: flex; gap: 10px; margin-top: 6px; }
.user-menu-actions a {
  font-size: .85rem;
  color: var(--primary);
  text-decoration: none;
  padding: 2px 0;
}
.user-menu-actions a:hover { text-decoration: underline; }

.role-badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: var(--primary-hover);
  font-size: .72rem;
  font-weight: 650;
  width: fit-content;
}

/* Account-Infos */
.account-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 0 0 16px;
}
.account-info > div { display: grid; gap: 2px; }
.account-info dt { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.account-info dd { margin: 0; font-weight: 600; }

/* Benutzer-Tabelle */
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; }
.data-table .muted { color: var(--muted); }

.form-grid.compact { gap: 8px; margin-bottom: 12px; }
.user-edit-panel {
  margin-top: 10px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  display: grid;
  gap: 10px;
  min-width: 260px;
}
.user-edit-row { display: flex; gap: 10px; flex-wrap: wrap; }
.user-actions details > summary { cursor: pointer; list-style: none; display: inline-flex; }
.user-actions details > summary::-webkit-details-marker { display: none; }

@media (max-width: 600px) {
  .auth-card { max-width: 100%; }
}

/* ============================================================
   Mobile-Optimierung (v2.8.0)
   Rein additive Regeln über Media Queries.
   Die Desktop-Darstellung bleibt unverändert.
   ============================================================ */

/* Karten als Alternative zu breiten Tabellen.
   Standard (Desktop): ausgeblendet, die Tabelle bleibt sichtbar. */
.responsive-cards { display: none; }

.data-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 14px 15px;
  display: grid;
  gap: 9px;
}
.data-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.data-card-title {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -.01em;
  word-break: break-word;
  line-height: 1.3;
}
.data-card-title small { margin-top: 2px; color: var(--muted); font-size: .82rem; }
.data-card-kcal {
  flex: 0 0 auto;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.data-card-kcal strong { font-size: 1.15rem; font-weight: 700; }
.data-card-kcal span { display: block; color: var(--muted); font-size: .74rem; }
.data-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-soft);
}
.data-card-meta span { color: var(--muted); }
.data-card-meta b { font-weight: 650; color: var(--text); }
.data-card-note {
  color: var(--muted);
  font-size: .86rem;
  word-break: break-word;
}
.data-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 3px;
}
.data-card-actions form { margin: 0; display: inline-flex; }
.data-card-actions > *,
.data-card-actions form > button,
.data-card-actions > .button,
.data-card-actions > button { flex: 1 1 auto; min-height: 40px; }

/* Umschalten Tabelle <-> Karten bei kleiner Breite.
   Nur Tabellen mit .swap-to-cards werden ersetzt. */
@media (max-width: 768px) {
  .table-wrap.swap-to-cards,
  .table-scroll.swap-to-cards { display: none; }
  .responsive-cards { display: grid; gap: 12px; }
}

/* ---------- Allgemeine mobile Anpassungen ---------- */
@media (max-width: 820px) {
  /* KPI-Karten zweispaltig statt einspaltig (besser nutzbarer Platz) */
  .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.stats .stat > strong { font-size: 1.3rem; }
  .small-stats .stat > strong { font-size: 1.15rem; }

  /* Mobiler Header etwas kompakter, aber gut lesbar */
  .topbar { gap: 12px; margin-bottom: 18px; }
  .topbar p { font-size: .85rem; }

  /* Touch-freundliche Bedienelemente */
  .button, button,
  .sidebar nav a,
  input, select, textarea,
  input[type=file]::file-selector-button { min-height: 44px; }
  input[type=checkbox], input[type=radio] { min-height: 0; width: 20px; height: 20px; }
  .button.small, button.small, .small { min-height: 40px; }
  .sidebar nav a { padding: 11px 12px; }

  /* Eingaben mit 16px gegen automatisches Zoomen auf iOS */
  input, select, textarea { font-size: 16px; }

  /* Werkzeugleisten brechen sauber um, Eingaben volle Breite */
  .toolbar, .inline-form { gap: 8px; }
  .toolbar > .button,
  .toolbar > form,
  .inline-form { flex: 1 1 100%; }
  .toolbar .inline-form { display: flex; gap: 8px; }
  .toolbar input[name=q],
  .toolbar select[name=category],
  .toolbar input[type=date],
  .inline-form input[type=date] { flex: 1 1 auto; width: auto; min-width: 0; }
  .toolbar .inline-form button,
  .inline-form button { flex: 0 0 auto; }

  /* Schnellaktionen / Aktionsreihen volle Breite, gut tippbar */
  .quick-actions { flex-direction: column; align-items: stretch; }
  .quick-actions .button { width: 100%; }
}

@media (max-width: 600px) {
  body { font-size: 16px; }
  .main { padding: 16px 13px 44px; }
  .card { padding: 15px 14px; border-radius: 12px; }
  .topbar h1 { font-size: 1.25rem; }

  /* Formular-Aktionen untereinander */
  .form-grid > button,
  .stack > button,
  .actions { width: 100%; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions .button, .actions button { width: 100%; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .button, .dialog-actions button { width: 100%; }

  /* Alerts volle Breite */
  .alert { font-size: .9rem; }

  /* Legende der Kalenderfarben kompakter */
  .legend { gap: 8px 14px; font-size: .8rem; }
}

@media (max-width: 380px) {
  .grid.stats { grid-template-columns: 1fr; }
}

/* ---------- Dialoge / Modale auf Mobil ---------- */
@media (max-width: 600px) {
  dialog {
    width: 95vw;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    border-radius: 16px;
  }
  /* Aktionsleiste im Dialog bleibt unten gut erreichbar */
  .dialog-form .dialog-actions {
    position: sticky;
    bottom: -16px;
    background: var(--surface);
    margin: 6px -16px -16px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  }
}

/* ---------- Kalender auf sehr kleinen Geräten ---------- */
@media (max-width: 520px) {
  .calendar-grid { gap: 4px; }
  .calendar-day {
    min-height: 60px;
    padding: 6px 5px;
    border-radius: 9px;
    align-content: start;
    gap: 2px;
  }
  .calendar-day strong { font-size: .9rem; }
  .calendar-day span { font-size: .66rem; line-height: 1.2; }
  .calendar-grid.header span { font-size: .68rem; }
}

/* ---------- Benutzer-Bearbeiten-Panel auf Mobil ---------- */
@media (max-width: 600px) {
  .user-edit-panel { min-width: 0; }
  .user-edit-row { flex-direction: column; }
  .user-edit-row form, .user-edit-row .button, .user-edit-row button { width: 100%; }
}

/* Lange Inhalte nie aus dem Bildschirm laufen lassen */
body { overflow-wrap: anywhere; }
.data-card-title, td strong, .stat > strong { word-break: break-word; }
