:root {
  --brand-blue: #205C8E; --brand-navy: #1C2C50; --brand-amber: #FFB000; --brand-orange: #FF6900;
  --bg: #F3F5F8; --surface: #FFFFFF; --surface-alt: #EEF1F6; --text: #16213A; --muted: #5B6B82;
  --border: #E1E6ED; --link: #1C6FB0; --accent: #205C8E; --track: #E1E6ED;
  --shadow: 0 1px 2px rgba(22,33,58,.06), 0 8px 24px rgba(22,33,58,.06);
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  --gradient-brand: linear-gradient(150deg, #205C8E, #1C2C50);
  --gradient-warm: linear-gradient(120deg, #FFB000, #FF6900);
}
:root[data-theme="dark"] {
  --bg: #0D1626; --surface: #131F31; --surface-alt: #1A2637; --text: #EEF3F8; --muted: #A2AEBA;
  --border: #2B3B52; --link: #4D99D6; --accent: #4D99D6; --track: #2B3B52;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 400 15px/1.55 var(--font); overflow-x: hidden;
}
h1, h2, h3 { margin: 0; text-wrap: balance; line-height: 1.2; }
p { margin: 0; text-wrap: pretty; }
button, input, textarea { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Cabeçalho */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--gradient-brand); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 10px calc(16px + env(safe-area-inset-left));
  display: flex; align-items: center; gap: 12px; min-height: 60px;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; flex: 1; min-width: 0; }
.topbar .brand svg { color: var(--brand-amber); width: 26px; height: 26px; stroke-width: 2.5; }
.topbar .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tools { display: flex; gap: 8px; }
.icon-btn {
  min-width: 44px; height: 44px; border-radius: 8px; border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.1); color: #fff; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 0 10px; cursor: pointer; font-weight: 700; font-size: 13px;
}
.icon-btn:hover { background: rgba(255,255,255,.2); }

/* Layout */
.wrap {
  max-width: 960px; margin: 0 auto;
  padding: 20px calc(16px + env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  display: grid; gap: 18px;
}
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); }
.card h2 { font-size: 17px; font-weight: 600; }
.sub { color: var(--muted); font-size: 13px; }
.eyebrow { font-size: 11.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.row { display: flex; align-items: center; gap: 14px; }
.between { justify-content: space-between; }
.grid2 { display: grid; gap: 18px; }

/* Botões */
.btn {
  min-height: 48px; padding: 0 20px; border-radius: 8px; border: 1px solid transparent; font-weight: 600; font-size: 14.5px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
}
.btn.primary { background: var(--brand-blue); color: #fff; }
.btn.warm { background: var(--gradient-warm); color: var(--brand-navy); box-shadow: 0 8px 20px rgba(255,105,0,.25); min-height: 56px; font-size: 16px; }
.btn.ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn.ghost:hover { border-color: var(--accent); }
.btn.danger { background: transparent; border-color: var(--border); color: #C0392B; }
.btn.small { min-height: 40px; width: auto; padding: 0 14px; font-size: 13.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--brand-amber); outline-offset: 2px; }

/* Avatar */
.avatar {
  width: 76px; height: 76px; border-radius: 50%; background: var(--gradient-brand); color: #fff; border: 3px solid var(--brand-amber);
  display: grid; place-items: center; font-size: 26px; font-weight: 700; overflow: hidden; padding: 0; cursor: pointer; flex: none; position: relative;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar .cam { position: absolute; right: 0; bottom: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--brand-amber); color: var(--brand-navy); display: grid; place-items: center; }
.avatar .cam svg { width: 14px; height: 14px; }
.avatar.big { width: 140px; height: 140px; font-size: 48px; margin: 0 auto; }

/* Barras de progresso */
.bars { display: grid; gap: 22px; }
.bar-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 8px; flex-wrap: wrap; }
.bar-head strong { font-size: 14.5px; font-weight: 600; }
.track { height: 14px; background: var(--track); border-radius: 9999px; overflow: hidden; }
.fill { height: 100%; border-radius: 9999px; background: var(--brand-blue); transition: width .5s; min-width: 4px; }
:root[data-theme="dark"] .fill { background: #4D99D6; }
.fill.alert { background: var(--brand-amber) !important; }
.fill.expired { background: var(--brand-orange) !important; }
.fill.ok { background: #2E9E6B !important; }
.bar-foot { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-top: 6px; gap: 8px; }

/* Lista de treinos */
.wk-list { display: grid; gap: 14px; }
.wk { display: grid; gap: 12px; position: relative; }
.wk.next { border-color: var(--brand-amber); border-width: 2px; }
.badge { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; background: var(--brand-amber); color: var(--brand-navy); padding: 3px 10px; border-radius: 9999px; }
.letter { width: 52px; height: 52px; border-radius: 12px; background: var(--gradient-brand); color: #fff; font-size: 24px; font-weight: 700; display: grid; place-items: center; flex: none; }
.wk .names { color: var(--muted); font-size: 13.5px; }
.wk h3 { font-size: 16.5px; font-weight: 600; }

/* Formulários */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); font-size: 16px; /* 16px evita zoom no iOS */
}
textarea { resize: vertical; min-height: 70px; }
.field { margin-bottom: 14px; }
.fields3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ex-edit { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-alt); }
.stack { display: grid; gap: 12px; }

/* Login */
.login-page {
  min-height: 100dvh; display: grid; place-items: center; background: var(--gradient-brand);
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
}
.login-box { width: 100%; max-width: 420px; background: var(--surface); border-radius: 14px; padding: 28px 24px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-box .logo { width: 64px; height: 64px; border-radius: 16px; background: var(--gradient-brand); display: grid; place-items: center; margin: 0 auto 14px; color: var(--brand-amber); }
.login-box .logo svg { width: 36px; height: 36px; stroke-width: 2.5; }
.login-box h1 { font-size: 23px; font-weight: 600; text-align: center; }
.login-box .sub { text-align: center; margin: 4px 0 22px; }
.login-tools { position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 12px; display: flex; gap: 8px; }
.err { background: #FDECEA; color: #8A1C12; border-radius: 8px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 14px; }

/* Sessão de treino */
.lock { background: var(--surface-alt); border: 1px dashed var(--accent); border-radius: 12px; padding: 12px 14px; font-size: 13.5px; display: flex; gap: 10px; align-items: center; }
.ex { display: flex; gap: 14px; align-items: flex-start; cursor: pointer; padding: 16px; width: 100%; text-align: left; }
.ex .check { width: 32px; height: 32px; border-radius: 8px; border: 2px solid var(--border); display: grid; place-items: center; flex: none; color: transparent; margin-top: 2px; }
.ex.done .check { background: #2E9E6B; border-color: #2E9E6B; color: #fff; }
.ex.done .ex-name { text-decoration: line-through; color: var(--muted); }
.ex-name { font-weight: 600; font-size: 16.5px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { background: var(--surface-alt); border-radius: 9999px; padding: 3px 12px; font-size: 13px; font-weight: 600; }
.finish-bar {
  position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }

/* Modal e toast */
.overlay { position: fixed; inset: 0; background: rgba(13,22,38,.6); z-index: 50; display: grid; place-items: center; padding: 16px; }
.dialog { background: var(--surface); border-radius: 16px; padding: 24px; max-width: 400px; width: 100%; display: grid; gap: 16px; box-shadow: 0 20px 50px rgba(0,0,0,.35); max-height: 90dvh; overflow: auto; }
.dialog h2 { font-size: 18px; font-weight: 600; }
.dialog .actions { display: grid; gap: 10px; }
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px); opacity: 0;
  background: var(--brand-navy); color: #fff; padding: 12px 18px; border-radius: 8px; z-index: 60; max-width: calc(100% - 32px);
  transition: .25s; pointer-events: none; font-size: 14px; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; display: grid; gap: 8px; justify-items: center; }

/* Tablet e maior */
@media (min-width: 720px) {
  body { font-size: 16px; }
  .wrap { padding-top: 28px; gap: 22px; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .wk-list { grid-template-columns: 1fr 1fr; }
  .btn { width: auto; min-width: 200px; }
  .btn.block { width: 100%; }
  .login-box { padding: 36px 32px; }
  .dialog .actions { grid-template-columns: 1fr 1fr; }
  .dialog .actions .btn { width: 100%; min-width: 0; }
  .ex-edit .fields3 { gap: 14px; }
}
@media (max-width: 380px) {
  .avatar { width: 64px; height: 64px; }
  .fields3 { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
