/* CSS Unificado - Estilo SIS VISION Dark Premium */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap');

:root {
    --bg-color: #0d1117;
    --card-bg: rgba(22, 27, 34, 0.8);
    --border-color: rgba(255, 255, 255, 0.1);
    --accent-color: #58a6ff;
    --accent-gradient: linear-gradient(135deg, #58a6ff 0%, #3062af 100%);
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --success: #3fb950;
    --sidebar-width: 260px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar Estilo SIS VISION */
.sidebar {
    width: var(--sidebar-width);
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px;
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 30px;
    border-bottom: 1px solid var(--border-color);
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: var(--accent-gradient);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(88, 166, 255, 0.3);
}

.nav-menu {
    margin-top: 30px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.3s;
    margin-bottom: 8px;
    cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(88, 166, 255, 0.1);
    color: var(--accent-color);
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    background: radial-gradient(circle at top right, rgba(88, 166, 255, 0.05), transparent);
}

/* Header & Stats */
.header {
    margin-bottom: 40px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    transition: transform 0.3s;
}

.stat-card:hover {
    transform: translateY(-5px);
    border-color: rgba(88, 166, 255, 0.3);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
}

/* Table Style */
.table-container {
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 15px 20px;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 40%, #1e3a5f 100%);
    color: #c7d2fe;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    border-bottom: 2px solid rgba(99, 102, 241, 0.4);
    position: relative;
}

th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.3s ease, color 0.2s ease;
}

th.sortable:hover {
    background: linear-gradient(135deg, #312e81 0%, #4338ca 40%, #2563eb 100%);
    color: #e0e7ff;
}

th.sortable:active {
    transform: scale(0.98);
}

.sort-indicator {
    font-size: 0.7rem;
    margin-left: 4px;
    opacity: 0.4;
    transition: opacity 0.2s ease;
}

th.sortable:hover .sort-indicator {
    opacity: 0.8;
}

th.sort-asc .sort-indicator,
th.sort-desc .sort-indicator {
    opacity: 1;
    color: #818cf8;
}

/* Excel-style Column Dropdown Filters */
.th-filter-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
}

.filter-btn {
    background: none;
    border: none;
    color: rgba(199, 210, 254, 0.5);
    cursor: pointer;
    font-size: 0.7rem;
    padding: 2px 4px;
    border-radius: 4px;
    transition: all 0.2s;
    line-height: 1;
}

.filter-btn:hover,
.filter-btn.active {
    color: #818cf8;
    background: rgba(129, 140, 248, 0.15);
}

.filter-btn.active {
    color: #a78bfa;
    background: rgba(167, 139, 250, 0.2);
}

.filter-dropdown {
    display: none;
    position: fixed;
    z-index: 999;
    background: #1e2230;
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 10px;
    min-width: 220px;
    max-height: 320px;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    padding: 8px 0;
}

.filter-dropdown.show {
    display: block;
}

.filter-dropdown label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 400;
    color: #c9d1d9;
    text-transform: none;
    letter-spacing: 0;
    transition: background 0.15s;
    white-space: nowrap;
}

.filter-dropdown label:hover {
    background: rgba(88, 166, 255, 0.08);
}

.filter-dropdown input[type="checkbox"] {
    accent-color: #818cf8;
    width: 14px;
    height: 14px;
}

.filter-dropdown .filter-actions {
    display: flex;
    gap: 6px;
    padding: 8px 12px 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: 4px;
}

.filter-dropdown .filter-actions button {
    flex: 1;
    padding: 5px 8px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 600;
}

.filter-dropdown .filter-actions .btn-filter-all {
    background: rgba(88, 166, 255, 0.12);
    color: #58a6ff;
}

.filter-dropdown .filter-actions .btn-filter-none {
    background: rgba(248, 81, 73, 0.12);
    color: #f85149;
}

td {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.01);
}

.badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: rgba(63, 185, 80, 0.1);
    color: var(--success);
}

.badge-info {
    background: rgba(88, 166, 255, 0.12);
    color: #58a6ff;
}

.badge-warning {
    background: rgba(210, 153, 34, 0.15);
    color: #d29922;
}

/* Buttons & Links */
.btn-primary {
    background: var(--accent-gradient);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.3s;
}

.btn-primary:hover {
    opacity: 0.9;
}

.link-icon {
    color: var(--accent-color);
    text-decoration: none;
}

.link-icon:hover {
    text-decoration: underline;
}

/* === ESTILOS DE IA (FASE 1) === */

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.3rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 2rem;
    cursor: pointer;
    transition: color 0.3s;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

/* Botones de IA */
.btn-ai {
    background: var(--accent-gradient);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: opacity 0.3s, transform 0.2s;
    white-space: nowrap;
}

.btn-ai:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

.btn-ai-secondary {
    background: rgba(88, 166, 255, 0.1);
    color: var(--accent-color);
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid rgba(88, 166, 255, 0.3);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.3s;
    white-space: nowrap;
}

.btn-ai-secondary:hover {
    background: rgba(88, 166, 255, 0.2);
    border-color: var(--accent-color);
}

/* Botón de Descarga - Pendiente */
.btn-download {
    background: rgba(128, 128, 128, 0.1);
    color: #8b949e;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid rgba(128, 128, 128, 0.3);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s;
}

.btn-download:hover {
    background: rgba(128, 128, 128, 0.2);
    border-color: #8b949e;
    transform: translateY(-2px);
}

/* Botón de Descarga - Completado */
.btn-download-done {
    background: rgba(63, 185, 80, 0.1);
    color: #3fb950;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid rgba(63, 185, 80, 0.3);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s;
}

.btn-download-done:hover {
    background: rgba(63, 185, 80, 0.2);
    border-color: #3fb950;
    transform: translateY(-2px);
}

/* === MODO CLARO === */
body.light-mode {
    --bg-color: #f5f7fa;
    --card-bg: #ffffff;
    --border-color: #e1e5eb;
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
}

body.light-mode .sidebar {
    background: #ffffff;
    border-right-color: #e1e5eb;
}

body.light-mode .main-content {
    background: #f5f7fa;
}

body.light-mode .stat-card {
    background: #ffffff;
    border-color: #e1e5eb;
}

body.light-mode .table-container {
    background: #ffffff;
}

body.light-mode th {
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 40%, #dbeafe 100%);
    color: #3730a3;
    border-bottom: 2px solid rgba(99, 102, 241, 0.25);
}

body.light-mode th.sortable:hover {
    background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 40%, #bfdbfe 100%);
    color: #4338ca;
}

body.light-mode th.sort-asc .sort-indicator,
body.light-mode th.sort-desc .sort-indicator {
    color: #4338ca;
}

body.light-mode td {
    border-color: #e1e5eb;
}

body.light-mode #theme-toggle {
    background: #e5e7eb;
    border: 2px solid #d1d5db;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

body.light-mode .modal-content {
    background: #ffffff;
    border-color: #e1e5eb;
}

/* ══════════════════════════════════════════════════════════
   ANALYTICS DASHBOARD STYLES (KPIs, Funnel, Charts)
   ══════════════════════════════════════════════════════════ */

/* ── KPI Cards ── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

.kpi-card .kpi-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-bottom: 12px;
}

.kpi-card .kpi-value {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 4px;
}

.kpi-card .kpi-label {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
}

.kpi-card .kpi-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    border-radius: 0 0 16px 16px;
}

.kpi-1 .kpi-icon {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.kpi-1 .kpi-value {
    color: #3b82f6;
}

.kpi-1 .kpi-bar {
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
}

.kpi-2 .kpi-icon {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.kpi-2 .kpi-value {
    color: #10b981;
}

.kpi-2 .kpi-bar {
    background: linear-gradient(90deg, #10b981, #34d399);
}

.kpi-3 .kpi-icon {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
}

.kpi-3 .kpi-value {
    color: #a855f7;
}

.kpi-3 .kpi-bar {
    background: linear-gradient(90deg, #a855f7, #c084fc);
}

.kpi-4 .kpi-icon {
    background: rgba(244, 114, 182, 0.15);
    color: #f472b6;
}

.kpi-4 .kpi-value {
    color: #f472b6;
}

.kpi-4 .kpi-bar {
    background: linear-gradient(90deg, #f472b6, #fb7185);
}

.kpi-5 .kpi-icon {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}

.kpi-5 .kpi-value {
    color: #fbbf24;
}

.kpi-5 .kpi-bar {
    background: linear-gradient(90deg, #fbbf24, #fcd34d);
}

/* ── Pipeline Funnel ── */
.funnel-container {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 24px;
}

.funnel-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.funnel-steps {
    display: flex;
    align-items: center;
    gap: 0;
}

.funnel-step {
    flex: 1;
    text-align: center;
    padding: 16px 8px;
    position: relative;
    transition: all 0.3s;
}

.funnel-step .step-value {
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 4px;
}

.funnel-step .step-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.funnel-step .step-pct {
    font-size: 0.7rem;
    margin-top: 6px;
    padding: 2px 8px;
    border-radius: 10px;
    display: inline-block;
}

.funnel-arrow {
    color: rgba(255, 255, 255, 0.15);
    font-size: 1.5rem;
    flex-shrink: 0;
}

.fs-1 .step-value {
    color: #3b82f6;
}

.fs-1 .step-pct {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

.fs-2 .step-value {
    color: #10b981;
}

.fs-2 .step-pct {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.fs-3 .step-value {
    color: #a855f7;
}

.fs-3 .step-pct {
    background: rgba(168, 85, 247, 0.15);
    color: #c084fc;
}

.fs-4 .step-value {
    color: #f472b6;
}

.fs-4 .step-pct {
    background: rgba(244, 114, 182, 0.15);
    color: #fb7185;
}

/* ── Charts Grid ── */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.chart-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    min-height: 320px;
}

.chart-card h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-card h3 i {
    color: #818cf8;
    font-size: 0.85rem;
}

.chart-card canvas {
    width: 100% !important;
    max-height: 280px;
}

.chart-card.full-width {
    grid-column: span 2;
}

/* ── Dashboard Responsive ── */
@media (max-width: 1200px) {
    .kpi-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .chart-card.full-width {
        grid-column: span 1;
    }
}

@media (max-width: 768px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .funnel-steps {
        flex-direction: column;
    }

    .funnel-arrow {
        transform: rotate(90deg);
    }
}