/* LifeHub — main.css */
:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --surface-2: #fafaf9;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --text: #1c1917;
  --muted: #78716c;
  --accent: #0f766e;
  --accent-hover: #0d9488;
  --accent-light: #f0fdfa;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --success: #16a34a;
  --success-light: #d1fae5;
  --cal-color: #f97316;
  --pro-color: #3b82f6;
  --act-color: #22c55e;
  --r: 8px;
  --r-sm: 4px;
  --r-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --nav-h: 56px;
}

*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
img { display: block; max-width: 100%; }
button,input,select,textarea { font: inherit; }
a { color: inherit; }

body {
  font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Auth / Login ─────────────────────────────────── */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-md); padding: 2rem; width: 100%; max-width: 380px; }
.auth-logo { font-size: 1.5rem; font-weight: 800; color: var(--accent); text-align: center; letter-spacing: -.5px; margin-bottom: .25rem; }
.auth-tagline { text-align: center; color: var(--muted); font-size: .875rem; margin-bottom: 1.5rem; }

/* ── Nav ──────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--nav-h);
  display: flex; align-items: center;
  padding: 0 1.5rem; gap: 2rem;
  box-shadow: var(--shadow-sm);
}
.nav-user { display: flex; align-items: center; gap: .625rem; flex-shrink: 0; margin-left: auto; }
.nav-username { font-size: .8rem; color: var(--muted); font-weight: 500; }
.nav-brand {
  font-weight: 700; font-size: 1.05rem;
  color: var(--accent); text-decoration: none; letter-spacing: -.5px;
  flex-shrink: 0;
}
.nav-links { display: flex; list-style: none; gap: .125rem; flex: 1; }
.nav-links a {
  text-decoration: none; color: var(--muted);
  font-size: .875rem; font-weight: 500;
  padding: .375rem .7rem; border-radius: var(--r-sm);
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.nav-links a:hover, .nav-links a.active {
  background: var(--accent-light); color: var(--accent);
}

/* ── Layout ───────────────────────────────────────── */
.main-content { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem; flex-wrap: wrap; gap: .75rem;
}
.page-title { font-size: 1.3rem; font-weight: 700; }

/* ── Cards ────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}
.card-body { padding: 1.25rem; }
.card-title {
  font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-bottom: .875rem;
}

.section-grid { display: grid; gap: 1rem; grid-template-columns: repeat(3,1fr); }
@media(max-width:800px) { .section-grid { grid-template-columns: 1fr; } }

/* ── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .5rem .9rem; border: none; border-radius: var(--r-sm);
  font-size: .875rem; font-weight: 500; cursor: pointer;
  text-decoration: none; transition: opacity .15s, background .15s;
  white-space: nowrap; line-height: 1;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: .85; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.btn-sm { padding: .275rem .6rem; font-size: .8rem; }
.btn-icon { padding: .35rem; border-radius: var(--r-sm); background: transparent; border: none; cursor: pointer; color: var(--muted); transition: color .15s; }
.btn-icon:hover { color: var(--text); }

/* ── Forms ────────────────────────────────────────── */
.form-group { margin-bottom: .875rem; }
.form-label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; }
.form-control {
  width: 100%; padding: .5rem .7rem;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text);
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }
.form-row { display: flex; gap: .75rem; }
.form-row .form-group { flex: 1; min-width: 0; }
.form-hint { font-size: .75rem; color: var(--muted); margin-top: .25rem; }

/* ── Flash ────────────────────────────────────────── */
.flash {
  padding: .7rem 1rem; border-radius: var(--r-sm);
  margin-bottom: .875rem; font-size: .875rem; font-weight: 500;
}
.flash-success { background: var(--success-light); color: var(--success); border: 1px solid #86efac; }
.flash-error   { background: var(--danger-light);  color: var(--danger);  border: 1px solid #fca5a5; }
.flash-info    { background: var(--accent-light);  color: var(--accent);  border: 1px solid #99f6e4; }

/* ── Macro rings ──────────────────────────────────── */
.rings-row { display: flex; gap: 1.5rem; justify-content: center; flex-wrap: wrap; padding: .25rem 0; }
.ring-wrap { display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.ring-svg { width: 108px; height: 108px; }
.ring-info { text-align: center; line-height: 1.2; }
.ring-current { font-size: 1.35rem; font-weight: 800; }
.ring-of { font-size: .75rem; color: var(--muted); }
.ring-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ── Meal rows ────────────────────────────────────── */
.meal-type-header {
  font-size: .7rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted);
  padding: .75rem 0 .375rem; border-bottom: 1px solid var(--border);
  margin-bottom: .375rem; margin-top: .5rem;
}
.meal-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem .25rem; border-bottom: 1px solid var(--border);
}
.meal-row:last-child { border-bottom: none; }
.meal-name { flex: 1; font-size: .9375rem; }
.meal-macros { font-size: .8rem; color: var(--muted); display: flex; gap: .625rem; flex-wrap: wrap; }
.meal-actions { display: flex; gap: .25rem; flex-shrink: 0; }

/* ── Totals bar ───────────────────────────────────── */
.totals-bar {
  display: flex; gap: 1.25rem; padding: .75rem 1.25rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); flex-wrap: wrap; margin-bottom: 1rem;
  align-items: center;
}
.total-item { display: flex; flex-direction: column; align-items: center; }
.total-val { font-size: 1.2rem; font-weight: 800; line-height: 1; }
.total-lbl { font-size: .65rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.total-sep { width: 1px; height: 32px; background: var(--border); }

/* ── Badges ───────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: .15rem .55rem; border-radius: 999px;
  font-size: .72rem; font-weight: 700; text-transform: capitalize;
  white-space: nowrap;
}
.badge-breakfast  { background:#fef3c7; color:#92400e; }
.badge-lunch      { background:#d1fae5; color:#065f46; }
.badge-dinner     { background:#dbeafe; color:#1e40af; }
.badge-snack      { background:#ede9fe; color:#5b21b6; }
.badge-push       { background:#fee2e2; color:#991b1b; }
.badge-pull       { background:#dbeafe; color:#1e40af; }
.badge-legs       { background:#d1fae5; color:#065f46; }
.badge-cardio     { background:#fef3c7; color:#92400e; }
.badge-rest       { background:#f3f4f6; color:#374151; }
.badge-other      { background:#ede9fe; color:#5b21b6; }
.badge-goal       { background:#dbeafe; color:#1e40af; }
.badge-observation{ background:#d1fae5; color:#065f46; }
.badge-health_flag{ background:#fee2e2; color:#991b1b; }
.badge-plan_change{ background:#fef3c7; color:#92400e; }
.badge-life_event { background:#ede9fe; color:#5b21b6; }
.badge-note       { background:#f3f4f6; color:#374151; }
.badge-completed  { background:var(--success-light); color:var(--success); }
.badge-pending    { background:var(--warning-light);  color:var(--warning); }

/* ── Table ────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .875rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .7rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* ── Recipe grid ──────────────────────────────────── */
.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px,1fr)); gap: .875rem; }
.recipe-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); overflow: hidden;
  display: flex; flex-direction: column;
  text-decoration: none; color: inherit;
  transition: box-shadow .2s, transform .15s;
}
.recipe-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.recipe-card-img { width: 100%; height: 130px; object-fit: cover; background: var(--bg); }
.recipe-card-ph {
  width: 100%; height: 130px;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
  font-size: 2.25rem; color: var(--border-strong);
}
.recipe-card-body { padding: .875rem; flex: 1; display: flex; flex-direction: column; gap: .25rem; }
.recipe-card-name { font-weight: 600; font-size: .9375rem; }
.recipe-card-course { font-size: .78rem; color: var(--muted); }
.recipe-card-macros { font-size: .78rem; color: var(--muted); margin-top: auto; padding-top: .5rem; }

/* ── Recipe detail ────────────────────────────────── */
.recipe-hero { display: flex; gap: 1.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.recipe-hero-img { width: 220px; height: 170px; object-fit: cover; border-radius: var(--r); flex-shrink: 0; }
.recipe-hero-ph { width: 220px; height: 170px; background: var(--bg); border-radius: var(--r); display: flex; align-items: center; justify-content: center; font-size: 3rem; color: var(--border-strong); flex-shrink: 0; }
.recipe-hero-info { flex: 1; min-width: 200px; }
.recipe-hero-name { font-size: 1.5rem; font-weight: 800; margin-bottom: .375rem; }
.recipe-hero-meta { font-size: .875rem; color: var(--muted); margin-bottom: .625rem; }
.nutrition-chips { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }
.nutrition-chip { display: flex; flex-direction: column; align-items: center; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); padding: .375rem .7rem; }
.chip-val { font-weight: 800; font-size: 1rem; line-height: 1; }
.chip-lbl { font-size: .65rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.scaler-bar { display: flex; align-items: center; gap: .75rem; padding: .625rem 1rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); margin-bottom: 1rem; font-size: .875rem; }
.scaler-bar label { font-weight: 500; white-space: nowrap; }
.scaler-bar input { width: 64px; padding: .3rem .5rem; border: 1px solid var(--border-strong); border-radius: var(--r-sm); text-align: center; }
.scaler-base { color: var(--muted); }

.ingredient-list { list-style: none; }
.ingredient-list li { display: flex; gap: .5rem; padding: .4rem 0; border-bottom: 1px solid var(--border); font-size: .9375rem; }
.ingredient-list li:last-child { border-bottom: none; }
.ing-qty { font-weight: 700; min-width: 52px; color: var(--accent); }
.ing-unit { color: var(--muted); min-width: 36px; }
.directions-text { white-space: pre-wrap; line-height: 1.8; font-size: .9375rem; }

/* ── Workout week grid ────────────────────────────── */
.week-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: .5rem; margin-bottom: 1.25rem; }
.day-cell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: .625rem .375rem; text-align: center;
}
.day-cell.is-today { border-color: var(--accent); border-width: 2px; }
.day-cell.has-workout { background: var(--accent-light); }
.day-cell.completed { background: var(--success-light); border-color: var(--success); }
.day-name { font-size: .65rem; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.day-date { font-size: .9375rem; font-weight: 800; margin: .2rem 0; }
.day-type { font-size: .7rem; color: var(--accent); font-weight: 600; }
@media(max-width:560px) {
  .day-name { font-size: .6rem; }
  .day-date { font-size: .8125rem; }
  .week-grid { gap: .25rem; }
}

/* ── Modal ────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 200; display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-md); width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 700; font-size: 1rem; }
.modal-close { background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--muted); line-height: 1; padding: .2rem .4rem; border-radius: var(--r-sm); }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 1.25rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .5rem; padding: 1rem 1.25rem; border-top: 1px solid var(--border); }

/* ── Tabs ─────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tab-btn { padding: .5rem 1rem; border: none; background: none; font-size: .875rem; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s, border-color .15s; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Filter bar ───────────────────────────────────── */
.filter-bar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.125rem; }
.filter-bar input, .filter-bar select {
  padding: .4375rem .7rem; border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); font-size: .875rem; background: var(--surface);
  color: var(--text);
}
.filter-bar input { flex: 1; min-width: 160px; }
.filter-bar input:focus, .filter-bar select:focus { outline: none; border-color: var(--accent); }

/* ── Workout status ───────────────────────────────── */
.workout-card { display: flex; align-items: center; gap: .875rem; padding: .875rem; border-radius: var(--r); border: 1px solid var(--border); background: var(--surface); }
.workout-card.done { background: var(--success-light); border-color: #86efac; }
.workout-card.none { background: var(--surface-2); }
.workout-icon { font-size: 1.75rem; flex-shrink: 0; }
.workout-info { flex: 1; }
.workout-info strong { font-size: .9375rem; font-weight: 700; display: block; }
.workout-info span { font-size: .8125rem; color: var(--muted); }

/* ── Context page ─────────────────────────────────── */
.ctx-content { max-width: 380px; }
.ctx-content p { font-size: .875rem; }
.ctx-meta { font-size: .75rem; color: var(--muted); }
.tag-pill { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: .1rem .45rem; font-size: .7rem; color: var(--muted); }
.pinned-star { color: #eab308; font-size: .9rem; }
.expired-row td { opacity: .5; }

/* ── Settings ─────────────────────────────────────── */
.settings-section { margin-bottom: 1.5rem; }
.settings-section-title { font-size: 1.05rem; font-weight: 700; margin-bottom: .875rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: .375rem; }
.dot-green { background: var(--success); }
.dot-red { background: var(--danger); }

/* ── Workout week grid (template classes) ─────────── */
.week-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: .5rem; }
.week-day {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: .625rem .375rem; text-align: center;
}
.week-day.today { border-color: var(--accent); border-width: 2px; }
.wday-label { font-size: .65rem; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.wday-date { font-size: .9375rem; font-weight: 800; margin: .2rem 0; }
.wday-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  font-size: .75rem; font-weight: 700; color: #fff;
  margin: .25rem auto 0;
}
.wday-badge.push    { background: #ef4444; }
.wday-badge.pull    { background: #3b82f6; }
.wday-badge.legs    { background: #22c55e; }
.wday-badge.cardio  { background: #f97316; }
.wday-badge.rest    { background: #9ca3af; }
.wday-badge.other   { background: #a78bfa; }
.wday-badge.empty   { background: var(--border); color: var(--muted); }
.wday-badge.incomplete { opacity: .55; }
.wday-cal { font-size: .65rem; color: var(--muted); margin-top: .15rem; }
@media(max-width:560px) { .wday-label { font-size: .6rem; } .wday-date { font-size: .8125rem; } .week-grid { gap: .25rem; } }

/* ── Data table ───────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: .6rem .875rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table th { font-size: .7rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; background: var(--surface-2); white-space: nowrap; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }

/* ── Context type tabs ────────────────────────────── */
.context-type-tabs { display: flex; gap: .375rem; flex-wrap: wrap; }
.tab-link {
  padding: .35rem .8rem; border-radius: 999px;
  font-size: .8rem; font-weight: 500; text-decoration: none;
  color: var(--muted); border: 1px solid var(--border);
  background: var(--surface); transition: all .15s;
}
.tab-link:hover { border-color: var(--accent); color: var(--accent); }
.tab-link.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Context table ────────────────────────────────── */
.context-table .ctx-content { max-width: 340px; font-size: .875rem; word-break: break-word; }
.pinned-row { background: #fffbeb; }

/* ── Settings integrations ────────────────────────── */
.settings-integration-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  padding: .875rem 0; border-bottom: 1px solid var(--border);
}
.settings-integration-row:last-child { border-bottom: none; }
.settings-integration-row p { margin-top: .25rem; }

/* ── Badge extras ─────────────────────────────────── */
.badge-success { background: var(--success-light); color: var(--success); }
.badge-neutral { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

/* ── Utilities ────────────────────────────────────── */
.mt-1{margin-top:.25rem} .mt-2{margin-top:.5rem} .mt-3{margin-top:.75rem} .mt-4{margin-top:1rem}
.mb-1{margin-bottom:.25rem} .mb-2{margin-bottom:.5rem} .mb-3{margin-bottom:.75rem} .mb-4{margin-bottom:1rem}
.gap-1{gap:.25rem} .gap-2{gap:.5rem} .gap-3{gap:.75rem}
.flex{display:flex} .items-center{align-items:center} .justify-between{justify-content:space-between}
.hidden{display:none!important} .w-full{width:100%}
.text-muted{color:var(--muted)} .text-sm{font-size:.875rem} .text-xs{font-size:.75rem}
.text-right{text-align:right} .font-bold{font-weight:700}
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state p { margin-top: .5rem; font-size: .9rem; }

/* ── Food search (meal modal) ───────────────────────── */
.food-results { display: flex; flex-direction: column; gap: .25rem; max-height: 14rem; overflow-y: auto; margin-bottom: .75rem; }
.food-result { display: flex; justify-content: space-between; gap: .75rem; text-align: left; padding: .5rem .75rem; border: 1px solid var(--border, #ddd); border-radius: 6px; background: transparent; color: inherit; cursor: pointer; font: inherit; }
.food-result:hover, .food-result.active { border-color: var(--accent, #4f46e5); }
.food-selected { padding: .75rem; border: 1px solid var(--border, #ddd); border-radius: 6px; margin-bottom: .5rem; }
