/* ============================================================
   DESIGN SYSTEM
   ============================================================ */
:root {
  --bg:         #0F0F14;
  --bg-card:    #1A1A24;
  --bg-input:   #22222E;
  --border:     #2A2A3A;
  --accent:     #FF6B35;
  --accent-dim: #cc4f1f;
  --accent-glow:rgba(255,107,53,.18);
  --text:       #F0F0F5;
  --text-muted: #888899;
  --text-dim:   #555566;
  --success:    #4ADE80;
  --danger:     #F87171;
  --warning:    #FBBF24;
  --nav-h:      64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius-sm:  8px;
  --radius:     14px;
  --radius-lg:  20px;
  --shadow:     0 4px 24px rgba(0,0,0,.5);
}

/* ============================================================
   RESET / BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

input, textarea, select { user-select: auto; }

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

#page-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
}

/* ============================================================
   BOTTOM NAV
   ============================================================ */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--nav-h);
  cursor: pointer;
  color: var(--text-dim);
  transition: color .2s;
  border: none;
  background: none;
  -webkit-appearance: none;
}

.nav-item.active { color: var(--accent); }
.nav-item svg { width: 24px; height: 24px; flex-shrink: 0; }
.nav-item span { font-size: 10px; font-weight: 600; letter-spacing: .3px; }

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
  padding: 56px 20px 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -.5px;
}

.page-header .subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 2px;
}

.page-content { padding: 0 16px 16px; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
}

.card-clickable {
  cursor: pointer;
  transition: transform .12s, border-color .12s;
  -webkit-tap-highlight-color: transparent;
}
.card-clickable:active { transform: scale(.98); border-color: var(--accent); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-appearance: none;
}
.btn:active { transform: scale(.97); opacity: .9; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-success {
  background: var(--success);
  color: #000;
}

.btn-block { width: 100%; }

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
}

.btn-lg {
  padding: 16px 24px;
  font-size: 17px;
  border-radius: var(--radius);
}

.btn:disabled { opacity: .4; pointer-events: none; }

/* ============================================================
   INPUTS
   ============================================================ */
.input-group { margin-bottom: 16px; }
.input-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}
.input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .2s;
  -webkit-appearance: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-dim); }

/* number inputs: bigger for workout tracking */
.input-number {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  padding: 10px 8px;
  width: 80px;
}

/* ============================================================
   BADGES / TAGS
   ============================================================ */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
}
.badge-accent  { background: var(--accent-glow); color: var(--accent); }
.badge-success { background: rgba(74,222,128,.15); color: var(--success); }
.badge-muted   { background: var(--bg-input); color: var(--text-muted); }
.badge-warning { background: rgba(251,191,36,.15); color: var(--warning); }

/* difficulty */
.diff-beginner     { color: var(--success); }
.diff-intermediate { color: var(--warning); }
.diff-advanced     { color: var(--danger); }

/* ============================================================
   SEARCH BAR
   ============================================================ */
.search-wrap {
  position: relative;
  margin-bottom: 14px;
}
.search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  padding-left: 40px !important;
}

/* ============================================================
   FILTER CHIPS
   ============================================================ */
.chips-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 14px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.chips-scroll::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ============================================================
   EXERCISE CARD (list)
   ============================================================ */
.exercise-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.exercise-item:active { transform: scale(.99); border-color: var(--accent); }

.exercise-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  background: var(--accent-glow);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.exercise-info { flex: 1; min-width: 0; }
.exercise-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.exercise-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.exercise-chevron { color: var(--text-dim); }

/* ============================================================
   STAT GRID (Home dashboard)
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.stat-value {
  font-size: 30px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 600;
}

/* ============================================================
   WORKOUT SESSION
   ============================================================ */
.session-header {
  background: linear-gradient(135deg, var(--accent-dim), var(--accent));
  padding: 20px 20px 16px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  margin-bottom: 16px;
}

.session-title {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
}

.session-timer {
  font-size: 14px;
  color: rgba(255,255,255,.8);
  margin-top: 4px;
}

/* Sets table */
.sets-table {
  width: 100%;
  border-collapse: collapse;
}
.sets-table th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  padding: 6px 8px;
  text-align: center;
}
.sets-table td {
  padding: 6px 4px;
  text-align: center;
  vertical-align: middle;
}

.set-row { transition: opacity .2s; }
.set-row.completed { opacity: .5; }
.set-row.completed .input { background: transparent; border-color: transparent; }

.set-check {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  -webkit-appearance: none;
}
.set-check.done {
  background: var(--success);
  border-color: var(--success);
  color: #000;
}

/* Rest timer overlay */
.rest-timer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.rest-timer-circle {
  width: 180px; height: 180px;
  border-radius: 50%;
  border: 4px solid var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 32px;
  position: relative;
}

.rest-timer-seconds {
  font-size: 56px;
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
}

.rest-timer-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ============================================================
   HISTORY
   ============================================================ */
.history-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  cursor: pointer;
}

.history-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  background: var(--accent-glow);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.history-date { font-size: 12px; color: var(--text-muted); }
.history-name { font-size: 15px; font-weight: 700; }
.history-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ============================================================
   PLANS
   ============================================================ */
.plan-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 16px;
  cursor: pointer;
  transition: border-color .15s;
}
.plan-card:active { border-color: var(--accent); }

.plan-card-banner {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  border-bottom: 1px solid var(--border);
}

.plan-card-body { padding: 14px 16px; }
.plan-card-name { font-size: 17px; font-weight: 800; }
.plan-card-desc { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.plan-card-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

/* ============================================================
   EXERCISE DETAIL (modal / page)
   ============================================================ */
.exercise-detail-icon {
  font-size: 64px;
  text-align: center;
  padding: 24px 0;
}

.muscle-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: var(--bg-input);
  border-radius: 99px;
  font-size: 12px;
  color: var(--text-muted);
  margin: 3px;
}

.instruction-list { list-style: none; }
.instruction-list li {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}
.instruction-list li:last-child { border-bottom: none; }
.instruction-step {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ============================================================
   MODAL
   ============================================================ */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 300;
  display: flex;
  align-items: flex-end;
}
#modal-overlay.hidden { display: none; }

#modal-content {
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
}

.modal-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}

/* ============================================================
   TOAST
   ============================================================ */
#toast-container {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 400px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toastIn .25s ease;
  border-left: 3px solid var(--accent);
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  gap: 12px;
}
.empty-state .icon { font-size: 56px; }
.empty-state h3 { font-size: 18px; font-weight: 700; }
.empty-state p { font-size: 14px; color: var(--text-muted); max-width: 240px; }

/* ============================================================
   SECTION LABEL
   ============================================================ */
.section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  margin-bottom: 12px;
  margin-top: 20px;
}

/* ============================================================
   DIVIDER
   ============================================================ */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-bar-wrap {
  background: var(--bg-input);
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width .4s ease;
}

/* ============================================================
   BACK BUTTON
   ============================================================ */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  margin-bottom: 12px;
}

/* ============================================================
   ACTIVE WORKOUT FLOATING
   ============================================================ */
.active-banner {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--accent);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

/* ============================================================
   RESPONSIVE (tablet+)
   ============================================================ */
@media (min-width: 600px) {
  #page-container { max-width: 480px; margin: 0 auto; }
}

/* ============================================================
   UTILS
   ============================================================ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.font-bold { font-weight: 700; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.text-center { text-align: center; }

/* ── Animazione esecuzione esercizio (foto inizio ↔ fine) ───────── */
.exercise-anim {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: 12px;
  overflow: hidden;
  background: #0b0b0f;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}
.exercise-anim img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.exercise-anim .frame-end {
  animation: exFrameSwap 2.6s ease-in-out infinite;
}
@keyframes exFrameSwap {
  0%, 40%   { opacity: 0; }
  50%, 90%  { opacity: 1; }
  100%      { opacity: 0; }
}
.exercise-anim-caption {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 18px;
}
/* Rispetta chi preferisce meno animazioni: mostra le due foto affiancate */
@media (prefers-reduced-motion: reduce) {
  .exercise-anim .frame-end { animation: none; opacity: 1; position: static; }
  .exercise-anim .frame-start { display: none; }
}

/* ── Skeleton di caricamento (shimmer) ──────────────────────────── */
.skeleton {
  position: relative;
  overflow: hidden;
  background: #1a1a24;
  border-radius: 10px;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent);
  animation: skelShimmer 1.2s infinite;
}
.skeleton-row { height: 64px; margin-bottom: 10px; }
@keyframes skelShimmer { 100% { transform: translateX(100%); } }

/* ── Transizione di entrata pagina ──────────────────────────────── */
.page-in { animation: pageIn .22s ease both; }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .page-in { animation: none; }
  .skeleton::after { animation: none; }
}

/* ── Indicatore offline ─────────────────────────────────────────── */
.offline-badge {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: #3a2a12;
  color: #FCD34D;
  border: 1px solid rgba(245,158,11,.4);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

/* ── Banner aggiornamento disponibile ───────────────────────────── */
.update-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 76px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-card, #1a1a24);
  border: 1px solid var(--border, #2A2A3A);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
  animation: pageIn .25s ease both;
}
.update-banner span { font-size: 14px; font-weight: 600; }
