/* ---------- Reset + base ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

:root {
  --bg: #0b0d12;
  --bg-elev: #141821;
  --bg-elev-2: #1c2230;
  --border: #252b39;
  --text: #e8ecf3;
  --muted: #8a93a6;
  --accent: #ff5a1f;
  --accent-2: #ffb547;
  --success: #22c55e;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ---------- App layout ---------- */
#app { padding: 16px 14px 8px; max-width: 720px; margin: 0 auto; }
.hidden { display: none !important; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.page-header h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.page-header .sub { color: var(--muted); font-size: 13px; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h2, .card h3 { margin: 0 0 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); font-size: 13px; }
.tag {
  display: inline-block; padding: 3px 8px; border-radius: 999px;
  background: var(--bg-elev-2); color: var(--muted); font-size: 11px;
  border: 1px solid var(--border);
}
.tag.accent { color: var(--accent); border-color: rgba(255,90,31,.4); background: rgba(255,90,31,.08); }
.tag.push { color: #ff7a59; border-color: rgba(255,122,89,.4); background: rgba(255,122,89,.08); }
.tag.pull { color: #60a5fa; border-color: rgba(96,165,250,.4); background: rgba(96,165,250,.08); }
.tag.leg { color: #34d399; border-color: rgba(52,211,153,.4); background: rgba(52,211,153,.08); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: transform .05s ease, background .15s ease;
  min-height: 44px;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #ff7a59); border-color: transparent; color: #fff; }
.btn.danger { background: rgba(239,68,68,.12); color: #fca5a5; border-color: rgba(239,68,68,.3); }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 12px; min-height: 36px; font-size: 13px; }
.btn.full { width: 100%; }
.btn.icon { padding: 10px; min-width: 44px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Inputs ---------- */
.input, .select, .textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  outline: none;
  transition: border-color .15s ease;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* ---------- Auth screen ---------- */
.auth-wrap {
  min-height: 80vh;
  display: flex; flex-direction: column; justify-content: center;
  max-width: 420px; margin: 0 auto;
}
.brand {
  text-align: center; margin-bottom: 22px;
}
.brand .logo { font-size: 48px; }
.brand h1 { margin: 6px 0 4px; font-size: 26px; }
.brand p { color: var(--muted); margin: 0; }
.tabs {
  display: flex; background: var(--bg-elev); border-radius: 12px;
  padding: 4px; margin-bottom: 14px; border: 1px solid var(--border);
}
.tabs button {
  flex: 1; background: transparent; border: 0; padding: 10px;
  color: var(--muted); border-radius: 9px; cursor: pointer; font-weight: 600;
}
.tabs button.active { background: var(--accent); color: #fff; }

/* ---------- Day / exercise cards ---------- */
.day-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.day-header {
  padding: 14px;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
  background: linear-gradient(180deg, rgba(255,255,255,.02), transparent);
}
.day-header h2 { margin: 0; font-size: 17px; }
.day-header .meta { color: var(--muted); font-size: 12px; }
.day-body { padding: 0 14px 14px; }
.warmup {
  background: var(--bg-elev-2); border: 1px dashed var(--border);
  padding: 10px 12px; border-radius: 10px; font-size: 13px; color: var(--muted);
  margin-bottom: 12px;
}
.exercise {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}
.exercise .ex-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
}
.exercise .ex-name { font-weight: 700; font-size: 15px; line-height: 1.25; }
.exercise .ex-muscle { color: var(--muted); font-size: 12px; margin-top: 2px; }
.exercise .ex-meta {
  display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px;
  font-size: 12px; color: var(--muted);
}
.exercise .ex-meta b { color: var(--text); font-weight: 600; }
.exercise .ex-notes { font-size: 13px; color: #c9d1de; margin-top: 8px; }
.exercise .ex-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

.last-time {
  margin-top: 8px;
  padding: 6px 10px;
  background: rgba(255, 181, 71, 0.08);
  border: 1px solid rgba(255, 181, 71, 0.2);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
}
.last-time b { color: var(--accent-2); }

/* Order badge */
.order-badge {
  flex: 0 0 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}

/* ---------- Sessions list ---------- */
.session-item {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex; justify-content: space-between; align-items: center;
  cursor: pointer;
}
.session-item .title { font-weight: 600; }
.session-item .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- Set logger ---------- */
.set-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr 60px auto;
  gap: 6px; align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.set-row:last-child { border-bottom: 0; }
.set-row .num { color: var(--muted); font-size: 12px; text-align: center; }
.set-row .input { padding: 8px 10px; font-size: 14px; }
.set-row .del {
  background: transparent; border: 0; color: var(--danger);
  padding: 4px 8px; cursor: pointer; font-size: 18px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(11,13,18,.92);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 50;
}
.nav-btn {
  background: transparent; border: 0; color: var(--muted);
  padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; cursor: pointer; border-radius: 10px;
}
.nav-btn .nav-icon { font-size: 22px; line-height: 1; }
.nav-btn.active { color: var(--accent); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  width: 100%; max-width: 640px;
  padding: 16px 14px calc(20px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-close {
  position: absolute; top: 8px; right: 10px;
  background: transparent; border: 0; color: var(--muted);
  font-size: 28px; cursor: pointer; line-height: 1;
}
#videoPlayer { width: 100%; border-radius: 12px; background: #000; max-height: 60vh; }
.video-tabs { display: flex; gap: 6px; margin: 8px 0; }
.video-tabs .tab {
  flex: 1; padding: 8px; border: 1px solid var(--border);
  background: var(--bg-elev-2); border-radius: 10px; cursor: pointer; color: var(--muted);
}
.video-tabs .tab.active { background: var(--accent); color: #fff; border-color: transparent; }
.video-tabs .tab:disabled { opacity: .35; cursor: not-allowed; }
.video-tabs:empty { display: none; }
.link-row { display: block; margin-top: 10px; color: var(--accent-2); text-align: center; text-decoration: none; }

/* @media (min-width: 600px) { .modal { align-items: center; } .modal-card { border-radius: 18px; } } */

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(90px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px; border-radius: 999px;
  z-index: 200;
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: fadeIn .2s ease;
}
.toast.error { border-color: rgba(239,68,68,.5); color: #fca5a5; }
.toast.success { border-color: rgba(34,197,94,.5); color: #86efac; }
@keyframes fadeIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Empty state ---------- */
.empty {
  text-align: center; padding: 40px 16px; color: var(--muted);
}
.empty .ico { font-size: 42px; margin-bottom: 8px; }

/* ---------- Loading ---------- */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* History chart-ish */
.history-set {
  display: grid; grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 6px; padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.history-set b { color: var(--text); }
.history-set span { color: var(--muted); }
.history-date {
  font-weight: 600; margin-top: 14px; margin-bottom: 4px;
  color: var(--accent-2); font-size: 13px;
}

/* Notes list */
.note-item {
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 14px;
}
