:root {
  --green: #2E7D32;
  --green-dark: #1B5E20;
  --green-light: #4CAF50;
  --green-bg: #E8F5E9;
  --surface: #ffffff;
  --surface2: #f5f5f5;
  --text: #212121;
  --text2: #757575;
  --border: #e0e0e0;
  --danger: #c62828;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #121212;
    --surface2: #1e1e1e;
    --text: #e0e0e0;
    --text2: #9e9e9e;
    --border: #333;
    --green-bg: #1a2e1b;
  }
}

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

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--surface);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* ── Layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

header {
  background: var(--green);
  color: #fff;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}

header h1 { font-size: 1.2rem; font-weight: 700; }

#btn-logout {
  background: none;
  border: 1px solid rgba(255,255,255,.5);
  color: #fff;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: .8rem;
  cursor: pointer;
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 80px;
}

/* ── Bottom nav ── */
nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  height: 60px;
  z-index: 100;
}

nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text2);
  font-size: .65rem;
  cursor: pointer;
  transition: color .15s;
}

nav button.active { color: var(--green); }
nav button svg { width: 24px; height: 24px; }

/* ── Views ── */
.view { display: none; }
.view.active { display: block; }

/* ── Cards / list items ── */
.card {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 24px;
  border: none;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--green); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-outline { background: none; border: 1.5px solid var(--green); color: var(--green); }
.btn-sm { padding: 6px 12px; font-size: .82rem; }

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: 76px; right: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  border: none;
  font-size: 1.6rem;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 99;
}

/* ── Inputs ── */
input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--green);
}
label { display: block; font-size: .85rem; color: var(--text2); margin-bottom: 4px; margin-top: 14px; }

/* ── Meals view ── */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.week-nav button {
  background: none; border: none; cursor: pointer;
  color: var(--green); font-size: 1.4rem; padding: 4px 8px;
}
.week-nav span { font-weight: 600; font-size: .95rem; }

.day-card { margin-bottom: 12px; }
.day-title { font-weight: 700; font-size: .95rem; margin-bottom: 8px; color: var(--green); }

.slot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.slot-row:last-child { border-bottom: none; }
.slot-label { font-size: .78rem; color: var(--text2); width: 80px; flex-shrink: 0; }
.slot-recipe { font-size: .92rem; }
.slot-recipe.empty { color: var(--text2); font-style: italic; }

/* ── Recipe list ── */
.recipe-name { font-weight: 600; }
.recipe-desc { font-size: .85rem; color: var(--text2); margin-top: 2px; }

/* ── Shopping ── */
.shop-add {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.shop-add input { flex: 1; }
.shop-add input.qty { width: 90px; flex: none; }

.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.shop-item:last-child { border-bottom: none; }
.shop-item input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--green); flex-shrink: 0; }
.shop-item .item-text { flex: 1; }
.shop-item .item-text.bought { text-decoration: line-through; color: var(--text2); }
.shop-item .item-qty { font-size: .82rem; color: var(--text2); }
.shop-del { background: none; border: none; color: var(--text2); font-size: 1.2rem; cursor: pointer; padding: 0 4px; }

/* ── Progress / Weight ── */
.weight-form {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.weight-form input { flex: 1; }

.stats-row {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  flex: 1;
  background: var(--green-bg);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--green); }
.stat-label { font-size: .75rem; color: var(--text2); margin-top: 2px; }

#weight-chart {
  width: 100%;
  height: 180px;
  display: block;
  margin-bottom: 20px;
}

.weight-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.weight-entry:last-child { border-bottom: none; }

/* ── Overlay / modal ── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 16px;
}
.overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 24px 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
}
.modal h2 { font-size: 1.2rem; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

/* ── Ingredient rows ── */
.ing-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.ing-row input { flex: 1; }
.ing-row input.ing-qty { width: 70px; flex: none; }
.ing-row input.ing-unit { width: 60px; flex: none; }
.ing-row button { background: none; border: none; color: var(--danger); font-size: 1.3rem; cursor: pointer; flex-shrink: 0; }

/* ── Recipe picker (modal list) ── */
.recipe-pick-item {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 8px;
}
.recipe-pick-item:hover { background: var(--green-bg); }

/* ── Empty state ── */
.empty { text-align: center; color: var(--text2); padding: 48px 16px; }
.empty svg { width: 64px; height: 64px; opacity: .3; margin-bottom: 12px; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 72px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #323232;
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: .9rem;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 300;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Login overlay ── */
#login-overlay .modal { max-width: 360px; }
#login-overlay h2 { color: var(--green); }
#login-overlay .logo { font-size: 2.5rem; text-align: center; margin-bottom: 8px; }
