/* FitCoach AI iOS Edition — Zero-Dependency Editorial Design System
 * Exact 1:1 visual & typographic parity with Android v2.8.1 (Warm Porcelain & Matte Obsidian)
 */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", "Helvetica Neue", sans-serif;

  --bg: #F4F3EF;
  --card: #FFFFFF;
  --soft: #F0EFEA;
  --bubble-ai: #F6F5F1;
  --hairline: rgba(17, 19, 21, 0.08);
  --ink: #121417;
  --ink-sec: #68707C;
  --ink-mut: #9AA2AE;
  --accent: #1B7F5C;
  --accent-light: #39A87E;
  --accent-soft: rgba(27, 127, 92, 0.11);
  --warm: #D4743B;
  --warm-soft: rgba(212, 116, 59, 0.12);
  --water: #2B7CB3;
  --water-soft: rgba(43, 124, 179, 0.12);
  --track: #ECEAE3;
  --cta-bg: #141619;
  --cta-fg: #FFFFFF;
  --glass: rgba(255, 255, 255, 0.92);
  --alert: #D9534F;
  --alert-soft: rgba(217, 83, 79, 0.12);
  --shadow-card: 0 2px 10px rgba(17, 19, 21, 0.035);
  --shadow-pill: 0 10px 26px rgba(17, 19, 21, 0.10);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body.theme-dark {
  --bg: #0D0E10;
  --card: #16181C;
  --soft: #1F2229;
  --bubble-ai: #1C1F26;
  --hairline: rgba(255, 255, 255, 0.09);
  --ink: #F3F4F6;
  --ink-sec: #8E95A0;
  --ink-mut: #5E6570;
  --accent: #45B88E;
  --accent-light: #67CFA8;
  --accent-soft: rgba(69, 184, 142, 0.16);
  --warm: #E28E56;
  --warm-soft: rgba(226, 142, 86, 0.16);
  --water: #63B3ED;
  --water-soft: rgba(99, 179, 237, 0.16);
  --track: #242830;
  --cta-bg: #F3F4F6;
  --cta-fg: #0D0E10;
  --glass: rgba(22, 24, 28, 0.92);
  --alert: #E57373;
  --alert-soft: rgba(229, 115, 115, 0.16);
  --shadow-card: none;
  --shadow-pill: 0 8px 24px rgba(0, 0, 0, 0.45);
}

*, *::before, *::after {
  box-sizing: border-box;
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

button {
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
}

.sr-only {
  position: fixed;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.hidden { display: none !important; }

/* Splash Cover */
.splash-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: #060B0C;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
.splash-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.splash-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  max-width: 480px;
}

/* Shell */
.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.screen-host {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}

.page-scroll {
  flex: 1;
  padding: 16px 20px calc(112px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page-scroll.no-nav {
  padding-bottom: calc(96px + var(--safe-bottom));
}

/* Unified Typography */
.t-num {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.t-page {
  font-size: 27px;
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.025em;
  color: var(--ink);
}
.t-hero {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.t-stat {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.t-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink);
}
.t-item {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink);
}
.t-body {
  font-size: 13.5px;
  font-weight: 400;
  line-height: 1.62;
  color: var(--ink);
}
.t-cap {
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--ink-sec);
}
.t-sub {
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  color: var(--ink-sec);
}
.t-micro {
  font-size: 11px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--ink-mut);
  font-variant-numeric: tabular-nums;
}

/* Cards & Surfaces */
.card {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 22px;
  box-shadow: var(--shadow-card);
}
.card-accent {
  border-color: rgba(27, 127, 92, 0.28);
}
.card-warm {
  border-color: rgba(212, 116, 59, 0.36);
}
.soft-box {
  background: var(--soft);
  border-radius: 14px;
}
.divider {
  height: 1px;
  background: var(--hairline);
  width: 100%;
}

/* Layout Helpers */
.row { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-end { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.row-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.col { display: flex; flex-direction: column; }
.flex-1 { flex: 1; min-width: 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid-7 { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.gap-4 { gap: 4px; }
.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-10 { gap: 10px; }
.gap-12 { gap: 12px; }
.gap-14 { gap: 14px; }
.gap-16 { gap: 16px; }
.p-14 { padding: 14px; }
.p-16 { padding: 16px; }
.p-18 { padding: 18px; }
.px-18-py-14 { padding: 14px 18px; }
.px-18-py-16 { padding: 16px 18px; }
.mt-2 { margin-top: 2px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Colors */
.c-ink { color: var(--ink); }
.c-sec { color: var(--ink-sec); }
.c-mut { color: var(--ink-mut); }
.c-acc { color: var(--accent); }
.c-warm { color: var(--warm); }
.c-water { color: var(--water); }
.c-alert { color: var(--alert); }

/* Badges & Buttons */
.icon-circle-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-card);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  flex-shrink: 0;
}
.icon-circle-btn:active { transform: scale(0.94); }

.pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.pill-badge.acc { background: var(--accent-soft); color: var(--accent); }
.pill-badge.warm { background: var(--warm-soft); color: var(--warm); }
.pill-badge.soft { background: var(--soft); color: var(--ink-sec); }

.btn-cta {
  width: 100%;
  height: 48px;
  border-radius: 999px;
  background: var(--cta-bg);
  color: var(--cta-fg);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.12s ease, opacity 0.15s ease;
}
.btn-cta:active { transform: scale(0.98); }
.btn-cta:disabled { opacity: 0.42; pointer-events: none; }

.btn-soft {
  padding: 8px 13px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}
.btn-soft.acc { background: var(--accent-soft); color: var(--accent); }
.btn-soft.cta { background: var(--cta-bg); color: var(--cta-fg); }
.btn-soft:active { transform: scale(0.96); }

/* Progress Bars */
.bar-track {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* Stepper */
.stepper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px;
  border-radius: 999px;
  background: var(--soft);
}
.step-btn {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.step-btn:active { transform: scale(0.9); }
.step-btn:disabled { opacity: 0.3; pointer-events: none; }
.step-btn.minus { background: var(--card); color: var(--ink); border: 1px solid var(--hairline); }
.step-btn.plus-acc { background: var(--accent); color: #fff; }
.step-btn.plus-cta { background: var(--cta-bg); color: var(--cta-fg); }
.step-btn.plus-water { background: var(--water); color: #fff; }
.step-val {
  min-width: 48px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Floating Bottom Pill Nav */
.pill-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(14px + var(--safe-bottom));
  width: calc(100% - 40px);
  max-width: 436px;
  background: var(--glass);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  box-shadow: var(--shadow-pill);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px;
  z-index: 60;
}
.pill-nav-item {
  border-radius: 999px;
  padding: 7px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--ink-mut);
  font-size: 11px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}
.pill-nav-item svg { width: 20px; height: 20px; }
.pill-nav-item.active {
  background: var(--soft);
  color: var(--ink);
  font-weight: 600;
}

/* Coach Full-Height Chat Layout */
.coach-shell {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--safe-top));
  padding-bottom: calc(84px + var(--safe-bottom));
}
.coach-header {
  padding: 14px 20px 10px;
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}
.chips-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 20px 6px;
  scrollbar-width: none;
  flex-shrink: 0;
}
.chips-row::-webkit-scrollbar { display: none; }
.chip-pill {
  flex-shrink: 0;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--hairline);
  font-size: 12px;
  color: var(--ink-sec);
  white-space: nowrap;
}
.chip-pill.active {
  background: var(--cta-bg);
  color: var(--cta-fg);
  border-color: var(--cta-bg);
}
.chat-stream {
  flex: 1;
  overflow-y: auto;
  padding: 10px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}
.bubble-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bubble-wrap.user { align-items: flex-end; }
.bubble-wrap.ai { align-items: flex-start; }

.bubble {
  max-width: 86%;
  padding: 11px 15px;
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.user {
  background: var(--cta-bg);
  color: var(--cta-fg);
  border-radius: 20px 20px 6px 20px;
}
.bubble.ai {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: 20px 20px 20px 6px;
}
.bubble.ai-soft {
  background: var(--bubble-ai);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: 18px 18px 18px 5px;
  max-width: 96%;
}
.bubble-photo {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 8px;
  display: block;
}

.composer-wrap {
  padding: 6px 16px 8px;
  flex-shrink: 0;
}
.composer-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-card);
}
.composer-icon {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.composer-send {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--cta-bg);
  color: var(--cta-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.composer-send:disabled {
  background: var(--soft);
  color: var(--ink-mut);
}
.composer-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  padding: 6px 4px;
}
.composer-input::placeholder { color: var(--ink-mut); }

/* Weekday Strip */
.day-pill {
  padding: 9px 2px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--ink);
}
.day-pill.today { border: 1.5px solid var(--accent); }
.day-pill.selected { background: var(--cta-bg); border-color: var(--cta-bg); color: var(--cta-fg); }
.day-dot { width: 5px; height: 5px; border-radius: 999px; }

/* Fields & Inputs */
.field-box {
  background: var(--soft);
  border-radius: 15px;
  padding: 10px 13px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.field-input {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  font-size: 15.5px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.field-input::placeholder { color: var(--ink-mut); font-weight: 400; }

/* Food Atlas */
.food-row {
  padding: 11px 13px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.food-thumb {
  width: 50px;
  height: 50px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--soft);
  flex-shrink: 0;
}

/* Segmented Control */
.seg-ctrl {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--soft);
}
.seg-btn {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-sec);
}
.seg-btn.active {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(0, 0, 0, 0.44);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-sheet {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 26px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 85dvh;
  overflow-y: auto;
}

/* Toast */
.toast-pill {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translate(-50%, 10px);
  max-width: calc(100% - 40px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--cta-bg);
  color: var(--cta-fg);
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  transition: opacity 0.2s ease, transform 0.2s ease;
  text-align: center;
}
.toast-pill.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Thinking Dots */
.dots { display: inline-flex; align-items: center; gap: 4px; }
.dots i {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  display: inline-block;
  animation: pulseDot 1.2s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulseDot {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.15); }
}

/* Range Sliders */
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

/* iOS Add-to-Home-Screen Subtle Tip Banner (only shown in mobile Safari browser, hidden once installed standalone!) */
.ios-install-bar {
  margin: 0 20px;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Daily Calorie History Ledger Table (Trends Tab) */
.ledger-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--soft);
  text-align: center;
}
.ledger-stat-val {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.ledger-head {
  display: grid;
  grid-template-columns: 1.25fr 0.85fr 0.8fr 1.15fr;
  align-items: center;
  padding: 4px 2px 6px;
  border-bottom: 1px solid var(--hairline);
}
.ledger-head span:nth-child(n+2) { text-align: right; }
.ledger-row-wrap {
  border-bottom: 1px solid var(--hairline);
}
.ledger-row-wrap:last-child { border-bottom: none; }
.ledger-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1.25fr 0.85fr 0.8fr 1.15fr;
  align-items: center;
  padding: 11px 2px;
  text-align: left;
  transition: opacity 0.12s ease;
}
.ledger-row:active { opacity: 0.65; }
.ledger-cell-num {
  text-align: right;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ledger-today-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  vertical-align: middle;
}
.ledger-detail {
  margin: 0 0 10px;
  padding: 12px;
  border-radius: 14px;
  background: var(--soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ledger-detail-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-sec);
}
.ledger-detail-item b {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
