/* ========== Farben & Grundwerte ========== */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1c2233;
  --muted: #6b7489;
  --border: #e3e7f0;
  --primary: #3b5bdb;
  --primary-soft: #e7ecff;
  --green: #2f9e44;
  --green-soft: #e6f6ea;
  --orange: #e8590c;
  --orange-soft: #fff0e6;
  --radius: 16px;
  --shadow: 0 4px 20px rgba(28, 34, 51, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11141c;
    --surface: #1a1f2b;
    --text: #e8ebf2;
    --muted: #8f97aa;
    --border: #2a3142;
    --primary: #5c7cfa;
    --primary-soft: #222b4a;
    --green: #51cf66;
    --green-soft: #1d3324;
    --orange: #ff922b;
    --orange-soft: #3a2a1c;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #11141c;
    --surface: #1a1f2b;
    --text: #e8ebf2;
    --muted: #8f97aa;
    --border: #2a3142;
    --primary: #5c7cfa;
    --primary-soft: #222b4a;
    --green: #51cf66;
    --green-soft: #1d3324;
    --orange: #ff922b;
    --orange-soft: #3a2a1c;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

h1 { font-size: 1.6rem; font-weight: 800; }
h2 { font-size: 1.5rem; font-weight: 800; }
h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; font-weight: 500; }
.hidden { display: none !important; }

/* ========== Buttons & Inputs ========== */
.btn {
  border: none;
  border-radius: 12px;
  padding: 11px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s, background .2s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--border); }
.btn-block { width: 100%; margin-top: 20px; }

input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .2s;
}
input:focus, textarea:focus { border-color: var(--primary); }
textarea { min-height: 80px; resize: vertical; margin-bottom: 12px; }
label { display: block; font-weight: 600; font-size: 0.9rem; margin: 16px 0 6px; }

/* ========== Login ========== */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: linear-gradient(135deg, var(--primary-soft), var(--bg) 60%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 24px;
  padding: 36px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card form { text-align: left; margin-top: 8px; }
.logo { font-size: 3rem; margin-bottom: 8px; }
.error { color: #e03131; font-size: 0.9rem; margin-top: 10px; }
.hint { margin-top: 18px; font-size: 0.85rem; color: var(--muted); }

/* ========== Kopfzeile ========== */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; display: flex; align-items: center; gap: 8px; }
.logo-sm { font-size: 1.4rem; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: none; background: transparent; font: inherit; font-weight: 600;
  color: var(--muted); padding: 9px 16px; border-radius: 10px; cursor: pointer;
}
.tab:hover { background: var(--bg); }
.tab.active { background: var(--primary-soft); color: var(--primary); }
.user { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--primary); color: #fff; font-weight: 700; text-transform: uppercase;
}

/* ========== Inhalt ========== */
.content { max-width: 1100px; margin: 0 auto; padding: 28px 24px 100px; }
.page { display: none; animation: fade .25s ease; }
.page.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}

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

.badge { padding: 6px 12px; border-radius: 999px; font-size: 0.82rem; font-weight: 700; }
.badge-ok { background: var(--green-soft); color: var(--green); }
.badge-warn { background: var(--orange-soft); color: var(--orange); }

/* ========== Essensplan ========== */
.day-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 16px; }
.day-chip {
  flex: 0 0 auto;
  border: 1.5px solid var(--border); background: var(--surface);
  border-radius: 14px; padding: 8px 14px; font: inherit; cursor: pointer;
  text-align: center; color: var(--text);
}
.day-chip b { display: block; font-size: 0.95rem; }
.day-chip span { font-size: 0.78rem; color: var(--muted); }
.day-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.day-chip.active span { color: rgba(255,255,255,.8); }
.day-chip.today:not(.active) { border-color: var(--primary); }

.meal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.meal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.meal-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.meal-type { font-weight: 700; color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: .04em; }
.meal-time { font-size: 0.8rem; color: var(--muted); }
.meal-icon { font-size: 2rem; margin-bottom: 8px; }
.meal-main { font-weight: 700; font-size: 1.1rem; margin-bottom: 6px; }
.meal-list { list-style: none; color: var(--muted); font-size: 0.92rem; }
.meal-list li::before { content: "• "; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.tag { font-size: 0.75rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--green-soft); color: var(--green); }

/* Aufklappbare Mahlzeit */
details.meal { padding: 0; }
details.meal > summary { list-style: none; cursor: pointer; padding: 20px; border-radius: var(--radius); }
details.meal > summary::-webkit-details-marker { display: none; }
details.meal > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.meal-toggle {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
  font-size: 0.9rem; font-weight: 600; color: var(--primary);
}
.chev { transition: transform .2s; }
details[open] .chev { transform: rotate(180deg); }
.nutri { padding: 0 20px 20px; display: grid; gap: 12px; }
.kcal { font-size: 0.95rem; color: var(--muted); }
.kcal b { font-size: 1.6rem; color: var(--text); font-variant-numeric: tabular-nums; }
.macro-bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; gap: 2px; background: var(--border); }
.macro-bar span { display: block; height: 100%; }
.protein { background: var(--green); }
.carb { background: var(--primary); }
.fat { background: var(--orange); }
.sugar { background: transparent; border: 2px solid var(--primary); }
.nutri-list { display: grid; gap: 6px; }
.nutri-list div { display: flex; justify-content: space-between; align-items: center; }
.nutri-list dt { display: flex; align-items: center; gap: 8px; }
.nutri-list dd { font-weight: 700; font-variant-numeric: tabular-nums; }
.nutri-list .sub { padding-left: 18px; color: var(--muted); font-size: 0.9rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; box-sizing: border-box; }
.nutri .small { margin: 0; }

/* Vegetarische Option & Teller */
.veg-option {
  display: flex; flex-direction: column; gap: 2px;
  margin-top: 12px; padding: 10px 12px; border-radius: 12px;
  background: var(--green-soft);
}
.veg-label { font-size: 0.78rem; font-weight: 700; color: var(--green); text-transform: uppercase; letter-spacing: .04em; }
.veg-main { font-weight: 600; }
.plates { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.stepper { display: flex; align-items: center; gap: 4px; background: var(--bg); border-radius: 12px; padding: 4px; }
.stepper b { min-width: 28px; text-align: center; font-variant-numeric: tabular-nums; }
.step {
  width: 36px; height: 36px; border: none; border-radius: 9px;
  background: var(--surface); color: var(--primary); font: inherit; font-size: 1.2rem; font-weight: 700;
  cursor: pointer; box-shadow: var(--shadow);
}
.step:disabled { opacity: .4; cursor: not-allowed; }

/* ========== Bus ========== */
.card-list { display: grid; gap: 12px; }
.bus {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow);
}
.bus-date {
  flex: 0 0 64px; text-align: center; background: var(--primary-soft);
  color: var(--primary); border-radius: 12px; padding: 8px 4px;
}
.bus-date b { display: block; font-size: 1.3rem; line-height: 1.1; }
.bus-date span { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; }
.bus-info { flex: 1; min-width: 0; }
.bus-route { font-weight: 700; }
.bus-meta { color: var(--muted); font-size: 0.88rem; }
.seats { height: 6px; background: var(--border); border-radius: 99px; margin-top: 8px; overflow: hidden; max-width: 220px; }
.seats div { height: 100%; background: var(--primary); border-radius: 99px; }
.bus .btn.joined { background: var(--green-soft); color: var(--green); }

/* ========== Wochenende ========== */
.choice-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
.choice {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--radius); padding: 24px 16px; cursor: pointer;
  font: inherit; color: var(--text); transition: border-color .2s, transform .1s;
}
.choice:hover { border-color: var(--primary); }
.choice:active { transform: scale(0.98); }
.choice.selected { border-color: var(--primary); background: var(--primary-soft); }
.choice-icon { font-size: 2.2rem; }
.choice-title { font-weight: 700; }
.choice-sub { font-size: 0.85rem; color: var(--muted); text-align: center; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { background: var(--bg); border-radius: 12px; padding: 14px; text-align: center; }
.stat b { display: block; font-size: 1.6rem; }
.stat span { font-size: 0.85rem; color: var(--muted); }

.info-box {
  background: var(--primary-soft); color: var(--text);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 0.92rem;
}
.choice .check {
  margin-left: auto; flex: 0 0 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--border); display: grid; place-items: center;
  color: #fff; font-size: 0.85rem; font-weight: 800;
}
.choice.selected .check { background: var(--primary); border-color: var(--primary); }
.choice.selected .check::after { content: "✓"; }

.onboarding-card { text-align: left; }
.onboarding-card .logo, .onboarding-card h1 { text-align: center; }
.onboarding-card > .muted { text-align: center; margin: 6px 0 18px; }
.pref-form .choice-grid { margin-bottom: 4px; }
.pref-form label { margin-top: 12px; }
.seg { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 12px; }
.seg-btn {
  flex: 1; border: none; background: transparent; font: inherit; font-weight: 600;
  color: var(--muted); padding: 10px; border-radius: 9px; cursor: pointer;
}
.seg-btn.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
#settings-form { margin-bottom: 14px; }
button.avatar { border: none; cursor: pointer; font: inherit; font-weight: 700; }
.link { border: none; background: none; font: inherit; font-weight: 700; color: var(--primary); cursor: pointer; padding: 0; text-decoration: underline; }
.bus-route .tag { margin-left: 4px; vertical-align: middle; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ========== Personenlisten ========== */
.bus-people { width: 100%; border-top: 1px solid var(--border); padding-top: 10px; }
.bus-people summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; color: var(--primary); }
.bus-people .people { margin-top: 10px; }
.people-group + .people-group { margin-top: 16px; }
.people-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-bottom: 8px; }
.count { background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: 2px 10px; font-size: 0.85rem; }
.people { list-style: none; display: grid; gap: 6px; }
.people li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; background: var(--bg); }
.people li.me { background: var(--primary-soft); font-weight: 700; }
.people small { display: block; color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.mini-avatar {
  flex: 0 0 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: 0.72rem; font-weight: 700;
  background: var(--surface); color: var(--primary); border: 1px solid var(--border); text-transform: uppercase;
}

/* ========== Modal & Toast ========== */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 14, 25, 0.5);
  display: grid; place-items: center; padding: 16px;
}
.modal-box { background: var(--surface); border-radius: 20px; padding: 24px; width: 100%; max-width: 420px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  border: 2px dashed var(--border); border-radius: 16px;
  padding: 32px 16px; margin: 16px 0; cursor: pointer; font-weight: 600; color: var(--muted);
}
.dropzone:hover { border-color: var(--primary); color: var(--primary); }
.dz-icon { font-size: 2.4rem; }
.dropzone { position: relative; }
/* Das echte Auswahlfeld liegt unsichtbar über dem ganzen Kästchen,
   damit man auf dem Handy direkt darauf tippt */
.file-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; font-size: 0; z-index: 1;
}
.dropzone:focus-within { border-color: var(--primary); color: var(--primary); }
.upload-preview { max-width: 100%; max-height: 220px; border-radius: 10px; object-fit: contain; }
.analyze-status { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-weight: 600; color: var(--primary); }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; flex: 0 0 18px;
  border: 3px solid var(--primary-soft); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
#upload-error { margin: 0 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 12px 20px; border-radius: 12px; font-weight: 600; z-index: 60;
}

/* ========== Immer Handy-Layout ========== */
/* Die App ist immer so breit wie ein Handy – auch am PC (dann mittig). */
html { background: var(--border); }
body { max-width: 430px; margin: 0 auto; min-height: 100vh; box-shadow: 0 0 40px rgba(0,0,0,.12); }
.login-screen { min-height: 100vh; }

.desktop-only { display: none !important; }
.topbar { padding: 12px 16px; }
.content { padding: 20px 16px 100px; }
.page-head h2 { font-size: 1.35rem; }
.meal-grid, .choice-grid { grid-template-columns: 1fr; }
.choice { flex-direction: row; justify-content: flex-start; padding: 16px; gap: 14px; text-align: left; }
.choice-icon { font-size: 1.9rem; }
.choice-text { display: flex; flex-direction: column; }
.choice-sub { text-align: left; }
.bus { flex-wrap: wrap; }
.bus .btn { width: 100%; }
.stat b { font-size: 1.3rem; }

.bottom-nav {
  display: flex;
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 430px; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--border);
  justify-content: space-around; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.bottom-nav .tab {
  display: flex; flex-direction: column; align-items: center;
  font-size: 0.75rem; padding: 6px 14px; flex: 1;
}
.bottom-nav .tab span { font-size: 1.3rem; }
