/* 30/FIT — v2 styles. Phone-first; desktop adds a top navigation. */

:root {
  --ink: #17231f;
  --ink-2: #3d4b44;
  --muted: #56655d;          /* 5.6:1 on paper — passes WCAG AA */
  --line: #dfe7e2;
  --line-2: #cfdad3;
  --paper: #f5f8f5;
  --white: #ffffff;
  --green: #1f7659;
  --green-dark: #145640;
  --green-ink: #0d3a2b;
  --mint: #e4f3eb;
  --mint-2: #b9e8cf;
  --amber-bg: #fbf3e4;
  --amber: #b8792a;
  --amber-ink: #7a4a10;
  --red: #a13f3f;
  --orange: #e8761f;
  --blue: #2d6cb0;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(25, 54, 41, .06);
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 'DM Sans', system-ui, sans-serif;
}
h1, h2, h3, strong, .brand { font-family: 'Manrope', 'DM Sans', sans-serif; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); line-height: 1.1; letter-spacing: -.035em; margin: .2rem 0 .5rem; }
h2 { font-size: 1.15rem; letter-spacing: -.02em; margin: 0 0 .5rem; }
p { margin: .35rem 0 1rem; }
a { color: var(--green-dark); }
a:hover { color: var(--green-ink); }
.muted { color: var(--muted); }
.tiny { font-size: .8rem; }
.eyebrow { color: var(--green-dark); font-size: .74rem; font-weight: 800; letter-spacing: .14em; margin: 0 0 .3rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--white); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.icon { display: block; flex: none; }

/* ---------- Top bar & tab bar ---------- */
.topbar { background: var(--white); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1160px; margin: 0 auto; padding: 0 20px; height: 64px; display: flex; align-items: center; gap: 24px; }
.brand { font-size: 1.2rem; font-weight: 800; letter-spacing: -.06em; color: var(--ink); text-decoration: none; }
.brand span { color: var(--green); }
.desktop-nav { display: flex; gap: 6px; flex: 1; }
.desktop-nav a { color: var(--ink-2); font-weight: 600; font-size: .92rem; text-decoration: none; padding: 8px 12px; border-radius: 10px; }
.desktop-nav a:hover { background: var(--paper); }
.desktop-nav a[aria-current="page"] { background: var(--mint); color: var(--green-dark); }
.userbox { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.userbox form { margin: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--green-dark); color: var(--white); display: grid; place-items: center; font: 800 .9rem 'Manrope', sans-serif; flex: none; }
.username { font-weight: 700; font-size: .92rem; max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-button { border: 0; background: transparent; color: var(--muted); width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; cursor: pointer; }
.icon-button:hover { background: var(--paper); color: var(--ink); }

.tabbar { display: none; }

/* ---------- Layout ---------- */
.container { max-width: 1160px; margin: 0 auto; padding: 28px 20px 56px; }
.container.narrow { max-width: 880px; }
.footer { text-align: center; color: var(--muted); font-size: .82rem; padding: 0 20px 32px; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-heading p.muted { margin-bottom: 0; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.panel { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.two-col, .profile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 18px; align-items: start; }
.two-col .panel + .panel, .profile-grid .panel + .panel { margin-top: 0; }
.text-link { font-weight: 700; font-size: .9rem; }

/* ---------- Alerts, chips, buttons ---------- */
.alert { border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; font-size: .94rem; border: 1px solid transparent; }
.alert.success { background: var(--mint); color: var(--green-ink); border-color: #c8e6d6; }
.alert.error { background: #fbeaea; color: #7a2626; border-color: #f0cccc; }
.alert.info { background: #eaf1fa; color: #1f4f85; border-color: #cfdff1; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: .8rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--paper); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.chip-done { background: var(--mint); color: var(--green-dark); border-color: #c8e6d6; }
.chip-muscle { background: #fff1e6; color: #8a3d0a; border-color: #ffd9bd; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 20px; border-radius: 12px; border: 1px solid transparent; font: 700 .95rem 'DM Sans', sans-serif; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--green); color: var(--white); }
.btn.primary:hover { background: var(--green-dark); color: var(--white); }
.btn.secondary { background: var(--white); color: var(--green-dark); border-color: var(--line-2); }
.btn.secondary:hover { background: var(--mint); }
.btn.danger { background: var(--red); color: var(--white); }
.btn.full { width: 100%; }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: .9rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input:not([type]), textarea {
  font: 400 1rem 'DM Sans', sans-serif; color: var(--ink); background: var(--white);
  border: 1px solid var(--line-2); border-radius: 12px; padding: 11px 13px; min-height: 46px; width: 100%;
}
textarea { resize: vertical; }
input:focus, textarea:focus { border-color: var(--green); outline: 3px solid rgba(31, 118, 89, .18); outline-offset: 0; }
.input-suffix { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--muted); }
.input-suffix input { flex: 1; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 700; font-size: .9rem; margin-bottom: 6px; padding: 0; }
.segmented { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.segmented legend { grid-column: 1 / -1; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: flex; align-items: center; justify-content: center; min-height: 46px; padding: 0 10px; border: 1.5px solid var(--line-2); border-radius: 12px; font-weight: 700; text-align: center; cursor: pointer; }
.segmented input:checked + span { border-color: var(--green); background: var(--mint); color: var(--green-dark); }
.segmented input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }
.inline-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.inline-fields legend { grid-column: 1 / -1; }
.check-inline { flex-direction: row; align-items: center; gap: 10px; font-weight: 600; }
.check-inline input { width: 20px; height: 20px; accent-color: var(--red); }
details > summary { cursor: pointer; font-weight: 700; color: var(--green-dark); min-height: 44px; display: flex; align-items: center; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: '+'; display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: 8px; border-radius: 6px; background: var(--mint); font-weight: 800; }
details[open] > summary::before { content: '−'; }

/* ---------- Today ---------- */
.greeting h1 { margin-bottom: 18px; }
.hero { background: var(--green-dark); color: var(--white); border-radius: 22px; padding: 20px 22px; display: flex; align-items: center; gap: 18px; margin-bottom: 18px; }
.hero h1 { margin: 0; font-size: 1.9rem; color: var(--white); }
.hero h1 span { font-size: 1.1rem; color: var(--mint-2); font-weight: 700; }
.hero-hello { margin: 0; font-weight: 800; letter-spacing: .02em; color: var(--mint-2); }
.hero-meta { margin: 2px 0 0; color: #d6efe2; }
.ring { flex: none; }
.backfill a { font-weight: 700; color: #1f4f85; }

.ex-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ex-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: stretch; background: var(--white); border: 1.5px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.ex-row:has(input[type="checkbox"]:checked) { border-color: var(--green); background: #fbfefc; }
.ex-thumb { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 10px 6px 8px 10px; text-decoration: none; color: var(--green-dark); }
.ex-art { width: 64px; height: 64px; border-radius: 12px; background: var(--mint); border: 1px solid #cfe5d8; overflow: hidden; display: block; }
.ex-art svg { width: 100%; height: 100%; display: block; }
.ex-art.sm { width: 48px; height: 48px; }
.ex-thumb:hover .ex-art { border-color: var(--green); }
.ex-howto { display: inline-flex; align-items: center; gap: 3px; font-size: .72rem; font-weight: 800; }
.ex-howto .icon { width: 14px; height: 14px; }
.ex-check { position: relative; flex-direction: row; align-items: center; gap: 10px; padding: 10px 8px; font-weight: 400; cursor: pointer; min-height: 64px; }
.ex-check input, .pick-label input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ex-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.ex-text strong { font-size: .98rem; line-height: 1.25; }
.ex-target { color: var(--green-dark); font-weight: 700; font-size: .86rem; }
.ex-text small { color: var(--muted); font-size: .8rem; }
.tick { width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--line-2); flex: none; display: grid; place-items: center; background: var(--white); }
input:checked + .ex-text + .tick { background: var(--green); border-color: var(--green); }
input:checked + .ex-text + .tick::after { content: ''; width: 12px; height: 7px; border: 3px solid var(--white); border-top: 0; border-right: 0; transform: translateY(-2px) rotate(-45deg); }
input:focus-visible + .ex-text + .tick { outline: 3px solid var(--blue); outline-offset: 2px; }
.ex-amount { flex-direction: row; align-items: center; gap: 6px; padding: 10px 12px 10px 4px; font-size: .8rem; color: var(--muted); }
.ex-amount input { width: 72px; text-align: center; padding: 8px 6px; }
.hint { color: var(--muted); font-size: .88rem; margin: 12px 2px 16px; }
.form-panel { display: flex; flex-direction: column; gap: 10px; }
.save-bar { margin-top: 16px; }

.empty-state { background: var(--white); border: 1px solid var(--line); border-radius: 22px; padding: 40px 24px; text-align: center; box-shadow: var(--shadow); }
.empty-icon { width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 22px; background: var(--green-dark); color: var(--white); display: grid; place-items: center; font: 800 1.6rem 'Manrope', sans-serif; }

/* ---------- Calendar ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 8px; }
.cal-tile { min-height: 72px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; text-decoration: none; padding: 6px 2px; }
.cal-tile strong { font-size: 1.15rem; line-height: 1; }
.cal-tile small { font-size: .64rem; font-weight: 800; letter-spacing: .03em; }
.cal-tile.done { background: var(--green); color: var(--white); }
.cal-tile.done small { color: var(--mint-2); }
.cal-tile.missed { background: var(--amber-bg); border: 1.5px dashed var(--amber); color: var(--amber-ink); }
.cal-tile.today { background: var(--white); border: 2.5px solid var(--green); color: var(--green-dark); }
.cal-tile.done.is-today { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--green); }
.cal-tile.future { background: #edf1ee; color: #6c7a72; }
.cal-tile:hover:not(.future) { filter: brightness(.97); }
.legend, .guide-legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: .84rem; color: var(--ink-2); margin: 14px 2px 0; }
.legend span, .guide-legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i, .guide-legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.lg-done { background: var(--green); }
.lg-missed { background: var(--amber-bg); border: 1.5px dashed var(--amber); }
.lg-future { background: #edf1ee; }
.routine-list { list-style: none; padding: 0; margin: 0; }
.routine-list li { display: flex; align-items: center; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.routine-list li:last-child { border-bottom: 0; }
.routine-list .ex-thumb { padding: 4px; }
.routine-list div { display: flex; flex-direction: column; }
.routine-list small { color: var(--muted); }
.danger-zone > summary { color: var(--red); }
.danger-zone > summary::before { background: #fbeaea; }

/* ---------- Progress ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat strong { display: block; font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: .84rem; }
.good { color: var(--green-dark); }
.chart { width: 100%; height: auto; display: block; margin: 4px 0 16px; font-family: 'DM Sans', sans-serif; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-size: .78rem; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid #edf1ee; white-space: nowrap; }
.num { text-align: right; }
td.good { font-weight: 700; }
.status { font-size: .78rem; font-weight: 800; padding: 3px 9px; border-radius: 999px; }
.status.active { background: #eaf1fa; color: #1f4f85; }
.status.completed { background: var(--mint); color: var(--green-dark); }
.status.ended { background: #edf1ee; color: var(--ink-2); }
.table-progress { display: inline-block; vertical-align: middle; width: 60px; height: 7px; border-radius: 9px; background: #e7eee9; margin-right: 8px; overflow: hidden; }
.table-progress span { display: block; height: 100%; background: var(--green); }

/* ---------- Routine picker ---------- */
.pick-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pick { display: flex; align-items: stretch; border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--white); }
.pick:has(input:checked) { border-color: var(--green); background: #f6fcf8; }
.pick-label { flex: 1; flex-direction: row; align-items: center; gap: 10px; padding: 10px 12px 10px 4px; font-weight: 400; cursor: pointer; position: relative; }
.sticky-action { position: sticky; bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 12px 30px rgba(25, 54, 41, .12); }

/* ---------- Profile & users ---------- */
.bmi-panel { text-align: center; }
.bmi-number { font: 800 3rem/1 'Manrope', sans-serif; color: var(--green-dark); margin: 6px 0; }
.bmi-scale { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; font-size: .74rem; color: var(--ink-2); margin: 12px 0; }
.bmi-scale span { background: var(--paper); border-radius: 10px; padding: 8px 4px; }
.user-list { list-style: none; margin: 0; padding: 0; }
.user-list li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.user-list li:last-child { border-bottom: 0; }
.user-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.user-info small { color: var(--muted); }
.user-info .chip { font-size: .7rem; padding: 2px 8px; }
.reset form { margin-top: 6px; }

/* ---------- Auth ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--paper); }
.auth-card { width: min(100%, 430px); background: var(--white); border: 1px solid var(--line); border-radius: 22px; padding: 32px; box-shadow: var(--shadow); }
.auth-card .brand { display: inline-block; margin-bottom: 22px; }
.auth-switch { text-align: center; color: var(--muted); font-size: .88rem; margin: 20px 0 0; }

/* ---------- Exercise guide (full screen) ---------- */
.guide-body { background: var(--paper); }
.guide { max-width: 1240px; margin: 0 auto; padding: 0 20px 32px; }
.guide-top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 12px 0; background: var(--paper); }
.guide-top h1 { font-size: clamp(1.3rem, 3.5vw, 2rem); margin: 0; }
.guide-top .eyebrow { margin: 0; }
.guide-close { width: 48px; height: 48px; border-radius: 14px; background: var(--white); border: 1px solid var(--line); display: grid; place-items: center; color: var(--ink); flex: none; }
.guide-close:hover { background: var(--mint); }
.guide-intro p { max-width: 70ch; color: var(--ink-2); margin: 4px 0 10px; }
.step-dots { display: flex; gap: 8px; margin: 16px 0 12px; overflow-x: auto; }
.step-dots a { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--white); border: 1px solid var(--line); text-decoration: none; color: var(--ink-2); font-weight: 700; font-size: .85rem; white-space: nowrap; min-height: 40px; }
.step-dots span { width: 28px; height: 28px; border-radius: 50%; background: var(--green-dark); color: var(--white); display: grid; place-items: center; font: 800 .85rem 'Manrope', sans-serif; }
.steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.step { background: var(--white); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; box-shadow: var(--shadow); scroll-margin-top: 80px; }
.step:target { border-color: var(--green); box-shadow: 0 0 0 3px var(--mint-2); }
.step-art { margin: 10px 10px 0; border-radius: 14px; overflow: hidden; background: #f2f7f3; }
.fig { width: 100%; height: auto; display: block; border-radius: 14px; }
.step-body { padding: 14px 18px 18px; }
.step-num { margin: 0; color: var(--green-dark); font-weight: 800; font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; }
.step-body h2 { font-size: 1.2rem; margin: 2px 0 8px; }
.cues { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); }
.cues li::marker { color: var(--green); font-weight: 800; }
.lg-muscle { background: #ff6b1f; opacity: .8; }
.lg-move { background: var(--orange); height: 4px !important; border-radius: 4px; }
.lg-guide { background: repeating-linear-gradient(90deg, var(--blue) 0 5px, transparent 5px 9px); height: 3px !important; }
.lg-ghost { background: #cad8d0; }
.guide-extra { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 18px; }
.guide-extra .panel + .panel { margin-top: 0; }
.mistakes { margin: 0; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.mistakes li { display: flex; gap: 10px; align-items: flex-start; }
.mistakes li::before { content: '×'; flex: none; width: 22px; height: 22px; border-radius: 50%; background: #fbeaea; color: var(--red); display: grid; place-items: center; font-weight: 800; line-height: 1; }
.guide-done { margin: 20px auto 0; max-width: 420px; }

/* ---------- Phones ---------- */
@media (max-width: 860px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col, .profile-grid, .guide-extra, .pick-list { grid-template-columns: minmax(0, 1fr); }
  .cal-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  /* Guide: swipe between steps. */
  .steps { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 12px; margin: 0 -20px; padding: 0 20px 6px; scroll-padding: 0 20px; }
  .step { flex: 0 0 88%; scroll-snap-align: start; }
}

@media (max-width: 760px) {
  body.app { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .desktop-nav { display: none; }
  .topbar-inner { height: 56px; padding: 0 16px; gap: 12px; }
  .container { padding: 18px 16px 40px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--white); border-top: 1px solid var(--line);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 50px; font-size: .72rem; font-weight: 600; color: var(--muted); text-decoration: none; border-radius: 12px; }
  .tabbar a[aria-current="page"] { color: var(--green-dark); font-weight: 800; background: var(--mint); }
  .hero { padding: 18px; gap: 14px; }
  .hero h1 { font-size: 1.65rem; }
  .ex-row { grid-template-columns: auto minmax(0, 1fr); }
  .ex-amount { grid-column: 2; padding: 0 12px 10px 8px; justify-content: flex-end; }
  .sticky-action { bottom: calc(var(--tabbar-h) + 10px); flex-direction: column; align-items: stretch; }
  .panel { padding: 16px; }
  .guide { padding: 0 16px 24px; }
  .steps { margin: 0 -16px; padding: 0 16px 6px; }
  .footer { padding-bottom: 20px; }
}

@media (max-width: 380px) {
  .username { display: none; }
  .ex-art { width: 54px; height: 54px; }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
