:root {
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --bg: #f8fafc;
    --card: white;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: var(--text); }

/* Header */
.page-header {
    background: linear-gradient(135deg, var(--primary), #764ba2);
    padding: 1.5rem 2rem;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; display: flex; align-items: center; gap: 0.75rem; }
.page-header h1 i { font-size: 1.3rem; }
.header-buttons { display: flex; gap: 0.5rem; }
.header-buttons a, .header-buttons button {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.2s;
}
.header-buttons a:hover, .header-buttons button:hover { background: rgba(255,255,255,0.25); }
.header-buttons .primary-btn { background: white; color: var(--primary); font-weight: 600; }

.sales-container { max-width: 1600px; margin: 0 auto; padding: 1.5rem; }

/* ===== Unified Filter Bar ===== */
.unified-filters {
    background: var(--card);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}
.filter-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.filter-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.filter-dates { flex-shrink: 0; }
.date-range {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.date-range input[type="date"] {
    padding: 0.45rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.82rem;
    color: var(--text);
    background: white;
    width: 140px;
}
.date-range input[type="date"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(102,126,234,0.2);
}
.date-sep {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
}
.filter-search {
    flex: 1;
    min-width: 180px;
}
.filter-search input {
    width: 100%;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
}
.filter-search input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(102,126,234,0.2);
}
.filter-group select {
    padding: 0.45rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.82rem;
    color: var(--text);
    background: white;
    cursor: pointer;
    min-width: 130px;
}
.filter-group select:focus {
    outline: none;
    border-color: var(--primary);
}
.filter-btn-search {
    padding: 0.45rem 0.75rem;
    border: none;
    border-radius: 6px;
    background: var(--primary);
    color: white;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
    flex-shrink: 0;
}
.filter-btn-search:hover { background: var(--primary-dark); }
.filter-btn-clear {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--danger);
    border-radius: 6px;
    background: white;
    color: var(--danger);
    cursor: pointer;
    font-size: 0.85rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    transition: all 0.2s;
    flex-shrink: 0;
}
.filter-btn-clear:hover { background: var(--danger); color: white; }

/* Date Presets */
.date-presets {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.6rem;
    flex-wrap: wrap;
}
.preset-chip {
    padding: 0.25rem 0.7rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--text-muted);
    background: #f1f5f9;
    border: 1px solid var(--border);
    transition: all 0.2s;
    white-space: nowrap;
}
.preset-chip:hover {
    background: rgba(102,126,234,0.1);
    color: var(--primary);
    border-color: var(--primary);
}
.preset-chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.preset-period {
    font-size: 0.8rem;
    color: var(--text);
    font-weight: 600;
    margin-left: auto;
}
@media (max-width: 768px) {
    .filter-form { gap: 0.4rem; }
    .date-range input[type="date"] { width: 120px; }
    .filter-search { min-width: 100%; order: -1; }
    .preset-period { margin-left: 0; width: 100%; text-align: center; }
}

/* KPI Cards */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card {
    background: var(--card);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    border-left: 4px solid var(--primary);
    transition: transform 0.2s;
}
.kpi-card:hover { transform: translateY(-2px); }
.kpi-card.green { border-left-color: var(--success); }
.kpi-card.orange { border-left-color: var(--warning); }
.kpi-card.blue { border-left-color: var(--info); }
.kpi-icon {
    width: 48px; height: 48px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}
.kpi-icon.purple { background: rgba(102,126,234,0.15); color: var(--primary); }
.kpi-icon.green { background: rgba(16,185,129,0.15); color: var(--success); }
.kpi-icon.orange { background: rgba(245,158,11,0.15); color: var(--warning); }
.kpi-icon.blue { background: rgba(59,130,246,0.15); color: var(--info); }
.kpi-info { flex: 1; }
.kpi-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.kpi-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 0.25rem; }
.kpi-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.35rem; }

/* Main Layout */
.main-grid { display: grid; grid-template-columns: 300px 1fr; gap: 1.5rem; }
@media (max-width: 1024px) { .main-grid { grid-template-columns: 1fr; } }

/* Cards */
.card {
    background: var(--card);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 1rem;
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.card-header i { color: var(--primary); }
.card-body { padding: 1rem 1.25rem; }

/* Chart */
.chart-wrap { height: 180px; margin-bottom: 1rem; }

/* Tipo list — compacto */
.tipo-list { display: flex; flex-direction: column; gap: 0.35rem; }
.tipo-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.6rem;
    background: var(--bg);
    border-radius: 8px;
    transition: background 0.2s;
}
.tipo-row:hover { background: #e2e8f0; }
.tipo-row .left { display: flex; align-items: center; gap: 0.4rem; }
.tipo-row .icon { font-size: 0.9rem; }
.tipo-row .name { font-size: 0.78rem; font-weight: 500; }
.tipo-row .right { text-align: right; }
.tipo-row .amount { font-weight: 600; font-size: 0.82rem; color: var(--text); }
.tipo-row .count { font-size: 0.65rem; color: var(--text-muted); }

/* Ranking */
.ranking-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}
.ranking-item:last-child { border-bottom: none; }
.ranking-num {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    margin-right: 0.75rem;
}
.ranking-item:nth-child(1) .ranking-num { background: #fbbf24; }
.ranking-item:nth-child(2) .ranking-num { background: #94a3b8; }
.ranking-item:nth-child(3) .ranking-num { background: #c2884e; }
.ranking-name { flex: 1; font-size: 0.8rem; }
.ranking-value { font-size: 0.8rem; font-weight: 600; color: var(--primary); }

/* Filters */
.filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.filters input, .filters select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    background: white;
    transition: border 0.2s;
}
.filters input:focus, .filters select:focus { border-color: var(--primary); outline: none; }
.filters input { flex: 1; min-width: 200px; }
.filters input[type="date"] { flex: 0 0 auto; min-width: auto; width: 140px; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.table-wrap thead {
    background: linear-gradient(135deg, var(--primary), #764ba2);
    color: white;
    position: sticky;
    top: 0;
    z-index: 10;
}
th { padding: 0.75rem 0.75rem; text-align: left; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap; }
td { padding: 0.7rem 0.75rem; border-bottom: 1px solid var(--border); font-size: 0.85rem; vertical-align: middle; }
tbody tr:hover { background: #eef2ff !important; }
tbody tr:nth-child(even) { background: #f8fafc; }

.invoice-cell { font-weight: 600; color: var(--text); white-space: nowrap; font-size: 0.8rem; }
.badge { display: inline-flex; align-items: center; padding: 0.25rem 0.6rem; border-radius: 20px; font-size: 0.7rem; font-weight: 600; white-space: nowrap; }
.badge-pagado, .badge-contado { background: #dcfce7; color: #166534; }
.badge-credito { background: #dbeafe; color: #1e40af; }
.badge-pendiente { background: #fef3c7; color: #92400e; }
.badge-cambio { background: #ede9fe; color: #5b21b6; }
.badge-consignado { background: #ffedd5; color: #9a3412; }
.badge-exonerado { background: #f3f4f6; color: #4b5563; }
.badge-cashea { background: #fce7f3; color: #db2777; }
.deuda-label { font-size: 0.65rem; color: #ef4444; font-weight: 600; margin-top: 2px; }

/* System Alerts */
.system-alert {
    border-radius: 12px;
    padding: 0.95rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}
.system-alert.success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.system-alert.danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.system-alert.warning { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
.system-alert-title { font-weight: 700; margin-bottom: 0.35rem; display: flex; align-items: center; gap: 0.5rem; }
.alert-list { margin: 0.35rem 0 0 1rem; padding: 0; }
.alert-list li { margin-bottom: 0.25rem; }
.row-alerta-consignacion { background: #fff7ed !important; }
.invoice-alert { font-size: 0.66rem; color: #c2410c; font-weight: 700; margin-top: 4px; }

/* Table Cells */
.productos-cell { max-width: 280px; font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.monto-cell { font-weight: 700; color: var(--text); font-size: 0.9rem; white-space: nowrap; }
.cliente-cell { font-size: 0.8rem; min-width: 120px; }
.cliente-cell .titular-info { display: block; font-size: 0.7rem; color: var(--text-muted); margin-top: 1px; }
.cliente-cell .historial-link { font-size: 0.6rem; color: #667eea; margin-top: 1px; opacity: 0; transition: opacity 0.2s; }
tbody tr:hover .historial-link { opacity: 1; }
.serial-cell { font-family: 'SF Mono', 'Cascadia Code', monospace; font-size: 0.73rem; color: var(--text-muted); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fecha-cell { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }

/* Actions */
.actions { display: flex; gap: 0.35rem; }
.action-btn {
    width: 30px; height: 30px; border-radius: 8px; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 0.8rem;
    transition: all 0.2s;
}
.action-btn.view { background: #ede9fe; color: #5b21b6; }
.action-btn.delete { background: #fee2e2; color: #b91c1c; }
.action-btn:hover { transform: scale(1.1); box-shadow: 0 2px 8px rgba(0,0,0,0.15); }

/* Result counter bar */
.result-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: #f1f5f9;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}
.result-bar .count { font-weight: 600; color: var(--text); }
.result-bar .filter-active {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    background: #dbeafe;
    color: #1e40af;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 600;
}
.result-bar .filter-active i { font-size: 0.6rem; }
.export-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.85rem;
    background: white;
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.export-btn:hover { background: var(--primary); color: white; }

/* Modal */
.modal {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15,23,42,0.6); backdrop-filter: blur(4px); z-index: 1100;
    align-items: center; justify-content: center;
}
.modal.active { display: flex; }
.modal-box {
    background: white; border-radius: 16px; width: 95%; max-width: 800px; max-height: 85vh; overflow: auto;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}
.modal-header {
    background: linear-gradient(135deg, var(--primary), #764ba2); color: white;
    padding: 1rem 1.5rem; display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; color: white; font-size: 1.5rem; cursor: pointer; opacity: 0.8; }
.modal-close:hover { opacity: 1; }
.modal-body { padding: 1.5rem; }



/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; margin-bottom: 0.75rem; opacity: 0.4; }
.empty-state div { font-size: 0.9rem; }

/* Badge Outline — crédito/cashea ya pagado */
.badge-pagado-outline {
    background: transparent !important;
    border: 2px solid var(--success);
    color: var(--success) !important;
}

/* KPI Value Colors */
.kpi-value.text-purple { color: var(--primary); }
.kpi-value.text-success { color: var(--success); }
.kpi-value.text-warning { color: var(--warning); }
.kpi-value.text-primary { color: var(--info); }

/* Clear Filter Button */
.clear-btn {
    padding: 0.5rem 0.8rem;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
}
.clear-btn:hover { background: #fee2e2; color: var(--danger); border-color: var(--danger); }

/* Layout Utilities */
.card-header-flex { display: flex; align-items: center; gap: 0.5rem; flex: 1; }
.search-wrap { display: flex; gap: 0.5rem; flex: 1; min-width: 250px; }
.search-wrap input { width: 100%; }
.no-data { text-align: center; color: #999; font-size: 0.85rem; padding: 1rem; }
.monto-filtrado { font-weight: 600; }
.clickable { cursor: pointer; }

/* Pagination */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.85rem 1rem;
    border-top: 1px solid var(--border);
    background: #f8fafc;
    flex-wrap: wrap;
}
.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 0.5rem;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    background: white;
    border: 1px solid var(--border);
    transition: all 0.2s;
    cursor: pointer;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); background: #f0f0ff; }
.page-btn.active {
    background: linear-gradient(135deg, var(--primary), #764ba2);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 6px rgba(102,126,234,0.35);
}
.page-btn.disabled { opacity: 0.4; pointer-events: none; }
.page-ellipsis { color: var(--text-muted); font-size: 0.85rem; padding: 0 0.2rem; }
.page-info { font-size: 0.75rem; color: var(--text-muted); margin-left: 0.75rem; }
