/**
 * Tema claro/oscuro global — activado con html[data-theme="light|dark"].
 */

:root,
html[data-color-theme] {
  --mantis-bg: var(--body-bg);
  --mantis-surface: var(--body-bg);
  --mantis-surface-2: var(--light);
  --mantis-text: var(--body-color);
  --mantis-muted: var(--gray-600);
  --mantis-border: var(--border-color);
  --mantis-card-header: var(--light);
  --mantis-input-bg: var(--body-bg);
  --mantis-input-border: var(--border-color);
  --mantis-table-stripe: rgba(var(--body-color-rgb), 0.03);
  --mantis-table-hover: rgba(var(--body-color-rgb), 0.05);
  --mantis-shadow: rgba(var(--black-rgb), 0.08);
  --mantis-navbar: var(--gray-700);
}
.card { --mantis-surface: var(--card-bg); --mantis-input-bg: var(--card-bg); }
html[data-color-theme="dark"] { color-scheme: dark; }
html[data-color-theme="light"] { color-scheme: light; }

/* --- Helpdesk: tickets y dashboard --- */
html[data-theme="dark"] .ticket-list-toolbar,
html[data-theme="dark"] .ticket-list-breadcrumb-home a {
  color: var(--mantis-text);
}

html[data-theme="dark"] .filters-form,
html[data-theme="dark"] .filters-form-compact {
  background-color: var(--mantis-surface-2) !important;
  border-color: var(--mantis-border) !important;
  color: var(--mantis-text);
  box-shadow: none;
}

html[data-theme="dark"] .filters-form .form-label,
html[data-theme="dark"] .filters-form-compact .form-label {
  color: var(--mantis-muted) !important;
}

html[data-theme="dark"] .tickets-table,
html[data-theme="dark"] .table-container {
  background-color: var(--mantis-surface) !important;
  border-color: var(--mantis-border) !important;
}

html[data-theme="dark"] .tickets-table thead th {
  background-color: var(--mantis-surface-2) !important;
  color: var(--mantis-text) !important;
  border-color: var(--mantis-border) !important;
}

html[data-theme="dark"] .tickets-table thead th.sortable-col:hover {
  background-color: var(--mantis-table-hover) !important;
}

html[data-theme="dark"] .sort-arrow {
  color: rgba(var(--primary-rgb), .12);
}

html[data-theme="dark"] .tickets-table tbody tr:nth-child(odd),
html[data-theme="dark"] .tickets-table tbody tr:nth-child(even) {
  background-color: transparent !important;
}

html[data-theme="dark"] .tickets-table tbody tr:nth-child(odd) td {
  background-color: var(--mantis-surface) !important;
}

html[data-theme="dark"] .tickets-table tbody tr:nth-child(even) td {
  background-color: var(--mantis-table-stripe) !important;
}

html[data-theme="dark"] .tickets-table tbody tr:hover td,
html[data-theme="dark"] .tickets-table tbody tr:hover {
  background-color: var(--mantis-table-hover) !important;
}

html[data-theme="dark"] .tickets-table tbody td {
  color: var(--mantis-text);
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .tickets-table a {
  color: var(--primary);
}

html[data-theme="dark"] .respuesta-pendiente {
  background-color: rgba(var(--yellow-rgb), 0.18) !important;
  border-left-color: var(--yellow) !important;
  color: var(--mantis-text) !important;
}

html[data-theme="dark"] .tickets-table tbody tr:hover .respuesta-pendiente {
  background-color: rgba(var(--yellow-rgb), 0.28) !important;
}

html[data-theme="dark"] .detalle-sin-respuesta {
  background-color: rgba(var(--warning-rgb), 0.18) !important;
  border-left-color: var(--warning) !important;
}

html[data-theme="dark"] .tickets-table tbody tr:hover .detalle-sin-respuesta {
  background-color: rgba(var(--warning-rgb), 0.28) !important;
}

html[data-theme="dark"] .fecha-ticket-resuelto {
  background-color: rgba(var(--success-rgb), 0.18) !important;
  border-left-color: var(--success) !important;
  color: var(--success) !important;
}

html[data-theme="dark"] .tickets-table tbody tr:hover .fecha-ticket-resuelto {
  background-color: rgba(var(--success-rgb), 0.28) !important;
}

html[data-theme="dark"] .fecha-resuelto-badge {
  color: var(--success);
}

html[data-theme="dark"] .editable-cell-titulo:hover,
html[data-theme="dark"] .editable-cell-horas:hover,
html[data-theme="dark"] .editable-cell-orden:hover {
  background-color: rgba(var(--primary-rgb), 0.2) !important;
  outline-color: var(--primary);
}

html[data-theme="dark"] .priority-dropdown {
  background: var(--mantis-surface);
  border-color: var(--mantis-border);
  box-shadow: 0 4px 14px var(--mantis-shadow);
}

html[data-theme="dark"] .priority-dropdown-item {
  color: var(--mantis-text);
}

html[data-theme="dark"] .priority-dropdown-item:hover {
  background: var(--mantis-table-hover);
}

html[data-theme="dark"] .priority-dropdown-item.active {
  background: var(--mantis-surface-2);
  color: var(--mantis-text);
}

html[data-theme="dark"] .table-container::-webkit-scrollbar-track {
  background: var(--mantis-surface-2);
}

html[data-theme="dark"] .table-container::-webkit-scrollbar-thumb {
  background: rgba(var(--primary-rgb), 0.45);
}

html[data-theme="dark"] .table-container::-webkit-scrollbar-thumb:hover {
  background: rgba(var(--primary-rgb), 0.65);
}

html[data-theme="dark"] .pagination .page-link {
  background-color: var(--mantis-surface);
  border-color: var(--mantis-border);
  color: var(--mantis-muted);
}

html[data-theme="dark"] .pagination .page-item.active .page-link,
html[data-theme="dark"] .pagination-sm .page-item.active .page-link {
  background-color: var(--primary);
  border-color: var(--primary);
  color: rgb(var(--white-rgb));
}

html[data-theme="dark"] .pagination .page-link:hover {
  background-color: var(--mantis-surface-2);
  color: var(--mantis-text);
}

html[data-theme="dark"] .empresas-table,
html[data-theme="dark"] .alerts-table-thead,
html[data-theme="dark"] .agentes-table-thead,
html[data-theme="dark"] .dashboard-card,
html[data-theme="dark"] .chart-container,
html[data-theme="dark"] .alerts-section,
html[data-theme="dark"] .filters-bar {
  background: var(--mantis-surface) !important;
  color: var(--mantis-text);
  border-color: var(--mantis-border);
  box-shadow: 0 1px 3px var(--mantis-shadow);
}

html[data-theme="dark"] .dashboard-card-value,
html[data-theme="dark"] .chart-title,
html[data-theme="dark"] .section-title {
  color: var(--mantis-text);
}

html[data-theme="dark"] .dashboard-card-label,
html[data-theme="dark"] .dashboard-card-footer,
html[data-theme="dark"] .alert-time,
html[data-theme="dark"] .empty-state {
  color: var(--mantis-muted);
}

html[data-theme="dark"] .empresas-table thead,
html[data-theme="dark"] .empresas-table tfoot td,
html[data-theme="dark"] .agentes-dashboard-table thead,
html[data-theme="dark"] .agentes-dashboard-table tfoot td,
html[data-theme="dark"] .alerts-table thead th {
  background: var(--mantis-surface-2) !important;
  color: var(--mantis-text);
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .empresas-table td,
html[data-theme="dark"] .empresas-table th,
html[data-theme="dark"] .agentes-dashboard-table td,
html[data-theme="dark"] .agentes-dashboard-table th,
html[data-theme="dark"] .agentes-table td,
html[data-theme="dark"] .agentes-table th,
html[data-theme="dark"] .alerts-table td,
html[data-theme="dark"] .alerts-table th {
  border-color: var(--mantis-border);
  color: var(--mantis-text);
}

html[data-theme="dark"] .empresas-table tbody tr:hover,
html[data-theme="dark"] .agentes-dashboard-table tbody tr:hover,
html[data-theme="dark"] .agentes-table tbody tr:hover,
html[data-theme="dark"] .alerts-table tbody tr:hover {
  background-color: var(--mantis-table-hover) !important;
}

html[data-theme="dark"] .alerts-paginator {
  background: var(--mantis-surface) !important;
  border-top-color: var(--mantis-border);
}

html[data-theme="dark"] .alert-item {
  background: rgba(var(--danger-rgb), 0.12);
  border-left-color: var(--danger);
}

html[data-theme="dark"] .alert-title {
  color: rgba(var(--danger-rgb), .12);
}

html[data-theme="dark"] .alert-body {
  color: var(--mantis-text);
}

html[data-theme="dark"] .alert-row-urgent {
  background: rgba(var(--danger-rgb), 0.12) !important;
}

html[data-theme="dark"] .alert-row-urgent td {
  background: transparent !important;
}

html[data-theme="dark"] .cell-num,
html[data-theme="dark"] .agente-nombre,
html[data-theme="dark"] .agentes-dashboard-table .agente-nombre {
  color: var(--mantis-text);
}

html[data-theme="dark"] .badge-count {
  background-color: rgba(var(--primary-rgb), 0.2);
  color: rgba(var(--primary-rgb), .12);
}

html[data-theme="dark"] .badge-open {
  background-color: rgba(var(--warning-rgb), 0.2);
  color: var(--warning);
}

html[data-theme="dark"] .badge-urgent {
  background-color: rgba(var(--danger-rgb), 0.2);
  color: rgba(var(--danger-rgb), .12);
}

html[data-theme="dark"] .carga-bar-track {
  background: var(--mantis-surface-2);
}

html[data-theme="dark"] .input-group-text {
  background-color: var(--mantis-surface-2);
  border-color: var(--mantis-input-border);
  color: var(--mantis-muted);
}

html[data-theme="dark"] .text-muted {
  color: var(--mantis-muted) !important;
}

html[data-theme="dark"] .modal-content {
  background-color: var(--mantis-surface);
  color: var(--mantis-text);
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer {
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .modal .table thead,
html[data-theme="dark"] .modal .table thead tr,
html[data-theme="dark"] .modal .table thead th {
  background-color: var(--mantis-surface-2) !important;
  border-color: var(--mantis-border) !important;
  color: var(--mantis-text) !important;
}

html[data-theme="dark"] .modal .table tbody td {
  color: var(--mantis-text);
  border-color: var(--mantis-border);
}

/* --- Kanban tickets --- */
html[data-theme="dark"] .kanban-title {
  color: var(--mantis-text);
}

html[data-theme="dark"] .kanban-col {
  background: var(--mantis-surface-2);
}

html[data-theme="dark"] .kanban-card {
  background: var(--mantis-surface);
  box-shadow: 0 1px 4px var(--mantis-shadow);
  border-left-color: var(--mantis-border);
}

html[data-theme="dark"] .kcard-empresa {
  color: var(--mantis-muted);
}

html[data-theme="dark"] .kcard-subject {
  color: var(--mantis-text);
}

html[data-theme="dark"] .kcard-titulo,
html[data-theme="dark"] .kcard-footer,
html[data-theme="dark"] .kcard-closed-date,
html[data-theme="dark"] .kanban-placeholder,
html[data-theme="dark"] .kanban-empty {
  color: var(--mantis-muted);
}

html[data-theme="dark"] .kcard-num {
  color: var(--primary);
}

html[data-theme="dark"] .kanban-cards.drag-over {
  background: rgba(var(--primary-rgb), 0.15);
  outline-color: var(--primary);
}

html[data-theme="dark"] .kanban-cards {
  scrollbar-color: rgba(var(--primary-rgb), 0.45) transparent;
}

html[data-theme="dark"] .kanban-cards::-webkit-scrollbar-thumb {
  background: rgba(var(--primary-rgb), 0.45);
}

/* --- Ticket detalle (/helpdesk/tickets/<id>/) --- */
html[data-theme="dark"] .ticket-header,
html[data-theme="dark"] .ticket-footer-estado {
  background: linear-gradient(
    135deg,
    var(--mantis-surface-2) 0%,
    var(--mantis-surface) 100%
  ) !important;
  border-color: var(--mantis-border);
  color: var(--mantis-text);
}

html[data-theme="dark"] .ticket-empresa-asunto,
html[data-theme="dark"] .ticket-asunto-tag,
html[data-theme="dark"] .ticket-header .ticket-titulo {
  color: var(--mantis-text);
}

html[data-theme="dark"] .ticket-metrica {
  background: var(--mantis-surface) !important;
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .ticket-metrica-ticket {
  background: linear-gradient(
    180deg,
    var(--mantis-surface) 0%,
    var(--mantis-surface-2) 100%
  ) !important;
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .ticket-metrica-label,
html[data-theme="dark"] .ticket-asignado-label {
  color: var(--mantis-muted);
}

html[data-theme="dark"] .ticket-metrica-value,
html[data-theme="dark"] .ticket-asignado-valor,
html[data-theme="dark"] .footer-metrica {
  color: var(--mantis-text);
}

html[data-theme="dark"] .ticket-metrica-subvalue,
html[data-theme="dark"] .footer-estado-label {
  color: var(--mantis-muted);
}

html[data-theme="dark"] .ticket-progress {
  background: var(--mantis-surface-2);
}

html[data-theme="dark"] .ticket-metrica-working.working-on {
  background: rgba(var(--success-rgb), 0.12) !important;
}

html[data-theme="dark"] .ticket-metrica-working.working-off {
  background: var(--mantis-surface-2) !important;
}

html[data-theme="dark"] .footer-agente,
html[data-theme="dark"] .footer-metrica {
  background: var(--mantis-surface) !important;
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .mensaje-item {
  background: var(--mantis-surface) !important;
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .mensaje-contenido {
  background: var(--mantis-surface) !important;
  color: var(--mantis-text);
}

html[data-theme="dark"] .mensaje-tipo-m .mensaje-header {
  background: rgba(var(--primary-rgb), 0.15) !important;
}

html[data-theme="dark"] .mensaje-tipo-r .mensaje-header {
  background: rgba(var(--success-rgb), 0.15) !important;
}

html[data-theme="dark"] .mensaje-tipo-n .mensaje-header {
  background: rgba(var(--yellow-rgb), 0.15) !important;
}

html[data-theme="dark"] .mensaje-tipo-a .mensaje-header {
  background: var(--mantis-surface-2) !important;
}

html[data-theme="dark"] .mensaje-meta-item .meta-label {
  color: var(--mantis-muted);
}

html[data-theme="dark"] .mensaje-meta-item .meta-value {
  color: var(--mantis-text);
}

html[data-theme="dark"] .mensaje-contenido blockquote,
html[data-theme="dark"] .mensaje-contenido:deep(blockquote) {
  color: var(--mantis-muted);
  border-left-color: var(--primary);
}

html[data-theme="dark"] .mensaje-contenido code,
html[data-theme="dark"] .mensaje-contenido pre,
html[data-theme="dark"] .mensaje-contenido:deep(code),
html[data-theme="dark"] .mensaje-contenido :deep(pre) {
  background-color: var(--mantis-surface-2) !important;
  border-color: var(--mantis-border);
  color: var(--mantis-text);
}

html[data-theme="dark"] .gravatar-fallback-icon {
  background: var(--mantis-surface-2);
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .archivo-adjunto {
  background: var(--mantis-surface-2) !important;
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .archivo-adjunto h6 {
  color: var(--mantis-text);
}

html[data-theme="dark"] .actividad-evento {
  background: var(--mantis-surface-2) !important;
  border-color: var(--mantis-border);
  color: var(--mantis-muted);
}

html[data-theme="dark"] .actividad-texto strong {
  color: var(--mantis-text);
}

html[data-theme="dark"] .reply-form-card {
  background: var(--mantis-surface) !important;
  border-color: var(--mantis-border);
  box-shadow: 0 2px 10px var(--mantis-shadow);
}

html[data-theme="dark"] .reply-form-header {
  background: var(--mantis-surface-2) !important;
  border-bottom-color: var(--mantis-border);
}

html[data-theme="dark"] .reply-form-title {
  color: var(--mantis-text);
}

html[data-theme="dark"] .btn-fmt {
  background: var(--mantis-input-bg);
  border-color: var(--mantis-input-border);
  color: var(--mantis-muted);
}

html[data-theme="dark"] .btn-fmt.active {
  background: var(--indigo);
  color: rgb(var(--white-rgb));
  border-color: var(--indigo);
}

html[data-theme="dark"] #reply-quill-wrapper {
  border-bottom-color: var(--mantis-border);
}

html[data-theme="dark"] #reply-quill-wrapper .ql-toolbar,
html[data-theme="dark"] .ql-snow .ql-toolbar,
html[data-theme="dark"] .ql-snow.ql-toolbar {
  background: var(--mantis-surface-2) !important;
  border-color: var(--mantis-border) !important;
}

html[data-theme="dark"] #reply-quill-wrapper .ql-container,
html[data-theme="dark"] .ql-snow .ql-container {
  background: var(--mantis-surface) !important;
  border-color: var(--mantis-border) !important;
  color: var(--mantis-text);
}

html[data-theme="dark"] .ql-editor,
html[data-theme="dark"] .ql-snow .ql-editor {
  color: var(--mantis-text);
}

html[data-theme="dark"] .ql-snow .ql-stroke {
  stroke: var(--mantis-muted);
}

html[data-theme="dark"] .ql-snow .ql-fill,
html[data-theme="dark"] .ql-snow .ql-picker {
  fill: var(--mantis-muted);
  color: var(--mantis-muted);
}

html[data-theme="dark"] .ql-snow .ql-picker-options {
  background: var(--mantis-surface);
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .reply-textarea {
  background: var(--mantis-surface);
  color: var(--mantis-text);
}

html[data-theme="dark"] .reply-attachments-section,
html[data-theme="dark"] .reply-footer {
  background: var(--mantis-surface-2) !important;
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .reply-dropzone {
  background: var(--mantis-surface) !important;
  border-color: var(--mantis-border);
  color: var(--mantis-muted);
}

html[data-theme="dark"] .reply-dropzone:hover,
html[data-theme="dark"] .reply-dropzone.drag-over {
  background: rgba(var(--primary-rgb), 0.12) !important;
  border-color: var(--primary);
  color: var(--mantis-text);
}

html[data-theme="dark"] .reply-file-item {
  background: rgba(var(--primary-rgb), 0.12) !important;
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .reply-file-name {
  color: var(--mantis-text);
}

html[data-theme="dark"] .btn-toggle-notas {
  color: var(--mantis-muted);
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .ticket-detail-container .empty-state h4 {
  color: var(--mantis-text);
}

/* Controles inline de ticket.html */
html[data-theme="dark"] .badge-estado-ctrl.estado-abierto {
  background: rgba(var(--success-rgb), 0.2) !important;
  color: var(--success) !important;
}

html[data-theme="dark"] .badge-estado-ctrl.estado-cerrado {
  background: rgba(var(--danger-rgb), 0.2) !important;
  color: rgba(var(--danger-rgb), .12) !important;
}

html[data-theme="dark"] .badge-estado-ctrl.estado-resuelto {
  background: rgba(var(--primary-rgb), 0.2) !important;
  color: rgba(var(--primary-rgb), .12) !important;
}

html[data-theme="dark"] .badge-estado-ctrl.estado-archivado {
  background: var(--mantis-surface-2) !important;
  color: var(--mantis-muted) !important;
}

html[data-theme="dark"] .badge-estado-ctrl.estado-default {
  background: var(--mantis-surface-2) !important;
  color: var(--mantis-muted) !important;
}

html[data-theme="dark"] .badge-agente-ctrl {
  background: rgba(var(--primary-rgb), 0.18) !important;
  color: rgba(var(--primary-rgb), .12) !important;
}

html[data-theme="dark"] .badge-agente-ctrl .agente-nombre.sin-asignar {
  color: var(--mantis-muted) !important;
}

html[data-theme="dark"] .badge-resuelto-ctrl {
  background: rgba(var(--primary-rgb), 0.18) !important;
  color: rgba(var(--primary-rgb), .12) !important;
}

html[data-theme="dark"] .resolved-at-fecha,
html[data-theme="dark"] .modal-nota-label,
html[data-theme="dark"] .ticket-ctrl-label {
  color: var(--mantis-muted);
}

html[data-theme="dark"] .ticket-ctrl-block--compact {
  border-top-color: var(--mantis-border) !important;
}

html[data-theme="dark"] .reply-tipo-toggle {
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .btn-ctrl-estado {
  background: transparent;
}

html[data-theme="dark"] .btn-tipo {
  background: var(--mantis-surface-2);
  color: var(--mantis-muted);
}

html[data-theme="dark"] .reply-mode-nota {
  background: rgba(var(--yellow-rgb), 0.1) !important;
  border-left-color: var(--yellow) !important;
}

html[data-theme="dark"] .reply-mode-nota .reply-form-title {
  color: var(--yellow);
}

html[data-theme="dark"] .canned-sidebar {
  background: var(--mantis-surface-2);
  border-color: var(--mantis-border);
}

html[data-theme="dark"] .canned-search input {
  background: var(--mantis-input-bg);
  border-color: var(--mantis-input-border);
  color: var(--mantis-text);
}

html[data-theme="dark"] .canned-list-item {
  color: var(--mantis-text);
  border-bottom-color: var(--mantis-border);
}

html[data-theme="dark"] .canned-list-item:hover {
  background: var(--mantis-table-hover) !important;
}

html[data-theme="dark"] .canned-list-item.active {
  background: rgba(var(--primary-rgb), 0.2) !important;
  color: rgba(var(--primary-rgb), .12) !important;
}

html[data-theme="dark"] .canned-preview-title,
html[data-theme="dark"] .canned-preview-notes {
  background: var(--mantis-surface-2) !important;
  border-color: var(--mantis-border);
  color: var(--mantis-text);
}

html[data-theme="dark"] .canned-preview-body {
  color: var(--mantis-text);
}

/* --- Infrastructure: filas semanticas y notificaciones --- */
html[data-theme="dark"] .row-instancia-inactiva td,
html[data-theme="dark"] .row-instancia-inactiva th {
  background: rgba(var(--warning-rgb), 0.15) !important;
  color: var(--warning) !important;
}

html[data-theme="dark"] .row-instancia-inactiva:hover td,
html[data-theme="dark"] .row-instancia-inactiva:hover th {
  background: rgba(var(--warning-rgb), 0.25) !important;
}

html[data-theme="dark"] .row-notif-inactiva td {
  background: var(--mantis-surface-2) !important;
  color: var(--mantis-muted) !important;
}

html[data-theme="dark"] .dj-notif-status-banner {
  background: linear-gradient(
    135deg,
    rgba(var(--danger-rgb), 0.12) 0%,
    rgba(var(--danger-rgb), 0.18) 100%
  ) !important;
  border-color: rgba(var(--danger-rgb), 0.35);
}

html[data-theme="dark"] .dj-notif-status__titulo {
  color: rgba(var(--danger-rgb), .12);
}

html[data-theme="dark"] .dj-notif-status__text,
html[data-theme="dark"] .dj-notif-status__cuerpo {
  color: var(--mantis-text);
}

/* --- SweetAlert2 --- */
html[data-theme="dark"] .swal2-popup {
  background: var(--mantis-surface) !important;
  color: var(--mantis-text);
}

html[data-theme="dark"] .swal2-title,
html[data-theme="dark"] .swal2-html-container {
  color: var(--mantis-text);
}
