/* ============================================================
   GestionaOK — Tema claro / oscuro
   Fuente de verdad: [data-theme] y [data-bs-theme] en <html>
   ============================================================ */

/* ---------- DARK (identidad actual, SIN cambios de paleta) ---------- */
:root,
[data-theme="dark"] {
    --bg-body:      #121418;
    --bg-sidebar:   #1a1d24;
    --bg-card:      #232730;
    --text-main:    #e2e8f0;
    --text-muted:   #94a3b8;
    --border-color: #334155;
    --primary:      #3b82f6;

    --bg-input:              #1a1d24;
    --border-strong:         #475569;
    --scrollbar-thumb:       #334155;
    --scrollbar-thumb-hover: #475569;
    --shadow-card:           0 4px 6px rgba(0,0,0,0.3);
    --hover-row:             rgba(255,255,255,0.05);

    --color-success: #10b981;
    --color-danger:  #ef4444;
    --color-warning: #f59e0b;
    --color-info:    #3b82f6;

    --rank-bg: #334155;
    --rank-fg: #ffffff;
}

/* ---------- LIGHT (nuevo, misma identidad adaptada) ---------- */
[data-theme="light"] {
    --bg-body:      #f5f6f8;
    --bg-sidebar:   #ffffff;
    --bg-card:      #ffffff;
    --text-main:    #1a202c;
    --text-muted:   #64748b;
    --border-color: #e2e8f0;
    --primary:      #2563eb;

    --bg-input:              #ffffff;
    --border-strong:         #cbd5e1;
    --scrollbar-thumb:       #cbd5e1;
    --scrollbar-thumb-hover: #94a3b8;
    --shadow-card:           0 1px 3px rgba(0,0,0,0.08);
    --hover-row:             rgba(0,0,0,0.04);

    --color-success: #059669;
    --color-danger:  #dc2626;
    --color-warning: #d97706;
    --color-info:    #2563eb;

    --rank-bg: #cbd5e1;
    --rank-fg: #1a202c;
}

/* ============================================================
   BASE
   ============================================================ */
body {
    background-color: var(--bg-body);
    color: var(--text-main);
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-body); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* ============================================================
   BOTÓN TOGGLE
   ============================================================ */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s, color 0.2s;
    padding: 0;
    line-height: 1;
}
.theme-toggle:hover {
    background-color: rgba(59, 130, 246, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}
.theme-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.theme-toggle i { font-size: 1.1rem; }

/* ============================================================
   COMPONENTES BOOTSTRAP adaptados a nuestras variables
   ============================================================ */
.card,
.modal-content {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-main);
    --bs-table-border-color: var(--border-color);
    color: var(--text-main);
    border-color: var(--border-color);
}
.table > :not(caption) > * > * {
    background-color: transparent;
    color: inherit;
    border-color: var(--border-color);
}
.table-light th,
.table thead.table-light th {
    background-color: var(--bg-body);
    color: var(--text-muted);
    border-color: var(--border-color);
}
.table-hover tbody tr:hover {
    color: var(--text-main);
    background-color: var(--hover-row);
}

.form-control,
.form-select {
    background-color: var(--bg-input);
    border-color: var(--border-color);
    color: var(--text-main);
}
.form-control:focus,
.form-select:focus {
    background-color: var(--bg-input);
    color: var(--text-main);
    border-color: var(--primary);
    box-shadow: none;
}
.form-control::placeholder { color: var(--text-muted); opacity: 0.8; }
.form-select option { background: var(--bg-card); color: var(--text-main); }

.text-muted { color: var(--text-muted) !important; }

a { color: var(--primary); }

.alert-error {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}
[data-theme="dark"] .alert-error {
    background-color: #2a0e0e;
    color: #fca5a5;
    border-color: #7f1d1d;
}

/* ============================================================
   OVERRIDES DE ESTILOS INLINE (templates de módulos)
   ============================================================ */
[style*="background: white"], [style*="background:white"],
[style*="background: #fff"],  [style*="background:#fff"],
[style*="background: #ffffff"], [style*="background:#ffffff"] {
    background: var(--bg-card) !important;
}

[style*="background: #f8f9fa"], [style*="background:#f8f9fa"],
[style*="background: #f9f9f9"], [style*="background:#f9f9f9"],
[style*="background: #f5f5f5"], [style*="background:#f5f5f5"],
[style*="background: #f0f0f0"], [style*="background:#f0f0f0"] {
    background: var(--bg-card) !important;
}

[style*="background: #eee"],   [style*="background:#eee"],
[style*="background: #e9ecef"], [style*="background:#e9ecef"] {
    background: var(--bg-body) !important;
}

[style*="color: #333"], [style*="color:#333"],
[style*="color: #222"], [style*="color:#222"] {
    color: var(--text-main) !important;
}

[style*="color: #666"], [style*="color:#666"],
[style*="color: #888"], [style*="color:#888"],
[style*="color: #999"], [style*="color:#999"] {
    color: var(--text-muted) !important;
}

[style*="border: 1px solid #ddd"], [style*="border:1px solid #ddd"],
[style*="border: 1px solid #ccc"], [style*="border:1px solid #ccc"],
[style*="border: 1px solid #eee"], [style*="border:1px solid #eee"],
[style*="border-bottom: 1px solid #ddd"], [style*="border-bottom:1px solid #ddd"],
[style*="border-bottom: 1px solid #eee"], [style*="border-bottom:1px solid #eee"],
[style*="border-bottom: 1px solid #f0f0f0"], [style*="border-bottom:1px solid #f0f0f0"] {
    border-color: var(--border-color) !important;
}
[style*="border: 2px dashed #ccc"], [style*="border:2px dashed #ccc"] {
    border-color: var(--border-strong) !important;
}

hr { border-color: var(--border-color) !important; }

.btn-icono { background-color: var(--bg-card) !important; }
.btn-wa:hover     { background-color: #25D366 !important; color: #fff !important; }
.btn-mail:hover   { background-color: #6f42c1 !important; color: #fff !important; }
.btn-venta:hover  { background-color: #333333 !important; color: #fff !important; }
.btn-edit:hover   { background-color: #6c757d !important; color: #fff !important; }
.btn-delete:hover { background-color: #dc3545 !important; color: #fff !important; }
.btn-history:hover{ background-color: #17a2b8 !important; color: #fff !important; }

[data-theme="light"] .text-success,
[data-theme="light"] .delta-pos   { color: var(--color-success) !important; }
[data-theme="light"] .text-danger,
[data-theme="light"] .delta-neg   { color: var(--color-danger) !important; }
[data-theme="light"] .text-warning{ color: var(--color-warning) !important; }
[data-theme="light"] .text-info,
[data-theme="light"] .text-primary{ color: var(--color-info) !important; }

[data-theme="light"] .rank-badge {
    background: var(--rank-bg);
    color: var(--rank-fg);

/* Cubre el gris claro hardcodeado en algunos templates (ej. dashboard) */
[style*="color: #cbd5e1"] {
    color: var(--text-muted) !important;
}


/* ============================================================
   AJUSTES LIGHT para dashboard.html (sin tocar el template)
   Los colores base del dashboard están pensados para dark.
   Estas reglas solo activan en light.
   ============================================================ */

/* Sombras y hover de las tarjetas-stat del dashboard */
.card-stat {
    box-shadow: var(--shadow-card) !important;
}
a.card-stat:hover {
    border-color: var(--border-strong) !important;
}

/* Headers de tablas dentro de cards en light */
[data-theme="light"] .table-light th {
    background-color: var(--bg-body) !important;
    color: var(--text-muted) !important;
    border-color: var(--border-color) !important;
}

/* Deltas (flechas verde/rojo de "Hoy / Sem / Mes") en light */
[data-theme="light"] .delta-pos { color: var(--color-success) !important; }
[data-theme="light"] .delta-neg { color: var(--color-danger)  !important; }