/* ForgeFit web — same palette as the iOS app (Theme.swift). Dark by default, light follows the system. */
:root {
  --bg: #0A0A0C; --surface: #17181B; --surface-2: #222327; --separator: #2B2D32;
  --text: #F5F6F7; --muted: #9CA1AB;
  --accent: #C6F432; --accent-text: #C6F432; --on-accent: #0B0B0D;
  --protein: #4C8DFF; --carbs: #2DD4BF; --fat: #FF5C7A; --water: #4CB8FF;
  --positive: #3DDC72; --warning: #FF9F2E; --negative: #FF5A5A;
  --track: #2B2D32; --bar-muted: #3A3D44;
  --radius: 18px; --radius-s: 12px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F2F3F5; --surface: #FFFFFF; --surface-2: #F0F1F4; --separator: #E2E4E9;
    --text: #0B0B0D; --muted: #5F6570;
    --accent: #B4E61D; --accent-text: #4F7A00;
    --protein: #2F6FED; --carbs: #0FA896; --fat: #E5456A; --water: #1B8FDB;
    --positive: #1E9E4A; --warning: #E07B00; --negative: #D93636;
    --track: #E2E4E9; --bar-muted: #C9CDD4;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #F2F3F5; --surface: #FFFFFF; --surface-2: #F0F1F4; --separator: #E2E4E9;
  --text: #0B0B0D; --muted: #5F6570;
  --accent: #B4E61D; --accent-text: #4F7A00;
  --protein: #2F6FED; --carbs: #0FA896; --fat: #E5456A; --water: #1B8FDB;
  --positive: #1E9E4A; --warning: #E07B00; --negative: #D93636;
  --track: #E2E4E9; --bar-muted: #C9CDD4;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 650; }
p { margin: 0; }
.icon { width: 22px; height: 22px; flex: none; }
.icon.sm { width: 18px; height: 18px; }
.icon.big { width: 44px; height: 44px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.accent { color: var(--accent-text); }
.warn { color: var(--warning); }
.neg { color: var(--negative); }
.pos { color: var(--positive); }
.mt { margin-top: 16px; } .mt-s { margin-top: 8px; } .mb { margin-bottom: 16px; }
.row { display: flex; align-items: center; } .gap { gap: 10px; } .gap-s { gap: 6px; } .wrap { flex-wrap: wrap; }
.between { justify-content: space-between; } .end { justify-content: flex-end; } .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.center { text-align: center; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; min-height: 0 !important; padding: 0 !important; border: 0 !important; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Layout */
#view {
  max-width: 620px; margin: 0 auto; outline: none;
  padding: calc(16px + var(--safe-t)) 16px calc(var(--tabs-h) + var(--safe-b) + 28px);
  min-height: 100vh;
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 18px; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.boot { display: grid; place-items: center; min-height: 60vh; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--track); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Cards */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; }
.card + .card, .card + .section, .section + .card, .section + .section { margin-top: 14px; }
.card.tight { padding: 12px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-title h3 { font-size: 16px; }
.section-title { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 22px 4px 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 > .card, .grid3 > .card { margin-top: 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: var(--radius-s); padding: 10px 12px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 14px; border: 0; cursor: pointer;
  background: var(--surface-2); color: var(--text); font-weight: 650; text-decoration: none;
  transition: transform 0.08s ease, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { background: var(--negative); color: #fff; }
.btn.ghost { background: transparent; color: var(--accent-text); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: var(--surface-2); color: var(--text); cursor: pointer; flex: none;
}
.icon-btn.plain { background: transparent; }
.icon-btn.accent { background: var(--accent); color: var(--on-accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Forms */
label.field { display: block; }
label.field > span, .field-label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; }
input[type=text], input[type=number], input[type=search], input[type=email], input[type=date], input[type=time], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--separator); background: var(--surface-2); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[aria-invalid=true] { border-color: var(--negative); }
.field-error { color: var(--negative); font-size: 13px; margin-top: 4px; }
.input-unit { position: relative; }
.input-unit input { padding-right: 48px; }
.input-unit em { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 14px; }
.search { position: relative; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 42px; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 36px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; font-size: 14px; }
.seg button[aria-pressed=true] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--separator);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 14px; font-weight: 550;
}
.chip[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.options { display: grid; gap: 10px; }
.option {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  padding: 14px 16px; border-radius: 14px; border: 1.5px solid var(--separator); background: var(--surface); cursor: pointer;
}
.option[aria-pressed=true] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.option b { display: block; }
.option small { color: var(--muted); }
.check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--separator); display: grid; place-items: center; flex: none; }
.option[aria-pressed=true] .check { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.check .icon { width: 14px; height: 14px; }

/* Lists */
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; width: 100%;
  border: 0; background: transparent; text-align: left; cursor: pointer; color: var(--text); text-decoration: none;
}
.list-item + .list-item { border-top: 1px solid var(--separator); }
.list-item .meta { color: var(--muted); font-size: 13px; }
.list-item .right { text-align: right; flex: none; }
.list-item:active { background: var(--surface-2); }
.thumb { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; background: var(--surface-2); flex: none; }

/* Rings and bars */
.ring { position: relative; flex: none; }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-label strong { font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.ring-label span { font-size: 12px; color: var(--muted); }
.bar { height: 8px; background: var(--track); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 99px; transition: width 0.3s; }
.macro { flex: 1; min-width: 0; }
.macro-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.macro-val { font-size: 14px; margin: 1px 0 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  height: calc(var(--tabs-h) + var(--safe-b)); padding: 6px 8px var(--safe-b);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--separator);
}
.tabs a {
  flex: 1; max-width: 110px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; border-radius: 12px;
}
.tabs a[aria-current=page] { color: var(--accent-text); }
.workout-pill {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 21;
  bottom: calc(var(--tabs-h) + var(--safe-b) + 10px);
  display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px; border: 0;
  background: var(--accent); color: var(--on-accent); font-weight: 700; box-shadow: 0 6px 20px rgba(0,0,0,.35); cursor: pointer;
}
.offline-banner {
  position: sticky; top: 0; z-index: 30; background: var(--warning); color: #111; text-align: center;
  font-size: 13px; font-weight: 600; padding: calc(6px + var(--safe-t)) 12px 6px;
}

/* Sheets */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center; animation: fade 0.16s ease;
}
.sheet {
  width: 100%; max-width: 620px; max-height: 92vh; background: var(--bg); border-radius: 22px 22px 0 0;
  display: flex; flex-direction: column; animation: up 0.2s ease; padding-bottom: var(--safe-b);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 8px; }
.sheet-head h2 { font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 8px 16px 20px; -webkit-overflow-scrolling: touch; }
.sheet-backdrop.closing { opacity: 0; transition: opacity 0.15s; }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 22px; max-height: 86vh; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0.6; } }

/* Toast */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 12px); transform: translate(-50%, -20px);
  z-index: 60; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: 0.2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--negative); color: #fff; }

/* Empty states */
.empty { text-align: center; padding: 34px 16px; }
.empty h3 { margin: 10px 0 6px; }
.empty .btn { margin-top: 16px; }

/* Charts */
.chart { margin: 0; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--separator); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart .target { stroke: var(--muted); stroke-dasharray: 5 4; stroke-width: 1.2; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend i.dash { background: none; border-top: 2px dashed var(--muted); height: 0; width: 14px; border-radius: 0; vertical-align: 3px; }

/* Food */
.date-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.date-nav strong { font-size: 16px; }
.date-pick { position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 10px; cursor: pointer; }
.date-pick .icon { color: var(--muted); }
/* The native date input sits invisibly on top, so a tap opens the system date picker. */
.date-pick input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; padding: 0; border: 0; opacity: 0; cursor: pointer; }
.meal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.meal-head h3 { font-size: 16px; }
.food-result .name { font-weight: 600; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); vertical-align: 1px; }
.badge.accent { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent-text); }
.nutri-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.nutri-table td { padding: 7px 0; border-top: 1px solid var(--separator); }
.nutri-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.video-box { position: relative; background: #000; border-radius: var(--radius-s); overflow: hidden; }
.video-box video { width: 100%; display: block; max-height: 360px; }
#scanner-video { width: 100%; border-radius: var(--radius-s); background: #000; aspect-ratio: 4/3; object-fit: cover; }

/* Exercises */
.ex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.ex-card { background: var(--surface); border-radius: 16px; overflow: hidden; text-decoration: none; color: var(--text); display: block; }
.ex-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: var(--surface-2); }
.ex-card div { padding: 9px 11px 11px; }
.ex-card b { display: block; font-size: 14px; line-height: 1.25; }
.ex-card span { font-size: 12px; color: var(--muted); }
.demo { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); aspect-ratio: 4/3; }
.demo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: opacity 0.35s ease; }
.demo .frame-b { opacity: 0; }
.demo.flip .frame-b { opacity: 1; }
.demo .demo-ctl { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; }
.demo .demo-ctl button { background: rgba(0,0,0,.6); color: #fff; }
.steps { padding-left: 22px; margin: 0; }
.steps li + li { margin-top: 8px; }
.bullets { padding-left: 20px; margin: 0; }
.bullets li + li { margin-top: 6px; }
.tagrow { display: flex; flex-wrap: wrap; gap: 6px; }

/* Active workout */
.set-table { width: 100%; border-collapse: separate; border-spacing: 0 6px; }
.set-table th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: center; padding: 0 4px; }
.set-table td { text-align: center; padding: 0 3px; }
.set-table td:first-child { width: 34px; color: var(--muted); font-weight: 700; }
.set-table input { text-align: center; min-height: 42px; padding: 6px; }
.set-table tr.done input { border-color: color-mix(in srgb, var(--positive) 60%, transparent); }
.set-done { width: 42px; height: 42px; border-radius: 12px; border: 0; background: var(--surface-2); color: var(--muted); cursor: pointer; display: grid; place-items: center; }
tr.done .set-done { background: var(--positive); color: #08210f; }
.prev { font-size: 12px; color: var(--muted); }
.rest-bar {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 40; width: min(588px, calc(100% - 24px));
  bottom: calc(var(--tabs-h) + var(--safe-b) + 10px);
  background: var(--surface-2); border: 1px solid var(--separator); border-radius: 18px; padding: 10px 12px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 26px rgba(0,0,0,.35);
}
.rest-bar strong { font-size: 24px; font-variant-numeric: tabular-nums; min-width: 66px; }
.workout-top { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: calc(8px + var(--safe-t)) 0 10px; margin-top: calc(-16px - var(--safe-t)); }
.elapsed { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* Onboarding */
.onb { max-width: 520px; margin: 0 auto; }
.onb-progress { height: 4px; background: var(--track); border-radius: 99px; overflow: hidden; margin: 6px 0 22px; }
.onb-progress span { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }
.onb h1 { font-size: 28px; margin-bottom: 6px; }
.onb .lead { color: var(--muted); margin-bottom: 20px; }
.onb-actions { display: flex; gap: 10px; margin-top: 26px; }
.hero-mark { width: 64px; height: 64px; border-radius: 18px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; margin-bottom: 18px; }
.hero-mark .icon { width: 36px; height: 36px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 900px) {
  #view { max-width: 720px; }
  .ex-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
}

/* ───────── Columns used by screens (stack on phones) ───────── */
.cols { display: block; }
.col > :first-child { margin-top: 0; }
.brand { display: none; }

/* ───────── Laptop and desktop ───────── */
@media (min-width: 1000px) {
  :root { --side: 248px; }
  body { font-size: 16.5px; }
  h1 { font-size: 36px; }
  .page-head { margin: 4px 0 24px; }

  /* Sidebar instead of bottom tabs. */
  .tabs {
    top: 0; bottom: 0; right: auto; width: var(--side); height: auto;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 24px 16px; border-top: 0; border-right: 1px solid var(--separator);
    background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; letter-spacing: -0.01em; padding: 0 10px 22px; }
  .brand img { border-radius: 10px; }
  .tabs a { flex: none; max-width: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 12px 14px; font-size: 15px; color: var(--muted); }
  .tabs a:hover { background: var(--surface-2); color: var(--text); }
  .tabs a[aria-current=page] { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent-text); }

  #view { max-width: 1180px; margin: 0 0 0 var(--side); padding: 36px 48px 64px; }
  body:has(#tabs[hidden]) #view { margin: 0 auto; max-width: 860px; }

  .workout-pill { left: calc(50% + var(--side) / 2); bottom: 28px; }
  .toast { left: calc(50% + var(--side) / 2); }
  .rest-bar { bottom: 24px; }
  .offline-banner { margin-left: var(--side); }

  /* Two-column screens. */
  .cols { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 24px; align-items: start; }
  .ex-cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
  .sticky-col { position: sticky; top: 24px; }
  .col > .card:first-child, .col > .list:first-child, .col > .grid2:first-child { margin-top: 0; }
  .first-mt0 { margin-top: 0 !important; }
  .card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
  .card-grid > .card { margin-top: 0; }
  .range-seg { max-width: 420px; }
  .profile-cols { columns: 2; column-gap: 24px; }
  .pgroup { break-inside: avoid; display: inline-block; width: 100%; margin-bottom: 4px; }
  .pgroup .section-title { margin-top: 8px; }

  .card { padding: 20px; }
  .ring { transform-origin: left center; }
  .ex-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 18px; }
  .ex-card b { font-size: 15px; }
  .demo { aspect-ratio: 4 / 3; }
  .seg { max-width: 520px; }
  .sheet { max-width: 640px; }
  .sheet.wide { max-width: 860px; }
}
@media (min-width: 1400px) {
  #view { max-width: 1280px; }
}
