:root {
  --bg: #0e1116;
  --surface: #171b22;
  --surface-2: #1f242d;
  --border: #39414e;
  --text: #ffffff;
  --dim: #b8c0cc;
  --accent: #22b8a6;
  --accent-dim: #14544c;
  --accent-glow: rgba(34, 184, 166, 0.14);
  --hot: #ff5c33;
  --ok: #3ddc84;
  --warn: #ffb020;
  --err: #ff5470;
  --radius: 14px;
  --tap: 48px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior-y: contain; }
body { padding-top: env(safe-area-inset-top); padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

.app { max-width: 640px; margin: 0 auto; padding: 0 14px; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 0 10px; }
.topbar h1 { font-size: 21px; margin: 0; }
.meta { font-size: 13px; color: var(--dim); font-weight: 600; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(14,17,22,.94); backdrop-filter: blur(12px); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { background: none; border: 0; padding: 8px 0 10px; font-size: 12px; font-weight: 600; color: var(--dim);
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 60px; }
.tabbar button .ico { font-size: 21px; filter: grayscale(1); opacity: .7; }
.tabbar button[aria-selected="true"] { color: var(--accent); }
.tabbar button[aria-selected="true"] .ico { filter: none; opacity: 1; }

/* ---------- blocos ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.hl { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-glow), transparent 70%), var(--surface); }
.card h2 { font-size: 17px; margin: 0 0 4px; }
.card h3 { font-size: 15px; margin: 0; }
.sub { color: var(--dim); font-size: 14px; }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 8px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); font-weight: 700; margin: 20px 2px 8px; }
.empty { text-align: center; padding: 28px 12px; color: var(--dim); }
.empty .big { font-size: 40px; }

.btn { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; min-height: var(--tap);
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); font-weight: 700; padding: 10px 14px; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04110f; }
.btn.danger { color: var(--err); border-color: #5a2230; }
.btn.ghost { background: transparent; }
.btn.sm { width: auto; min-height: 38px; padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: .4; }
.btns { display: flex; gap: 8px; }
.btns > .btn { flex: 1; }
.link { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 8px 0; cursor: pointer; }
.icon-btn { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; min-width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 16px; cursor: pointer; padding: 0 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 9px 14px; font-weight: 600;
  font-size: 15px; cursor: pointer; min-height: 42px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #04110f; }
.tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-dim); color: #bff5ec; }

.chip-sync { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; font-size: 12px; font-weight: 700;
  padding: 6px 10px; color: var(--dim); cursor: pointer; white-space: nowrap; }
.chip-sync.ok { color: var(--ok); }
.chip-sync.pending { color: var(--warn); }
.chip-sync.err { color: var(--err); }

input.field, select.field, textarea.field { width: 100%; min-height: var(--tap); background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; font-size: 16px; }
input.field:focus, textarea.field:focus { outline: 2px solid var(--accent); border-color: transparent; }
label.lbl { display: block; font-size: 13px; color: var(--dim); font-weight: 700; margin: 12px 0 6px; }

/* ---------- questionário ---------- */
#onboarding { max-width: 560px; margin: 0 auto; padding: 24px 18px 40px; min-height: 100vh; display: flex; flex-direction: column; }
.ob-progress { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-bottom: 28px; }
.ob-progress i { display: block; height: 100%; background: var(--accent); transition: width .25s; }
.ob-q { font-size: 26px; font-weight: 800; line-height: 1.2; margin: 0 0 8px; }
.ob-hint { color: var(--dim); margin: 0 0 22px; }
.ob-body { flex: 1; }
.ob-foot { display: flex; gap: 10px; margin-top: 24px; }
.ob-foot .btn { flex: 1; }
.ob-foot .btn.back { flex: 0 0 30%; }
.freq { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.freq button { min-height: 64px; font-size: 24px; font-weight: 800; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
.freq button.on { background: var(--accent); color: #04110f; border-color: var(--accent); }
.wd { display: grid; grid-template-columns: 1fr; gap: 8px; }
.wd button { text-align: left; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2);
  font-weight: 700; font-size: 17px; cursor: pointer; display: flex; justify-content: space-between; }
.wd button.on { border-color: var(--accent); background: var(--accent-glow); }
.wd button.on::after { content: "✓"; color: var(--accent); }

/* ---------- plano ---------- */
.day-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.ex-line { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--border); }
.ex-line:first-of-type { border-top: 0; }
.ex-line .name { flex: 1; min-width: 0; }
.ex-line .name b { display: block; font-size: 15px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.stepper button { background: var(--surface-2); border: 0; width: 34px; height: 36px; font-size: 18px; cursor: pointer; }
.stepper span { min-width: 54px; text-align: center; font-size: 13px; font-weight: 700; }

/* ---------- treino ---------- */
.wo-head { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.wo-head input[type=date] { flex: 1; min-width: 0; }
input, select, textarea { min-width: 0; max-width: 100%; }
.ex { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.ex.complete { border-color: var(--ok); }
.ex-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.ex-top h3 { font-size: 17px; margin: 0 0 4px; }
.last { font-size: 13px; color: var(--dim); margin: 6px 0 8px; }
.last b { color: var(--text); }
.set { display: grid; grid-template-columns: 28px minmax(0,1fr) minmax(0,1fr) 48px 34px; gap: 6px; align-items: center; margin-top: 6px; }
.set.one { grid-template-columns: 28px minmax(0,1fr) 48px 34px; }
.set .n { text-align: center; font-weight: 800; color: var(--dim); }
.set input { width: 100%; min-height: 48px; text-align: center; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; font-size: 18px; font-weight: 700; padding: 0 4px; }
.set input::placeholder { color: #5b6574; font-weight: 600; }
.set input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.set .done { min-height: 48px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); font-size: 20px; cursor: pointer; color: var(--dim); }
.set.is-done .done { background: var(--ok); border-color: var(--ok); color: #03140a; }
.set.is-done input { border-color: #2c6b48; }
.set .del { background: none; border: 0; color: var(--dim); font-size: 18px; cursor: pointer; }
.set-labels { display: grid; grid-template-columns: 28px minmax(0,1fr) minmax(0,1fr) 48px 34px; gap: 6px; font-size: 11px; color: var(--dim); text-align: center; font-weight: 700; text-transform: uppercase; }
.set-labels.one { grid-template-columns: 28px minmax(0,1fr) 48px 34px; }
.ex-note { margin-top: 8px; min-height: 40px; font-size: 14px; }
.notice { background: rgba(255,176,32,.1); border: 1px solid #6b4d12; color: #ffd98a; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.sticky-foot { position: sticky; bottom: calc(68px + env(safe-area-inset-bottom)); padding: 10px 0; background: linear-gradient(transparent, var(--bg) 30%); }

/* ---------- histórico ---------- */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button { border: 0; background: none; padding: 9px; border-radius: 9px; font-weight: 700; color: var(--dim); cursor: pointer; }
.seg button.on { background: var(--surface-2); color: var(--text); }
.sess { cursor: pointer; }
.sess-detail { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
.sess-detail .exr { margin-bottom: 8px; }
.sets-txt { font-size: 14px; color: var(--dim); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl td, table.tbl th { padding: 8px 4px; border-top: 1px solid var(--border); text-align: left; vertical-align: top; }
table.tbl th { color: var(--dim); font-size: 12px; text-transform: uppercase; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--dim); }
svg.spark { width: 100%; height: 70px; display: block; margin: 4px 0 10px; }

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); border: 1px solid var(--border); border-bottom: 0; border-radius: 18px 18px 0 0; width: 100%; max-width: 640px;
  max-height: 92vh; overflow: auto; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .2s ease; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet h2 { margin: 0 0 6px; font-size: 19px; }
.pick-list { margin-top: 10px; }
.pick { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; text-align: left; background: none; border: 0;
  border-top: 1px solid var(--border); padding: 12px 2px; cursor: pointer; }
.pick .add { font-size: 22px; color: var(--accent); font-weight: 800; }
.pick.added .add { color: var(--ok); }
.sheet-top { position: sticky; top: -16px; background: var(--surface); padding-top: 4px; padding-bottom: 8px; z-index: 1; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
.chips.scroll .chip { flex: 0 0 auto; min-height: 36px; padding: 6px 12px; font-size: 14px; }

#toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 80;
  display: flex; gap: 10px; align-items: center; background: #2a313c; border: 1px solid var(--border); padding: 10px 14px; border-radius: 12px;
  font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; pointer-events: auto; }
#toast button { background: none; border: 0; color: var(--accent); font-weight: 800; cursor: pointer; }

.code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 18px; letter-spacing: .04em; background: var(--bg);
  border: 1px dashed var(--border); border-radius: 10px; padding: 12px; text-align: center; word-break: break-all; user-select: all; }
