/* ===== Base ===== */
:root {
  --bg: #0b0d12;
  --bg-2: #141821;
  --bg-3: #1c2130;
  --line: #262c3b;
  --text: #ecf0f1;
  --muted: #9aa3b2;
  --accent: #2ecc71;
  --accent-2: #27ae60;
  --warn: #f1c40f;
  --danger: #e74c3c;
  --info: #3498db;
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
  overscroll-behavior-y: contain;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: .4rem 0; }
small, .muted { color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
[hidden] { display: none !important; }

/* ===== Barra superior ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .5rem;
  padding: calc(.6rem + var(--safe-t)) .9rem .6rem;
  background: rgba(11,13,18,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: .02em; flex: 1; text-transform: uppercase; }
.topbar-actions { display: flex; gap: .4rem; }
.icon-btn {
  background: var(--bg-3); color: var(--text); border: 1px solid var(--line);
  width: 40px; height: 40px; border-radius: 50%; font-size: 1.1rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { transform: scale(.96); }

/* ===== Conteúdo ===== */
.view { padding: .9rem .9rem 1.5rem; max-width: 760px; margin: 0 auto; }
.card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem; margin-bottom: .8rem;
}
.card.compact { padding: .7rem .8rem; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .4rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.stack > * + * { margin-top: .6rem; }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.empty .big { font-size: 2.4rem; margin-bottom: .4rem; }

/* ===== Botões ===== */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--bg-3); color: var(--text);
  border-radius: 12px; padding: .7rem 1rem; font-size: 1rem; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06250f; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: .4rem .7rem; font-size: .9rem; min-height: 36px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

/* ===== Chips / badges ===== */
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px;
  padding: .15rem .6rem; font-size: .82rem; color: var(--muted); white-space: nowrap;
}
.chip.accent { color: var(--accent); border-color: rgba(46,204,113,.4); }
.chip.warn { color: var(--warn); border-color: rgba(241,196,15,.4); }
.chip.info { color: var(--info); border-color: rgba(52,152,219,.4); }
.badge-day {
  font-size: .75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--accent); background: rgba(46,204,113,.12); padding: .15rem .5rem; border-radius: 6px;
}

/* ===== Formulários ===== */
label.field { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
label.field span { display: block; margin-bottom: .25rem; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=url], select, textarea {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: .6rem .7rem; font-size: 1rem; min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(46,204,113,.5); border-color: var(--accent); }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.switch { display: flex; justify-content: space-between; align-items: center; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.switch:last-child { border-bottom: 0; }
.switch small { display: block; }

/* ===== Tabela de prescrição (igual ao formato do treino) ===== */
.ptable { width: 100%; border-collapse: collapse; font-size: .95rem; }
.ptable th { text-align: left; color: var(--muted); font-weight: 600; font-size: .8rem; padding: .3rem .25rem; border-bottom: 1px solid var(--line); }
.ptable td { padding: .55rem .25rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.ptable tr:last-child td { border-bottom: 0; }
.ptable td.num, .ptable th.num { text-align: center; white-space: nowrap; }
.ptable .exname { font-weight: 600; }
.ptable .exname button { all: unset; cursor: pointer; }
.ptable .exname button:hover { text-decoration: underline; }
.ptable .exnote { display: block; font-size: .8rem; color: var(--muted); font-weight: 400; }

/* ===== Sessão de treino ===== */
.session-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.session-head .elapsed { font-variant-numeric: tabular-nums; color: var(--muted); }
.ex-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; margin-bottom: .8rem; }
.ex-card.done { border-color: rgba(46,204,113,.45); }
.ex-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.ex-head h3 { flex: 1; }
.ex-head .ex-actions { display: flex; gap: .3rem; }
.ex-presc { display: flex; gap: .35rem; flex-wrap: wrap; margin: .35rem 0 .5rem; }
.ex-prev { font-size: .82rem; color: var(--muted); margin-bottom: .4rem; }
.ex-hint { font-size: .82rem; color: var(--warn); margin-bottom: .4rem; }
.sets { width: 100%; border-collapse: collapse; }
.sets th { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; padding: .2rem .15rem; text-align: center; }
.sets th:first-child { text-align: left; }
.sets td { padding: .25rem .15rem; text-align: center; }
.sets td:first-child { text-align: left; width: 28px; color: var(--muted); font-weight: 700; }
.sets td.prev { font-size: .8rem; color: var(--muted); white-space: nowrap; width: 72px; }
.sets input { text-align: center; padding: .45rem .2rem; min-height: 42px; font-size: 1.05rem; font-weight: 600; }
.sets input::placeholder { color: #566074; font-weight: 400; }
.sets tr.done input { color: var(--accent); }
.sets tr.done { background: rgba(46,204,113,.06); }
.check {
  width: 44px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-3);
  color: var(--muted); font-size: 1.2rem; cursor: pointer;
}
.check.on { background: var(--accent); color: #06250f; border-color: var(--accent); }
.set-actions { display: flex; gap: .4rem; margin-top: .4rem; justify-content: flex-end; }

body.has-rest { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 84px); }

/* ===== Barra de descanso ===== */
.rest-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b)); z-index: 30;
  background: #10231a; border-top: 2px solid var(--accent);
  padding: .6rem .9rem; display: flex; align-items: center; gap: .7rem;
  box-shadow: 0 -8px 24px rgba(0,0,0,.5);
}
.rest-bar.over { background: #2a1c10; border-top-color: var(--warn); }
.rest-bar .ring { width: 58px; height: 58px; flex: none; position: relative; }
.rest-bar .ring svg { transform: rotate(-90deg); }
.rest-bar .ring circle { fill: none; stroke-width: 5; }
.rest-bar .ring .bgc { stroke: rgba(255,255,255,.12); }
.rest-bar .ring .fgc { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .25s linear; }
.rest-bar .ring .t { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 800; font-variant-numeric: tabular-nums; font-size: .95rem; }
.rest-bar .info { flex: 1; min-width: 0; }
.rest-bar .info strong { display: block; font-size: .95rem; }
.rest-bar .info small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rest-bar .ctl { display: flex; gap: .35rem; }
.rest-bar .ctl .btn { padding: .4rem .55rem; min-height: 38px; font-size: .85rem; }

/* ===== Faixa de treino ativo ===== */
.active-banner {
  position: fixed; left: .9rem; right: .9rem; bottom: calc(var(--nav-h) + var(--safe-b) + .6rem); z-index: 25;
  background: var(--accent); color: #06250f; font-weight: 700; border-radius: 12px; padding: .7rem .9rem;
  display: flex; justify-content: space-between; align-items: center; box-shadow: 0 8px 24px rgba(0,0,0,.45);
}

/* ===== Navegação inferior ===== */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(20,24,33,.96); backdrop-filter: blur(8px); border-top: 1px solid var(--line);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .7rem; font-weight: 600;
}
.bottomnav a .ico { font-size: 1.3rem; }
.bottomnav a.active { color: var(--accent); }

/* ===== Toast / diálogos ===== */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 1rem);
  background: #222a3a; color: var(--text); padding: .6rem 1rem; border-radius: 999px; z-index: 50;
  border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,.5); font-size: .95rem; max-width: 90vw; text-align: center;
}
.dialog { border: 1px solid var(--line); background: var(--bg-2); color: var(--text); border-radius: 16px; padding: 1rem; width: min(92vw, 520px); }
.dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
.modal { max-height: 90vh; overflow: auto; padding: 0; }
.modal .modal-head { position: sticky; top: 0; background: var(--bg-2); display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--line); z-index: 1; }
.modal .modal-body { padding: 1rem; }

/* ===== Imagens de exercício ===== */
.ex-img-wrap { position: relative; background: #fff; border-radius: 12px; overflow: hidden; aspect-ratio: 4/3; display: flex; align-items: center; justify-content: center; }
.ex-img-wrap img { width: 100%; height: 100%; object-fit: contain; }
.ex-img-wrap .ph { color: #666; font-size: .9rem; padding: 1rem; text-align: center; }
.ex-img-nav { display: flex; gap: .4rem; margin-top: .5rem; }
.cues { padding-left: 1.1rem; margin: .4rem 0; }
.cues li { margin: .2rem 0; }

/* ===== Listas ===== */
.list-item {
  display: flex; justify-content: space-between; align-items: center; gap: .6rem;
  padding: .75rem 0; border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: 0; }
.list-item .meta { color: var(--muted); font-size: .85rem; }
.list-item .lead { font-weight: 600; }
.kpi { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.kpi .k { background: var(--bg-3); border-radius: 10px; padding: .6rem; text-align: center; }
.kpi .k b { display: block; font-size: 1.2rem; }
.kpi .k small { font-size: .72rem; }

/* ===== Gráfico ===== */
.chart { width: 100%; height: 180px; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart .dot { fill: var(--accent); }
.chart text { fill: var(--muted); font-size: 10px; }

/* ===== Cronômetro de corrida ===== */
.stopwatch { text-align: center; padding: .8rem 0; }
.stopwatch .time { font-size: 2.8rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.laps { max-height: 180px; overflow: auto; font-variant-numeric: tabular-nums; }

/* ===== Edição de treino ===== */
.edit-ex { border: 1px solid var(--line); border-radius: 12px; padding: .6rem; margin-bottom: .6rem; background: var(--bg); }
.edit-ex .grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.edit-ex .grid-4 label { font-size: .72rem; color: var(--muted); }
.edit-ex input { min-height: 40px; padding: .4rem .5rem; }
.edit-ex .tools { display: flex; gap: .3rem; justify-content: flex-end; margin-top: .4rem; }

pre.preview { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .6rem; font-size: .8rem; overflow: auto; white-space: pre-wrap; }

@media (min-width: 640px) {
  .view { padding: 1.2rem; }
}
