/**
 * Sistema Administrativo Express
 * Estilos para el Módulo de VENTAS (Pedidos, Facturación y CXC)
 */

/* Badges de Estado de Venta y Pedidos */
.badge-converted {
    background-color: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.badge-completed {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.badge-pending {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.badge-partial {
    background-color: #f3e8ff;
    color: #6b21a8;
    border: 1px solid #e9d5ff;
}

.badge-paid {
    background-color: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

.badge-cancelled {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* Grillas de Formulario Compacto para Encabezados de Pedido y Venta */
.sales-header-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.grid-col-span-2 {
    grid-column: span 2;
}

.grid-col-span-3 {
    grid-column: span 3;
}

@media (max-width: 768px) {
    .grid-col-span-2,
    .grid-col-span-3 {
        grid-column: span 1;
    }
}

/* Autocompletado de Clientes */
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #ffffff;
    border: 1px solid var(--border, #cbd5e1);
    border-radius: var(--radius-sm, 6px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    max-height: 220px;
    overflow-y: auto;
    z-index: 1050;
    margin-top: 2px;
}

.autocomplete-item {
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    box-sizing: border-box;
    transition: background 0.15s ease;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background-color: var(--primary-light, #eff6ff);
    color: var(--primary, #2563eb);
}

.autocomplete-item-taxid {
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--text-muted, #64748b);
}

.autocomplete-item .badge,
.autocomplete-item .item-amount,
.autocomplete-item > span:last-child {
    margin-left: auto;
    text-align: right !important;
    white-space: nowrap !important;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

/* El listado desplegable de renglones tan ancho como el campo de descripción */
.service-autocomplete-results {
    left: 0.3rem !important;
    right: 0.3rem !important;
    width: calc(100% - 0.6rem) !important;
    min-width: calc(100% - 0.6rem) !important;
    max-width: calc(100% - 0.6rem) !important;
    box-sizing: border-box !important;
}

/* Tabla de Renglones de Pedido / Factura */
.sales-items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.sales-items-table th {
    background: var(--bg-surface-secondary, #f8fafc);
    padding: 0.5rem 0.6rem;
    font-weight: 700;
    font-size: 0.78rem;
    color: var(--text-secondary, #475569);
    border: 1px solid var(--border, #e2e8f0);
}

.sales-items-table td {
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border, #e2e8f0);
    vertical-align: middle;
}

/* Tarjetas de Resumen de Totales y Multimoneda */
.sales-totals-box {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: 1rem;
    padding: 1rem 1.25rem;
    background: var(--bg-surface-secondary, #f8fafc);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: var(--radius-md, 8px);
}

.sales-totals-summary {
    min-width: 280px;
    margin-left: auto;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 0.35rem 0;
    font-size: 0.9rem;
    color: var(--text-secondary, #475569);
}

.totals-row.grand-total {
    border-top: 2px solid var(--primary, #2563eb);
    margin-top: 0.4rem;
    padding-top: 0.5rem;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-main, #0f172a);
}

.equiv-bs-card {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-left: 4px solid #10b981;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-sm, 6px);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Desglose de Movimientos CXC */
.cxc-movements-subrow {
    background-color: #f8fafc !important;
}

.cxc-movements-box {
    padding: 0.85rem 1.25rem;
    border: 1px dashed #cbd5e1;
    border-radius: var(--radius-sm, 6px);
    margin: 0.35rem 0.5rem;
    background: #ffffff;
}

.cxc-movements-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.cxc-movements-table th {
    background: #f1f5f9;
    padding: 0.4rem 0.6rem;
    font-weight: 700;
    border: 1px solid #e2e8f0;
}

.cxc-movements-table td {
    padding: 0.4rem 0.6rem;
    border: 1px solid #e2e8f0;
}

/* Regla Crítica: Todos los montos alineados a la derecha */
.sales-items-table td.col-amount,
.sales-items-table th.col-amount,
.cxc-movements-table td.col-amount,
.cxc-movements-table th.col-amount,
.totals-row span:last-child {
    text-align: right !important;
    font-variant-numeric: tabular-nums;
}

/* Grilla de Estadísticas CXC (Idéntica a CXP) */
.sales-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.75rem;
}

/* Menú Desplegable Unificado de Operaciones en Cuentas por Cobrar */
.ar-action-dropdown {
    position: relative;
    display: inline-block;
    text-align: left;
}

.ar-action-dropdown .btn-ar-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
    padding: 0.32rem 0.65rem;
    border-radius: var(--radius-sm, 6px);
    transition: all 0.2s ease;
    cursor: pointer;
}

.ar-action-menu {
    display: none;
    position: fixed;
    background: #ffffff;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.22), 0 8px 10px -6px rgba(0, 0, 0, 0.12);
    min-width: 250px;
    z-index: 999999;
    overflow: hidden;
}

.ar-action-menu.active {
    display: block;
    animation: fadeInMenu 0.12s ease-out;
}

@keyframes fadeInMenu {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ar-action-menu-header {
    padding: 0.45rem 0.85rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted, #64748b);
    background: var(--light-bg, #f8fafc);
    border-bottom: 1px solid var(--border, #e2e8f0);
}

.ar-action-menu a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.6rem 0.85rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-main, #334155);
    transition: background-color 0.15s ease, color 0.15s ease;
    text-decoration: none;
    border-bottom: 1px solid #f8fafc;
}

.ar-action-menu a:hover {
    background: var(--primary-light, #f0fdf4);
    color: var(--primary, #059669);
}

.ar-action-menu a.item-purple:hover {
    background: #f5f3ff;
    color: #6d28d9;
}

.ar-action-menu a.item-danger:hover {
    background: #fef2f2;
    color: #b91c1c;
}

.ar-action-menu a:last-child {
    border-bottom: none;
}

