/* css/training-redesign.css
   Redesign primitives (ported from prototype tokens.css). Additive + reversible:
   remove the <link> to fully revert. Reuses css/theme.css variables. */

:root {
  --rl-train: #22c55e;        --rl-train-dark: #16a34a;
  --rl-preset: #7c3aed;       --rl-preset-soft: #a78bfa;
  --rl-warm: #f59e0b;         --rl-work: var(--gradient-app-start, #667eea);  --rl-cool: #11998e;
}
.dark-mode {
  --rl-train: #34d399;        --rl-train-dark: #22c55e;
  --rl-preset: #a78bfa;       --rl-preset-soft: #c4b5fd;
  --rl-warm: #fbbf24;         --rl-work: var(--gradient-app-start, #8093f0); --rl-cool: #2dd4bf;
}

/* Value tiles — scannable read-state */
.rl-vrow { display: flex; flex-wrap: wrap; gap: 7px; }
.rl-vtile { display: flex; flex-direction: column; gap: 1px; min-width: 52px; padding: 6px 11px; border-radius: 10px;
  background: var(--bg-surface-raised); border: 1.5px solid var(--border-light); }
.rl-vtile .vl { font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.rl-vtile .vv { font-size: 14px; font-weight: 800; color: var(--text-heading); font-variant-numeric: tabular-nums; }
.rl-vtile--target { background: color-mix(in srgb, var(--rl-warm) 11%, transparent); border-color: color-mix(in srgb, var(--rl-warm) 30%, transparent); }
.rl-vtile--target .vv { color: var(--warning, #d97706); }

/* Grouped value-fields — edit-state */
.rl-fgset { display: flex; flex-wrap: wrap; gap: 16px; padding: 12px 14px; border-radius: 12px;
  background: var(--bg-surface-raised); border: 1.5px solid var(--border-light); }
.rl-fg { display: inline-flex; flex-direction: column; gap: 4px; }
.rl-fg > span { font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.rl-fg-inputs { display: inline-flex; align-items: center; gap: 5px; }
.rl-fg input, .rl-fg select { width: 56px; text-align: center; padding: 8px 6px; border: 1.5px solid var(--border-medium);
  border-radius: 9px; background: var(--bg-surface); color: var(--text-heading); font: inherit; font-size: 13px; font-weight: 700; outline: none; }
.rl-fg input.w { width: 70px; }
.rl-fg input:focus, .rl-fg select:focus { border-color: var(--gradient-app-start); }
.rl-fg .sep { color: var(--text-hint); font-weight: 800; }
.rl-reps-max-wrap { display: inline-flex; }
.rl-reps-max-wrap.hidden,
.rl-reps-range-only.hidden { display: none !important; }

/* Technique pills + add / advanced toggle */
.rl-tadd { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 99px; font-size: 11px; font-weight: 800;
  border: 1.5px dashed color-mix(in srgb, var(--rl-preset) 40%, var(--border-medium)); background: transparent; color: var(--rl-preset); cursor: pointer; font-family: inherit; }
.rl-tadd:hover { background: color-mix(in srgb, var(--rl-preset) 9%, transparent); }
.rl-adv-toggle { display: inline-flex; align-items: center; gap: 6px; background: none; border: none; color: var(--text-secondary);
  font: inherit; font-weight: 700; font-size: 11.5px; cursor: pointer; }
.rl-adv-toggle:hover { color: var(--text-heading); }
.rl-adv { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 11px; }
@media (max-width: 600px) { .rl-adv { grid-template-columns: 1fr; } }

/* Chips + segmented control */
.rl-chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 13px; border-radius: 99px; border: 1.5px solid var(--border-medium);
  background: var(--bg-surface); color: var(--text-secondary); font-size: 12.5px; font-weight: 700; cursor: pointer; transition: .15s; font-family: inherit; }
.rl-chip:hover { color: var(--text-heading); border-color: var(--border-dark); }
.rl-chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ex-color, var(--gradient-app-start)); }
.rl-chip .cnt { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 99px;
  background: var(--bg-surface-sunken); color: var(--text-muted); font-size: 11px; font-weight: 800; }
.rl-chip.is-active { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--rl-train-dark), var(--rl-train)); }
.rl-chip.is-active .cnt { background: rgba(255,255,255,.25); color: #fff; }
.rl-chip.m-active { color: var(--ex-color); border-color: color-mix(in srgb, var(--ex-color) 50%, transparent); background: color-mix(in srgb, var(--ex-color) 12%, transparent); }
.rl-seg { display: inline-flex; background: var(--bg-surface-raised); border: 1.5px solid var(--border-light); border-radius: 99px; padding: 3px; gap: 2px; }
.rl-seg button { border: none; background: transparent; font: inherit; font-size: 12.5px; font-weight: 700; color: var(--text-secondary); padding: 6px 15px; border-radius: 99px; cursor: pointer; }
.rl-seg button.is-active { background: var(--bg-surface); color: var(--text-heading); box-shadow: 0 2px 8px var(--shadow-sm, rgba(0,0,0,.08)); }

/* Command-center stat tiles */
.rl-stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.rl-stat { position: relative; padding: 15px 16px; border: 1.5px solid var(--border-medium); border-radius: 16px; background: var(--bg-surface); overflow: hidden; }
.rl-stat::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--acc, var(--gradient-app-start)); }
.rl-stat-v { font-size: 25px; font-weight: 800; line-height: 1.05; color: var(--text-heading); font-variant-numeric: tabular-nums; }
.rl-stat-l { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); margin-top: 3px; }
@media (max-width: 720px) { .rl-stat-grid { grid-template-columns: repeat(2, minmax(0,1fr)); } }

/* Library grid + card (Esercizi) */
.rl-libgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(252px, 1fr)); grid-auto-rows: 1fr; gap: 14px; align-items: stretch; }
.rl-exlib { text-align: left; cursor: pointer; border: 1.5px solid var(--border-light); border-left: 4px solid var(--ex-color, var(--border-medium)); border-radius: 16px;
  background: var(--bg-surface); padding: 15px 16px; transition: .16s; font-family: inherit; display: flex; flex-direction: column; gap: 11px; width: 100%; height: 100%; }
.rl-exlib:hover { box-shadow: 0 8px 26px var(--shadow-md, rgba(0,0,0,.12)); transform: translateY(-2px); }
.rl-new-tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 132px;
  border: 1.5px dashed var(--border-dark); border-radius: 16px; background: transparent; color: var(--text-secondary); cursor: pointer; font: inherit; font-weight: 700; }
.rl-new-tile:hover { border-color: var(--rl-train); color: var(--rl-train-dark); }

/* Preset Allenamento */
.rl-preset-eyebrow { margin-bottom: 14px; color: var(--rl-preset); font-size: 12px; font-weight: 900; letter-spacing: 0; text-transform: uppercase; }
.rl-preset-page-title { margin-bottom: 10px; font-size: 30px; line-height: 1.08; font-weight: 900; letter-spacing: 0; }
#presets-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 20px; align-items: start; }
#presets-list .rl-preset-card { margin: 0; border: none; border-radius: 18px; background: var(--bg-surface); box-shadow: 0 1px 0 rgba(15,23,42,.04), 0 18px 38px rgba(15,23,42,.08); overflow: hidden; }
.rl-preset-head { min-height: 67px; padding: 16px 20px; border: none; background: linear-gradient(135deg, var(--rl-preset), #9b5cf6); color: #fff; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.rl-preset-titlewrap { min-width: 0; display: flex; align-items: center; gap: 12px; }
.rl-preset-title { min-width: 0; color: #fff; font-size: 18px; font-weight: 900; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rl-preset-badge { display: inline-flex; align-items: center; min-height: 25px; padding: 4px 11px; border-radius: 99px; background: rgba(255,255,255,.22); color: #fff; font-size: 11.5px; font-weight: 800; white-space: nowrap; }
.rl-preset-tools { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.rl-preset-count { color: rgba(255,255,255,.94); font-size: 13.5px; font-weight: 900; white-space: nowrap; }
.rl-preset-action { width: 34px; height: 34px; padding: 0; border: none; border-radius: 10px; background: rgba(255,255,255,.19); display: inline-grid; place-items: center; cursor: pointer; transition: background-color .15s, transform .15s; }
.rl-preset-action:hover { background: rgba(255,255,255,.3); transform: translateY(-1px); }
.rl-preset-action .ui-icon { width: 15px; height: 15px; filter: brightness(0) invert(1); opacity: .95; }
.rl-preset-body { padding: 18px 20px 20px; background: var(--bg-surface); }
.rl-preset-desc { margin: 0 0 17px; color: var(--text-secondary); font-size: 14px; line-height: 1.45; }
#presets-list .preset-summary-list { display: flex; flex-direction: column; gap: 0; }
#presets-list .preset-summary-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border-light); font-size: 14px; }
#presets-list .preset-summary-row:first-child { padding-top: 0; }
#presets-list .preset-summary-row:last-child { padding-bottom: 0; border-bottom: none; }
.rl-preset-row-main { min-width: 0; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
#presets-list .preset-summary-name { color: var(--text-heading); font-weight: 900; }
.rl-preset-tech { color: var(--rl-preset); font-size: 11px; font-weight: 900; white-space: nowrap; }
#presets-list .preset-summary-params { color: #7f8a9f; font-size: 13.5px; font-weight: 900; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rl-preset-empty { color: var(--text-muted); font-size: 13px; }

.dark-mode #presets-list .rl-preset-card { box-shadow: 0 1px 0 rgba(255,255,255,.04), 0 18px 38px rgba(0,0,0,.22); }
.dark-mode #presets-list .preset-summary-params { color: var(--text-muted); }

body.rl-preset-modal-open { overflow: hidden; }
.rl-preset-edit-dialog { width: min(100%, 980px); max-height: min(90vh, 860px); }
.rl-preset-edit-header { min-height: 64px; }
.rl-preset-edit-header h3 { min-width: 0; }
.rl-preset-edit-header h3 > .ui-icon { width: 19px; height: 19px; filter: brightness(0) invert(1); flex-shrink: 0; }
.rl-preset-edit-titlewrap { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.rl-preset-edit-kicker { font-size: 10px; font-weight: 900; letter-spacing: 0; text-transform: uppercase; opacity: .78; }
.rl-preset-edit-title { min-width: 0; color: var(--text-stable-white); font-size: 18px; line-height: 1.15; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rl-preset-edit-close { display: inline-grid; place-items: center; padding: 0; flex-shrink: 0; }
.rl-preset-edit-close .ui-icon { width: 16px; height: 16px; filter: brightness(0) invert(1); }
.rl-preset-edit-close:hover .ui-icon { filter: none; }
.rl-preset-edit-body { background: var(--bg-surface); }
.rl-preset-edit-fields { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(180px, .65fr); gap: 14px; margin: 0 0 18px; padding: 16px; border: 1.5px solid var(--border-light); border-radius: 12px; background: var(--bg-surface-raised); }
.rl-preset-edit-fields .tmgmt-form-group--full { grid-column: 1 / -1; }
.rl-preset-edit-section-head { margin: 0 0 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--text-secondary); font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: 0; }
.rl-preset-edit-section-head small { color: var(--text-muted); font-size: 12px; font-weight: 800; text-transform: none; }
.rl-preset-edit-add { margin-top: 10px; }
.rl-preset-edit-footer { min-height: 68px; padding: 14px 20px; border-top: 1.5px solid var(--border-light); background: var(--bg-surface); display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-shrink: 0; }

@media (max-width: 720px) {
  .rl-preset-page-title { font-size: 26px; }
  #presets-list { grid-template-columns: 1fr; gap: 14px; }
  .rl-preset-head { align-items: flex-start; flex-direction: column; }
  .rl-preset-tools { width: 100%; justify-content: flex-end; }
  #presets-list .preset-summary-row { grid-template-columns: 1fr; gap: 4px; }
  #presets-list .preset-summary-params { white-space: normal; }
  .rl-preset-edit-dialog { max-height: calc(100vh - 24px); }
  .rl-preset-edit-title { font-size: 16px; }
  .rl-preset-edit-footer { padding-left: 16px; padding-right: 16px; }
  .rl-preset-edit-fields { grid-template-columns: 1fr; padding: 14px; }
}

/* Center modal (Esercizi edit) */
.rl-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.42); backdrop-filter: blur(2px); z-index: 90; opacity: 0; pointer-events: none; transition: .2s; }
.rl-scrim.open { opacity: 1; pointer-events: auto; }
body:has(#exercise-scrim.open) { overflow: hidden; }
#new-exercise-form {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px);
  margin: 0;
  z-index: 100;
  background: var(--bg-surface);
  box-shadow: 0 26px 70px var(--shadow-lg, rgba(0,0,0,.24));
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
}
#new-exercise-form .tmgmt-form-grid {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#new-exercise-form .tmgmt-form-grid::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}
.rl-drawer { position: fixed; top: 50%; left: 50%; height: auto; max-height: calc(100dvh - 40px); width: min(740px, calc(100vw - 32px)); background: var(--bg-surface); z-index: 100;
  border: 1.5px solid var(--border-medium); border-radius: 16px; box-shadow: 0 26px 70px var(--shadow-lg, rgba(0,0,0,.24)); transform: translate(-50%, -48%) scale(.96);
  opacity: 0; pointer-events: none; overflow: hidden; transition: transform .24s cubic-bezier(.4,0,.2,1), opacity .18s ease; display: flex; flex-direction: column; }
.rl-drawer.open { transform: translate(-50%, -50%) scale(1); opacity: 1; pointer-events: auto; }
#exercise-drawer .tmgmt-card-body {
  min-height: 0;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#exercise-drawer .tmgmt-card-body::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

@media (max-width: 640px) {
  #new-exercise-form { max-height: calc(100dvh - 24px); width: min(100vw - 16px, 640px); }
  .rl-drawer { max-height: calc(100dvh - 24px); width: min(100vw - 16px, 640px); border-radius: 14px; }
}

/* Plan-card volume preview (lista schede) — light at-a-glance days + muscle volume */
.plan-prev { display: flex; flex-direction: column; gap: 7px; margin-top: 10px; }
.plan-prevmeta { display: flex; align-items: center; gap: 9px; font-size: 11.5px; font-weight: 800; color: var(--text-muted); }
.plan-prevmeta .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--text-hint); }
.rl-volbar { display: flex; height: 7px; border-radius: 99px; overflow: hidden; background: var(--bg-surface-sunken); max-width: 380px; }
.rl-volbar > span { display: block; height: 100%; }
.rl-vol-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.rl-vol-legend .lg { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; font-weight: 700; color: var(--text-secondary); }
.rl-vol-legend .lg .d { width: 8px; height: 8px; border-radius: 3px; flex-shrink: 0; }
.rl-vol-legend .lg .n { color: var(--text-muted); font-weight: 800; }
