/* ─── RESET & BASE ────────────────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --green-light: #dcfce7;
  --green-mid: #bbf7d0;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 4px rgba(0,0,0,0.07);
  /* iPhone safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --nav-height: 64px;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  /* ruumis ei mene bottom-navin alle */
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

/* Estä iOS zoom inputeissa — font-size min 16px */
input, textarea, select {
  font-size: 16px;
  font-family: inherit;
}

/* ─── AUTH-NÄKYMÄ ────────────────────────────────────────────────────────── */
#auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #f0fdf4 0%, #dcfce7 100%);
  padding: 1.5rem;
  padding-top: calc(1.5rem + var(--safe-top));
  padding-bottom: calc(1.5rem + var(--safe-bottom));
}

.auth-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
}

.auth-logo {
  font-size: 3rem;
  text-align: center;
  margin-bottom: 0.4rem;
}

.auth-title {
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  color: var(--green);
}

.auth-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 1.75rem;
}

.auth-form-title {
  font-size: 1.05rem;
  margin-bottom: 1rem;
  color: var(--text);
}

.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2rem;
  margin-bottom: 0.5rem;
}

.auth-toggle {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 1rem;
}

.auth-toggle button {
  background: none;
  border: none;
  color: var(--green);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: underline;
}

/* ─── HEADER ──────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  box-shadow: 0 1px 0 var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  padding-top: var(--safe-top);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

#refresh-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: 8px;
  line-height: 1;
  margin-left: auto;
  transition: color 0.15s;
}
#refresh-btn:hover { color: var(--text-muted); }
#refresh-btn:active { color: var(--green); }

.logo {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--green);
  letter-spacing: -0.01em;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--green-light);
  border-radius: 50px;
  padding: 0.3rem 0.75rem 0.3rem 0.3rem;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#user-info-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--green-dark);
}

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.logout-btn:hover { border-color: var(--danger); color: var(--danger); background: #fff5f5; }
.logout-btn:active { background: #fee2e2; color: var(--danger); }

/* ─── TABS ────────────────────────────────────────────────────────────────── */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── YHTEENVETO ──────────────────────────────────────────────────────────── */
.summary-bar {
  background: linear-gradient(135deg, #16a34a, #15803d);
  color: #fff;
  padding: 1.25rem 1rem;
}

.summary-inner {
  max-width: 800px;
  margin: 0 auto;
}

.summary-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.75;
  margin-bottom: 0.75rem;
}

.macro-totals {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.macro-total {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.macro-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
}

.macro-label {
  font-size: 0.68rem;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.2rem;
}

.macro-divider {
  width: 1px;
  height: 36px;
  background: rgba(255,255,255,0.25);
  flex-shrink: 0;
}

/* ─── YHTEENVETO — kaloritavoite ─────────────────────────────────────────── */
.summary-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.goal-edit-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  border-radius: 50px;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}

.goal-edit-btn:active { background: rgba(255,255,255,0.25); }

.kcal-progress-wrap {
  margin-bottom: 0.85rem;
}

.kcal-main {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  margin-bottom: 0.4rem;
}

.kcal-main .macro-value { font-size: 2rem; }

.kcal-sep { font-size: 1.2rem; opacity: 0.6; }

.kcal-goal { font-size: 1.1rem; opacity: 0.75; }

.kcal-unit { font-size: 0.85rem; opacity: 0.7; }

.kcal-bar-track {
  height: 6px;
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
  overflow: hidden;
}

.kcal-bar-fill {
  height: 100%;
  border-radius: 3px;
  width: 0%;
  transition: width 0.4s ease, background 0.4s ease;
  background: rgba(255,255,255,0.8);
}

.kcal-bar-fill.over    { background: #fca5a5; }
.kcal-bar-fill.warning { background: #fde68a; }

/* Kaloritavoite-editori */
.goal-editor {
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.goal-editor-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.goal-editor-inner label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  flex-shrink: 0;
}

.goal-editor-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex: 1;
}

.goal-editor-row input {
  width: 110px;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
}

.goal-editor-row input:focus { border-color: var(--green); outline: none; }

.goal-save-btn {
  width: auto;
  padding: 0.55rem 1.25rem;
  font-size: 0.9rem;
  margin-top: 0;
}

/* ─── VIIKKOKALENTERI ─────────────────────────────────────────────────────── */
.week-section {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.week-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 0.85rem 0.75rem;
}

.week-calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
}

.week-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.6rem 0.25rem;
  border-radius: 10px;
  background: #f8fafc;
  border: 2px solid transparent;
  transition: all 0.2s;
}

.week-day { cursor: pointer; }
.week-day.future { opacity: 0.4; cursor: default; }

.week-day.today {
  border-color: var(--green);
}

.week-day.selected {
  background: var(--green);
  border-color: var(--green);
}

.week-day.selected .week-day-name,
.week-day.selected .week-day-kcal { color: rgba(255,255,255,0.85); }

.week-day-name {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

.week-day.today .week-day-name { color: var(--green); }

.week-day-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  color: #fff;
}

.week-day-dot.empty    { background: #e2e8f0; color: var(--text-faint); }
.week-day-dot.ok       { background: #16a34a; }
.week-day-dot.warning  { background: #f59e0b; }
.week-day-dot.over     { background: #ef4444; }

.week-day-kcal {
  font-size: 0.62rem;
  color: var(--text-faint);
  text-align: center;
  line-height: 1.2;
}

/* ─── ATERIAT ─────────────────────────────────────────────────────────────── */
.meals-container {
  max-width: 800px;
  margin: 1rem auto;
  padding: 0 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.meal-section {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.meal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #f8fafc;
}

.meal-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #374151;
}

.add-entry-btn {
  background: var(--green-light);
  color: var(--green);
  border: none;
  border-radius: 50px;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  transition: background 0.15s;
  -webkit-touch-callout: none;
}

.add-entry-btn:active { background: var(--green-mid); }

/* Merkintärivi */
.entry-row {
  display: flex;
  align-items: center;
  padding: 0.65rem 1rem;
  gap: 0.5rem;
  border-bottom: 1px solid #f8fafc;
}

.entry-row:last-child { border-bottom: none; }

.entry-info {
  flex: 1;
  min-width: 0;
}

.entry-name {
  font-weight: 500;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-grams {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 0.1rem;
}

.entry-macros-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

.entry-macro {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 36px;
  text-align: center;
}

.entry-macro .macro-tag {
  font-size: 0.6rem;
  color: var(--text-faint);
  text-transform: uppercase;
}

.entry-kcal {
  font-weight: 700;
  color: var(--green-dark);
  font-size: 0.85rem;
  min-width: 52px;
  text-align: right;
  flex-shrink: 0;
}

.delete-entry-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 1rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.delete-entry-btn:active {
  color: var(--danger);
  background: #fee2e2;
}

.meal-total {
  padding: 0.55rem 1rem;
  background: #f8fafc;
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
}

.meal-total:empty { display: none; }

.meal-total-item strong { color: #374151; }

.empty-meal {
  padding: 0.85rem 1rem;
  color: var(--text-faint);
  font-size: 0.85rem;
  font-style: italic;
}

/* Tyhjennä */
.reset-bar {
  max-width: 800px;
  margin: 0 auto 1.5rem;
  padding: 0 0.75rem;
  text-align: right;
}

#reset-day-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-faint);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.83rem;
  min-height: 40px;
  transition: all 0.15s;
}

#reset-day-btn:active {
  border-color: var(--danger);
  color: var(--danger);
}

/* ─── TUOTENÄKYMÄ ─────────────────────────────────────────────────────────── */
.products-container {
  max-width: 800px;
  margin: 1rem auto;
  padding: 0 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.product-form-card,
.product-list-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.product-form-card h2,
.product-list-card h2 {
  font-size: 1rem;
  margin-bottom: 0.2rem;
}

.form-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1.1rem;
}

.form-row {
  margin-bottom: 0.85rem;
}

.form-row label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.form-row input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s;
  background: #fff;
  color: var(--text);
}

.form-row input:focus {
  border-color: var(--green);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 0.75rem;
}

.btn-primary {
  width: 100%;
  padding: 0.85rem;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.25rem;
  min-height: 48px;
  transition: background 0.15s;
}

.btn-primary:active { background: var(--green-dark); }

/* Tuotehaku */
.search-input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
  outline: none;
  transition: border-color 0.15s;
  background: #fff;
  color: var(--text);
}

.search-input:focus { border-color: var(--green); }

.product-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid #f1f5f9;
  gap: 0.25rem;
}

.product-item-info { flex: 1; min-width: 0; }

.product-item:last-child { border-bottom: none; }

.product-item-name {
  font-weight: 500;
  font-size: 0.9rem;
}

.product-item-macros {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.delete-product-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 1rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.delete-product-btn:active {
  color: var(--danger);
  background: #fee2e2;
}

.no-products {
  color: var(--text-faint);
  font-size: 0.85rem;
  font-style: italic;
  padding: 0.5rem 0;
}

.badge-fineli {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  background: #dbeafe;
  color: #1d4ed8;
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: middle;
  margin-left: 4px;
  font-style: normal;
}

/* ─── SUOSIKKI-NAPIT ─────────────────────────────────────────────────────── */
.fav-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  color: #cbd5e1;
  transition: color 0.15s, background 0.15s;
}

.fav-btn:active  { background: #fef9c3; }
.fav-btn.is-fav  { color: #f59e0b; }

.modal-fav-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  color: #cbd5e1;
  transition: color 0.15s, background 0.15s;
}

.modal-fav-btn:active { background: #fef9c3; }
.modal-fav-btn.is-fav { color: #f59e0b; }

/* ─── MODAL ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: flex-end;   /* Bottom sheet mobiilissa */
  justify-content: center;
}

.modal {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 0.75rem 1.25rem 1.25rem;
  padding-bottom: calc(1.25rem + var(--safe-bottom));
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 1rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-header h3 { font-size: 1.05rem; }

.modal-close {
  background: #f1f5f9;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#modal-favs-list {
  max-height: 38dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.5rem;
}

#modal-product-list {
  max-height: 38dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.5rem;
}

#product-list {
  max-height: 60dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 0.5rem;
}

.modal-list-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 0.4rem 0 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-loading {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--green);
  font-size: 0.78rem;
}

.modal-empty-favs {
  color: var(--text-faint);
  font-size: 0.85rem;
  font-style: italic;
  padding: 0.75rem 0;
  text-align: center;
}

.modal-product-item {
  display: flex;
  align-items: center;
  padding: 0.6rem 0.5rem 0.6rem 0.75rem;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 0.15rem;
  min-height: 52px;
  transition: background 0.12s;
  gap: 0.25rem;
}

.modal-product-item:active { background: #f0fdf4; }
.modal-product-item.selected { background: var(--green-light); }

.modal-product-item-info {
  flex: 1;
  min-width: 0;
}

.modal-product-item-name {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-product-item-macros {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.selected-product-info {
  background: #f0fdf4;
  border: 1.5px solid var(--green-mid);
  border-radius: 8px;
  padding: 0.7rem;
  margin: 0.75rem 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--green-dark);
}

.macro-preview {
  background: #f8fafc;
  border-radius: 8px;
  padding: 0.75rem;
  margin: 0.6rem 0;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
}

.macro-preview:empty { display: none; }

.macro-preview-item strong {
  font-size: 0.95rem;
  color: var(--green-dark);
}

/* ─── ALANAVIGAATIO ───────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  height: calc(var(--nav-height) + var(--safe-bottom));
}

.bottom-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem 0;
  color: var(--text-faint);
  transition: color 0.15s;
  gap: 0.2rem;
}

.bottom-nav-btn.active {
  color: var(--green);
}

.bnav-icon { font-size: 1.4rem; line-height: 1; }
.bnav-label { font-size: 0.7rem; font-weight: 500; }

/* ─── TOAST ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 0.75rem);
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: #1e293b;
  color: #fff;
  padding: 0.65rem 1.4rem;
  border-radius: 50px;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  z-index: 999;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ─── CHEAT DAY ─────────────────────────────────────────────────────────── */
.cheat-toggle-inline {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.cheat-toggle-inline input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.cheat-toggle-pill {
  font-size: 1.1rem;
  padding: 0.25rem 0.55rem;
  border-radius: 50px;
  background: rgba(255,255,255,0.15);
  border: 1.5px solid rgba(255,255,255,0.3);
  transition: all 0.2s;
  line-height: 1;
  user-select: none;
  opacity: 0.55;
}

.cheat-toggle-inline input:checked + .cheat-toggle-pill {
  background: #eab308;
  border-color: #ca8a04;
  opacity: 1;
  box-shadow: 0 0 0 3px rgba(234,179,8,0.3);
}

/* Cheat day värit kalenterissa */
.week-day.cheat { border-color: #eab308; background: #fef9c3; }
.week-day.cheat .week-day-name { color: #a16207; }
.week-day-dot.cheat { background: #fef08a; border: 2px solid #eab308; font-size: 0.7rem; }
.cal-cell.cheat { background: #fef9c3; }
.cal-cell.cheat .cal-day-num { color: #a16207; font-weight: 700; }
.cal-dot.cheat { background: transparent; font-size: 0.6rem; width: auto; height: auto; }

/* ─── TILASTOKORTIT (kalenteri) ──────────────────────────────────────────── */
.cal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  padding: 1rem 1rem 0.25rem;
}

.cal-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.85rem 0.5rem;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.cal-stat-icon { font-size: 1.5rem; line-height: 1; }

.cal-stat-num {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
}

.cal-stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-align: center;
}

.cal-stat--ok   { border-top: 3px solid #16a34a; }
.cal-stat--ok   .cal-stat-num { color: #16a34a; }
.cal-stat--over { border-top: 3px solid #ef4444; }
.cal-stat--over .cal-stat-num { color: #ef4444; }
.cal-stat--cheat { border-top: 3px solid #eab308; }
.cal-stat--cheat .cal-stat-num { color: #a16207; }

/* ─── PÄIVÄNAVIGAATIO ────────────────────────────────────────────────────── */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.date-nav button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
}

#date-prev, #date-next {
  width: 36px;
  height: 36px;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

#date-prev:disabled, #date-next:disabled {
  opacity: 0.3;
  cursor: default;
}

#date-label {
  flex: 1;
  max-width: 260px;
  padding: 0.45rem 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  color: var(--green);
  border-radius: 8px;
}

#date-label:hover { background: var(--green-light); }

/* ─── KALENTERIVÄLILEHTI ─────────────────────────────────────────────────── */
#tab-kalenteri {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem;
}

.cal-tab-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.cal-month-label {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.cal-nav-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  box-shadow: var(--shadow);
}

.cal-nav-btn:disabled { opacity: 0.3; cursor: default; }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 0.4rem;
}

.cal-weekdays span {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.25rem 0;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.cal-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0.35rem 0.1rem;
  cursor: pointer;
  min-height: 46px;
  transition: background 0.12s;
}

.cal-cell:hover:not(.empty):not(.future) { background: var(--green-light); }

.cal-cell.empty { cursor: default; }
.cal-cell.future { opacity: 0.3; cursor: default; }

.cal-cell.today { background: var(--green-light); }
.cal-cell.today .cal-day-num { color: var(--green); font-weight: 700; }

.cal-cell.selected { background: var(--green); }
.cal-cell.selected .cal-day-num { color: #fff; font-weight: 700; }
.cal-cell.selected .cal-kcal { color: rgba(255,255,255,0.85); }

.cal-day-num {
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1;
}

.cal-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-top: 3px;
}

.cal-dot.ok      { background: var(--green); }
.cal-dot.warning { background: #f59e0b; }
.cal-dot.over    { background: var(--danger); }

.cal-kcal {
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1;
}

.cal-cell.pop-active {
  outline: 2px solid var(--green);
  outline-offset: -2px;
  border-radius: 8px;
}

/* ─── RESEPTIT ───────────────────────────────────────────────────────────────── */
.recipe-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  max-width: 800px;
  margin: 0 auto;
}
.recipe-builder-card, .recipe-list-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.recipe-builder-card h2, .recipe-list-card h2 {
  font-size: 1rem; font-weight: 700; margin-bottom: 0.75rem;
}
.recipe-ing-search-wrap { position: relative; margin-bottom: 0.75rem; }
.recipe-ing-search-wrap label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.recipe-ing-results {
  position: absolute; left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  z-index: 100; max-height: 220px; overflow-y: auto;
}
.recipe-ing-result-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 0.9rem; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 0.88rem;
}
.recipe-ing-result-item:last-child { border-bottom: none; }
.recipe-ing-result-item:hover { background: var(--bg); }
.recipe-ing-result-kcal { font-size: 0.78rem; color: var(--text-muted); }
.recipe-ing-noresult { padding: 0.75rem; font-size: 0.85rem; color: var(--text-muted); }
.recipe-ing-list {
  display: flex; flex-direction: column; gap: 0.4rem;
  margin-bottom: 0.75rem; max-height: 240px; overflow-y: auto;
}
.recipe-ing-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg); border-radius: 8px; padding: 0.5rem 0.75rem; font-size: 0.88rem;
}
.recipe-ing-name { font-weight: 500; flex: 1; }
.recipe-ing-right { display: flex; align-items: center; gap: 0.5rem; }
.recipe-ing-grams, .recipe-ing-kcal { font-size: 0.78rem; color: var(--text-muted); }
.recipe-ing-remove { background: none; border: none; cursor: pointer; color: var(--text-faint); font-size: 0.9rem; padding: 2px 4px; }
.recipe-ing-remove:hover { color: var(--danger); }
.recipe-ing-empty { font-size: 0.85rem; color: var(--text-faint); padding: 0.5rem 0; }
.recipe-ing-gram-row {
  display: flex; align-items: center; gap: 0.5rem;
  margin-top: 0.5rem; padding: 0.6rem 0.75rem;
  background: var(--green-light); border-radius: 10px;
}
.recipe-ing-sel-name { flex: 1; font-size: 0.85rem; font-weight: 600; color: var(--green-dark); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipe-gram-input { width: 70px; padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 8px; font-size: 16px; text-align: center; }
.recipe-ing-add-btn { padding: 0.45rem 0.9rem !important; font-size: 0.85rem !important; width: auto !important; margin: 0 !important; }
.recipe-totals {
  background: var(--green-light); border-radius: 10px; padding: 0.65rem 0.85rem; margin-bottom: 0.75rem;
}
.recipe-totals-title { font-size: 0.8rem; color: var(--green-dark); font-weight: 600; margin-bottom: 0.3rem; }
.recipe-totals-macros { display: flex; gap: 0.75rem; flex-wrap: wrap; font-size: 0.82rem; }
.btn-secondary {
  width: 100%; padding: 0.7rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; font-size: 0.9rem; color: var(--text-muted); cursor: pointer; margin-top: 0.4rem;
}
.recipe-card { background: var(--bg); border-radius: 10px; padding: 0.8rem 0.9rem; margin-bottom: 0.6rem; }
.recipe-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.25rem; }
.recipe-card-name { font-weight: 700; font-size: 0.95rem; }
.recipe-card-delete { background: none; border: none; cursor: pointer; font-size: 1rem; color: var(--text-faint); }
.recipe-card-delete:hover { color: var(--danger); }
.recipe-card-meta { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.2rem; }
.recipe-card-macros, .recipe-card-ing { font-size: 0.78rem; color: var(--text-muted); }
.recipe-empty { font-size: 0.85rem; color: var(--text-faint); padding: 0.5rem 0; }
.recipe-modal-item { background: #f0fdf4 !important; }

@media (min-width: 640px) {
  .recipe-layout { flex-direction: row; align-items: flex-start; }
  .recipe-builder-card, .recipe-list-card { flex: 1; }
}

/* ─── KALENTERI POPOVER ───────────────────────────────────────────────────── */
.cal-popover {
  margin: 0.75rem 0 0.25rem;
  background: var(--surface);
  border-radius: 14px;
  padding: 1rem 1.1rem;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  border: 1px solid var(--border);
  animation: popIn 0.15s ease;
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cpop-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.cpop-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.cpop-kcal-row {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.cpop-kcal {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--green);
  line-height: 1;
}

.cpop-kcal-sep {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.cpop-bar-track {
  height: 6px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 0.65rem;
}

.cpop-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.3s;
}
.cpop-bar-fill.ok   { background: var(--green); }
.cpop-bar-fill.warn { background: #f59e0b; }
.cpop-bar-fill.over { background: var(--danger); }

.cpop-macros {
  display: flex;
  gap: 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.cpop-hint {
  font-size: 0.7rem;
  color: var(--text-faint);
  text-align: center;
}

.cal-hint {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-faint);
  margin-top: 0.5rem;
  padding-bottom: 0.5rem;
}

/* Desktop-nav (piilossa mobiilissa) */
.desktop-nav {
  display: none;
  gap: 0.25rem;
  background: var(--bg);
  border-radius: 50px;
  padding: 0.3rem;
}

.top-nav-btn {
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  background: transparent;
  color: var(--text-muted);
  transition: all 0.15s;
  white-space: nowrap;
}

.top-nav-btn:hover { color: var(--text); background: rgba(0,0,0,0.04); }

.top-nav-btn.active {
  background: var(--surface);
  color: var(--green);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* ─── DESKTOP OVERRIDES (≥ 640px) ────────────────────────────────────────── */
@media (min-width: 640px) {
  :root { --nav-height: 0px; }

  body { padding-bottom: 0; }

  header { padding-top: 0; }

  .header-inner { justify-content: space-between; }

  .desktop-nav { display: flex; }

  .bottom-nav { display: none; }

  /* Lisää desktop-navigaatio headeriin dynaamisesti JS:llä —
     tai käytämme jo olemassa olevaa alanavigaatiota piilotetulta */

  .products-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
  }

  .modal {
    border-radius: 16px;
    max-width: 480px;
    max-height: 80dvh;
    margin: auto;
    padding: 1.5rem;
  }

  .modal-overlay { align-items: center; }
  .modal-handle { display: none; }

  .macro-value { font-size: 1.75rem; }

  .entry-macro { min-width: 44px; }
}
