/* ============================================
   Reporte de Rentabilidad V2 - PROFESSIONAL LIGHT THEME
   Totalmente integrado con el ecosistema Gestor PRO
   ============================================ */

.rentabilidad-v2 {
    /* Mantenemos variables de script.js/style.css y agregamos propias */
    --v2-bg-card: rgba(255, 255, 255, 0.95);
    --v2-glass-bg: rgba(0, 0, 0, 0.02);
    --v2-border: #e5e7eb;
    --v2-accent: #3b82f6;
    --v2-success: #10b981;
    --v2-warning: #f59e0b;
    --v2-error: #ef4444;
    --v2-text-main: #1a1d23;
    --v2-text-dim: #6b7280;

    /* Layout Stability */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.rentabilidad-v2 .main-content {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    animation: fadeIn 0.5s ease-out;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* --- LOADING & EMPTY STATES (Layout Stability) --- */
#v2-results-container,
#v2-loading-state {
    min-height: 400px;
    width: 100%;
    transition: opacity 0.3s ease;
    flex: 1;
}

/* fadeIn — defined in style.css */

/* --- SELECTOR DE FECHAS --- */
.rentabilidad-v2 .summary-section {
    width: 100%;
    margin-bottom: 2.5rem;
}

.rentabilidad-v2 .summary-section .summary-card {
    background: var(--v2-bg-card);
    border: 1px solid var(--v2-border);
    border-radius: 0.75rem;
    padding: 1.25rem 2.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: row;
    /* Horizontal */
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    width: 100%;
}

.rentabilidad-v2 .form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--v2-text-dim);
    margin-bottom: 0.5rem;
}

.rentabilidad-v2 .form-group input[type="date"] {
    background: #f8f9fb;
    border: 1px solid var(--v2-border);
    border-radius: 0.75rem;
    color: var(--v2-text-main);
    padding: 0.75rem 1rem;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.3s;
}

.rentabilidad-v2 .form-group input[type="date"]:focus {
    border-color: var(--v2-accent);
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* --- MINIMALIST FILTER BAR --- */
.rentabilidad-v2 .filter-bar-minimalist {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    transition: all 0.3s ease;
}

.rentabilidad-v2 .filter-bar-minimalist:hover {
    border-color: #d1d5db;
    background: #ffffff;
}

/* Input Groups */
.rentabilidad-v2 .filter-inputs-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.rentabilidad-v2 .input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.rentabilidad-v2 .input-label-mini {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(107, 114, 128, 0.8);
    margin: 0;
}

.rentabilidad-v2 .input-minimalist,
.rentabilidad-v2 .select-minimalist {
    background: #f8f9fb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    color: #1a1d23;
    padding: 0.5rem 0.75rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    min-width: 130px;
}

.rentabilidad-v2 .input-minimalist:focus,
.rentabilidad-v2 .select-minimalist:focus {
    outline: none;
    border-color: rgba(59, 130, 246, 0.4);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.rentabilidad-v2 .select-minimalist {
    cursor: pointer;
    min-width: 150px;
}

.rentabilidad-v2 .input-separator {
    color: rgba(107, 114, 128, 0.3);
    font-size: 1rem;
    font-weight: 300;
    padding: 0 0.25rem;
    user-select: none;
}

/* Action Groups */
.rentabilidad-v2 .filter-actions-group {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.rentabilidad-v2 .quick-dates {
    display: flex;
    gap: 0.5rem;
}

.rentabilidad-v2 .chip-btn {
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    color: #4b5563;
    padding: 0.4rem 0.9rem;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.02em;
}

.rentabilidad-v2 .chip-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    border-color: #d1d5db;
    transform: translateY(-1px);
    color: #1a1d23;
}

.rentabilidad-v2 .chip-btn:active {
    transform: translateY(0);
}

.rentabilidad-v2 .action-divider {
    width: 1px;
    height: 24px;
    background: #e5e7eb;
}

.rentabilidad-v2 .btn-generate {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border: none;
    border-radius: 8px;
    color: #fff;
    padding: 0.6rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.rentabilidad-v2 .btn-generate:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.rentabilidad-v2 .btn-generate:active {
    transform: translateY(0);
}

.rentabilidad-v2 .btn-secondary-mini {
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: #6b7280;
    padding: 0.6rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rentabilidad-v2 .btn-secondary-mini:hover {
    background: rgba(0, 0, 0, 0.06);
    border-color: #d1d5db;
    color: #1a1d23;
}

/* Responsive */
@media (max-width: 1200px) {
    .rentabilidad-v2 .filter-bar-minimalist {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .rentabilidad-v2 .filter-inputs-group {
        flex-wrap: wrap;
    }

    .rentabilidad-v2 .filter-actions-group {
        justify-content: space-between;
    }
}

/* --- OLD STYLES REMOVED - REPLACED BY MINIMALIST DESIGN --- */
.rentabilidad-v2 .btn-date {

    background: var(--v2-glass-bg);
    border: 1px solid var(--v2-border);
    color: var(--v2-text-main);
    padding: 0.6rem 1.2rem;
    border-radius: 9999px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.rentabilidad-v2 .btn-date:hover {
    background: rgba(0, 0, 0, 0.05);
    border-color: var(--v2-accent);
    transform: translateY(-1px);
}

/* --- DASHBOARD STATS (COMPACT) --- */
.rentabilidad-v2 .summary-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    /* Fixed 5 columns */
    gap: 0.75rem;
    /* Reduced gap */
    margin-bottom: 1.5rem;
    /* Less margin */
}

.rentabilidad-v2 .summary-grid .summary-card {
    background: var(--v2-bg-card);
    border: 1px solid var(--v2-border);
    border-radius: 0.875rem;
    /* Slightly smaller radius */
    padding: 1rem;
    /* Reduced padding */
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.rentabilidad-v2 .summary-grid .summary-card:hover {
    transform: translateY(-1px);
    /* Less movement */
    border-color: #d1d5db;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.rentabilidad-v2 .summary-grid .summary-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 60px;
    /* Smaller decoration */
    height: 60px;
    background: linear-gradient(135deg, transparent 50%, rgba(0, 0, 0, 0.01) 100%);
    pointer-events: none;
}

.rentabilidad-v2 .summary-card h3 {
    font-size: 0.75rem;
    /* Smaller label */
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--v2-text-dim);
    margin-bottom: 0.5rem;
    /* Less space */
}

.rentabilidad-v2 .summary-value {
    font-size: 1.5rem;
    /* Reduced from 2.25rem */
    font-weight: 700;
    color: var(--v2-text-main);
    margin-bottom: 0.25rem;
    /* Less margin */
    letter-spacing: -0.02em;
}

.rentabilidad-v2 .summary-value.positive {
    color: #059669;
}

.rentabilidad-v2 .summary-value.negative {
    color: var(--v2-error);
}

.rentabilidad-v2 .summary-meta {
    font-size: 0.75rem;
    /* Smaller meta text */
    color: var(--v2-text-dim);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Responsive: 3 columns on tablets, 2 on mobile */
@media (max-width: 1024px) {
    .rentabilidad-v2 .summary-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 640px) {
    .rentabilidad-v2 .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* --- CANALES DE VENTA (COMPACT HORIZONTAL) --- */
.rentabilidad-v2 .conditions-grid {
    display: flex;
    /* Horizontal layout */
    gap: 1rem;
    /* Reduced gap */
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    /* Allow wrapping on small screens */
}

.rentabilidad-v2 .condition-card {
    background: #ffffff;
    border: 1px solid var(--v2-border);
    border-radius: 0.875rem;
    /* Slightly smaller */
    padding: 1rem;
    /* Reduced padding */
    position: relative;
    border-left: 3px solid var(--v2-accent);
    /* Thinner border */
    flex: 1;
    /* Equal width distribution */
    min-width: 200px;
    /* Minimum width before wrapping */
}

.rentabilidad-v2 .condition-card.mercado-libre {
    border-left-color: #d97706;
}

.rentabilidad-v2 .condition-card.woocommerce {
    border-left-color: #96588a;
}

.rentabilidad-v2 .condition-card.tienda-fisica {
    border-left-color: #059669;
}

.rentabilidad-v2 .condition-card h4 {
    color: var(--v2-text-main);
    font-size: 0.85rem;
    /* Smaller heading */
    font-weight: 600;
    margin-bottom: 0.75rem;
    /* Less margin */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.rentabilidad-v2 .condition-badge {
    background: rgba(0, 0, 0, 0.04);
    color: var(--v2-text-dim);
    padding: 2px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
}

.rentabilidad-v2 .v2-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 6px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-size: 0.6rem;
    padding: 2px 8px;
    border: 1px solid transparent;
}

.rentabilidad-v2 .v2-badge.badge-gray {
    background: rgba(107, 114, 128, 0.1);
    color: #6b7280;
    border-color: rgba(107, 114, 128, 0.2);
}

.rentabilidad-v2 .v2-badge.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
    border-color: rgba(16, 185, 129, 0.2);
}

.rentabilidad-v2 .v2-badge.badge-info {
    background: rgba(59, 130, 246, 0.1);
    color: #2563eb;
    border-color: rgba(59, 130, 246, 0.2);
}

.rentabilidad-v2 .v2-badge.badge-warning {
    background: rgba(250, 173, 20, 0.1);
    color: #d97706;
    border-color: rgba(250, 173, 20, 0.2);
}

.rentabilidad-v2 .stat-box {
    background: #f8f9fb;
    padding: 0.75rem;
    /* Reduced padding */
    border-radius: 0.5rem;
    /* Slightly smaller radius */
}

.rentabilidad-v2 .stat-box .stat-label {
    font-size: 0.75rem !important;
    /* Smaller labels */
}

.rentabilidad-v2 .stat-box .stat-value {
    font-size: 1rem !important;
    /* Smaller values */
}

.rentabilidad-v2 .date-actions {
    margin-top: 0;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Boton secundario premium */
.rentabilidad-v2 .btn-secondary {
    background: rgba(107, 114, 128, 0.08);
    border: 1px solid rgba(107, 114, 128, 0.2);
    color: #4b5563;
    padding: 0.6rem 1.2rem;
    border-radius: 9999px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.rentabilidad-v2 .btn-secondary:hover {
    background: rgba(107, 114, 128, 0.15);
    border-color: #9ca3af;
    color: #1a1d23;
    transform: translateY(-1px);
}

.rentabilidad-v2 .margin-indicator {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.rentabilidad-v2 .margin-bar-container {
    flex: 1;
    height: 8px;
    background: #f1f3f6;
    border-radius: 10px;
    overflow: hidden;
}

.rentabilidad-v2 .margin-bar-fill {
    height: 100%;
    transition: width 1s ease-out;
}

/* --- TABLA DE COMPROBANTES --- */
.rentabilidad-v2 .card {
    background: var(--v2-bg-card);
    border: 1px solid var(--v2-border);
    border-radius: 0.75rem;
    overflow: hidden;
}

/* Fixed Viewport Table Container */
.rentabilidad-v2 .fixed-viewport-table {
    position: relative;
    max-height: calc(100vh - 180px);
    /* Dynamic height based on viewport */
    overflow: hidden;
    margin-top: 1.5rem;
}

.rentabilidad-v2 .scrollable-table-container {
    overflow-y: auto;
    max-height: calc(100vh - 230px);
    /* Account for card padding */
    overflow-x: auto;
    /* Horizontal scroll on small screens */
}

/* Sticky Table Header */
.rentabilidad-v2 .scrollable-table-container .products-table {
    position: relative;
    width: 100%;
}

.rentabilidad-v2 .scrollable-table-container .products-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f8f9fb !important;
}

.rentabilidad-v2 .scrollable-table-container .products-table thead::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--v2-border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.rentabilidad-v2 .products-table {
    border-collapse: separate;
    border-spacing: 0;
}

.rentabilidad-v2 .products-table thead tr {
    background: #f8f9fb !important;
}

.rentabilidad-v2 .products-table th {
    color: var(--v2-text-dim) !important;
    font-weight: 700 !important;
    text-transform: uppercase;
    font-size: 0.7rem !important;
    letter-spacing: 0.05em;
    padding: 1rem !important;
}

.rentabilidad-v2 .products-table td {
    border-bottom: 1px solid var(--v2-border);
    padding: 1rem !important;
    color: var(--v2-text-main);
}

.rentabilidad-v2 .products-table tr:hover td {
    background: rgba(0, 0, 0, 0.02);
}

/* --- LOADING STATE --- */
.rentabilidad-v2 .loading-card {
    background: var(--v2-bg-card);
    border: 1px solid var(--v2-border);
    border-radius: 0.75rem;
    padding: 4rem 2rem;
    text-align: center;
    max-width: 600px;
    margin: 40px auto;
}

.rentabilidad-v2 .spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(59, 130, 246, 0.1);
    border-top-color: var(--v2-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1.5rem;
}

.rentabilidad-v2 .progress-container {
    width: 100%;
    height: 8px;
    background: #f1f3f6;
    border-radius: 10px;
    margin-top: 2rem;
    overflow: hidden;
}

.rentabilidad-v2 .progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--v2-accent), #60a5fa);
    width: 0%;
    transition: width 0.3s;
}

/* --- MODAL DETALLE V2 (PREMIUM) --- */
.v2-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.4) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000 !important;
    padding: 20px;
}

.v2-modal.hidden {
    display: none !important;
}

.v2-modal-content {
    background: #ffffff !important;
    width: 100% !important;
    max-width: 1100px !important;
    max-height: 85vh !important;
    border-radius: 0.75rem !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.12) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    border: 1px solid #e5e7eb !important;
    position: relative !important;
    animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* modalSlideUp — defined in style.css */

.v2-modal-header {
    background: #f8f9fb;
    padding: 2rem 2.5rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.v2-modal-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: #1a1d23;
    letter-spacing: -0.02em;
    margin: 0;
}

.v2-modal-header p {
    color: #6b7280;
    font-size: 0.95rem;
    margin-top: 6px;
    font-weight: 400;
}

.v2-modal-body {
    padding: 1.5rem 2.5rem 2.5rem;
    overflow-y: auto;
    flex: 1;
}

.v2-modal .close-modal {
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid #e5e7eb;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    color: #6b7280;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.v2-modal .close-modal:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
    transform: rotate(90deg);
}

/* Estilos para detalles detallados dentro de modales */
.v2-detail-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
}

.v2-detail-table th {
    text-align: left;
    padding: 12px;
    color: #6b7280 !important;
    font-size: 0.7rem !important;
    font-weight: 700 !important;
    text-transform: uppercase;
    border-bottom: 2px solid #e5e7eb;
}

.v2-detail-table td {
    padding: 15px 12px;
    border-bottom: 1px solid #f1f3f6;
    vertical-align: top;
}

.v2-detail-table .item-name {
    font-weight: 600;
    color: #1a1d23;
    font-size: 0.95rem;
    line-height: 1.3;
}

.v2-detail-table .item-sku {
    font-size: 0.75rem;
    color: #6b7280;
    font-family: monospace;
    margin-top: 2px;
}

.v2-detail-table .item-qty {
    font-size: 0.7rem;
    color: #2563eb;
    background: rgba(59, 130, 246, 0.1);
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    margin-top: 6px;
    font-weight: 700;
}

.v2-detail-table .val-main {
    font-size: 0.95rem;
    color: #1a1d23;
    font-weight: 500;
}

.v2-detail-table .val-sub {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 2px;
    line-height: 1.2;
}

/* Resumen de Operacion */
.v2-operation-summary {
    background: #f8f9fb;
    border-radius: 1rem;
    padding: 1.75rem;
    border: 1px solid #e5e7eb;
    margin-top: 1rem;
}

.v2-operation-summary .summary-header {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--v2-accent);
    text-transform: uppercase;
    margin-bottom: 1.5rem;
    letter-spacing: 0.1em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.v2-operation-summary .summary-header::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #e5e7eb;
}

.v2-operation-summary .summary-grid-compact {
    display: grid;
    gap: 14px;
}

.v2-operation-summary .summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
}

.v2-operation-summary .summary-item .label {
    color: #6b7280;
}

.v2-operation-summary .summary-item .value {
    font-weight: 600;
    color: #1a1d23;
    font-family: 'Outfit', sans-serif;
}

.v2-operation-summary .summary-item.highlight {
    margin-top: 10px;
    padding-top: 15px;
    border-top: 1px dashed #d1d5db;
}

.v2-operation-summary .summary-item.highlight .label {
    font-weight: 800;
    color: #1a1d23;
    font-size: 1.1rem;
}

.v2-operation-summary .summary-item.highlight .value {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.v2-operation-summary .summary-item.highlight .value.pos {
    color: #059669;
}

.v2-operation-summary .summary-item.highlight .value.neg {
    color: var(--v2-error);
}

.v2-operation-summary .tax-info {
    margin-top: 1.25rem;
    padding: 10px;
    background: #f1f3f6;
    border-radius: 8px;
    font-size: 0.75rem;
    color: #6b7280;
    text-align: center;
    font-weight: 500;
}

/* Responsividad */
@media (max-width: 768px) {
    .rentabilidad-v2 .main-content {
        padding: 1rem;
    }

    .rentabilidad-v2 .summary-value {
        font-size: 1.75rem;
    }

    .rentabilidad-v2 .stat-box {
        padding: 0.75rem;
    }
}
