:root {
  --bg: #0a0c10;
  --surface: #12151c;
  --surface2: #1a1f2b;
  --surface3: #222836;
  --border: #2a3142;
  --text: #f0f3fa;
  --muted: #8b95a8;
  --accent: #3dd68c;
  --accent2: #4f8cff;
  --warn: #ffb020;
  --danger: #ff5d5d;
  --peito: #ff5d5d;
  --costas: #ff8c42;
  --ombros: #ffb020;
  --bracos: #3dd68c;
  --pernas: #4f8cff;
  --posterior: #a78bfa;
  --radius: 16px;
  --nav-h: 68px;
  --top-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .65rem 1rem;
  padding-top: max(.65rem, env(safe-area-inset-top));
  background: rgba(10,12,16,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  flex-shrink: 0;
}

.topbar-brand { display: flex; align-items: center; gap: .6rem; }
.topbar-brand strong { font-size: .95rem; display: block; }
.topbar-brand small { color: var(--muted); font-size: .72rem; }

.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 0 12px rgba(61,214,140,.5);
}

.date-pill {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .35rem .6rem;
  border-radius: 99px;
  font-size: .78rem;
  width: auto;
}

/* Content */
.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 1rem);
  -webkit-overflow-scrolling: touch;
}

.page { display: none; animation: fadeIn .25s ease; }
.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.page-title { font-size: 1.35rem; font-weight: 700; margin-bottom: .15rem; }
.page-sub { color: var(--muted); font-size: .85rem; margin-bottom: 1rem; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  display: flex;
  background: rgba(18,21,28,.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: .5rem .15rem .4rem;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: .58rem;
  transition: color .2s;
}

.nav-btn svg { width: 22px; height: 22px; }
.nav-btn.active { color: var(--accent); }
.nav-btn.active svg { filter: drop-shadow(0 0 6px rgba(61,214,140,.4)); }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: .85rem;
}

.card-glow {
  background: linear-gradient(145deg, var(--surface2), var(--surface));
  border-color: rgba(61,214,140,.15);
}

.card h3, .card-label {
  font-size: .78rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .5rem;
}

/* Hero stats */
.hero-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .65rem;
  margin-bottom: .85rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem;
  position: relative;
  overflow: hidden;
}

.stat-card .label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 1.5rem; font-weight: 800; margin-top: .15rem; }
.stat-card .sub { font-size: .75rem; color: var(--muted); margin-top: .1rem; }
.stat-card.accent { border-color: rgba(61,214,140,.3); }
.stat-card.accent .value { color: var(--accent); }

/* Ring chart container */
.ring-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .5rem 0;
}

.ring-wrap {
  position: relative;
  width: 90px;
  height: 90px;
  flex-shrink: 0;
}

.ring-wrap canvas { width: 90px !important; height: 90px !important; }

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  color: var(--muted);
  pointer-events: none;
}

.ring-center strong { font-size: 1rem; color: var(--text); }

.macro-bars { flex: 1; display: flex; flex-direction: column; gap: .5rem; }

.macro-item { display: flex; flex-direction: column; gap: .2rem; }
.macro-item .row { display: flex; justify-content: space-between; font-size: .78rem; }
.macro-item .bar { height: 6px; background: var(--surface3); border-radius: 99px; overflow: hidden; }
.macro-item .bar span { display: block; height: 100%; border-radius: 99px; transition: width .4s ease; }

/* Segmented control */
.seg-control {
  display: flex;
  background: var(--surface2);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 1rem;
  gap: 2px;
}

.seg-btn {
  flex: 1;
  padding: .45rem .5rem;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--surface3);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

/* Horizontal bar list (exercise chart style) */
.hbar-list { display: flex; flex-direction: column; gap: .55rem; }

.hbar-item { display: grid; grid-template-columns: 1fr auto; gap: .35rem .5rem; align-items: center; }
.hbar-item .name { font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-item .count { font-size: .75rem; color: var(--muted); }
.hbar-track { grid-column: 1 / -1; height: 8px; background: var(--surface3); border-radius: 99px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 99px; transition: width .5s ease; }

/* Muscle map */
.muscle-map {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: 1rem;
}

.body-svg { width: 100%; max-height: 200px; }
.body-svg path, .body-svg ellipse, .body-svg rect {
  fill: var(--surface3);
  stroke: var(--border);
  stroke-width: 1;
  transition: fill .4s ease;
}

.muscle-legend { display: flex; flex-direction: column; gap: .45rem; justify-content: center; }

.muscle-leg {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8rem;
}

.muscle-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.muscle-leg .pct { margin-left: auto; color: var(--muted); font-size: .75rem; }

/* Progress photos */
.photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .65rem;
}

.photo-card {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface2);
}

.photo-card img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  display: block;
}

.photo-card .caption {
  padding: .5rem .65rem;
  font-size: .72rem;
  color: var(--muted);
}

/* Workout */
.treino-pdfs { margin-bottom: .75rem; }
.treino-pdfs-summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
}
.treino-pdfs-count { color: var(--muted); font-size: .75rem; }
.treino-pdfs-body { margin-top: .65rem; }

.treino-setup select { margin-bottom: .55rem; }
.treino-meta-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .45rem;
}

.exercise-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem;
  margin-bottom: .75rem;
}

.ex-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .65rem;
}

.exercise-block h4 { font-size: .95rem; line-height: 1.25; flex: 1; }

.ex-demo-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--accent);
  font-size: .85rem;
  line-height: 1;
  cursor: pointer;
}

.ex-demo-btn:hover { border-color: var(--accent); }

.ex-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .45rem;
  margin-bottom: .75rem;
}

.ex-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: .55rem .25rem;
  border-radius: 50%;
  aspect-ratio: 1;
  max-width: 72px;
  margin: 0 auto;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}

.ex-stat-rest { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.ex-stat-sets {
  background: color-mix(in srgb, #ff6b9d 18%, transparent);
  border-color: color-mix(in srgb, #ff6b9d 35%, transparent);
}

.ex-stat-val { font-size: .95rem; font-weight: 700; line-height: 1.1; }
.ex-stat-lbl { font-size: .58rem; color: var(--muted); margin-top: .15rem; text-align: center; }

.exercise-demo {
  margin-bottom: .65rem;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface2);
  border: 1px solid var(--border);
}

.exercise-demo img {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  display: block;
  background: #0d1018;
}

.resource-list { display: flex; flex-direction: column; gap: .45rem; }

.resource-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .65rem;
  padding: .6rem .75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  font-size: .82rem;
  transition: border-color .15s;
}

.resource-item:hover { border-color: var(--accent2); }
.resource-item small { color: var(--muted); font-size: .7rem; }
.resource-item .tag { font-size: .65rem; color: var(--accent); }

.set-header,
.set-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr 48px;
  gap: .35rem;
  align-items: center;
}

.set-header {
  margin-bottom: .25rem;
  font-size: .62rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.set-header span:not(:first-child) { text-align: center; }

.set-row { margin-bottom: .35rem; }

.set-row input {
  padding: .5rem .45rem;
  font-size: .82rem;
  text-align: center;
}

.set-num { color: var(--muted); font-size: .8rem; text-align: center; }

/* Treino — exercícios recolhíveis */
.exercise-block.collapsed { opacity: .55; }
.exercise-block.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent);
}
.exercise-block.done { opacity: .7; }
.exercise-block.done .ex-status { background: var(--accent); color: #0a0c10; }

.ex-collapse-header {
  display: flex;
  align-items: center;
  gap: .55rem;
  width: 100%;
  padding: 0;
  margin-bottom: 0;
  background: none;
  border: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.exercise-block.active .ex-collapse-header { cursor: default; margin-bottom: .65rem; }

.ex-status {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.exercise-block.active .ex-status {
  background: var(--accent);
  color: #0a0c10;
  border-color: var(--accent);
}

.ex-header-text { flex: 1; min-width: 0; }
.ex-header-text strong { display: block; font-size: .9rem; line-height: 1.2; }
.ex-header-text small { color: var(--muted); font-size: .72rem; }

.ex-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface2);
}

.ex-demo-inline img { max-height: 160px; }

/* Planos */
.planos-toolbar select { margin-bottom: .5rem; }
.planos-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .35rem; }
.planos-focus { color: var(--muted); font-size: .78rem; }

.planos-ex-row {
  display: flex;
  align-items: center;
  gap: .65rem;
}

.planos-ex-gif {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface2);
}

.planos-ex-gif.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  border: 1px dashed var(--border);
}

.planos-ex-info { flex: 1; min-width: 0; }
.planos-ex-info strong { display: block; font-size: .88rem; }
.planos-ex-info small { color: var(--muted); font-size: .72rem; }

.planos-ex-btns { display: flex; gap: .25rem; flex-shrink: 0; }
.planos-ex-item { padding: .7rem .85rem; }

.gif-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .45rem;
  margin: .65rem 0;
  max-height: 280px;
  overflow-y: auto;
}

.gif-pick {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  padding: .35rem;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  font-size: .62rem;
  text-align: center;
}

.gif-pick img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: #0d1018;
}

.gif-pick.selected { border-color: var(--accent); }
.gif-pick:hover { border-color: var(--accent2); }

.planos-add-form { margin-top: .65rem; }

.planos-gif-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: .45rem;
  margin-bottom: .45rem;
}

.planos-ex-edit {
  margin-top: .65rem;
  padding-top: .65rem;
  border-top: 1px solid var(--border);
}

.planos-ex-edit-grid { margin-bottom: .5rem; }

.set-adjust-row {
  display: flex;
  gap: .4rem;
  margin-top: .45rem;
}

/* Meal */
.meal-slot { margin-bottom: .85rem; }
.meal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5rem;
  gap: .5rem;
}

.meal-header h4 { font-size: .88rem; }
.meal-kcal { font-size: .75rem; color: var(--accent); font-weight: 600; }

.meal-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .82rem;
}

.meal-item:last-child { border-bottom: none; }

/* Forms */
input, select, textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .55rem .7rem;
  border-radius: 10px;
  width: 100%;
  font-size: .9rem;
}

label.field { display: flex; flex-direction: column; gap: .3rem; font-size: .78rem; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }

.btn {
  background: linear-gradient(135deg, var(--accent), #2eb872);
  color: #0a0c10;
  border: none;
  padding: .65rem 1.1rem;
  border-radius: 12px;
  font-weight: 700;
  font-size: .88rem;
  cursor: pointer;
  width: 100%;
}

.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.sm { padding: .4rem .7rem; font-size: .78rem; width: auto; }

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.tag {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 600;
}

.tag.ok { background: rgba(61,214,140,.15); color: var(--accent); }
.tag.warn { background: rgba(255,176,32,.15); color: var(--warn); }

.chart-box { position: relative; height: 220px; margin: .5rem 0; }
.chart-box.sm { height: 160px; }

.tabs { display: flex; gap: .5rem; margin-bottom: 1rem; }
.tab-btn {
  padding: .45rem .85rem;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: .8rem;
  cursor: pointer;
}
.tab-btn.active { background: var(--accent); color: #0a0c10; border-color: var(--accent); font-weight: 700; }

.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-b) + 1rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--accent);
  padding: .65rem 1.2rem;
  border-radius: 99px;
  z-index: 200;
  font-size: .85rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  max-width: 90%;
  text-align: center;
}

.toast.hidden { display: none; }
.hidden { display: none !important; }
.empty { color: var(--muted); text-align: center; padding: 2rem 1rem; font-size: .88rem; }

.fab-row { position: sticky; bottom: 0; padding: .75rem 0; background: linear-gradient(transparent, var(--bg) 30%); }

#page-treino.active { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 1rem); }

.treino-fab {
  margin-top: .5rem;
  padding-bottom: .5rem;
}

.treino-fab .btn { width: 100%; }

#meal-food-filter { margin-bottom: .4rem; }

#meal-food {
  min-height: 8.5rem;
  max-height: 10rem;
}

/* Desktop */
@media (min-width: 521px) {
  .app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

@media (min-width: 768px) {
  .hero-grid { grid-template-columns: repeat(4, 1fr); }
  .form-grid { grid-template-columns: repeat(3, 1fr); }
}
