/* ============================================================
   RINOTRACK - CORRECCIONES DE MODO OSCURO
   Cargar al final, después de clickup-screens.css.

   El proyecto tiene ~2.900 atributos style="" en las vistas, y
   muchos fijan fondo blanco o texto oscuro. Un estilo inline solo
   puede vencerse con !important desde una hoja, así que aquí se
   usan selectores de atributo para neutralizarlos SOLO en modo
   oscuro. En modo claro no se aplica ninguna de estas reglas.

   Se corrige únicamente color y fondo. Nunca display, position ni
   visibility, para no interferir con el JavaScript que muestra y
   oculta elementos mediante style.display.
   ============================================================ */

/* ------------------------------------------------------------
   FONDOS BLANCOS FORZADOS EN LÍNEA
   ------------------------------------------------------------ */
[data-theme="dark"] [style*="background: white"],
[data-theme="dark"] [style*="background:white"],
[data-theme="dark"] [style*="background-color: white"],
[data-theme="dark"] [style*="background-color:white"],
[data-theme="dark"] [style*="background: #fff"],
[data-theme="dark"] [style*="background:#fff"],
[data-theme="dark"] [style*="background-color: #fff"],
[data-theme="dark"] [style*="background-color:#fff"],
[data-theme="dark"] [style*="background: #FFF"],
[data-theme="dark"] [style*="background:#FFF"] {
    background-color: var(--cu-surface) !important;
    color: var(--cu-text);
}

/* ------------------------------------------------------------
   FONDOS GRISES MUY CLAROS (superficies secundarias)
   ------------------------------------------------------------ */
[data-theme="dark"] [style*="background: #f8fafc"],
[data-theme="dark"] [style*="background:#f8fafc"],
[data-theme="dark"] [style*="background: #f9fafb"],
[data-theme="dark"] [style*="background:#f9fafb"],
[data-theme="dark"] [style*="background: #f3f4f6"],
[data-theme="dark"] [style*="background:#f3f4f6"],
[data-theme="dark"] [style*="background: #f1f5f9"],
[data-theme="dark"] [style*="background:#f1f5f9"],
[data-theme="dark"] [style*="background: #fafafa"],
[data-theme="dark"] [style*="background:#fafafa"],
[data-theme="dark"] [style*="background: #f5f5f5"],
[data-theme="dark"] [style*="background:#f5f5f5"],
[data-theme="dark"] [style*="background-color: #f8fafc"],
[data-theme="dark"] [style*="background-color:#f8fafc"],
[data-theme="dark"] [style*="background-color: #f3f4f6"],
[data-theme="dark"] [style*="background-color:#f3f4f6"],
[data-theme="dark"] [style*="background-color: #f9fafb"],
[data-theme="dark"] [style*="background-color:#f9fafb"] {
    background-color: var(--cu-surface-2) !important;
    color: var(--cu-text);
}

[data-theme="dark"] [style*="background: #e2e8f0"],
[data-theme="dark"] [style*="background:#e2e8f0"] {
    background-color: var(--cu-surface-3) !important;
}

/* Fondo lavanda claro: se conserva como acento suave */
[data-theme="dark"] [style*="background: #eff6ff"],
[data-theme="dark"] [style*="background:#eff6ff"] {
    background-color: var(--cu-accent-soft) !important;
}

/* ------------------------------------------------------------
   TEXTO OSCURO FORZADO EN LÍNEA
   Se aclara para mantener legibilidad sobre fondo oscuro.
   ------------------------------------------------------------ */
[data-theme="dark"] [style*="color: #1e293b"],
[data-theme="dark"] [style*="color:#1e293b"],
[data-theme="dark"] [style*="color: #1f2937"],
[data-theme="dark"] [style*="color:#1f2937"],
[data-theme="dark"] [style*="color: #111827"],
[data-theme="dark"] [style*="color:#111827"],
[data-theme="dark"] [style*="color: #374151"],
[data-theme="dark"] [style*="color:#374151"],
[data-theme="dark"] [style*="color: #333"],
[data-theme="dark"] [style*="color:#333"] {
    color: var(--cu-text) !important;
}

[data-theme="dark"] [style*="color: #6b7280"],
[data-theme="dark"] [style*="color:#6b7280"],
[data-theme="dark"] [style*="color: #64748b"],
[data-theme="dark"] [style*="color:#64748b"],
[data-theme="dark"] [style*="color: #475569"],
[data-theme="dark"] [style*="color:#475569"],
[data-theme="dark"] [style*="color: #666"],
[data-theme="dark"] [style*="color:#666"] {
    color: var(--cu-text-2) !important;
}

[data-theme="dark"] [style*="color: #9ca3af"],
[data-theme="dark"] [style*="color:#9ca3af"],
[data-theme="dark"] [style*="color: #94a3b8"],
[data-theme="dark"] [style*="color:#94a3b8"],
[data-theme="dark"] [style*="color: #999"],
[data-theme="dark"] [style*="color:#999"] {
    color: var(--cu-text-3) !important;
}

/* Azules corporativos heredados: pasan al acento del tema */
[data-theme="dark"] [style*="color: #1e3a8a"],
[data-theme="dark"] [style*="color:#1e3a8a"],
[data-theme="dark"] [style*="color: #1e40af"],
[data-theme="dark"] [style*="color:#1e40af"],
[data-theme="dark"] [style*="color: #0073ea"],
[data-theme="dark"] [style*="color:#0073ea"],
[data-theme="dark"] [style*="color: #3b82f6"],
[data-theme="dark"] [style*="color:#3b82f6"] {
    color: var(--cu-accent) !important;
}

/* ------------------------------------------------------------
   BORDES CLAROS FORZADOS EN LÍNEA
   ------------------------------------------------------------ */
[data-theme="dark"] [style*="border: 1px solid #e5e7eb"],
[data-theme="dark"] [style*="border:1px solid #e5e7eb"],
[data-theme="dark"] [style*="border: 1px solid #e2e8f0"],
[data-theme="dark"] [style*="border:1px solid #e2e8f0"],
[data-theme="dark"] [style*="border: 1px solid #eee"],
[data-theme="dark"] [style*="border:1px solid #eee"],
[data-theme="dark"] [style*="border: 1px solid #ddd"],
[data-theme="dark"] [style*="border:1px solid #ddd"] {
    border-color: var(--cu-border) !important;
}

/* ------------------------------------------------------------
   ELEMENTOS QUE NO DEBEN PERDER SU COLOR PROPIO
   Los badges de estado, botones de acción y avatares llevan color
   semántico intencional; se excluyen de las correcciones de arriba.
   ------------------------------------------------------------ */
[data-theme="dark"] .btn-primary[style*="background"],
[data-theme="dark"] .status-badge[style*="background"],
[data-theme="dark"] .priority-badge[style*="background"],
[data-theme="dark"] .sidebar-badge[style*="background"],
[data-theme="dark"] .badge[style*="background"] {
    color: inherit;
}

/* ------------------------------------------------------------
   COLORES FIJADOS DESDE HOJAS (no inline)
   Los selectores de atributo de arriba no alcanzan a las reglas
   declaradas en <style> o en los .css de cada vista. Estos casos
   se detectaron midiendo el contraste real en el navegador.
   ------------------------------------------------------------ */

/* Celdas de tabla con fondo blanco fijo: dejaban texto claro sobre blanco */
html[data-theme="dark"] .tasks-table td,
html[data-theme="dark"] .tasks-table th,
html[data-theme="dark"] .data-table td,
html[data-theme="dark"] .data-table th {
    background-color: transparent;
}

/* Filas alternas: el gris casi blanco del zebra hacía ilegible la fila entera */
html[data-theme="dark"] .tasks-table tbody tr,
html[data-theme="dark"] .data-table tbody tr {
    background-color: transparent;
}

html[data-theme="dark"] .tasks-table tbody tr:nth-child(even),
html[data-theme="dark"] .data-table tbody tr:nth-child(even) {
    background-color: var(--cu-surface-2);
}

/* Cifras de las tarjetas de estadísticas: color navy fijo sobre fondo oscuro.
   Sin !important a propósito, para que los colores semánticos que vienen
   en atributos style (naranja, verde) sigan mandando. */
html[data-theme="dark"] .stat-number,
html[data-theme="dark"] .stat-value,
html[data-theme="dark"] .task-name,
html[data-theme="dark"] .project-name {
    color: var(--cu-text);
}

/* Botón "Limpiar": fondo gris claro con texto claro */
html[data-theme="dark"] .btn-reset,
html[data-theme="dark"] .btn-clear-monday {
    background-color: var(--cu-surface-3);
    border-color: var(--cu-border);
    color: var(--cu-text-2);
}

/* Contenedores de pestañas con gris claro fijo */
html[data-theme="dark"] .stats-tabs-row,
html[data-theme="dark"] .tabs-wrapper,
html[data-theme="dark"] .tabs-container,
html[data-theme="dark"] .dashboard-tabs {
    background-color: var(--cu-surface-3);
}

/* Etiquetas secundarias en gris medio: por debajo del mínimo sobre fondo oscuro */
html[data-theme="dark"] .stat-label,
html[data-theme="dark"] .filter-group label,
html[data-theme="dark"] .form-group label,
html[data-theme="dark"] label {
    color: var(--cu-text-2);
}

/* Chat interno: el panel conservaba fondo blanco */
html[data-theme="dark"] .chat-window,
html[data-theme="dark"] .chat-header,
html[data-theme="dark"] .chat-list-view,
html[data-theme="dark"] .chat-conversation-view,
html[data-theme="dark"] .chat-list,
html[data-theme="dark"] .chat-search {
    background-color: var(--cu-surface);
    color: var(--cu-text);
}

html[data-theme="dark"] .chat-header {
    border-bottom: 1px solid var(--cu-border);
}

html[data-theme="dark"] .chat-loading {
    color: var(--cu-text-2);
}

/* Estados vacíos: el gris #999 quedaba por debajo del mínimo legible */
html[data-theme] .empty-column,
html[data-theme] .column-body > div:only-child {
    color: var(--cu-text-2);
}

/* ------------------------------------------------------------
   IMÁGENES Y GRÁFICAS
   ------------------------------------------------------------ */
[data-theme="dark"] canvas {
    filter: saturate(0.92);
}

/* El logotipo es arte oscuro sobre fondo transparente: en modo oscuro
   se invierte a blanco para que siga siendo visible. */
[data-theme="dark"] .sidebar-logo img,
[data-theme="dark"] img[src*="logo-rinorisk"] {
    filter: brightness(0) invert(1);
    opacity: 0.92;
}

/* ------------------------------------------------------------
   CONTRASTE EN AMBOS TEMAS
   Corrige combinaciones heredadas ilegibles, como texto gris muy
   claro sobre superficie clara en el selector de empresa.
   ------------------------------------------------------------ */
html[data-theme] .cs-active-name {
    color: var(--cu-text);
}

html[data-theme] .sidebar-user-name {
    color: var(--cu-text);
}

html[data-theme] .sidebar-title {
    color: var(--cu-text);
}
