/* ============================================================
   BUILT — global styles
   Mobile-first, dark, clean. Theme via CSS variables.
   ============================================================ */
:root {
  --bg: #0b0d10;
  --bg-2: #12151b;
  --card: #161a21;
  --card-2: #1c212a;
  --line: #262c37;
  --line-2: #333b48;
  --text: #f3f5f8;
  --muted: #98a2b3;
  --muted-2: #6b7585;
  --accent: #c8ff3e;
  --accent-2: #a6e021;
  --accent-ink: #1a2200;
  --blue: #4aa8ff;
  --orange: #ff9f43;
  --red: #ff5e6c;
  --green: #36d39a;
  --purple: #b58bff;
  --radius: 16px;
  --radius-sm: 11px;
  --maxw: 720px;
  --tabbar-h: 64px;
  --topbar-h: 56px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea, button { font-family: inherit; font-size: 1rem; color: var(--text); }
::placeholder { color: var(--muted-2); }
a { color: var(--accent); }

/* ---------- Layout shell ---------- */
#app { min-height: 100%; display: flex; flex-direction: column; }

#topbar {
  position: sticky; top: 0; z-index: 40;
  background: linear-gradient(180deg, rgba(11,13,16,.96), rgba(11,13,16,.82));
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-t);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 900; font-size: 18px;
  box-shadow: 0 0 18px rgba(200,255,62,.35);
}
.brand-text { font-weight: 800; letter-spacing: 2px; font-size: 18px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.view {
  flex: 1; width: 100%; max-width: var(--maxw); margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 28px);
}

/* ---------- Tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(13,16,21,.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex; justify-content: center;
}
.tab {
  flex: 1; max-width: 180px; background: none; border: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--muted-2); font-size: 11px; font-weight: 600;
  padding: 6px 4px; transition: color .15s;
}
.tab-ic { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); }
.tab.active .tab-ic { filter: drop-shadow(0 0 8px rgba(200,255,62,.45)); }

/* ---------- Typography helpers ---------- */
h1,h2,h3,h4 { margin: 0; font-weight: 800; letter-spacing: -.2px; }
.page-title { font-size: 26px; margin-bottom: 2px; }
.page-sub { color: var(--muted); font-size: 14px; margin-bottom: 16px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--muted); font-weight: 700; margin: 22px 2px 10px; }
.section-row { display: flex; align-items: center; justify-content: space-between; margin: 22px 2px 10px; }
.section-row .section-title { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card-tight { padding: 13px; }
.card-row { display: flex; align-items: center; gap: 12px; }
.flex { display: flex; }
.between { justify-content: space-between; }
.center-y { align-items: center; }
.gap8 { gap: 8px; } .gap12 { gap: 12px; } .gap6 { gap: 6px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.col { display: flex; flex-direction: column; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-2); background: var(--card-2); color: var(--text);
  padding: 11px 16px; border-radius: 12px; font-weight: 700; font-size: 15px;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: 0 6px 20px rgba(200,255,62,.22); }
.btn-ghost { background: transparent; border-color: var(--line-2); }
.btn-danger { background: rgba(255,94,108,.12); border-color: rgba(255,94,108,.4); color: var(--red); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn-icon { padding: 9px; width: 40px; height: 40px; border-radius: 11px; }
.btn-pill { border-radius: 999px; }
.btn:disabled { opacity: .45; pointer-events: none; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 11px; border: 1px solid var(--line); background: var(--card);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Chips / pills ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--card-2); border: 1px solid var(--line); color: var(--muted);
}
.chip.accent { background: rgba(200,255,62,.12); border-color: rgba(200,255,62,.35); color: var(--accent); }
.chip.blue { background: rgba(74,168,255,.12); border-color: rgba(74,168,255,.35); color: var(--blue); }
.chip.orange { background: rgba(255,159,67,.12); border-color: rgba(255,159,67,.35); color: var(--orange); }
.chip.green { background: rgba(54,211,154,.12); border-color: rgba(54,211,154,.35); color: var(--green); }
.chip.purple { background: rgba(181,139,255,.12); border-color: rgba(181,139,255,.35); color: var(--purple); }
.chip-row { display: flex; flex-wrap: wrap; gap: 7px; }

.badge { font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); }
.badge.soft { background: var(--card-2); color: var(--muted); border: 1px solid var(--line); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field > label, .label { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 6px; letter-spacing: .3px; }
.input, .select, .textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line-2);
  border-radius: 11px; padding: 12px 13px; color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(200,255,62,.14); }
.textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2398a2b3' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 13px center; padding-right: 36px; }
.input-suffix { position: relative; }
.input-suffix .unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted-2); font-size: 13px; font-weight: 600; pointer-events: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* selectable option cards (quiz, pickers) */
.opt-grid { display: grid; gap: 10px; }
.opt-grid.cols2 { grid-template-columns: 1fr 1fr; }
.opt {
  text-align: left; background: var(--bg-2); border: 1.5px solid var(--line-2);
  border-radius: 13px; padding: 13px 14px; transition: border-color .12s, background .12s; position: relative;
}
.opt .opt-title { font-weight: 700; font-size: 15px; }
.opt .opt-desc { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.opt.selected { border-color: var(--accent); background: rgba(200,255,62,.08); }
.opt.selected::after { content: "✓"; position: absolute; top: 10px; right: 12px; color: var(--accent); font-weight: 900; }

.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 0; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: none; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--line-2); border-radius: 999px; transition: .2s; }
.switch .slider::before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.seg { display: flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: none; background: transparent; color: var(--muted); padding: 8px 6px; border-radius: 8px; font-weight: 700; font-size: 13px; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 13px 0;
  border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: none; }
.list-item .li-title { font-weight: 700; }
.li-sub { color: var(--muted); font-size: 12.5px; }
.li-thumb { width: 44px; height: 44px; border-radius: 11px; background: var(--card-2); display: grid; place-items: center; font-size: 20px; flex: none; overflow: hidden; }
.li-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Progress / stats ---------- */
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 13px; }
.stat .stat-num { font-size: 22px; font-weight: 900; }
.stat .stat-lbl { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.progress { height: 9px; background: var(--bg-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.ring { transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; stroke-linecap: round; }
.ring .bg { stroke: var(--bg-2); }
.ring .fg { stroke: var(--accent); transition: stroke-dashoffset .4s; }

/* macro bars */
.macro { display: flex; flex-direction: column; gap: 5px; }
.macro .progress > span.protein { background: var(--blue); }
.macro .progress > span.carbs { background: var(--orange); }
.macro .progress > span.fat { background: var(--purple); }
.macro .progress > span.water { background: var(--blue); }

/* ---------- Plan carousel ---------- */
.carousel { display: flex; gap: 14px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 4px 2px 6px; margin: 0 -2px; scrollbar-width: none; }
.carousel::-webkit-scrollbar { display: none; }
.plan-card { scroll-snap-align: center; flex: 0 0 86%; max-width: 560px; }
.plan-card.add { display: flex; align-items: center; justify-content: center; min-height: 200px; border-style: dashed; color: var(--muted); }
.dots { display: flex; justify-content: center; gap: 7px; margin-top: 10px; }
.dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--line-2); transition: .2s; }
.dots span.on { background: var(--accent); width: 20px; border-radius: 4px; }

.plan-hero {
  border-radius: var(--radius); padding: 18px; color: #fff; position: relative; overflow: hidden;
  background: linear-gradient(135deg, #1e2530, #11151c);
  border: 1px solid var(--line);
}
.plan-hero.active-plan { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 12px 36px rgba(200,255,62,.12); }
.plan-hero .ph-type { font-size: 12px; color: var(--accent); font-weight: 800; letter-spacing: 1px; text-transform: uppercase; }
.plan-hero .ph-name { font-size: 22px; font-weight: 900; margin: 3px 0 8px; }

/* ---------- Calendar ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 5px; }
.cal-head { color: var(--muted-2); font-size: 11px; text-align: center; font-weight: 700; padding-bottom: 4px; }
.cal-cell { aspect-ratio: 1; border-radius: 10px; background: var(--bg-2); border: 1px solid transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 13px; position: relative; }
.cal-cell.empty { background: transparent; }
.cal-cell.today { border-color: var(--accent); }
.cal-cell.has-workout { background: rgba(200,255,62,.10); }
.cal-cell.done { background: rgba(54,211,154,.16); }
.cal-cell.rest { color: var(--muted-2); }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.cal-dot.done { background: var(--green); }

/* ---------- Set logger ---------- */
.set-row { display: grid; grid-template-columns: 32px 1fr 1fr 44px; gap: 8px; align-items: center; padding: 7px 0; }
.set-row .set-no { color: var(--muted); font-weight: 800; text-align: center; }
.set-row input { text-align: center; padding: 9px 6px; }
.set-row .set-done { width: 38px; height: 38px; border-radius: 10px; border: 1.5px solid var(--line-2); background: var(--bg-2); display: grid; place-items: center; }
.set-row .set-done.on { background: var(--green); border-color: var(--green); color: #07120d; }
.set-head { display: grid; grid-template-columns: 32px 1fr 1fr 44px; gap: 8px; font-size: 11px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; padding-bottom: 4px; }

/* rest timer */
.rest-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  z-index: 45; width: min(94%, var(--maxw)); background: var(--card); border: 1px solid var(--accent);
  border-radius: 14px; padding: 10px 12px; display: flex; align-items: center; gap: 8px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.rest-bar .rt-info { flex: 1; min-width: 0; }
.rest-bar #rt-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rest-bar .rt-time { font-size: 24px; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--accent); line-height: 1.1; }
.rest-bar .btn { flex: none; padding: 8px 11px; }

/* ---------- Modal & sheet ---------- */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.6); backdrop-filter: blur(3px); display: flex; opacity: 0; transition: opacity .18s; }
.overlay.show { opacity: 1; }
.modal { margin: auto; width: min(94%, 560px); max-height: 88vh; overflow: hidden; display: flex; flex-direction: column;
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 20px; box-shadow: var(--shadow);
  transform: translateY(10px); transition: transform .18s; }
.overlay.show .modal { transform: translateY(0); }

.sheet-overlay { align-items: flex-end; }
.sheet { width: 100%; max-width: var(--maxw); margin: 0 auto; max-height: 92vh; overflow: hidden; display: flex; flex-direction: column;
  background: var(--bg-2); border-top-left-radius: 22px; border-top-right-radius: 22px; border: 1px solid var(--line-2); border-bottom: none;
  transform: translateY(100%); transition: transform .22s cubic-bezier(.2,.8,.2,1); }
.sheet-overlay.show .sheet { transform: translateY(0); }
.sheet-grip { width: 40px; height: 4px; border-radius: 999px; background: var(--line-2); margin: 9px auto 2px; flex: none; }

.modal-head, .sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); flex: none; }
.modal-head h3, .sheet-head h3 { font-size: 17px; }
.modal-body, .sheet-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot, .sheet-foot { padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); display: flex; gap: 10px; flex: none; }
.x-btn { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); color: var(--muted); display: grid; place-items: center; font-size: 18px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 99999; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--card-2); border: 1px solid var(--line-2); color: var(--text); padding: 11px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); animation: toastIn .2s ease, toastOut .2s ease forwards 2.4s; max-width: 90%; }
.toast.good { border-color: rgba(54,211,154,.5); }
.toast.bad { border-color: rgba(255,94,108,.5); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .empty-emoji { font-size: 40px; margin-bottom: 8px; }
.empty h3 { color: var(--text); margin-bottom: 6px; }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.kv { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 700; }
.tap { cursor: pointer; }
.linkish { color: var(--accent); font-weight: 700; cursor: pointer; }
.hr-line { height: 1px; background: var(--line); border: none; margin: 16px 0; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.fade-in { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.bars .bar { flex: 1; background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-radius: 6px 6px 3px 3px; min-height: 4px; position: relative; }
.bars .bar .bv { position: absolute; top: -16px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); }
.bars .bar .bl { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted-2); }

/* line chart container */
.chart { width: 100%; height: 150px; }
.chart .grid-l { stroke: var(--line); stroke-width: 1; }
.chart .area { fill: rgba(200,255,62,.12); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart .pt { fill: var(--accent); }

@media (min-width: 560px) {
  .opt-grid.cols2 { grid-template-columns: 1fr 1fr; }
}
