/*
 * =============================================================================
 * INVENTARIO › PRODUCTOS — piloto del sistema visual 1.0 (Fase D)
 * =============================================================================
 *
 * Barra de filtros, celdas de dos líneas, la cifra de
 * existencia que abre el historial y el historial en el panel lateral.
 * Sólo fichas de tokens.css; los componentes (botones, campos, tabla,
 * estados, pestañas, drawer) vienen de components.css.
 * =============================================================================
 */

/* La cabecera de página (.page-header) es componente: components.css. */

/* --- Filtros -------------------------------------------------------------- */

.products__filters {
    align-items: flex-end;
}

.products__search {
    flex: 2 1 260px;
    display: flex;
    flex-direction: column;
}

.products__filters > .field {
    flex: 1 1 180px;
}

.products__lookup {
    flex: 1 1 300px;
    align-items: flex-end;
}

.products__lookup .field {
    flex: 1 1 auto;
}

.products__toolbar .field__hint {
    margin: var(--space-2) 0 0;
}

.products__count {
    margin: var(--space-4) 0 var(--space-1);
    color: var(--text-2);
    font-size: var(--text-sm);
}

.products__count:empty {
    display: none;
}

/* --- Celdas --------------------------------------------------------------- */

/* Dos líneas en una fila de 56 px: lo principal y un dato de apoyo. */
.cell-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 22rem;
    white-space: normal;
    line-height: 1.3;
}

.cell-stack__main {
    font-weight: 500;
}

.cell-stack__sub {
    color: var(--text-2);
    font-size: var(--text-sm);
}

/* El nombre no se aprieta a tres líneas: la tabla se desplaza de lado antes. */
.cell-stack--product {
    min-width: 14rem;
}

.cell-stack.num {
    white-space: nowrap;
}

.cell-stack.num .cell-stack__main {
    font-weight: 400;
}

.row-actions {
    justify-content: flex-end;
    gap: 2px;
}

/* --- La cifra de existencia: subrayado punteado + icono de historial ------ */

.stock-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    margin-right: calc(var(--space-1) * -1);
    padding: 2px var(--space-1);
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: inherit;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: background-color var(--dur-instant) var(--ease);
}

.stock-link__value {
    text-decoration: underline dotted var(--text-3);
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
}

.stock-link__icon {
    color: var(--text-2);
    opacity: 0;
    transition: opacity var(--dur-fast) var(--ease);
}

.table tbody tr:hover .stock-link__icon,
.stock-link:hover .stock-link__icon,
.stock-link:focus-visible .stock-link__icon {
    opacity: 1;
}

.stock-link:hover {
    background: var(--surface-2);
}

.stock-link:hover .stock-link__value {
    text-decoration-color: var(--text);
}

.stock-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Pantallas táctiles: no hay "pasar el ratón"; el icono se ve siempre y el
   blanco de toque vuelve a 44 px. */
@media (hover: none), (pointer: coarse) {
    .stock-link {
        min-height: var(--touch-target);
    }

    .stock-link__icon {
        opacity: 1;
    }
}

/* --- Historial en el panel lateral ---------------------------------------- */

.history__summary {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-3);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.history__label {
    margin: 0 0 var(--space-1);
    color: var(--text-2);
    font-size: var(--text-sm);
}

.history__stock {
    margin: 0;
    font-size: 2rem;
    font-weight: 500;
    line-height: 1;
}

.history {
    margin: 0;
    padding: 0;
    list-style: none;
}

.history__item {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border);
}

/* El pie ya trae su raya: el último movimiento no repite la suya. */
.history__item:last-child {
    border-bottom: 0;
}

.history__line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
}

.history__type {
    font-weight: 500;
}

.history__delta {
    font-weight: 500;
}

.history__delta--in { color: var(--ok); }
.history__delta--out { color: var(--danger); }

.history__meta {
    color: var(--text-2);
    font-size: var(--text-sm);
}

.history__detail {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
    margin: 0;
    color: var(--text-2);
    font-size: var(--text-sm);
}

.history__empty {
    padding: var(--space-8) 0;
    color: var(--text-2);
    text-align: center;
}

.history__error {
    padding: var(--space-4) 0;
}

.history__more {
    padding-top: var(--space-3);
    text-align: center;
}

.history__footer {
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
}

.history__footer .btn {
    width: 100%;
}
