/* ZCal — mobile-first stylesheet.
   Design is built for a phone screen first; there is no separate desktop
   layout since this app is meant to be used one-handed while eating. */

:root {
  --teal: #0f9b8e;
  --teal-dark: #0b7a70;
  --mint: #e6f7f4;
  --bg: #f7f8f9;
  --card: #ffffff;
  --text: #1c2321;
  --muted: #6b7573;
  --border: #e7eae9;
  --danger: #d64545;
  --radius: 14px;
  --nav-height: 60px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", "TH Sarabun New", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--nav-height) + 24px);
}

.page { max-width: 480px; margin: 0 auto; padding: 12px 16px 32px; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }

.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.error { color: var(--danger); }
.success { color: var(--teal-dark); }
.over { color: var(--danger) !important; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand-small { font-weight: 700; color: var(--teal-dark); font-size: 1.1em; }
.today-date { color: var(--muted); font-size: 0.9em; }

/* ---- Calorie summary ---- */
.cal-summary { margin: 14px 0; }
.cal-summary-top { display: flex; justify-content: space-between; align-items: flex-end; }
.cal-eaten { font-size: 2em; font-weight: 700; }
.cal-eaten .unit { font-size: 0.5em; font-weight: 400; color: var(--muted); }
.cal-remaining { font-weight: 600; color: var(--teal-dark); }
.progress-track { height: 10px; background: var(--mint); border-radius: 6px; margin: 10px 0; overflow: hidden; }
.progress-fill { height: 100%; background: var(--teal); border-radius: 6px; transition: width 0.3s; }
.progress-fill.over { background: var(--danger); }
.macro-row { margin-top: 6px; }

/* ---- Quick add chips ---- */
.section-title { font-weight: 600; margin: 18px 0 8px; }
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.chip {
  flex: 0 0 auto; background: var(--mint); color: var(--teal-dark); border: none;
  border-radius: 999px; padding: 10px 14px; font-size: 0.9em; white-space: nowrap;
}
.chip-kcal { color: var(--muted); font-weight: 400; }

/* ---- Log list ---- */
.meal-group { margin-bottom: 14px; }
.meal-label { font-weight: 600; color: var(--teal-dark); margin: 10px 0 6px; font-size: 0.9em; }
.log-item {
  display: flex; align-items: center; gap: 12px; background: var(--card);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.log-thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; flex: 0 0 auto; }
.log-thumb-placeholder { display: flex; align-items: center; justify-content: center; background: var(--mint); font-size: 1.2em; }
.log-info { flex: 1; min-width: 0; }
.log-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-delete { background: none; border: none; color: var(--muted); font-size: 1.1em; padding: 6px; }
.empty-state { text-align: center; padding: 24px 0; }

/* ---- History ---- */
.history-row { display: flex; justify-content: space-between; margin-bottom: 8px; text-decoration: none; color: var(--text); }
.history-row.selected { outline: 2px solid var(--teal); }

/* ---- Floating action button ---- */
.fab {
  position: fixed; right: 20px; bottom: calc(var(--nav-height) + 16px);
  width: 56px; height: 56px; border-radius: 50%; background: var(--teal);
  color: #fff; font-size: 1.8em; border: none; box-shadow: 0 4px 12px rgba(15,155,142,0.4);
  z-index: 20; line-height: 1;
}

/* ---- Bottom nav ---- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-height);
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; z-index: 15;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-decoration: none; font-size: 0.82em;
}
.nav-item.active { color: var(--teal-dark); font-weight: 600; }

/* ---- Bottom sheet (add food) ---- */
.sheet-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 30;
  display: flex; align-items: flex-end;
}
.sheet-overlay.hidden { display: none; }
.sheet {
  background: var(--card); width: 100%; max-height: 88vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet-handle { width: 40px; height: 4px; background: var(--border); border-radius: 4px; margin: 8px auto 14px; }
.sheet-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.sheet-tab { flex: 1; padding: 10px; border: 1px solid var(--border); background: var(--bg); border-radius: 10px; font-size: 0.9em; }
.sheet-tab.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.tab-panel.hidden { display: none; }

textarea, input[type=text], input[type=number], input[type=email], input[type=password], select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 1em; margin-top: 4px; font-family: inherit; background: #fff; color: var(--text);
}
label { display: block; margin: 10px 0; font-size: 0.9em; color: var(--text); }
.form-row { display: flex; gap: 10px; }
.form-row label { flex: 1; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; margin: 0; }

#photoPreview { width: 100%; border-radius: 12px; margin-top: 10px; }
#photoPreview.hidden { display: none; }

/* ---- Buttons ---- */
.btn { width: 100%; padding: 13px; border-radius: 12px; font-size: 1em; font-weight: 600; border: none; margin-top: 10px; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-outline { background: #fff; color: var(--teal-dark); border: 1.5px solid var(--teal); }
.btn-text { background: none; color: var(--muted); font-weight: 400; text-decoration: underline; }
.btn:disabled { opacity: 0.5; }

/* ---- Auth screens ---- */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 360px; }
.brand { color: var(--teal-dark); text-align: center; margin-bottom: 4px; }
.auth-card > p.muted { text-align: center; margin-top: 0; }
