/* ═══════════════════════════════════════════════
   MIND & FITNESS — style.css
   Light, earthy, nature theme
   All class names match index.html and app.js exactly
═══════════════════════════════════════════════ */

/* ─── Custom Properties ──────────────────────────────────────────────────── */
:root {
  --bg:           #F5F0E8;
  --card:         #FFFFFF;
  --elevated:     #F0EBE1;
  --accent:       #4A7C59;
  --accent-light: #5D9A6E;
  --brown:        #8B7355;
  --gold:         #C4951A;
  --danger:       #C0392B;
  --text:         #2D3436;
  --secondary:    #636E72;
  --muted:        #95A5A6;
  --border:       #E0D8CC;
  --radius-card:  14px;
  --radius-input: 8px;
  --nav-height:   64px;
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
  --safe-top:     env(safe-area-inset-top, 0px);
  --shadow-sm:    0 2px 8px rgba(45,52,54,0.06);
  --shadow-md:    0 4px 16px rgba(45,52,54,0.10);
  --shadow-lg:    0 8px 28px rgba(45,52,54,0.12);
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Base ───────────────────────────────────────────────────────────────── */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

/* CRITICAL: iOS bounce prevention */
body {
  position: fixed;
  overflow: hidden;
  width: 100%;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
}

/* ─── Accessibility ──────────────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── Views ──────────────────────────────────────────────────────────────── */
.view {
  display: none;
  height: 100dvh;
  background: var(--bg);
}

.view.active {
  display: flex;
  flex-direction: column;
}

/* Scrollable content area inside views */
.view-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--nav-height) + var(--safe-bottom) + 20px);
}

/* Add view has no nav so no extra nav padding */
#add-view .view-scroll {
  padding-bottom: 32px;
}

/* ─── Loading Overlay ────────────────────────────────────────────────────── */
#loading {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(245,240,232,0.88);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

#loading.active {
  display: flex;
}

.spinner-ring {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: var(--secondary);
  font-size: 14px;
  font-weight: 500;
}

/* ─── Toast ──────────────────────────────────────────────────────────────── */
#toast {
  display: none;
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 9000;
  transition: transform 0.25s ease, opacity 0.25s ease;
  opacity: 0;
  max-width: calc(100vw - 32px);
  text-align: center;
}

#toast.show {
  display: block;
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

#toast.toast-success { background: #27AE60; }
#toast.toast-error   { background: var(--danger); }
#toast.toast-warning { background: var(--gold); color: #1a1a1a; }

/* ─── View Header ────────────────────────────────────────────────────────── */
.view-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  background: var(--card);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  min-height: 56px;
  flex-shrink: 0;
}

.view-header-split {
  justify-content: space-between;
}

.view-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}

.view-title-center {
  text-align: center;
}

.view-header-spacer {
  width: 40px;
  flex-shrink: 0;
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  border-radius: 50%;
  flex-shrink: 0;
}

.back-btn:active {
  background: var(--elevated);
}

/* ─── Bottom Navigation ──────────────────────────────────────────────────── */
.bottom-nav {
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
}

/* nav-item — used in HTML and JS */
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 4px;
  min-height: 44px;
  font-size: 10px;
  font-weight: 500;
  transition: color 0.15s ease;
}

.nav-item:active {
  background: var(--elevated);
}

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

.nav-item svg {
  flex-shrink: 0;
}

/* ─── PIN View ───────────────────────────────────────────────────────────── */
#pin-view {
  align-items: center;
  justify-content: center;
}

.pin-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px 24px;
  width: 100%;
  max-width: 340px;
}

.pin-logo {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
}

.pin-subtitle {
  font-size: 14px;
  color: var(--secondary);
  margin-top: -8px;
}

/* 6-dot PIN display */
.pin-display {
  display: flex;
  gap: 14px;
  padding: 12px 0;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  background: transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}

/* Shake animation for wrong PIN — applied to .pin-display by JS */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15%       { transform: translateX(-8px); }
  30%       { transform: translateX(8px); }
  45%       { transform: translateX(-6px); }
  60%       { transform: translateX(6px); }
  75%       { transform: translateX(-3px); }
  90%       { transform: translateX(3px); }
}

.pin-display.shake {
  animation: shake 0.6s ease;
}

/* Hidden tel input for mobile keyboard fallback */
.pin-hidden-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

/* 3×4 keypad grid */
.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 280px;
}

.pin-key {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 64px;
  border: none;
  border-radius: 50%;
  background: var(--card);
  color: var(--text);
  font-size: 24px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.12s ease, transform 0.1s ease;
  -webkit-user-select: none;
  user-select: none;
}

.pin-key:active {
  background: var(--elevated);
  transform: scale(0.94);
}

.pin-key-empty {
  background: transparent;
  box-shadow: none;
  cursor: default;
}

.pin-key-delete {
  color: var(--secondary);
  font-size: 14px;
}

.pin-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
  min-height: 20px;
  text-align: center;
}

/* ─── Log View Header ────────────────────────────────────────────────────── */
.log-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  flex-shrink: 0;
}

.date-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.date-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  border-radius: 50%;
}

.date-nav-btn:active {
  background: var(--elevated);
}

.date-display {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

/* Weight badge row */
.weight-badge-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.weight-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--elevated);
  color: var(--secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.weight-badge:active {
  background: var(--border);
}

/* Macro summary grid with integrated bars */
.macro-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 0;
  padding: 8px 16px;
  text-align: center;
}

.macro-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.macro-col.with-bar {
  position: relative;
}

.macro-col-bar-track {
  width: 80%;
  height: 4px;
  background: rgba(0,0,0,0.06);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 4px;
}

.macro-col-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
  min-width: 0;
}

.macro-col-bar-fill.protein-fill { background: #3498DB; }
.macro-col-bar-fill.carb-fill { background: #E67E22; }
.macro-col-bar-fill.fat-fill { background: #9B59B6; }
.macro-col-bar-fill.over-limit { background: #E74C3C; }

.macro-limit-text {
  font-size: 0.6rem;
  color: #999;
  margin-top: 1px;
}

.macro-value {
  font-size: 1.2rem;
  font-weight: 800;
  color: #2D3436;
  line-height: 1.2;
}

.macro-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: #636E72;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Calorie progress bar */
.calorie-bar-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calorie-bar-track {
  width: 100%;
  height: 8px;
  background: var(--elevated);
  border-radius: 4px;
  overflow: hidden;
}

.calorie-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 4px;
  transition: width 0.4s ease;
  width: 0%;
}

.calorie-goal-text {
  font-size: 12px;
  color: var(--secondary);
  text-align: right;
}

/* ─── Meal Cards ─────────────────────────────────────────────────────────── */
#meal-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.meal-card {
  display: flex;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.meal-thumb {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.meal-thumb-empty {
  background: var(--elevated);
  display: flex;
  align-items: center;
  justify-content: center;
}

.meal-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.meal-card-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.meal-time {
  font-size: 12px;
  color: var(--secondary);
}

.meal-cal-badge {
  margin-left: auto;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(74,124,89,0.10);
  padding: 2px 8px;
  border-radius: 10px;
}

.meal-edit-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--secondary);
}

.meal-edit-btn:active {
  background: var(--elevated);
}

.meal-desc {
  font-size: 13px;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.meal-food-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.meal-food-list li {
  font-size: 11px;
  color: var(--secondary);
  background: var(--elevated);
  padding: 2px 8px;
  border-radius: 10px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.meal-macros {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.macro-pill {
  font-size: 11px;
  color: var(--secondary);
  background: var(--elevated);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

/* ─── FAB ────────────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(74,124,89,0.40);
  z-index: 100;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.fab:active {
  transform: scale(0.93);
  box-shadow: 0 2px 8px rgba(74,124,89,0.30);
}

/* ─── Empty State ────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  gap: 10px;
}

.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--secondary);
}

.empty-state-hint {
  font-size: 14px;
  color: var(--muted);
}

/* ─── Add Meal View ──────────────────────────────────────────────────────── */
.add-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Photo section */
.photo-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.photo-preview-area {
  position: relative;
  width: 100%;
  height: 180px;
  background: var(--elevated);
  border-radius: var(--radius-card);
  border: 2px dashed var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.photo-placeholder-text {
  font-size: 13px;
}

.photo-preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(45,52,54,0.65);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-btn-row {
  display: flex;
  gap: 10px;
}

.photo-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
}

.photo-btn:active {
  background: var(--elevated);
}

/* ─── Form Elements ──────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* CRITICAL: font-size 16px on all inputs — prevents iOS zoom */
.form-textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
  line-height: 1.5;
}

.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74,124,89,0.12);
}

.form-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74,124,89,0.12);
}

.char-count {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-input);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-primary:active {
  background: var(--accent-light);
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 24px;
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: var(--radius-input);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  transition: background 0.15s ease;
}

.btn-secondary:active {
  background: rgba(74,124,89,0.08);
}

.btn-danger {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 24px;
  background: transparent;
  color: var(--danger);
  border: 2px solid var(--danger);
  border-radius: var(--radius-input);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  transition: background 0.15s ease;
}

.btn-danger:active {
  background: rgba(192,57,43,0.08);
}

.btn-full {
  width: 100%;
}

/* Analyze button — contains .analyze-btn-text and .analyze-btn-spinner */
.analyze-btn {
  position: relative;
}

.analyze-btn-text {
  /* Visible by default; JS hides during submit */
}

.analyze-btn-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* ─── Result Card ────────────────────────────────────────────────────────── */
.result-card {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.result-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.confidence-badge {
  font-size: 13px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 10px;
  background: var(--elevated);
}

.result-food-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.result-food-list li {
  font-size: 13px;
  background: var(--elevated);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 10px;
}

.result-macros {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.result-macro-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--elevated);
  padding: 10px 4px;
  border-radius: 10px;
}

.result-macro-calories {
  background: rgba(74,124,89,0.10);
}

.result-macro-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.result-macro-calories .result-macro-value {
  color: var(--accent);
}

.result-macro-label {
  font-size: 10px;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.result-notes {
  font-size: 13px;
  color: var(--secondary);
  font-style: italic;
}

/* ─── Insight / General Cards ────────────────────────────────────────────── */
.insight-card {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ─── Insights View ──────────────────────────────────────────────────────── */
.insights-content {
  display: flex;
  flex-direction: column;
}

/* Period toggle */
.period-toggle {
  display: flex;
  background: var(--elevated);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}

.period-btn {
  border: none;
  background: transparent;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  min-height: 32px;
  min-width: 36px;
  transition: background 0.15s ease, color 0.15s ease;
}

.period-btn.active {
  background: var(--card);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* Journey progress bar */
.journey-bar-track {
  width: 100%;
  height: 10px;
  background: var(--elevated);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 6px;
}

.journey-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 5px;
  transition: width 0.5s ease;
  width: 0%;
}

.journey-bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--secondary);
}

/* Stats grid — 2 columns */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 14px 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}

.stat-card-highlight {
  border-color: rgba(74,124,89,0.35);
  background: rgba(74,124,89,0.05);
}

.stat-card-muted {
  border-color: rgba(192,57,43,0.20);
  background: rgba(192,57,43,0.04);
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.stat-label {
  font-size: 11px;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Macro averages */
.macro-avgs-row {
  display: flex;
  justify-content: space-around;
}

.macro-avg-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.macro-avg-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.macro-avg-label {
  font-size: 12px;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Chart wrapper — maintainAspectRatio: false in JS so height drives size */
.chart-wrapper {
  position: relative;
  height: 200px;
  width: 100%;
}

/* ─── Calendar View ──────────────────────────────────────────────────────── */
.calendar-content {
  display: flex;
  flex-direction: column;
}

/* 7-column grid shared by header row and days grid */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-header-row {
  padding: 0 4px;
  margin-bottom: 4px;
}

.cal-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--secondary);
  text-transform: uppercase;
  padding: 6px 0;
  letter-spacing: 0.3px;
}

.cal-days-grid {
  padding: 0 4px;
  margin-bottom: 16px;
}

/* Calendar day cell */
.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  min-height: 44px;
  border: none;
  background: transparent;
  transition: background 0.12s ease;
  padding: 0;
}

.cal-day:active {
  background: var(--elevated);
}

.cal-day.future {
  color: var(--muted);
  cursor: default;
  pointer-events: none;
}

.cal-day.empty {
  cursor: default;
  pointer-events: none;
}

.cal-day.today {
  font-weight: 800;
  color: var(--accent);
}

/* Status dot below day number */
.cal-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: transparent;
}

.cal-day.under .cal-dot  { background: #27AE60; }
.cal-day.over .cal-dot   { background: var(--danger); }
.cal-day.no-data .cal-dot { background: var(--muted); }

/* Legend */
.cal-legend {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 8px 0 4px;
}

.cal-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--secondary);
}

.cal-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.cal-legend-dot.under   { background: #27AE60; }
.cal-legend-dot.over    { background: var(--danger); }
.cal-legend-dot.no-data { background: var(--muted); }

/* ─── Weight View ────────────────────────────────────────────────────────── */
.weight-content {
  display: flex;
  flex-direction: column;
}

.current-weight-card {
  text-align: center;
}

.current-weight-main {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
}

.current-weight-value {
  font-size: 52px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}

.current-weight-unit {
  font-size: 20px;
  font-weight: 500;
  color: var(--secondary);
}

.current-weight-date {
  font-size: 13px;
  color: var(--secondary);
  margin-top: 6px;
}

/* Weight change indicator with .wci-arrow and .wci-value children */
.weight-change-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 15px;
  font-weight: 700;
}

.weight-change-indicator.gain    { color: var(--danger); }
.weight-change-indicator.loss    { color: var(--accent); }
.weight-change-indicator.neutral { color: var(--secondary); }

/* Weight input */
.weight-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.weight-input {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

.weight-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74,124,89,0.12);
}

.weight-input-unit {
  font-size: 14px;
  color: var(--secondary);
  font-weight: 500;
}

.weight-log-btn {
  width: auto;
  padding: 12px 20px;
  flex-shrink: 0;
}

/* Weight history list */
.weight-history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.weight-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.weight-history-item:last-child {
  border-bottom: none;
}

.weight-hist-date {
  font-size: 14px;
  color: var(--secondary);
}

.weight-hist-val {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.weight-hist-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.weight-edit-btn,
.weight-delete-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s;
}

.weight-edit-btn {
  background: rgba(74, 124, 89, 0.1);
  color: #4A7C59;
}

.weight-edit-btn:hover {
  background: rgba(74, 124, 89, 0.2);
}

.weight-delete-btn {
  background: rgba(200, 60, 60, 0.1);
  color: #C83C3C;
}

.weight-delete-btn:hover {
  background: rgba(200, 60, 60, 0.2);
}

/* Weight period toggle */
.weight-period-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.weight-period-btn {
  padding: 4px 10px;
  border-radius: 14px;
  border: 1px solid #D4C8B8;
  background: transparent;
  color: #636E72;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.weight-period-btn[aria-pressed="true"],
.weight-period-btn.active {
  background: #4A7C59;
  color: white;
  border-color: #4A7C59;
}

/* ─── Settings View ──────────────────────────────────────────────────────── */
.settings-content {
  display: flex;
  flex-direction: column;
}

.settings-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.settings-info-row:last-child {
  border-bottom: none;
}

.settings-info-label {
  font-size: 13px;
  color: var(--secondary);
}

.settings-info-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.settings-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.settings-input {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

.settings-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74,124,89,0.12);
}

.settings-input-unit {
  font-size: 14px;
  color: var(--secondary);
  font-weight: 500;
}

.settings-save-btn {
  width: auto;
  padding: 12px 20px;
  flex-shrink: 0;
}

.settings-hint {
  font-size: 13px;
  color: var(--secondary);
  margin-bottom: 12px;
}

/* iOS Shortcuts collapsible */
.shortcuts-details {
  user-select: none;
}

.shortcuts-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  padding: 2px 0;
}

.shortcuts-summary::-webkit-details-marker {
  display: none;
}

.shortcuts-chevron {
  margin-left: auto;
  transition: transform 0.2s ease;
}

details[open] .shortcuts-chevron {
  transform: rotate(180deg);
}

.shortcuts-body {
  margin-top: 12px;
  font-size: 13px;
  color: var(--secondary);
  line-height: 1.6;
}

.shortcuts-steps {
  margin-top: 8px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ─── Edit Modal (bottom sheet) ──────────────────────────────────────────── */
#edit-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 5000;
  align-items: flex-end;
}

#edit-modal.active {
  display: flex;
}

.edit-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(45,52,54,0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.edit-sheet {
  position: relative;
  width: 100%;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 85dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 1;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.edit-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.edit-close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--elevated);
  color: var(--secondary);
  font-size: 16px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.edit-close:active {
  background: var(--border);
}

.edit-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.edit-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.edit-input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--elevated);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  resize: none;
}

.edit-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--card);
  box-shadow: 0 0 0 3px rgba(74,124,89,0.12);
}

.edit-macros-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.edit-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ─── Scrollbar (desktop/WebKit) ─────────────────────────────────────────── */
.view-scroll::-webkit-scrollbar,
.edit-sheet::-webkit-scrollbar {
  width: 4px;
}

.view-scroll::-webkit-scrollbar-track,
.edit-sheet::-webkit-scrollbar-track {
  background: transparent;
}

.view-scroll::-webkit-scrollbar-thumb,
.edit-sheet::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ─── Calendar day food log section ─────────────────────────────────────── */
.cal-day-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(0,0,0,0.08);
}
.cal-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.cal-day-label {
  font-size: 1rem;
  font-weight: 600;
  color: #2D3436;
  margin: 0;
}
.cal-day-summary {
  font-size: 0.85rem;
  color: #636E72;
}
.cal-day-meals {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Calendar meal row */
.cal-meal-row {
  background: #fff;
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  border: 1px solid rgba(0,0,0,0.06);
  transition: all 0.2s ease;
}
.cal-meal-row:active {
  background: #f0ebe3;
}
.cal-meal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.cal-meal-name {
  font-weight: 500;
  font-size: 0.9rem;
  color: #2D3436;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 8px;
}
.cal-meal-time {
  font-size: 0.75rem;
  color: #636E72;
  flex-shrink: 0;
}
.cal-meal-stats {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.8rem;
}
.cal-meal-cal {
  font-weight: 600;
  color: #4A7C59;
}
.cal-meal-macro {
  color: #8B7355;
}

/* Expandable details */
.cal-meal-details {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.cal-meal-row.expanded .cal-meal-details {
  max-height: 200px;
}
.cal-meal-details-inner {
  padding-top: 10px;
  margin-top: 10px;
  border-top: 1px solid rgba(0,0,0,0.06);
}
.cal-meal-micros {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: #636E72;
}
.cal-meal-micro-item {
  display: flex;
  gap: 4px;
}
.cal-meal-micro-label {
  color: #8B7355;
}
.cal-meal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.cal-meal-tag {
  background: #E8F0E5;
  color: #4A7C59;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
}
.cal-meal-notes {
  font-size: 0.8rem;
  color: #636E72;
  font-style: italic;
  margin-top: 6px;
}

/* Calendar selected day */
.cal-day.selected {
  background: #4A7C59 !important;
  color: #fff !important;
  font-weight: 700;
}
.cal-day.selected .cal-dot {
  background: rgba(255,255,255,0.6) !important;
}

/* Today label inside calendar cell */
.cal-today-label {
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #4A7C59;
  display: block;
  margin-top: 2px;
  font-weight: 600;
}
.cal-day.selected .cal-today-label {
  color: rgba(255,255,255,0.8);
}

/* ─── Swipe to Delete ────────────────────────────────────────────────────── */
.swipeable {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
}
.swipe-actions {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 12px;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}
.swipeable.swiped .swipe-actions {
  transform: translateX(0);
}
.swipe-edit-btn,
.swipe-delete-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0;
  color: white;
  transition: transform 0.2s;
}
.swipe-edit-btn {
  background: #4A7C59;
}
.swipe-delete-btn {
  background: #C83C3C;
}
.swipe-inner {
  position: relative;
  transition: transform 0.2s ease;
  background: var(--card-bg, #fff);
}
.swipeable.swiped .swipe-inner {
  transform: translateX(-100px);
}

/* ─── Meal card short title ──────────────────────────────────────────────── */
.meal-short-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: #2D3436;
  margin: 2px 0 4px;
  line-height: 1.3;
}

/* ─── Fasting bar ────────────────────────────────────────────────────────── */
.fasting-bar {
  margin: 0 16px 8px;
  background: linear-gradient(135deg, #E8F5E9 0%, #F1F8E9 100%);
  border-radius: 12px;
  padding: 10px 14px;
  border: 1px solid rgba(74, 124, 89, 0.15);
}

.fasting-bar-inner {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fasting-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.fasting-icon {
  font-size: 1rem;
}

.fasting-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #4A7C59;
}

.fasting-timer {
  font-size: 0.85rem;
  font-weight: 800;
  color: #2D3436;
  margin-left: auto;
}

.fasting-progress-track {
  height: 5px;
  background: rgba(0,0,0,0.08);
  border-radius: 3px;
  overflow: hidden;
}

.fasting-progress-fill {
  height: 100%;
  background: #4A7C59;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.fasting-end-btn {
  align-self: flex-end;
  padding: 4px 12px;
  border-radius: 14px;
  border: 1px solid #4A7C59;
  background: transparent;
  color: #4A7C59;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.fasting-toggle-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 14px;
  border: 1px solid #D4C8B8;
  background: transparent;
  color: #636E72;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.fasting-toggle-btn.active {
  border-color: #4A7C59;
  color: #4A7C59;
  background: rgba(74, 124, 89, 0.08);
}

/* ─── Exercise list ──────────────────────────────────────────────────────── */
.exercise-list {
  margin: 0 16px 8px;
  background: rgba(230, 126, 34, 0.06);
  border-radius: 12px;
  padding: 8px 12px;
  border: 1px solid rgba(230, 126, 34, 0.15);
}

.exercise-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.exercise-header-icon {
  color: #E67E22;
  display: flex;
}

.exercise-header-text {
  font-size: 0.78rem;
  font-weight: 600;
  color: #E67E22;
}

.exercise-header-total {
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 700;
  color: #E67E22;
}

.exercise-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 0.78rem;
}

.exercise-type {
  font-weight: 600;
  color: #2D3436;
  text-transform: capitalize;
}

.exercise-detail {
  color: #636E72;
}

.exercise-cal {
  margin-left: auto;
  font-weight: 600;
  color: #E67E22;
}

.exercise-delete {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(200, 60, 60, 0.1);
  color: #C83C3C;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

/* ─── Secondary FAB (exercise) ───────────────────────────────────────────── */
.fab-secondary {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 84px);
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #E67E22;
  color: white;
  border: none;
  box-shadow: 0 2px 8px rgba(230, 126, 34, 0.3);
  cursor: pointer;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─── AI insights in insights view ──────────────────────────────────────── */
.ai-insights-content {
  font-size: 0.85rem;
  line-height: 1.6;
  color: #2D3436;
}

.ai-insights-content p {
  margin: 0 0 8px;
}

.ai-insights-content ul,
.ai-insights-content ol {
  margin: 4px 0 8px;
  padding-left: 20px;
}

.ai-insights-content li {
  margin-bottom: 4px;
}

.ai-insights-content strong {
  color: #4A7C59;
}

.ai-insights-placeholder {
  color: #999;
  font-style: italic;
}

/* ─── AI response formatted (settings ask AI) ────────────────────────────── */
.ai-response p {
  margin: 0 0 8px;
}

.ai-response ul {
  margin: 4px 0 8px;
  padding-left: 20px;
}

.ai-response li {
  margin-bottom: 4px;
}

.ai-response strong {
  color: #4A7C59;
}

/* ─── Settings macro row ─────────────────────────────────────────────────── */
.settings-macro-row {
  display: flex;
  gap: 12px;
}

.settings-macro-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-macro-label {
  font-size: 0.75rem;
  color: #636E72;
  font-weight: 600;
}

.settings-macro-input {
  text-align: center;
  padding: 8px !important;
}

/* ─── AI chat in settings ────────────────────────────────────────────────── */
.ai-question-input {
  font-size: 0.88rem;
}

.ai-chat-input-row {
  margin-top: 8px;
}

.ai-response {
  margin-top: 12px;
  padding: 12px;
  background: rgba(74, 124, 89, 0.06);
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: #2D3436;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ─── Form hint text ─────────────────────────────────────────────────────── */
.form-hint {
  font-size: 0.78rem;
  color: #636E72;
  margin-top: 4px;
  margin-bottom: 0;
}
