/* ---------- Design tokens (from Food Tracking Concepts, direction 2a/2b) ---------- */
:root {
  --bg: oklch(98% 0.003 90);
  --surface: #fff;
  --surface-2: oklch(94% 0.01 90);
  --track: oklch(93% 0.01 90);
  --border: oklch(92% 0.01 90);
  --divider: oklch(93% 0.01 90);
  --text: oklch(20% 0.01 90);
  --text-2: oklch(50% 0.01 90);
  --text-3: oklch(55% 0.01 90);
  --accent: oklch(55% 0.12 200);
  --accent-contrast: #fff;
  --accent-soft: oklch(94% 0.02 200);
  --accent-soft-text: oklch(35% 0.1 200);
  --tabbar-bg: #fff;
  --tabbar-border: oklch(92% 0.01 90);
  --tab-idle-icon: oklch(75% 0.01 90);
  --tab-idle-text: oklch(65% 0.01 90);
  --tile-icon: oklch(30% 0.01 90);
  --tile-label: oklch(30% 0.01 90);
  --hatch-a: oklch(93% 0.01 90);
  --hatch-b: oklch(96% 0.005 90);
  --search-border: transparent;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.18);
}

[data-theme="dark"] {
  --bg: oklch(15% 0.006 264);
  --surface: oklch(19% 0.008 264);
  --surface-2: oklch(22% 0.008 264);
  --track: oklch(26% 0.01 264);
  --border: oklch(27% 0.01 264);
  --divider: oklch(27% 0.01 264);
  --text: oklch(94% 0.005 90);
  --text-2: oklch(60% 0.01 264);
  --text-3: oklch(60% 0.01 264);
  --accent: oklch(70% 0.13 200);
  --accent-contrast: oklch(14% 0.006 264);
  --accent-soft: oklch(26% 0.03 200);
  --accent-soft-text: oklch(78% 0.1 200);
  --tabbar-bg: oklch(17% 0.007 264);
  --tabbar-border: oklch(24% 0.01 264);
  --tab-idle-icon: oklch(42% 0.01 264);
  --tab-idle-text: oklch(52% 0.01 264);
  --tile-icon: oklch(70% 0.13 200);
  --tile-label: oklch(94% 0.005 90);
  --hatch-a: oklch(26% 0.01 264);
  --hatch-b: oklch(22% 0.008 264);
  --search-border: oklch(28% 0.01 264);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Manrope', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: var(--text); }

.phone {
  position: relative;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* Mid-size windows: present the app in a phone-sized frame */
@media (min-width: 480px) and (max-width: 899px) and (min-height: 600px) {
  body { display: flex; align-items: center; justify-content: center; padding: 24px; }
  .phone {
    width: 402px;
    height: min(874px, calc(100dvh - 48px));
    border-radius: 28px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
  }
}

.brand { display: none; }

.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; overflow-y: auto; padding: max(env(safe-area-inset-top), 28px) 20px 12px; }

/* ---------- Home header ---------- */
.home-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.date { font-size: 13px; color: var(--text-2); }
.daynav { display: flex; align-items: center; gap: 6px; }
.daynav-btn {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-2); color: var(--text-2);
  font-size: 13px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.daynav-btn:disabled { opacity: 0.35; cursor: default; }
.daynav-date { font-size: 13px; color: var(--text-2); font-weight: 600; padding: 0 2px; }
.daynav-date.off-today { color: var(--accent); }
.greeting { margin: 0; font-size: 22px; font-weight: 700; color: var(--text); }
.header-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1;
}
.streak-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--accent-soft); padding: 8px 12px; border-radius: 100px;
}
.streak-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.streak-pill span:last-child { font-size: 13px; font-weight: 700; color: var(--accent-soft-text); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; }

.summary-card { border-radius: 20px; padding: 20px; margin-bottom: 16px; }
.summary-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.kcal-big { font-size: 34px; font-weight: 800; color: var(--text); }
.kcal-goal { font-size: 13px; color: var(--text-2); }
.progress { height: 8px; border-radius: 100px; background: var(--track); overflow: hidden; margin-bottom: 14px; }
.progress-fill { height: 100%; width: 0; border-radius: 100px; background: var(--accent); transition: width 0.4s ease; }
.macros { display: flex; gap: 10px; }
.macro { flex: 1; text-align: center; }
.macro-mid { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.macro-v { font-size: 15px; font-weight: 700; color: var(--text); }
.macro-l { font-size: 11px; color: var(--text-3); }

/* ---------- Section heading ---------- */
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.section-label {
  font-size: 13px; font-weight: 700; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.add-btn { font-size: 13px; font-weight: 700; color: var(--accent); padding: 2px 4px; }

/* ---------- Lists ---------- */
.list { overflow: hidden; margin-bottom: 16px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; }
.row + .row { border-top: 1px solid var(--divider); }
.thumb {
  flex: none; width: 40px; height: 40px; border-radius: 10px;
  background: repeating-linear-gradient(45deg, var(--hatch-a), var(--hatch-a) 4px, var(--hatch-b) 4px, var(--hatch-b) 8px);
}
.row-body { flex: 1; min-width: 0; }
.row-name { font-size: 14px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { font-size: 12px; color: var(--text-3); }
.row-kcal { font-size: 14px; font-weight: 700; color: var(--text); }
.row-remove {
  font-size: 12px; font-weight: 700; color: #fff;
  background: oklch(58% 0.19 25); border-radius: 100px; padding: 6px 12px;
}
.empty-row { padding: 18px 14px; font-size: 13px; color: var(--text-3); text-align: center; }

/* ---------- Tab bar ---------- */
.tabbar {
  display: flex; justify-content: space-around; align-items: center;
  padding: 10px 0 max(env(safe-area-inset-bottom), 20px);
  border-top: 1px solid var(--tabbar-border); background: var(--tabbar-bg);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tab-label { font-size: 10px; color: var(--tab-idle-text); }
.tab.active .tab-label { font-weight: 700; color: var(--accent); }
.tab-icon { display: block; }
.tab-icon-food { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--tab-idle-icon); }
.tab.active .tab-icon-food { border: 0; background: var(--accent); }
.tab-icon-workouts { width: 20px; height: 20px; border-radius: 5px; border: 2px solid var(--tab-idle-icon); }
.tab.active .tab-icon-workouts { border: 0; background: var(--accent); }
.tab-icon-shopping { width: 16px; height: 16px; border: 2px solid var(--tab-idle-icon); transform: rotate(45deg); margin: 2px; }
.tab.active .tab-icon-shopping { background: var(--accent); border-color: var(--accent); }
.tab-icon-more { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--tab-idle-icon); }

/* ---------- Log Food sheet ---------- */
.sheet {
  position: absolute; inset: 0; z-index: 10;
  background: var(--bg);
  display: flex; flex-direction: column;
  transform: translateY(100%);
  visibility: hidden;
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0.32s;
}
.sheet.open { transform: translateY(0); visibility: visible; transition-delay: 0s; }
.sheet .scroll { padding-bottom: 28px; }

.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.close-btn { width: 28px; height: 28px; font-size: 14px; color: var(--text-2); }
.sheet-title { font-size: 16px; font-weight: 700; color: var(--text); }
.sheet-spacer { width: 28px; }

.chips { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip { padding: 7px 14px; border-radius: 100px; background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 600; }
.chip.active { background: var(--accent); color: var(--accent-contrast); font-weight: 700; }

.search {
  width: 100%; background: var(--surface-2); border: 1px solid var(--search-border);
  border-radius: 12px; padding: 11px 14px; font-size: 14px; margin-bottom: 14px;
  outline: none; appearance: none;
}
.search::placeholder { color: var(--text-3); }
.search:focus { border-color: var(--accent); }

.log-actions { display: flex; gap: 10px; margin-bottom: 18px; }
.action-tile {
  flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.tile-label { font-size: 11px; font-weight: 600; color: var(--tile-label); }
.tile-icon-barcode {
  width: 22px; height: 16px; border-radius: 3px;
  background: repeating-linear-gradient(90deg, var(--tile-icon), var(--tile-icon) 2px, transparent 2px, transparent 4px);
}
.tile-icon-photo { width: 20px; height: 20px; border-radius: 5px; border: 2px solid var(--tile-icon); position: relative; }
.tile-icon-photo::after {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  border: 2px solid var(--tile-icon); position: absolute; top: 3px; left: 3px;
}
.tile-icon-manual { font-size: 18px; font-weight: 700; color: var(--tile-icon); line-height: 1; height: 20px; display: flex; align-items: center; }

.manual-form { padding: 14px; margin-bottom: 18px; display: flex; flex-direction: column; gap: 10px; }
.manual-form input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--search-border);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; outline: none;
}
.manual-form input:focus { border-color: var(--accent); }
.manual-row { display: flex; gap: 8px; }
.manual-row input { min-width: 0; }
.manual-submit {
  background: var(--accent); color: var(--accent-contrast);
  border-radius: 100px; padding: 10px; font-size: 13px; font-weight: 700;
}

.picker-label { font-size: 12px; margin-bottom: 8px; }
.food-row .thumb { width: 36px; height: 36px; border-radius: 9px; }
.food-row .row-name { font-size: 13px; }
.food-row .row-meta { font-size: 11px; }
.food-add {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: var(--accent-contrast);
  display: flex; align-items: center; justify-content: center; font-size: 14px; line-height: 1;
}

/* ---------- Calendar overview ---------- */
.section-actions { display: flex; gap: 14px; }
.cal-icon {
  width: 13px; height: 12px;
  border: 2px solid var(--text-2); border-radius: 3px;
  position: relative;
}
.cal-icon::before {
  content: ""; position: absolute; left: 1px; right: 1px; top: 1px;
  height: 2px; background: var(--text-2); border-radius: 1px;
}
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-title { font-size: 14px; font-weight: 700; color: var(--text); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow-row { margin-bottom: 4px; }
.cal-dow-cell { text-align: center; font-size: 10px; font-weight: 700; color: var(--text-3); text-transform: uppercase; }
.cal-day {
  aspect-ratio: 1; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 13px; color: var(--text);
}
.cal-day.empty { background: none; border: 0; }
.cal-day:disabled { opacity: 0.35; cursor: default; }
.cal-day.today { border-color: var(--accent); }
.cal-day.selected { background: var(--accent-soft); }
.cal-day.selected .cal-num { color: var(--accent-soft-text); font-weight: 700; }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); opacity: 0; }
.cal-dot.on { opacity: 1; }
.cal-hint { margin: 14px 2px 0; font-size: 12px; color: var(--text-3); }
.row-copy {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-soft-text);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1;
}
#log-list .row { cursor: pointer; }

/* ---------- Workouts ---------- */
#plan-list .row, #plan-ex-list .row { cursor: pointer; }
.plan-start {
  flex: none; font-size: 12px; font-weight: 700;
  color: var(--accent-contrast); background: var(--accent);
  border-radius: 100px; padding: 7px 14px;
}
.sheet-action { font-size: 14px; font-weight: 700; color: var(--accent); min-width: 28px; text-align: right; }
.ex-remove {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface-2); color: var(--text-2);
  display: flex; align-items: center; justify-content: center; font-size: 13px; line-height: 1;
}

.session-timer {
  font-size: 13px; font-weight: 700; color: var(--text-2);
  font-variant-numeric: tabular-nums; min-width: 28px; text-align: right;
}
.session-ex { padding: 12px 14px; margin-bottom: 12px; }
.session-ex-name { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.set-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.set-num {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface-2); color: var(--text-2);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.set-row.done .set-num { background: var(--accent-soft); color: var(--accent-soft-text); }
.set-field { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; }
.set-field input {
  width: 100%; min-width: 0; background: var(--surface-2);
  border: 1px solid var(--search-border); border-radius: 8px;
  padding: 7px 6px; font-size: 13px; text-align: center; outline: none;
  appearance: textfield;
}
.set-field input:focus { border-color: var(--accent); }
.set-unit { flex: none; font-size: 11px; color: var(--text-3); }
.set-done {
  flex: none; width: 30px; height: 30px; border-radius: 9px;
  background: var(--surface-2); color: var(--text-3);
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.set-done.on { background: var(--accent); color: var(--accent-contrast); }
.add-set { margin-top: 6px; font-size: 12px; font-weight: 700; color: var(--accent); padding: 4px 0; }
.finish-btn { display: block; width: 100%; margin-bottom: 24px; }

.ex-type-chips { margin-bottom: 0; }
.ex-type-chips .chip { padding: 6px 12px; }

.rest-bar {
  position: absolute; left: 20px; right: 20px;
  bottom: max(env(safe-area-inset-bottom), 20px); z-index: 5;
  display: flex; align-items: center; gap: 10px;
  background: var(--accent); color: var(--accent-contrast);
  border-radius: 100px; padding: 10px 12px 10px 18px;
  box-shadow: var(--shadow);
}
.rest-label { font-size: 13px; font-weight: 600; }
.rest-remaining { flex: 1; font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rest-skip {
  flex: none; background: var(--accent-contrast); color: var(--accent);
  border-radius: 100px; padding: 7px 14px; font-size: 12px; font-weight: 700;
}

/* ---------- Shopping ---------- */
#shopping-list .row, #shopping-done .row { cursor: pointer; }
.shop-form { display: flex; gap: 8px; padding: 10px; margin-bottom: 16px; }
.shop-form input {
  background: var(--surface-2); border: 1px solid var(--search-border);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; outline: none; min-width: 0;
}
.shop-form input:focus { border-color: var(--accent); }
#shop-name { flex: 1; }
#shop-qty { flex: none; width: 76px; }
.shop-add {
  flex: none; background: var(--accent); color: var(--accent-contrast);
  border-radius: 10px; padding: 0 16px; font-size: 13px; font-weight: 700;
}
.check {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--tab-idle-icon);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; line-height: 1; color: transparent;
}
.row.done .check { border-color: var(--accent); background: var(--accent); color: var(--accent-contrast); }
.row.done .row-name { text-decoration: line-through; color: var(--text-3); font-weight: 500; }

/* ---------- Account sheet ---------- */
.account-card { padding: 4px 14px; margin-bottom: 16px; }
.account-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 12px 0; font-size: 13px; color: var(--text); }
.account-line + .account-line { border-top: 1px solid var(--divider); }
.account-label { color: var(--text-3); flex: none; }
.goal-input {
  width: 90px; text-align: right;
  background: var(--surface-2); border: 1px solid var(--search-border);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; outline: none;
}
.goal-input:focus { border-color: var(--accent); }
.danger-btn {
  width: 100%; text-align: center; padding: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  font-size: 13px; font-weight: 700; color: oklch(58% 0.19 25);
}

/* ---------- Auth screen ---------- */
.auth {
  position: absolute; inset: 0; z-index: 30;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-inner { width: 100%; max-width: 320px; display: flex; flex-direction: column; align-items: center; }
.auth-logo { width: 56px; height: 56px; border-radius: 50%; background: var(--accent); margin-bottom: 16px; }
.auth-title { margin: 0 0 4px; font-size: 24px; font-weight: 800; color: var(--text); }
.auth-sub { margin: 0 0 24px; font-size: 13px; color: var(--text-2); }
.auth-form { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--search-border);
  border-radius: 12px; padding: 12px 14px; font-size: 14px; outline: none;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-error { min-height: 16px; font-size: 12px; font-weight: 600; color: oklch(58% 0.19 25); }
.auth-submit {
  background: var(--accent); color: var(--accent-contrast);
  border-radius: 100px; padding: 12px; font-size: 14px; font-weight: 700;
}
.auth-submit:disabled { opacity: 0.6; }
.auth-switch { margin-top: 18px; font-size: 13px; font-weight: 600; color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%);
  z-index: 20; background: var(--text); color: var(--bg);
  font-size: 13px; font-weight: 600; padding: 10px 16px; border-radius: 100px;
  white-space: nowrap; max-width: calc(100% - 40px); overflow: hidden; text-overflow: ellipsis;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Desktop layout (wide windows) ---------- */
/* The bottom tab bar becomes a left sidebar, content spreads into columns,
   and the full-screen sheets become centered modal dialogs. */
@media (min-width: 900px) {
  .phone { flex-direction: row; }

  /* Navigation rail */
  .tabbar {
    order: -1;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 4px;
    width: 236px;
    padding: 28px 16px;
    border-top: 0;
    border-right: 1px solid var(--tabbar-border);
  }
  .brand {
    display: flex; align-items: center; gap: 10px;
    padding: 2px 14px 22px;
    font-size: 16px; font-weight: 800; color: var(--text);
  }
  .brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
  .tab {
    flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 11px 14px; border-radius: 10px;
  }
  .tab-label { font-size: 14px; }
  .tab.active { background: var(--accent-soft); }
  .tab.active .tab-label { color: var(--accent-soft-text); }

  /* Content area: centered, capped, multi-column */
  .screen .scroll {
    width: 100%; max-width: 1240px; margin: 0 auto;
    padding: 40px 48px 32px;
  }
  .greeting { font-size: 26px; }
  .cols { display: grid; gap: 28px; align-items: start; }
  #screen-home .cols { grid-template-columns: minmax(340px, 400px) minmax(0, 1fr); }
  #screen-workouts .cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  #screen-shopping .cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .summary-card { padding: 24px; }
  .kcal-big { font-size: 42px; }
  .row { padding: 13px 16px; }

  /* Sheets become centered modals over a dimmed backdrop */
  .sheet {
    background: rgba(0, 0, 0, 0.45);
    align-items: center; justify-content: center;
    transform: none; opacity: 0;
    transition: opacity 0.18s ease, visibility 0s linear 0.18s;
  }
  .sheet.open { transform: none; opacity: 1; }
  .sheet .scroll, .sheet.open .scroll {
    flex: none; width: 480px; max-width: calc(100vw - 80px);
    max-height: min(760px, calc(100dvh - 80px));
    margin: 0; padding: 24px 24px 28px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 20px; box-shadow: var(--shadow);
  }
  .rest-bar { left: 50%; right: auto; transform: translateX(-50%); width: 432px; top: 36px; bottom: auto; }
  .toast { bottom: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet, .progress-fill { transition: none; }
  .toast { animation: none; }
}
