/* Carular — mobile-first styles.
   Layout rule: the app is a full-height column (header / scrolling main / fixed
   tab bar) so only `main` ever scrolls, which keeps the tab bar put on iOS. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --line: #dfe4ea;
  --text: #151a20;
  --muted: #667080;
  --primary: #17976a;
  --primary-soft: #d8f0e5;
  --danger: #d5443c;
  --warn: #c67d10;
  --kcal: #17976a;
  --protein: #2f6fed;
  --carbs: #d98a12;
  --fat: #a259d6;
  --fiber: #14967f;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
  --tap: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 62px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171c22;
    --surface-2: #1f252d;
    --line: #2a323c;
    --text: #e8edf3;
    --muted: #94a1b2;
    --primary: #34c48c;
    --primary-soft: #14312a;
    --danger: #ef6b62;
    --warn: #e0a23c;
    --kcal: #34c48c;
    --protein: #6a9bff;
    --carbs: #e8ab4a;
    --fat: #c08cf0;
    --fiber: #3fc0aa;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* Class selectors below would otherwise out-rank the browser default for
   [hidden], leaving "hidden" fields visible. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: calc(var(--safe-top) + 56px);
}

.topbar h1 { font-size: 19px; margin: 0; font-weight: 650; letter-spacing: -0.01em; flex: 1; }
.topbar .sub { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 17px;
  flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.ghost { border-color: transparent; background: transparent; }

/* ---------- main scroll area ---------- */
main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(var(--nav-h) + var(--safe-bottom) + 24px);
}

.stack { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-pad { padding: 14px; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 4px 2px;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- day header ---------- */
.daybar { display: flex; align-items: center; gap: 8px; }
.daybar .day-label { flex: 1; text-align: center; font-weight: 600; }

/* ---------- calorie summary ---------- */
.summary { display: flex; gap: 16px; align-items: center; padding: 16px 14px; }
.ring { flex: none; width: 116px; height: 116px; position: relative; }
.ring svg { transform: rotate(-90deg); display: block; }
.ring-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  line-height: 1.15;
}
.ring-center .big { font-size: 25px; font-weight: 700; letter-spacing: -0.02em; }
.ring-center .cap { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.macros { flex: 1; display: flex; flex-direction: column; gap: 11px; min-width: 0; }
.macro-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.macro-label b { font-weight: 600; }
.bar { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.over { color: var(--danger); }

.nutrient-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
}
.nutrient-grid div {
  padding: 10px 6px;
  text-align: center;
  border-right: 1px solid var(--line);
}
.nutrient-grid div:last-child { border-right: 0; }
.nutrient-grid b { display: block; font-size: 15px; font-weight: 650; }
.nutrient-grid span { font-size: 11px; color: var(--muted); }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 11px 14px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  color: inherit;
}
.list-item:last-child { border-bottom: 0; }
.list-item:active { background: var(--surface-2); }
.list-item .title { font-weight: 550; }
.list-item .meta { font-size: 12.5px; color: var(--muted); }
.list-item .amount { text-align: right; flex: none; }
.list-item .amount b { display: block; font-weight: 650; }

/* Foods list: name, category and nutrition stack on their own lines. The row
   itself already centres its children, so the calories sit halfway up the stack. */
.list.stacked .list-item { gap: 14px; }
.list.stacked .list-item .grow { display: flex; flex-direction: column; gap: 2px; }
.list.stacked .list-item .title { display: block; }
.list.stacked .list-item .meta { display: block; line-height: 1.35; }

.slot-card .slot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.slot-head .add {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 22px;
  line-height: 1;
  width: 34px;
  height: 34px;
  border-radius: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  min-height: 38px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
  white-space: nowrap;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.tabs button {
  flex: 1;
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: 14px;
  font-weight: 550;
  color: var(--muted);
}
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

input[type="text"], input[type="password"], input[type="number"], input[type="search"],
input[type="date"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  /* 16px keeps iOS Safari from zooming the page when a field takes focus. */
  font-size: 16px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 60%, transparent);
  outline-offset: 1px;
}
textarea { min-height: 78px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 15px;
  font-weight: 600;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); background: transparent; }
.btn[disabled] { opacity: 0.55; pointer-events: none; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.error-text { color: var(--danger); font-size: 14px; margin: 8px 0 0; }

/* ---------- bottom sheet ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8, 12, 18, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.16s ease;
}
.sheet {
  width: 100%;
  max-width: 720px;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding-bottom: var(--safe-bottom);
  animation: slide-up 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 650; flex: 1; }
.sheet-body { padding: 14px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot {
  padding: 12px 14px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  gap: 10px;
}
.grabber { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; }

@keyframes slide-up { from { transform: translateY(18px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- bottom nav ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1;
  min-height: var(--nav-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 550;
}
.tabbar a .ico { font-size: 21px; line-height: 1; }
.tabbar a.active { color: var(--primary); }

/* ---------- misc ---------- */
.toast-root {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: max-content;
  max-width: 92vw;
}
.toast {
  padding: 11px 16px;
  border-radius: 999px;
  background: #12171e;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: fade 0.15s ease;
}
.toast.error { background: var(--danger); }

.trend { display: flex; align-items: flex-end; gap: 4px; height: 132px; padding: 12px 8px 0; }
.trend .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; height: 100%; }
.trend .stem { width: 100%; max-width: 22px; border-radius: 5px 5px 2px 2px; background: var(--primary); min-height: 3px; }
.trend .stem.over { background: var(--warn); }
.trend .stem.empty { background: var(--surface-2); }
.trend .lab { font-size: 10px; color: var(--muted); }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  font-weight: 650;
}

.auth-wrap { padding: 32px 20px calc(40px + var(--safe-bottom)); max-width: 420px; margin: 0 auto; }
.brand { text-align: center; margin-bottom: 26px; }
.brand .logo { font-size: 44px; }
.brand h1 { margin: 8px 0 2px; font-size: 25px; letter-spacing: -0.02em; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
