/* ==========================================================================
   FitTrack — Design system & base layout
   Dark-first, mobile-first (390px baseline), no external CSS deps
   ========================================================================== */

:root {
  /* Palette */
  --bg: #0f0f0f;
  --bg-elevated: #1a1a1a;
  --bg-card: #171717;
  --border: #2a2a2a;
  --text: #f4f4f5;
  --text-dim: #a1a1aa;
  --text-faint: #6b6b70;

  --accent: #3b82f6;
  --accent-dim: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;

  --protein: #3b82f6;
  --carbs: #f59e0b;
  --fat: #ec4899;
  --sugar: #a855f7;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 999px;

  --nav-height: 64px;
  --header-height: 56px;
  --app-max-width: 560px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Landscape phones are short but wide — the portrait-tuned 560px column would otherwise
   leave big unused black bars on either side (most noticeable on the Form Check camera). */
@media (orientation: landscape) {
  :root {
    --app-max-width: min(96vw, 900px);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  background: var(--bg);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: var(--app-max-width);
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

input, select, textarea {
  font-family: inherit;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  font-size: 16px;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

a { color: var(--accent); text-decoration: none; }

h1, h2, h3 { font-weight: 600; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }

::-webkit-scrollbar { display: none; }

/* ---- Top header ---- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  /* Installed on iOS the app draws under the status bar (black-translucent in index.html),
     so the header grows by the notch/status-bar height and keeps its content below it. */
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 0px) var(--space-4) 0;
  background: rgba(15,15,15,0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

/* ---- Pages / routing ---- */
.page {
  display: none;
  padding: var(--space-4);
  padding-bottom: var(--space-6);
  animation: page-in 220ms ease;
}

.page.active {
  display: block;
}

@keyframes page-in {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ---- Bottom navigation ---- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-max-width);
  height: var(--nav-height);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text-faint);
  transition: color 150ms ease, transform 150ms ease;
}

.nav-btn .nav-icon {
  display: flex;
  line-height: 1;
  transition: transform 150ms ease;
}

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

.nav-btn.active .nav-icon {
  transform: translateY(-2px);
}

.nav-btn .nav-indicator {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: transparent;
  margin-top: 1px;
}

.nav-btn.active .nav-indicator {
  background: var(--accent);
}

/* ---- Cards ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.card-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: var(--space-3);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-block { width: 100%; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
}

.btn-danger-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
}

.btn-sm { padding: 8px 12px; font-size: 13px; }

.btn:active { transform: scale(0.97); }

/* ---- Form fields ---- */
.field {
  margin-bottom: var(--space-3);
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: var(--space-1);
}

.field-row {
  display: flex;
  gap: var(--space-2);
}
.field-row > .field { flex: 1; }

/* ---- Chips / toggle group ---- */
.chip-group {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.chip {
  padding: 8px 14px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-dim);
}

.chip.active {
  background: rgba(59,130,246,0.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
}
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-muted { background: var(--bg-elevated); color: var(--text-faint); }

/* ---- Empty states ---- */
.empty-state {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  color: var(--text-faint);
}
.empty-state .empty-icon {
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-2);
  color: var(--text-faint);
  opacity: 0.8;
}
.empty-state p { font-size: 14px; }

/* ---- Icons: page headers, icon-only buttons, icon+label buttons ---- */
.page-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.header-icon {
  display: inline-flex;
  color: var(--accent);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

.icon-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ---- Star rating ---- */
.star-rating {
  display: flex;
  gap: var(--space-2);
}

.star-btn {
  color: var(--text-faint);
  transition: color 150ms ease, transform 150ms ease;
}

.star-btn:active {
  transform: scale(0.9);
}

.star-btn.filled {
  color: var(--warning);
}

.star-btn svg {
  fill: none;
  transition: fill 150ms ease;
}

.star-btn.filled svg {
  fill: currentColor;
}

/* ---- Toast ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 13px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Autocomplete ---- */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 220px;
  overflow-y: auto;
  z-index: 30;
  display: none;
}
.autocomplete-list.show { display: block; }
.autocomplete-item {
  padding: 10px 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:active { background: var(--bg-card); }
.autocomplete-item .ac-meta { color: var(--text-faint); font-size: 12px; white-space: nowrap; }

/* ---- Loading / offline banner ---- */
.offline-banner {
  display: none;
  background: rgba(245,158,11,0.15);
  color: var(--warning);
  font-size: 12px;
  text-align: center;
  padding: 6px;
}
.offline-banner.show { display: block; }

/* ---- Utility ---- */
.row { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.text-dim { color: var(--text-dim); }
.text-faint { color: var(--text-faint); }
.text-center { text-align: center; }
.hidden { display: none !important; }

@media (min-width: 560px) {
  #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* ---- Modal sheets ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-sheet {
  width: 100%;
  max-width: 560px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-4);
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  max-height: 85dvh;
  overflow-y: auto;
  animation: sheet-in 220ms ease;
}

@keyframes sheet-in {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Back arrow in the header of pages that have no tab of their own (e.g. Camera Workout). */
.page-back-btn { margin-left: -8px; margin-right: 2px; }

/* Pro marker (js/entitlements.js) */
.pro-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1;
  padding: 3px 6px;
  border-radius: var(--radius-full);
  background: rgba(234, 179, 8, 0.18);
  color: #eab308;
  vertical-align: middle;
  margin-left: 4px;
}
.upgrade-list { margin: 0 0 var(--space-3); padding-left: 20px; font-size: 14px; line-height: 1.6; }
.upgrade-status { font-size: 13px; line-height: 1.45; margin-bottom: var(--space-4); }
.plan-label { cursor: default; user-select: none; }
.upgrade-buy { margin-bottom: var(--space-3); }
.upgrade-save { font-size: 11px; font-weight: 700; margin-left: 6px; padding: 2px 6px; border-radius: var(--radius-full); background: rgba(255,255,255,0.2); }
.upgrade-fine { font-size: 12px; line-height: 1.45; margin-top: var(--space-2); }

/* ---- First-run setup (js/onboarding.js) ---- */
.onboarding-overlay {
  position: fixed; inset: 0; z-index: 70; background: var(--bg);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
body.onboarding-open { overflow: hidden; }
.onboarding-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-3) var(--space-3) 0; max-width: 560px; width: 100%; margin: 0 auto; }
.onboarding-top .invisible { visibility: hidden; }
.ob-progress { display: flex; gap: 6px; flex: 1; justify-content: center; }
.ob-progress span { width: 28px; height: 4px; border-radius: 2px; background: var(--border); }
.ob-progress span.done { background: var(--accent); }
.onboarding-body { flex: 1; overflow-y: auto; padding: var(--space-4); max-width: 560px; width: 100%; margin: 0 auto; }
.onboarding-body h2 { font-size: 22px; margin-bottom: var(--space-2); }
.onboarding-bottom { padding: var(--space-3) var(--space-4) var(--space-4); max-width: 560px; width: 100%; margin: 0 auto; }
.ob-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: var(--space-2); }
.ob-hero { padding-top: 8vh; }
.ob-logo { font-size: 30px; font-weight: 800; color: var(--accent); margin-bottom: var(--space-3); letter-spacing: -0.02em; }
.ob-points { list-style: none; padding: 0; margin: var(--space-3) 0; display: flex; flex-direction: column; gap: var(--space-3); font-size: 15px; line-height: 1.45; }
.ob-points li { padding-left: 14px; border-left: 3px solid var(--accent); }
.ob-note { font-size: 13px; line-height: 1.5; color: var(--text-dim); margin: var(--space-2) 0 var(--space-3); }
.ob-choices { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-3); }
.ob-choice {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; width: 100%;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-elevated);
}
.ob-choice strong { font-size: 15px; }
.ob-choice span { font-size: 13px; color: var(--text-faint); }
.ob-choice.selected { border-color: var(--accent); background: rgba(59,130,246,0.12); }
.ob-plan { margin: var(--space-3) 0; padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-elevated); text-align: center; }
.ob-kcal { font-size: 15px; color: var(--text-dim); }
.ob-kcal span { display: block; font-size: 40px; font-weight: 800; color: var(--text); line-height: 1.1; }
.ob-macros { display: flex; justify-content: space-around; margin-top: var(--space-3); }
.ob-macros div { display: flex; flex-direction: column; }
.ob-macros strong { font-size: 18px; }
.ob-macros span { font-size: 12px; color: var(--text-faint); }
