/* Gym Tracker — tema escuro sólido com destaque âmbar, mobile-first */
:root {
  color-scheme: dark;
  --bg: #0b0b0c;
  --surface: #151517;
  --surface-2: #1f1f22;
  --line: #2a2a2e;
  --line-2: #3a3a40;
  --text: #f4f4f5;
  --text-2: #a1a1aa;
  --text-3: #71717a;
  --accent: #f59e0b;
  --accent-hi: #fbbf24;
  --accent-ink: #1c1303;
  --accent-soft: #261c08;
  --danger: #ef4444;
  --gut: 16px;
  --r: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.4 system-ui, -apple-system, Roboto, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  user-select: none;
}
body:has(dialog[open]) { overflow: hidden; }
input, textarea { font: inherit; color: inherit; user-select: text; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
[hidden] { display: none !important; }

.i { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Layout ---------- */
.view {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 12px) var(--gut) calc(92px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#workout { padding-bottom: calc(24px + var(--safe-b)); }
.top { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.brand h1 { font-size: 17px; font-weight: 700; }
.brand p { font-size: 13px; color: var(--text-3); }
.logo { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.label { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.accent { color: var(--accent-hi); }
.link { color: var(--accent); font-size: 14px; font-weight: 600; padding: 8px 0; }

/* ---------- Botões ---------- */
.icon-btn {
  width: 44px; height: 44px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text-2);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.icon-btn.plain { background: none; border-color: transparent; }
.icon-btn.toggle[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-hi); }
.btn {
  height: 48px; padding: 0 20px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
  font-size: 15px; font-weight: 600; white-space: nowrap;
}
.btn:active, .icon-btn:active, .chip:active, .set:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { background: var(--surface-2); border-color: var(--line); color: var(--text-3); transform: none; }
.btn.sm { height: 38px; padding: 0 14px; font-size: 14px; }
.btn.block { width: 100%; }

/* ---------- Chips, segmentos, busca ---------- */
.scroller {
  display: flex; gap: 8px;
  overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--gut)); padding: 0 var(--gut);
}
.scroller::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; height: 38px; padding: 0 14px;
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 19px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text-2);
  font-size: 14px; font-weight: 500; white-space: nowrap;
}
.chip .n { font-size: 12px; color: var(--text-3); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-hi); }
.chip.on .n { color: var(--accent); }
.chip.add { border-style: dashed; color: var(--accent); }
.chip .i { width: 16px; height: 16px; }

.seg { display: flex; padding: 3px; gap: 2px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.seg button { flex: 1; height: 36px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--text-2); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--accent-hi); font-weight: 600; }
.seg.sm button { height: 30px; font-size: 13px; padding: 0 10px; }

.search {
  display: flex; align-items: center; gap: 10px;
  height: 46px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text-3);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 16px; color: var(--text); }
.search input::placeholder { color: var(--text-3); }

.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 12px; border-radius: 12px;
  border: 1px solid var(--accent); background: var(--accent-soft);
  font-size: 14px;
}
.banner p { flex: 1; min-width: 0; }

/* ---------- Catálogo agrupado por músculo ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.groups { display: flex; flex-direction: column; gap: 8px; }
.group { border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); }
.group-head {
  position: sticky; top: var(--safe-t); z-index: 5;
  width: 100%; min-height: 56px; padding: 0 14px;
  display: flex; align-items: center; gap: 10px; text-align: left;
  border-radius: var(--r); background: var(--surface);
}
.group.open .group-head { border-radius: var(--r) var(--r) 0 0; border-bottom: 1px solid var(--line); }
.group-name { flex: 1; font-size: 16px; font-weight: 600; }
.group-total { font-size: 13px; color: var(--text-3); }
.group-sel {
  min-width: 24px; height: 24px; padding: 0 7px;
  display: grid; place-items: center;
  border-radius: 12px; background: var(--accent); color: var(--accent-ink);
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.chev { color: var(--text-3); transition: transform .2s; }
.group.open .chev { transform: rotate(180deg); }

.ex {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 4px 4px 4px 14px;
  content-visibility: auto; contain-intrinsic-size: auto 56px;
}
.ex + .ex { border-top: 1px solid var(--line); }
.ex:last-child { border-radius: 0 0 var(--r) var(--r); }
.ex.on { background: var(--accent-soft); }
.ex.on .ex-name { color: var(--accent-hi); }
.check {
  width: 24px; height: 24px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 7px; border: 2px solid var(--line-2); color: transparent;
}
.check .i { width: 16px; height: 16px; stroke-width: 3; }
.ex.on .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ex-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ex-name { font-size: 15px; font-weight: 600; line-height: 1.3; }
.ex-meta { font-size: 13px; color: var(--text-3); }
.yt .i { width: 30px; height: 22px; }
.yt:active .i { opacity: .8; }

/* ---------- Barra inferior ---------- */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px var(--gut) calc(12px + var(--safe-b));
  background: var(--bg); border-top: 1px solid var(--line);
}
.bar-in { max-width: 448px; margin: 0 auto; display: flex; align-items: center; gap: 16px; }
.count { display: flex; flex-direction: column; line-height: 1.15; }
.count strong { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar .btn { flex: 1; }

/* ---------- Treino ---------- */
.clock { flex: 1; text-align: center; font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }

.rest {
  position: sticky; top: calc(var(--safe-t) + 8px); z-index: 10;
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px 14px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface);
  transition: border-color .2s;
}
.rest.ding { border-color: var(--accent); }
.rest-time { flex: 1; font-size: 40px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.rest.running .rest-time { color: var(--accent-hi); }
.progress { height: 4px; border-radius: 2px; overflow: hidden; background: var(--surface-2); }
.progress div { height: 100%; background: var(--accent); transform-origin: left; transition: transform .25s linear; }

.wo {
  display: flex; flex-direction: column; gap: 12px;
  padding: 12px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface);
}
.wo.done { border-color: var(--accent); }
.wo-head { display: flex; align-items: center; gap: 10px; }
.wo-num {
  width: 28px; height: 28px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 8px; background: var(--surface-2);
  font-size: 13px; font-weight: 700; color: var(--text-2); font-variant-numeric: tabular-nums;
}
.wo.done .wo-num { background: var(--accent); color: var(--accent-ink); }
.drag { touch-action: none; cursor: grab; color: var(--text-3); }
.wo-row { display: flex; gap: 8px; }
.load {
  width: 96px; height: 48px; flex-shrink: 0;
  display: flex; align-items: center; gap: 4px; padding: 0 10px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
}
.load:focus-within { border-color: var(--accent); }
.load input { width: 100%; min-width: 0; border: 0; outline: 0; background: none; text-align: right; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.load input::placeholder { color: var(--text-3); }
.load span { font-size: 13px; color: var(--text-3); }
.sets { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.set {
  height: 48px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg);
  font-size: 16px; font-weight: 700; color: var(--text-2);
}
.set.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sets.single { grid-template-columns: 1fr; }

/* SortableJS */
.ghost { opacity: .3; }
.chosen { border-color: var(--accent); }
.dragging { border-color: var(--accent); box-shadow: 0 16px 40px #000; opacity: 1 !important; }


/* ---------- Diálogos (bottom sheets) ---------- */
dialog {
  position: fixed; inset: auto 0 0; margin: 0 auto;
  width: 100%; max-width: 480px; max-height: 90dvh;
  border: 0; border-top: 1px solid var(--line); border-radius: 20px 20px 0 0;
  padding: 0; background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .65); }
dialog[open] { animation: sheet-in .22s cubic-bezier(.2, .8, .2, 1); }
@keyframes sheet-in { from { transform: translateY(32px); opacity: 0; } }
.sheet {
  display: flex; flex-direction: column; gap: 14px;
  max-height: 90dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 18px var(--gut) calc(18px + var(--safe-b));
}
.sheet h3 { font-size: 18px; font-weight: 700; }
.sheet p { white-space: pre-line; }
.actions { display: flex; flex-direction: row-reverse; gap: 8px; }
.actions .btn { flex: 1; }

.input {
  width: 100%; padding: 12px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  font-size: 16px; outline: 0;
}
.input:focus { border-color: var(--accent); }

.note { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 13px; }
.note.err { border-color: var(--danger); color: #fca5a5; }

/* Fichas e histórico */
.item { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--bg); }
.item.on { border-color: var(--accent); }
.item-title { font-size: 15px; font-weight: 600; }
.item-sub { font-size: 13px; color: var(--text-3); line-height: 1.45; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-hi); }
.item summary { color: var(--accent); font-size: 14px; font-weight: 500; padding: 4px 0; cursor: pointer; }
.hist-ex { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.hist-ex b { font-weight: 600; color: var(--accent-hi); white-space: nowrap; font-variant-numeric: tabular-nums; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 40px 16px; text-align: center; font-size: 14px; color: var(--text-3); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 100; inset: auto; margin: 0;
  left: 50%; top: calc(var(--safe-t) + 12px);
  width: max-content; max-width: calc(100% - 32px);
  padding: 12px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transform: translate(-50%, -16px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: var(--accent); }
.toast.err { border-color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
