/* components.css — catálogo de componentes. CERO valores crudos: solo var(--token). */

@layer components {
  /* ── Iconos ── */
  .icon { width: 18px; height: 18px; flex: none; }
  .icon--sm { width: 14px; height: 14px; }

  /* ── Botones ── */
  .btn {
    display: inline-flex; align-items: center; gap: var(--space-2);
    font-weight: 500; font-size: var(--text-base); line-height: 1.4;
    padding: 7px 14px; border-radius: var(--radius-sm);
    border: 1px solid transparent; background: none; cursor: pointer;
    text-decoration: none; white-space: nowrap;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
                color var(--dur) var(--ease), transform var(--dur) var(--ease);
  }
  .btn:active { transform: scale(0.98); }
  .btn .icon { width: 16px; height: 16px; }
  .btn--primary { background: var(--accent); color: var(--accent-contrast); }
  .btn--primary:hover { background: var(--accent-hover); }
  .btn--secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
  .btn--secondary:hover { background: var(--surface-2); }
  .btn--ghost { color: var(--text-2); }
  .btn--ghost:hover { background: var(--surface-2); color: var(--text); }
  .btn--danger { background: var(--bad); color: var(--bad-contrast); }
  .btn--danger:hover { background: color-mix(in srgb, var(--bad) 88%, var(--gray-900)); }
  .btn--sm { padding: 4px 10px; font-size: var(--text-sm); }
  .btn:disabled { opacity: 0.55; cursor: not-allowed; }
  .btn--full { width: 100%; justify-content: center; }
  .btn-group { display: flex; gap: var(--space-2); flex-wrap: wrap; }
  .filter-form { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: flex-end; }

  /* ── Formularios manuales ── */
  .field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); }
  .field__label { font-size: var(--text-sm); font-weight: 500; display: inline-flex; align-items: center; gap: var(--space-1); }
  .field__help { font-size: var(--text-sm); color: var(--text-2); }
  .field__help-icon {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--text-3); color: var(--surface);
    font-size: 10px; font-weight: 600; line-height: 1;
    cursor: help; flex: none; user-select: none;
    transition: background var(--dur) var(--ease);
  }
  .field__help-icon::before { content: "?"; }
  .field__help-icon::after {
    content: attr(data-tip);
    position: absolute; bottom: calc(100% + 6px); left: 50%;
    transform: translateX(-50%);
    background: var(--gray-800); color: #fff;
    font-size: var(--text-xs); font-weight: 400;
    padding: 6px 10px; border-radius: var(--radius-sm);
    white-space: normal; width: max-content; max-width: 260px;
    pointer-events: none; opacity: 0;
    transition: opacity var(--dur) var(--ease);
    z-index: var(--z-dropdown); line-height: 1.4;
  }
  .field__help-icon:hover { background: var(--accent); }
  .field__help-icon:hover::after { opacity: 1; }
  .field__error { display: flex; align-items: center; gap: var(--space-1); font-size: var(--text-sm); color: var(--bad); }
  .field--error input, .field--error select, .field--error textarea { border-color: var(--bad); }
  .field--compact { margin-bottom: 0; }

  /* ── Formularios renderizados por Django ({{ form.as_p }}) ── */
  .form p { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); }
  .form label { font-size: var(--text-sm); font-weight: 500; }
  .form .helptext { font-size: var(--text-sm); color: var(--text-2); }
  .errorlist { list-style: none; padding: 0; font-size: var(--text-sm); color: var(--bad); }
  .form--inline { display: inline; }
  .form-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-6); }
  .form-actions--between { justify-content: space-between; }
  .fieldset-clean { border: 0; padding: 0; }
  .fieldset-clean legend.field__label { margin-bottom: var(--space-3); padding: 0; }

  /* ── Tablas de datos ── */
  .table-wrap {
    overflow-x: auto; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-md);
  }
  .table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
  .table th {
    text-align: left; font-size: var(--text-xs); text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--text-2); font-weight: 600;
    padding: 8px 12px; border-bottom: 1px solid var(--border);
    background: var(--surface-2); white-space: nowrap;
  }
  .table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table tbody tr:hover { background: var(--surface-2); }
  .row--atipico { background: var(--gray-100); }
  .row--atipico td:first-child::before { content: "⚠ "; color: var(--warn); font-size: var(--text-xs); }
  .table__row--link { cursor: pointer; }
  .table .num {
    font-family: var(--font-mono); font-variant-numeric: tabular-nums;
    text-align: right; white-space: nowrap;
  }
  .table .empty-cell { text-align: center; color: var(--text-2); padding: var(--space-8); }
  .table input, .table select { padding: 5px 8px; font-size: var(--text-sm); }
  .table-wrap--flush { border: none; border-radius: 0; }
  .table .cell--limit { max-width: 320px; }
  .table .cell-mono { font-weight: 500; }
  .table .cell-meta { font-size: var(--text-xs); color: var(--text-2); }
  .table--sticky-first th:first-child, .table--sticky-first td:first-child {
    position: sticky; left: 0; background: var(--surface);
    box-shadow: 1px 0 0 var(--border);
  }
  .table--sticky-first th:first-child { background: var(--surface-2); }

  /* ── Badges de semáforo (fondo teñido + punto) ── */
  .badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 2px 10px; border-radius: var(--radius-pill);
    font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
  }
  .badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
  .badge--ok   { background: var(--ok-bg);   color: var(--ok); }
  .badge--warn { background: var(--warn-bg); color: var(--warn); }
  .badge--bad  { background: var(--bad-bg);  color: var(--bad); }
  .badge--none { background: var(--none-bg); color: var(--none); }

  /* ── Pills de estado de ciclo ── */
  .pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 2px 10px; border-radius: var(--radius-pill);
    font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
  }
  .pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
  .pill--borrador  { background: var(--none-bg); color: var(--none); }
  .pill--abierto   { background: color-mix(in srgb, var(--estado-abierto) 10%, var(--surface)); color: var(--estado-abierto); }
  .pill--cerrado   { background: var(--warn-bg); color: var(--warn); }
  .pill--calculado { background: color-mix(in srgb, var(--estado-calculado) 10%, var(--surface)); color: var(--estado-calculado); }
  .pill--publicado { background: var(--ok-bg); color: var(--ok); }

  /* ── Tag (modalidad, metadata neutral) ── */
  .tag {
    display: inline-flex; padding: 2px 8px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
    font-size: var(--text-xs); color: var(--text-2); white-space: nowrap;
  }

  /* ── Flags (atípico, unidad) ── */
  .flag { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-xs); font-weight: 600; color: var(--warn); }
  .flag--bad { color: var(--bad); }
  .flag .icon { width: 14px; height: 14px; }

  /* ── Alertas (Django messages: success/error/warning/info/debug) ── */
  .alerts { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
  .alert {
    display: flex; gap: var(--space-2); align-items: flex-start;
    padding: 10px 14px; border-radius: var(--radius-sm);
    font-size: var(--text-sm); border: 1px solid var(--border);
    background: var(--surface-2); color: var(--text);
  }
  .alert .icon { width: 16px; height: 16px; margin-top: 2px; }
  .alert--success { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, var(--surface)); }
  .alert--error   { background: var(--bad-bg); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, var(--surface)); }
  .alert--warning { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, var(--surface)); }
  .alert--info    { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, var(--surface)); }

  /* ── Tarjetas ── */
  .card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); box-shadow: var(--shadow-card);
    padding: var(--space-5);
  }
  .card__area { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); }
  .card__title { font-size: var(--text-md); font-weight: 600; margin-top: 2px; }
  .card__meta { font-size: var(--text-sm); color: var(--text-2); margin: var(--space-2) 0 var(--space-4); }
  .card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); grid-auto-rows: 220px; gap: var(--space-4); margin-bottom: var(--space-8); }
  .card-grid .card { display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
  .card-grid .card > .btn { margin-top: auto; align-self: flex-start; }
  .card--narrow { max-width: 520px; }
  .card--flat { padding: 0; overflow: hidden; }
  .card--neutral { max-width: 480px; }
  .card + .card { margin-top: var(--space-4); }
  .card__title--sm { font-size: var(--text-md); margin-bottom: var(--space-4); }
  .section-title { font-size: var(--text-lg); margin-bottom: var(--space-3); }
  .stat { display: flex; flex-direction: column; gap: 2px; }
  .stat__value { font-family: var(--font-mono); font-size: var(--text-xl); font-weight: 600; font-variant-numeric: tabular-nums; }
  .stat__label { font-size: var(--text-sm); color: var(--text-2); }

  /* ── Empty state ── */
  .empty {
    display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
    padding: var(--space-10) var(--space-4); color: var(--text-2); text-align: center;
    font-size: var(--text-sm);
  }
  .empty .icon { width: 28px; height: 28px; color: var(--text-3); }

  /* ── Page header ── */
  .page-head {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-6);
  }
  .page-head__title { font-size: var(--text-xl); font-weight: 600; }
  .page-head__meta {
    display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
    color: var(--text-2); font-size: var(--text-sm); margin-top: var(--space-1);
  }
  .page-head__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

  /* ── Dropdown (menú de usuario, Alpine) ── */
  .dropdown { position: relative; }
  .dropdown__menu {
    position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-pop);
    padding: var(--space-1); z-index: var(--z-dropdown);
  }
  .dropdown__item {
    display: flex; align-items: center; gap: var(--space-2); width: 100%;
    padding: 8px 10px; border-radius: var(--radius-sm);
    font-size: var(--text-sm); color: var(--text); text-decoration: none;
  }
  .dropdown__item:hover { background: var(--surface-2); }
  .dropdown__item .icon { width: 16px; height: 16px; }

  /* ── Radio cards (cualitativos) ── */
  .radio-cards { display: flex; flex-direction: column; gap: var(--space-2); }
  .radio-card {
    display: flex; align-items: center; gap: var(--space-2);
    padding: 10px 12px; border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm); cursor: pointer; font-size: var(--text-sm);
    transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  }
  .radio-card:hover { border-color: var(--accent); }
  .radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
  .radio-card input { accent-color: var(--accent); }
  .radio-card--sm { padding: 4px 10px; font-size: var(--text-xs); font-weight: 500; }
  .manual-veredicto-row { border: 0; padding: 0; margin: 0; }
  .manual-veredicto-row legend { padding: 0; margin-bottom: var(--space-2); font-size: var(--text-sm); font-weight: 500; }
  .manual-veredicto-row__options { display: flex; flex-wrap: wrap; gap: var(--space-2); }

  /* ── Paginación ── */
  .pagination {
    display: flex; align-items: center; gap: var(--space-3);
    margin-top: var(--space-4); font-size: var(--text-sm); color: var(--text-2);
  }

  /* ── Caja de credenciales (alta de laboratorio) ── */
  .cred {
    background: var(--ok-bg); border: 1px solid color-mix(in srgb, var(--ok) 25%, var(--surface));
    color: var(--ok); padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm); font-size: var(--text-sm); margin-bottom: var(--space-4);
  }
  .cred code { font-weight: 600; }

  /* ── Bloque de sección ── */
  .block { margin-bottom: var(--space-8); }
  .sg-p { margin-top: 8px; }
  .sg-gap { margin-top: var(--space-4); }

  /* ── Breadcrumb (ruta de navegación) ── */
  .breadcrumb { margin-bottom: var(--space-4); }
  .breadcrumb__list {
    display: flex; align-items: center; flex-wrap: wrap;
    gap: var(--space-1); list-style: none; padding: 0; margin: 0;
  }
  .breadcrumb__item { display: inline-flex; align-items: center; gap: var(--space-1); }
  .breadcrumb__link {
    color: var(--text-2); text-decoration: none;
    padding: 2px 6px; border-radius: var(--radius-sm);
  }
  .breadcrumb__link:hover { color: var(--text); background: var(--surface-2); }
  .breadcrumb__current { color: var(--text); font-weight: 500; padding: 2px 6px; }
  .breadcrumb__sep { color: var(--text-3); display: inline-flex; }
  .breadcrumb__sep .icon { width: 12px; height: 12px; }

  /* ── Dropdown item como fila estática (avance panel ciclo) ── */
  .dropdown__item--static { cursor: default; justify-content: space-between; }
  .dropdown__item--static .num { font-family: var(--font-mono); }
  .dropdown__item--link { cursor: pointer; }

  /* ── Analito row (cuestionario cuantitativo) ── */
  .analito-row { padding: var(--space-4) 0; border-bottom: 1px solid var(--border); }
  .analito-row:first-child { padding-top: 0; }
  .analito-row:last-child { border-bottom: 0; }
  .analito-meta { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); max-width: 440px; }
  .field--tight { margin-bottom: var(--space-2); }
  .input--narrow { max-width: 220px; font-family: var(--font-mono); }

  /* ── Score (informe, calificación global) ── */
  .score { text-align: center; }
  .score__label { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); }
  .score__value { font-family: var(--font-mono); font-size: var(--text-2xl); font-weight: 600; font-variant-numeric: tabular-nums; margin-top: var(--space-2); }
  .score__sub { font-size: var(--text-sm); color: var(--text-2); }

  /* ── Section intro (dentro de card--flat) ── */
  .section-intro { padding: var(--space-4) var(--space-4) 0; }
  .section-intro__title { margin-bottom: var(--space-1); }
  .section-intro__title--lg { margin-bottom: var(--space-5); }
  .section-intro__body { color: var(--text-2); font-size: var(--text-sm); margin-bottom: var(--space-4); }

  /* ── Chart header & legend (informe cuantitativo) ── */
  .chart-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-4); }
  .legend { display: flex; gap: var(--space-3); font-size: var(--text-xs); }
  .legend__dot { display: inline-flex; align-items: center; gap: 4px; }
  .legend__dot::before { content: ""; width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
  .legend__dot--ok::before { background: var(--ok); }
  .legend__dot--warn::before { background: var(--warn); }
  .legend__dot--bad::before { background: var(--bad); }

  /* ── Chart section (informe cuantitativo) ── */
  .chart-section { margin-top: var(--space-6); }
  .chart-area { overflow-x: auto; }
  .chart-area svg { max-width: 100%; height: auto; }

  /* ── Stat grid (informe cuantitativo) ── */
  .stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-5); }
  .stat-box { padding: var(--space-3); background: var(--surface-2); border-radius: var(--radius-sm); }
  .badge-group { display: flex; flex-wrap: wrap; gap: var(--space-3); }

  /* ── Input width helper (captura lote) ── */
  .input--lote { min-width: 110px; }

  /* ── Config grid (config_cual, fieldset.card rows) ── */
  .config-grid { display: grid; grid-template-columns: minmax(220px, 2fr) 1fr 110px 1fr; gap: var(--space-2); }

  /* ── Config analito card (config_cuant) ── */
  .config-analito-grid {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    gap: var(--space-2) var(--space-3);
  }
  .config-analito-grid .field--span-2 { grid-column: span 2; }

  /* ── Config pregunta (config_cual) enunciado full-width + tipo/peso/respuesta ── */
  .config-pregunta { display: flex; flex-direction: column; gap: var(--space-3); }
  .config-pregunta-row {
    display: grid;
    grid-template-columns: 1fr 80px 1fr;
    gap: var(--space-2);
  }

  /* ── Config opción (config_cual) fila de opción múltiple ── */
  .config-opcion-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: var(--space-2);
    align-items: center;
  }
  .config-opcion-row .radio-card--sm { justify-self: start; }

  /* ── Avance card (panel ciclo, lista compacta) ── */
  .card--compact { padding: var(--space-2); }

  /* ── Adjuntos del ciclo (cuestionario lab) ── */
  .adjuntos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-2);
  }
  .adjunto {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
  }
  .adjunto--imagen {
    flex-direction: column;
    align-items: flex-start;
  }
  .adjunto--imagen img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: var(--radius-sm);
  }
  .adjunto__desc {
    font-size: var(--text-sm);
    color: var(--text-2);
  }
  .galeria {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: var(--space-2);
    margin-bottom: var(--space-3);
  }
  .galeria__btn {
    display: block;
    width: 100%;
    padding: 0;
    background: none;
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
  }
  .galeria img {
    width: 100%;
    height: 96px;
    object-fit: cover;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    transition: border-color var(--dur) var(--ease), opacity var(--dur) var(--ease);
  }
  .galeria__btn:hover img { border-color: var(--accent); opacity: 0.9; }
  .galeria__btn:focus-visible img { outline: 2px solid var(--accent); outline-offset: 2px; }

  /* ── Editor de adjuntos (editar_ciclo) ── */
  .adjunto-editor {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-3);
  }
  .adjunto-editor__file {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
    font-size: var(--text-sm);
    color: var(--text-2);
  }
  .adjunto-editor__file img {
    display: block;
    width: 100%;
    height: 72px;
    object-fit: cover;
  }



  /* ── Párrafo final de sección (informe) ── */
  .field__help--flush { margin-top: var(--space-4); }

  /* ── Modal (componente reutilizable: overlay + contenedor) ── */
  .modal-overlay {
    position: fixed; inset: 0;
    z-index: var(--z-modal);
    display: flex; align-items: center; justify-content: center;
    padding: var(--space-4);
    background: rgb(15 23 42 / 0.4);
    backdrop-filter: blur(2px);
  }
  .modal {
    display: flex; flex-direction: column;
    width: 100%; max-width: 520px;
    max-height: calc(100vh - var(--space-8) * 2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-pop);
    overflow: hidden;
  }
  .modal--sm { max-width: 380px; }
  .modal--lg { max-width: 680px; }
  .modal__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .modal__title { font-size: var(--text-md); font-weight: 600; }
  .modal__close {
    display: inline-flex; align-items: center; justify-content: center;
    padding: var(--space-1);
    border: none; background: none; cursor: pointer;
    color: var(--text-2); border-radius: var(--radius-sm);
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  }
  .modal__close:hover { background: var(--surface-2); color: var(--text); }
  .modal__close .icon { width: 18px; height: 18px; }
  .modal__body {
    padding: var(--space-5);
    overflow-y: auto; flex: 1;
  }
  .modal__footer {
    display: flex; justify-content: flex-end; gap: var(--space-2);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }

  /* ── Visor de imagen del cuestionario (lightbox con zoom/pan) ── */
  .img-modal {
    position: fixed; inset: 0;
    z-index: var(--z-modal);
    display: flex; align-items: center; justify-content: center;
    padding: var(--space-4);
  }
  .img-modal__backdrop {
    position: absolute; inset: 0;
    background: radial-gradient(circle at center, rgb(15 23 42 / 0.72), rgb(15 23 42 / 0.88));
    backdrop-filter: blur(2px);
    cursor: pointer;
  }
  .img-modal__dialog {
    position: relative;
    display: flex; flex-direction: column;
    width: min(95vh, 95vw, 1200px);
    aspect-ratio: 1 / 1;
    max-height: 95vh;
    background: var(--gray-900);
    border: 1px solid var(--gray-800);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-pop);
    overflow: hidden;
  }
  .img-modal__header {
    display: flex; align-items: center; gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--gray-800);
    flex-shrink: 0;
  }
  .img-modal__name {
    flex: 1;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--gray-300);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    padding: 0 var(--space-2);
  }
  .img-modal__action {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    padding: 0;
    background: none; border: 0;
    color: var(--gray-300);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  }
  .img-modal__action:hover { background: var(--gray-800); color: var(--surface); }
  .img-modal__action:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  .img-modal__action .icon { width: 18px; height: 18px; }
  .img-modal__stage {
    position: relative;
    flex: 1;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    min-height: 0;
    padding: var(--space-4);
    background: var(--gray-900);
    cursor: zoom-in;
  }
  .img-modal__img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    transform-origin: center center;
  }
  .img-modal__img.is-zoomed { cursor: grab; }
  .img-modal__img.is-dragging { cursor: grabbing; }
  .img-modal__skeleton {
    position: absolute;
    inset: var(--space-4);
    background: linear-gradient(90deg, var(--gray-800) 0%, var(--gray-700) 50%, var(--gray-800) 100%);
    background-size: 200% 100%;
    animation: img-modal-shimmer 1.5s linear infinite;
    border-radius: var(--radius-sm);
  }
  @keyframes img-modal-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }
  .img-modal__footer {
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-top: 1px solid var(--gray-800);
    flex-shrink: 0;
  }
  .img-modal__hint {
    color: var(--gray-400);
    font-size: var(--text-xs);
  }
  .img-modal__zoom {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--gray-200);
    padding: 2px 8px;
    background: var(--gray-800);
    border-radius: var(--radius-sm);
  }
}

.config-imagenes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.config-imagen {
  position: relative;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.config-imagen img {
  display: block;
  width: 100%;
  height: 96px;
  object-fit: cover;
}

.config-imagen .btn {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
}

.upload-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.stepper {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-4) 0;
  padding: 0;
  list-style: none;
}

.stepper__step {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1 1 0;
  min-width: 0;
}

.stepper__step + .stepper__step::before {
  content: "";
  flex: 1 1 0;
  height: 2px;
  background: var(--gray-200);
  border-radius: var(--radius-pill);
}

.stepper__dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-pill);
  background: var(--gray-200);
  color: var(--text-3);
  font-size: var(--text-xs);
  flex-shrink: 0;
}

.stepper__dot .icon { width: 14px; height: 14px; }

.stepper__label {
  font-size: var(--text-sm);
  color: var(--text-3);
  white-space: nowrap;
}

.stepper__step--done .stepper__dot {
  background: var(--accent);
  color: var(--accent-contrast);
}

.stepper__step--done .stepper__label { color: var(--accent); }

.stepper__step--current .stepper__dot {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.stepper__step--current .stepper__label {
  color: var(--text);
  font-weight: 600;
}

/* ── Consolidado global ──
   Los anchos de las barras de datos se inyectan con la custom property --pct
   (ver excepción documentada en docs/style.md). */

/* KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.kpi {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}
.kpi__value {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi__label { font-size: var(--text-sm); color: var(--text-2); }
.kpi__hint { font-size: var(--text-xs); color: var(--text-3); }
.kpi--ok .kpi__value { color: var(--ok); }
.kpi--warn .kpi__value { color: var(--warn); }
.kpi--bad .kpi__value { color: var(--bad); }

/* Distribución apilada */
.dist {
  display: flex;
  height: 14px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}
.dist__seg { height: 100%; width: var(--pct, 0%); }
.seg--ok { background: var(--ok); }
.seg--warn { background: var(--warn); }
.seg--bad { background: var(--bad); }
.seg--none { background: var(--none); }
.dist-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-2);
}
.dist-legend__item { display: inline-flex; align-items: center; gap: 6px; }
.dist-legend__dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* Meter (porcentaje en línea dentro de tabla) */
.meter-row { display: flex; align-items: center; gap: var(--space-3); min-width: 160px; }
.meter-row .num { min-width: 56px; }
.meter {
  flex: 1;
  min-width: 90px;
  height: 8px;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
}
.meter__fill {
  height: 100%;
  width: var(--pct, 0%);
  background: var(--accent);
  border-radius: var(--radius-pill);
}
.meter__fill--ok { background: var(--ok); }
.meter__fill--warn { background: var(--warn); }
.meter__fill--bad { background: var(--bad); }

/* Matriz de concordancia */
.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
.matrix .heat--ok { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.matrix .heat--warn { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.matrix .heat--bad { background: var(--bad-bg); color: var(--bad); font-weight: 600; }
.matrix .heat--zero { color: var(--text-3); }

/* Lista de alertas prioritarias */
.priority { display: flex; flex-direction: column; gap: var(--space-2); }
.priority__item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.priority__icon { color: var(--warn); flex: none; margin-top: 2px; }
.priority__icon--bad { color: var(--bad); }
.priority__icon--info { color: var(--text-2); }
.priority__body { flex: 1; min-width: 0; }
.priority__title { font-size: var(--text-sm); font-weight: 600; }
.priority__desc { font-size: var(--text-sm); color: var(--text-2); }

/* Grid de dos columnas responsivo */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--space-4);
}
.grid-2 > .card { margin-top: 0; }

/* Encabezado de sección numerado */
.section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
  margin-bottom: var(--space-2);
}

/* Estado global del ciclo */
.consolidado-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.consolidado-status--ok { border-color: color-mix(in srgb, var(--ok) 30%, var(--surface)); }
.consolidado-status--warn { border-color: color-mix(in srgb, var(--warn) 35%, var(--surface)); }
.consolidado-status--bad { border-color: color-mix(in srgb, var(--bad) 35%, var(--surface)); }
.consolidado-status--ok .consolidado-status__title { color: var(--ok); }
.consolidado-status--warn .consolidado-status__title { color: var(--warn); }
.consolidado-status--bad .consolidado-status__title { color: var(--bad); }
.consolidado-status__label { color: var(--text-2); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; }
.consolidado-status__title { margin-top: var(--space-1); }
.consolidado-status__summary { color: var(--text-2); margin-top: var(--space-1); }
.consolidado-status__meta { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); color: var(--text-2); font-size: var(--text-sm); }

/* Navegación interna del consolidado */
.consolidado-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1);
  margin-bottom: var(--space-5);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.consolidado-nav__link {
  display: inline-flex;
  align-items: center;
  flex: none;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-2);
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.consolidado-nav__link:hover { background: var(--surface); color: var(--text); }
.consolidado-nav__link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Ayuda metodológica (disclosure antes de tablas densas) */
.methodology-help {
  margin-bottom: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.methodology-help > summary {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
}
.methodology-help[open] > summary {
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.methodology-help > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.methodology-help__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-2);
}

/* Grupos de badges separados por método (ISO / EMA) */
.badge-group--metodo {
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-3) var(--space-4);
  padding: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.badge-group__label {
  flex-basis: 100%;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-2);
}

/* Pista de desplazamiento horizontal (visible solo en pantallas estrechas) */
.table-scroll-hint {
  display: none;
  padding: var(--space-2) var(--space-4) 0;
  font-size: var(--text-xs);
  color: var(--text-2);
}

/* Primera columna fija: fondo sólido y hover de fila preservados */
.table--sticky-first tbody tr:hover td:first-child { background: var(--surface-2); }
.table--sticky-first tbody tr.row--atipico:not(:hover) td:first-child { background: var(--gray-100); }

@media (max-width: 639px) {
  .consolidado-status {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    margin-bottom: var(--space-5);
  }
  .consolidado-status__meta { align-items: flex-start; }
  .consolidado-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin-bottom: var(--space-4);
  }
  .methodology-help { margin-bottom: var(--space-3); }
  .badge-group--metodo { padding: var(--space-2); }
  .table-scroll-hint { display: block; }
}

.stat-grid--inset { padding: 0 var(--space-4); }

/* Spinner de proceso (acciones largas del ciclo) */
.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.submit-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: color-mix(in srgb, var(--gray-900) 35%, transparent);
}
.submit-overlay__box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-8);
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  max-width: 320px;
  text-align: center;
}
.submit-overlay__text { font-size: var(--text-sm); color: var(--text-2); }
