/* library.css — Rutinas (plantillas) y biblioteca de ejercicios (.lib-…). */

.lib-seg { margin-bottom: 2px; }
.lib-seg .seg-btn { min-height: 44px; font-size: calc(16px * var(--ts)); }
.lib-body { display: flex; flex-direction: column; gap: 12px; }
.lib-add {
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--border-strong);
}
.lib-add.is-pressed { background: var(--accent-soft); }
.lib-badge-inline { margin-left: 8px; vertical-align: 2px; }

/* ---------- Lista de rutinas ---------- */
.lib-tpl {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.lib-tpl:last-child { border-bottom: 0; }
.lib-tpl-main {
  flex: 1;
  min-width: 0;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 4px 12px 14px;
  border: 0;
  background: none;
  color: var(--text);
  text-align: left;
}
.lib-tpl-main.is-pressed { background: var(--surface-2); }
.lib-tpl-name { font-size: calc(17px * var(--ts)); font-weight: 750; line-height: 1.25; overflow-wrap: anywhere; }
.lib-tpl-meta { font-size: calc(13px * var(--ts)); font-weight: 650; color: var(--accent); }
.lib-tpl-ex {
  font-size: calc(14px * var(--ts));
  color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.lib-more { flex: none; align-self: stretch; min-width: 52px; color: var(--muted); border-radius: 0; }

/* ---------- Biblioteca ---------- */
.lib-search { padding-left: 14px; }
.lib-search::-webkit-search-decoration { -webkit-appearance: none; }
.lib-filter { display: flex; flex-direction: column; gap: 6px; }
.lib-filter-label {
  font-size: calc(12px * var(--ts));
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding-left: 2px;
}
.lib-chips .chip { min-height: 44px; }
.lib-count-row { min-height: 48px; }
.lib-switch-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  font-size: calc(15px * var(--ts));
  font-weight: 600;
  color: var(--text-2);
}
.lib-ex-row { align-items: center; min-height: 64px; }
.lib-ex-name { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-weight: 700; line-height: 1.25; min-width: 0; }
.lib-ex-name > span:first-child { min-width: 0; overflow-wrap: anywhere; } /* un nombre de una sola palabra larga parte antes que salirse */
.lib-ex-muscles { font-size: calc(14px * var(--ts)); color: var(--text-2); }
.lib-ex-meta { font-size: calc(13px * var(--ts)); color: var(--muted); }

/* ---------- Ficha ---------- */
.lib-badges { gap: 6px; }
.lib-badges .badge { font-size: calc(13px * var(--ts)); padding: 3px 10px; }
.lib-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.lib-tag {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: calc(14px * var(--ts));
  font-weight: 650;
}
.lib-tag-primary { background: var(--accent-soft); color: var(--accent); }
.lib-kv-block { display: flex; flex-direction: column; gap: 6px; }
.lib-k { font-size: calc(13px * var(--ts)); font-weight: 700; color: var(--muted); }
.lib-kv {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  padding: 2px 0 10px;
  border-bottom: 1px solid var(--border);
}
.lib-kv:last-child { border-bottom: 0; padding-bottom: 0; }
.lib-v { text-align: right; font-weight: 650; overflow-wrap: anywhere; }
.lib-kv-text { flex-direction: column; align-items: stretch; gap: 4px; }
.lib-kv-text .lib-v { text-align: left; font-weight: 500; white-space: pre-wrap; color: var(--text-2); }
.lib-data .lib-kv-block { padding-top: 2px; }
.lib-tpl-chip { min-height: 44px; }
.lib-link { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.lib-link > .icon:first-child { color: var(--accent); flex: none; }
.lib-hist-head { margin-top: 4px; }
.lib-hist-row { align-items: center; }
.lib-hist-sets { font-size: calc(14px * var(--ts)); color: var(--text); font-weight: 600; white-space: normal; overflow-wrap: anywhere; }
/* Cada serie salta de línea entera («−15 kg asist. × 8 @1»); solo se parte si no cabe sola. */
.lib-hist-set { display: inline-block; }
.lib-e1rm { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.lib-e1rm-v { font-weight: 800; font-size: calc(16px * var(--ts)); color: var(--accent); white-space: nowrap; }
.lib-e1rm-l { font-size: var(--fs-xs); font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.lib-e1rm-note { padding: 0 2px; line-height: 1.45; }
.lib-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
/* De un vistazo (ronda 8, A5): última vez, mejor serie, 1RM estimado y tendencia, arriba de la ficha. */
.lib-glance { gap: 12px; }
.lib-glance-last { display: flex; flex-direction: column; gap: 4px; }
.lib-glance-sets { font-size: calc(17px * var(--ts)); font-weight: 750; line-height: 1.35; overflow-wrap: anywhere; }
.lib-glance-kpi { display: flex; flex-direction: column; gap: 2px; }
.lib-glance-set { font-size: calc(17px * var(--ts)); overflow-wrap: anywhere; }
.lib-glance-kpi .kpi-sub { line-height: 1.3; overflow-wrap: anywhere; }
.lib-glance-trend { display: flex; flex-direction: column; gap: 2px; }
/* Sin color de juicio (docs/PULIDO.md §12, §20): subir o bajar no es bueno ni malo por sí solo. */
.lib-glance-trend-v { font-size: calc(15px * var(--ts)); font-weight: 650; color: var(--text); }

/* ---------- Editor de ejercicio ---------- */
.lib-form .card { gap: 14px; }
.lib-type-chips .chip,
.lib-muscle-chips .chip,
.lib-pattern-chips .chip,
.lib-region-chips .chip { min-height: 44px; white-space: normal; text-align: left; line-height: 1.2; padding-top: 6px; padding-bottom: 6px; }
.lib-muscle-sec .chip.active { background: var(--info); border-color: var(--info); color: #06121f; }
.lib-form .seg-btn { min-height: 44px; }
.lib-draft .btn { flex: none; }
.lib-create { margin-top: 4px; }

/* ---------- Editor de rutina ---------- */
.lib-tpl-form { gap: 12px; }
.lib-items-head { margin-top: 4px; }
.lib-items-head .section-title { margin: 0 2px; }
.lib-items { display: flex; flex-direction: column; gap: 10px; }
.lib-section { color: var(--accent); margin: 8px 2px -2px; }
.lib-foot { padding: 0 2px; }

.lib-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 10px;
  border-left: 3px solid var(--info);
  border-radius: 2px;
}
.lib-group[data-type="circuit"] { border-left-color: var(--act-other); }
.lib-group-head { display: flex; align-items: center; gap: 8px; font-size: calc(13px * var(--ts)); color: var(--muted); font-weight: 650; }
.lib-group-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lib-group-kind { color: var(--info); font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.lib-group-sub { overflow-wrap: anywhere; }
.lib-group[data-type="circuit"] .lib-group-kind { color: var(--act-other); }
.lib-group-btn {
  flex: none;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: calc(14px * var(--ts));
  font-weight: 700;
  white-space: nowrap;
}

.lib-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* Cabecera sticky: 52 px + muesca/isla (--sat) + borde; con margen para que el ítem quede a la vista. */
  scroll-margin-top: calc(var(--topbar-h, calc(var(--sat) + 68px)) + 8px); /* alto real de la cabecera (ui.screen) */
  scroll-margin-bottom: calc(var(--tabbar-h) + var(--sab) + 16px);
}
.lib-item.open { border-color: var(--border-strong); background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 120px), var(--surface); }
.lib-item-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 60px;
  padding: 10px 12px;
  border: 0;
  background: none;
  color: var(--text);
  text-align: left;
  border-radius: var(--radius);
}
.lib-item-head.is-pressed { background: var(--surface-2); }
.lib-item-label {
  flex: none;
  min-width: 36px;
  min-height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--info-soft);
  color: var(--info);
  font-size: calc(14px * var(--ts));
  font-weight: 800;
}
.lib-group[data-type="circuit"] .lib-item-label { background: rgba(232, 121, 249, 0.16); color: var(--act-other); }
.lib-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lib-item-name { font-size: calc(17px * var(--ts)); font-weight: 720; line-height: 1.25; overflow-wrap: anywhere; }
.lib-item-alt { font-size: calc(14px * var(--ts)); color: var(--text-2); overflow-wrap: anywhere; }
.lib-item-note { font-size: calc(13px * var(--ts)); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item-target { flex: none; max-width: 38%; text-align: right; font-size: calc(16px * var(--ts)); font-weight: 800; color: var(--accent); }
.lib-item-chev { flex: none; color: var(--muted); }

.lib-item-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px 12px 14px;
  border-top: 1px solid var(--border);
}
.lib-ex-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
}
.lib-ex-btn.is-pressed { background: var(--surface-3); }
.lib-ex-btn-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lib-ex-btn-k { font-size: calc(12px * var(--ts)); font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.lib-ex-btn-v { font-weight: 700; overflow-wrap: anywhere; }
.lib-ex-btn-hint { flex: none; display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-weight: 700; font-size: calc(15px * var(--ts)); }
.lib-target { display: flex; flex-direction: column; gap: 10px; }
.lib-pair { gap: 8px; align-items: end; }
.lib-pair .stepper-label { text-align: left; padding-left: 2px; }
.lib-alts { display: flex; flex-wrap: wrap; gap: 8px; }
.lib-alt { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; color: var(--text); white-space: normal; text-align: left; }
.lib-alt .icon { color: var(--muted); flex: none; }
.lib-alt-add { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; color: var(--accent); border-style: dashed; background: transparent; }
.lib-sec-chips { margin-top: 2px; }
.lib-sec-chips .chip { min-height: 44px; }
.lib-grp-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lib-grp-btn { flex: 1 1 auto; }
.lib-item-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.lib-act {
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 4px 2px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: calc(13px * var(--ts));
  font-weight: 700;
}
.lib-act.is-pressed { background: var(--surface-3); }
.lib-act:disabled { opacity: 0.35; }
.lib-act.danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.45); }
