/* 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); }
  .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); }

  /* ── 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); }

  /* ── 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; }

  /* ── 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);
  }

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



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