/*
 * NutriLift — Training Plan Wizard
 * Stili dedicati al wizard di creazione/modifica scheda allenamento.
 * Prefisso: .tpw- (Training Plan Wizard)
 *
 * Dipende da:  css/theme.css  (per --gradient-app, --bg-surface, --text-*, ecc.)
 *              css/modal.css  (per .modal-overlay base)
 *
 * Include in index.html DOPO css/training.css e css/modal.css
 */

/* ─────────────────────────────────────────────────────────────────
   OVERLAY + MODAL SHELL
   ───────────────────────────────────────────────────────────────── */
.tpw-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-heavy, rgba(0, 0, 0, 0.5));
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: tpwFadeIn 0.18s ease;
}

@keyframes tpwFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.tpw-box {
  background: var(--bg-surface);
  border-radius: 16px;
  width: 100%;
  max-width: 860px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 60px var(--shadow-lg, rgba(0, 0, 0, 0.25));
  overflow: hidden;
  animation: tpwSlideUp 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* Variante "compatta" per la modifica scheda */
.tpw-box--compact { max-width: 480px; }

/* ─────────────────────────────────────────────────────────────────
   HEADER (gradient brand)
   ───────────────────────────────────────────────────────────────── */
.tpw-hdr {
  background: var(--gradient-app);
  padding: 18px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.tpw-hdr-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.tpw-hdr-title {
  flex: 1;
  min-width: 0;
}

.tpw-hdr-title h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.tpw-hdr-title small {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.75);
}

.tpw-hdr-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.tpw-hdr-close:hover { background: rgba(255, 255, 255, 0.32); }

/* ─────────────────────────────────────────────────────────────────
   STEPPER (Step 1 → Step 2)
   ───────────────────────────────────────────────────────────────── */
.tpw-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 24px;
  background: var(--bg-surface-raised);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.tpw-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}

.tpw-step-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-surface-sunken);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  border: 2px solid transparent;
  transition: all 0.2s;
}

.tpw-step.is-active { color: var(--text-primary); }
.tpw-step.is-active .tpw-step-dot {
  background: var(--gradient-app);
  color: #fff;
  box-shadow: 0 2px 8px var(--shadow-brand-md, rgba(102, 126, 234, 0.3));
}

.tpw-step.is-done .tpw-step-dot {
  background: #fff;
  color: var(--gradient-app-start);
  border-color: var(--gradient-app-start);
}

.tpw-step-divider {
  flex: 1;
  height: 2px;
  background: var(--border-light);
  border-radius: 2px;
  min-width: 24px;
}
.tpw-step-divider.is-done { background: var(--gradient-app-start); }

/* ─────────────────────────────────────────────────────────────────
   BODY (scrollable area)
   ───────────────────────────────────────────────────────────────── */
.tpw-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: none;
}

.tpw-body-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 4px 0;
}

.tpw-body-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 18px 0;
  line-height: 1.45;
}

/* ─────────────────────────────────────────────────────────────────
   STEP 1 — Source cards (Vuota / Preset / Duplica / Template)
   ───────────────────────────────────────────────────────────────── */
.tpw-source-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.tpw-source-card {
  position: relative;
  background: var(--bg-surface);
  border: 2px solid var(--border-light);
  border-radius: 12px;
  padding: 18px 16px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.18s;
  outline: none;
}

.tpw-source-card:hover:not(:disabled):not(.is-selected) {
  border-color: var(--gradient-app-start);
  background: var(--bg-surface-raised);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--shadow-brand-sm, rgba(102, 126, 234, 0.15));
}

.tpw-source-card:focus-visible {
  border-color: var(--gradient-app-start);
  box-shadow: 0 0 0 3px var(--shadow-brand-sm, rgba(102, 126, 234, 0.15));
}

.tpw-source-card.is-selected {
  border-color: var(--gradient-app-start);
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.06), rgba(118, 75, 162, 0.04));
  box-shadow: 0 4px 14px var(--shadow-brand-sm, rgba(102, 126, 234, 0.15));
}

.tpw-source-card:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.tpw-source-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg-surface-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.tpw-source-card.is-selected .tpw-source-card-icon {
  background: var(--gradient-app);
  filter: brightness(1.05);
}

.tpw-source-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.tpw-source-card-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.tpw-source-card-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-surface-sunken);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tpw-source-card-check {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gradient-app);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.18s;
}

.tpw-source-card.is-selected .tpw-source-card-check {
  opacity: 1;
  transform: scale(1);
}

/* ─────────────────────────────────────────────────────────────────
   STEP 1 — Sub-list (Preset chips OR Duplica list)
   ───────────────────────────────────────────────────────────────── */
.tpw-sublist {
  margin-top: 18px;
  padding: 16px;
  background: var(--bg-surface-raised);
  border-radius: 12px;
  border: 1px solid var(--border-light);
  animation: tpwSlideDown 0.2s ease;
}

@keyframes tpwSlideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tpw-sublist-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 10px 0;
}

/* preset cards */
.tpw-preset-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tpw-preset-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-light);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: all 0.15s;
}

.tpw-preset-row:hover:not(.is-selected) {
  border-color: var(--gradient-app-start);
  background: var(--bg-surface);
}

.tpw-preset-row.is-selected {
  border-color: var(--gradient-app-start);
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.08), rgba(118, 75, 162, 0.05));
}

.tpw-preset-row-emoji {
  font-size: 22px;
  flex-shrink: 0;
}

.tpw-preset-row-text {
  flex: 1;
  min-width: 0;
}

.tpw-preset-row-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.tpw-preset-row-meta {
  font-size: 11px;
  color: var(--text-secondary);
}

/* duplica list (ultime schede) */
.tpw-dup-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.tpw-dup-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-light);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: all 0.15s;
}

.tpw-dup-row:hover:not(.is-selected) {
  border-color: var(--gradient-app-start);
}

.tpw-dup-row.is-selected {
  border-color: var(--gradient-app-start);
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.06), rgba(118, 75, 162, 0.04));
}

.tpw-dup-row-text {
  flex: 1;
  min-width: 0;
}

.tpw-dup-row-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tpw-dup-row-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.tpw-dup-empty {
  padding: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-surface);
  border-radius: 8px;
  border: 1px dashed var(--border-medium);
}

.tpw-dup-empty-icon {
  font-size: 26px;
  margin-bottom: 6px;
  opacity: 0.6;
}

/* ─────────────────────────────────────────────────────────────────
   STEP 2 — Form a 2 colonne
   ───────────────────────────────────────────────────────────────── */
.tpw-step2 {
  display: grid;
  grid-template-columns: 1.2fr 1.3fr;
  gap: 22px;
  align-items: start;
}

@media (max-width: 640px) {
  .tpw-step2 { grid-template-columns: 1fr; gap: 16px; }
}

.tpw-form-col { display: flex; flex-direction: column; gap: 14px; }

.tpw-field { display: flex; flex-direction: column; gap: 6px; }

.tpw-field-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.tpw-field-label .tpw-required { color: #ef4444; }

.tpw-field-hint {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.tpw-input,
.tpw-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border-medium);
  border-radius: 8px;
  background: var(--bg-surface-raised);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tpw-input:focus,
.tpw-textarea:focus {
  outline: none;
  border-color: var(--gradient-app-start);
  box-shadow: 0 0 0 3px var(--shadow-brand-sm, rgba(102, 126, 234, 0.15));
}

.tpw-textarea {
  resize: vertical;
  min-height: 70px;
}

/* segmented control 1-7 */
.tpw-segmented {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--bg-surface-raised);
  border: 1.5px solid var(--border-medium);
  border-radius: 10px;
}

.tpw-segmented button {
  background: transparent;
  border: none;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
  font-family: inherit;
}

.tpw-segmented button:hover:not(.is-active) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tpw-segmented button.is-active {
  background: var(--gradient-app);
  color: #fff;
  box-shadow: 0 2px 6px var(--shadow-brand-md, rgba(102, 126, 234, 0.3));
}

/* stepper numerico (durata settimane) */
.tpw-stepper-num {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1.5px solid var(--border-medium);
  border-radius: 8px;
  background: var(--bg-surface-raised);
  width: fit-content;
}

.tpw-stepper-num button {
  background: transparent;
  border: none;
  width: 36px;
  height: 38px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s;
}
.tpw-stepper-num button:hover:not(:disabled) { color: var(--gradient-app-start); }
.tpw-stepper-num button:disabled { opacity: 0.4; cursor: not-allowed; }

.tpw-stepper-num input {
  width: 56px;
  text-align: center;
  border: none;
  background: transparent;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: inherit;
  -moz-appearance: textfield;
}
.tpw-stepper-num input::-webkit-outer-spin-button,
.tpw-stepper-num input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.tpw-stepper-num input:focus { outline: none; }

/* date row */
.tpw-date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ─────────────────────────────────────────────────────────────────
   STEP 2 — Pannello preview a destra
   ───────────────────────────────────────────────────────────────── */
.tpw-preview {
  background: linear-gradient(160deg, var(--bg-surface-raised) 0%, var(--bg-surface) 100%);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 16px;
  position: sticky;
  top: 0;
}

.tpw-preview-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.tpw-preview-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 12px;
  word-break: break-word;
}

.tpw-preview-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.tpw-preview-stat {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 8px 10px;
}

.tpw-preview-stat-num {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  background: var(--gradient-app);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tpw-preview-stat-lbl {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

/* mini schema settimane × giorni */
.tpw-preview-schema {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: none;
}

.tpw-preview-week {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.tpw-preview-week-lbl {
  font-weight: 700;
  color: var(--text-muted);
  width: 28px;
  flex-shrink: 0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tpw-preview-days {
  flex: 1;
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  min-width: 0;
}

.tpw-preview-day {
  flex: 1 1 0;
  min-width: 0;
  height: 26px;
  background: var(--bg-surface-card);
  border: 1px solid var(--border-light);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: var(--gradient-app-start);
}

.tpw-preview-day--empty {
  background: var(--bg-surface-sunken);
  border-color: transparent;
  color: var(--text-disabled);
}

.tpw-preview-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tpw-preview-state--bozza {
  background: rgba(150, 150, 150, 0.12);
  color: var(--text-secondary);
}
.tpw-preview-state--attiva {
  background: rgba(34, 197, 94, 0.15);
  color: #15803d;
}
.tpw-preview-state-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* fonte / origine scheda nel preview */
.tpw-preview-source {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  padding-top: 12px;
  margin-top: 12px;
  border-top: 1px dashed var(--border-light);
}

/* ─────────────────────────────────────────────────────────────────
   FOOTER (azioni)
   ───────────────────────────────────────────────────────────────── */
.tpw-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 24px;
  background: var(--bg-surface-raised);
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}

.tpw-footer-left { display: flex; gap: 8px; }
.tpw-footer-right { display: flex; gap: 8px; }

/* spinner inline durante creazione */
.tpw-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: tpwSpin 0.7s linear infinite;
  margin-right: 6px;
  vertical-align: -2px;
}

@keyframes tpwSpin {
  to { transform: rotate(360deg); }
}

/* progress text durante orchestrazione (step "Sto creando 4 settimane × 3 giorni…") */
.tpw-progress {
  text-align: center;
  padding: 30px 20px;
}
.tpw-progress-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-light);
  border-top-color: var(--gradient-app-start);
  border-radius: 50%;
  animation: tpwSpin 0.8s linear infinite;
  margin: 0 auto 14px;
}
.tpw-progress-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.tpw-progress-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ─────────────────────────────────────────────────────────────────
   RESPONSIVE — Mobile
   ───────────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .tpw-source-grid { grid-template-columns: 1fr; }
  .tpw-hdr { padding: 14px 18px; }
  .tpw-body { padding: 18px; }
  .tpw-footer { padding: 12px 18px; }
  .tpw-segmented button { padding: 10px 0; font-size: 14px; }
}
