/* === Reset y variables de diseño === */
:root {
  --color-bg: #f9fafb;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-text: #111827;
  --color-text-secondary: #4b5563;
  --color-primary: #2563eb;
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-hover: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

/* === Top Navigation === */
.top-navigation {
  background: var(--color-surface);
  box-shadow: var(--shadow);
  padding: 0.75rem 1.5rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1030;
}
.top-navigation h4 {
  font-weight: 600;
  color: var(--color-text);
}
.nav-item-btn {
  background: none;
  border: 1px solid transparent;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}
.nav-item-btn:hover,
.nav-item-btn.active {
  background: #eff6ff;
  color: var(--color-primary);
}
.nav-item-btn.active {
  font-weight: 600;
  border-left: 3px solid var(--color-primary);
}

/* === Command Palette === */
.command-palette-trigger {
  margin-top: 5px;
  padding: 0 1.5rem;
}
.command-palette-trigger button {
  width: 100%;
  text-align: left;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-weight: 500;
}
.command-palette {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  z-index: 9999;
  justify-content: center;
  align-items: flex-start;
  padding-top: 120px;
}
.command-palette-content {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 600px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  padding: 1.5rem;
}
.list-group-item {
  cursor: pointer;
  padding: 0.75rem 1rem;
  border-radius: 8px;
}
.list-group-item:hover {
  background: #f0f9ff;
}

/* === Monitores === */
.monitor-badge-group {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  min-width: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.monitor-badge-group:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

/* === Contenido principal === */
#dashboard-container {
  padding-top: 10px; /* Ajustado para top nav + monitors */
}

/* === Tipografía y utilidades === */
h2 {
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 1.5rem;
}
.badge {
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}
.btn {
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-weight: 500;
  border: 1px solid transparent;
}
.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

/* === Colores de badges y botones === */
/* === Badges de estado y tipo con alto contraste === */
.badge.bg-success,
.badge.bg-danger,
.badge.bg-warning,
.badge.bg-info,
.badge.bg-primary,
.badge.bg-secondary {
    color: white !important;
    border: none;
}
.badge.bg-primary { background-color: #2563eb !important; } /* azul */
.badge.bg-success { background-color: #16a34a !important; } /* verde */
.badge.bg-danger  { background-color: #dc2626 !important; } /* rojo */
.badge.bg-warning { background-color: #d97706 !important; } /* ámbar oscuro */
.badge.bg-info    { background-color: #0d9488 !important; } /* turquesa oscuro */
.badge.bg-secondary { background-color: #6b7280 !important; } /* gris */

/* === Íconos dentro de badges de estado y tipo === */
.badge.bg-primary i,
.badge.bg-success i,
.badge.bg-danger i,
.badge.bg-warning i,
.badge.bg-info i,
.badge.bg-secondary i {
    color: white !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    filter: brightness(1.1);
}

/* === Colores adicionales para tipos específicos === */
.badge.bg-purple {
    background-color: #6d28d9 !important;
    color: white !important;
}
.badge.bg-pink {
    background-color: #ec4899 !important;
    color: white !important;
}

/* === Íconos dentro de badges de tipos específicos === */
.badge.bg-purple i,
.badge.bg-pink i {
    color: white !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    filter: brightness(1.1);
}

.btn-success { background: var(--color-success); color: white; }
.btn-warning { background: var(--color-warning); color: white; }
.btn-danger { background: var(--color-danger); color: white; }
.btn-primary { background: var(--color-primary); }
.btn-outline-primary {
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-outline-primary:hover {
  background: #eff6ff;
}

/* === Toasts con alto contraste === */
.toast.bg-success {
    background-color: #16a34a !important;
    color: white !important;
}
.toast.bg-danger {
    background-color: #dc2626 !important;
    color: white !important;
}
.toast.bg-warning {
    background-color: #d97706 !important;
    color: white !important;
}
.toast.bg-info {
    background-color: #0d9488 !important;
    color: white !important;
}
.toast.bg-primary {
    background-color: #2563eb !important;
    color: white !important;
}
.toast .toast-header,
.toast .toast-body {
    color: white !important;
}
.toast .btn-close {
    filter: brightness(0) invert(1); /* icono blanco */
}

/* === Tarjetas y estadísticas === */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}
.card-body {
  padding: 1.5rem;
}
.hover-card {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.hover-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.display-4 {
  font-size: 2.25rem;
  font-weight: 700;
}

/* === Tablas === */
.table thead th {
  background: var(--color-surface);
  border-bottom: 2px solid var(--color-border);
  font-weight: 600;
}
.table-hover tbody tr:hover {
  background-color: #f9fafb;
}
.jobs-table-container {
  max-height: 600px;
  overflow-y: auto;
}
#jobs-table thead th {
  position: sticky;
  top: 0;
  background: white !important;
  z-index: 2;
}

/* === Selección múltiple === */
.selection-bar {
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  transition: all 0.2s ease;
}
.selection-bar.selected {
  background: #dbeafe;
  border-color: #93c5fd;
  box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.1);
}
#selected-icon.highlighted {
  color: var(--color-primary) !important;
  transform: scale(1.1);
}
#selected-count-badge.highlighted {
  background: #93c5fd;
  color: white;
  font-weight: 700;
}

/* === Toasts === */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  max-height: 80vh;
  overflow-y: auto;
}
.toast {
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: none;
  min-width: 300px;
}
.toast-header {
  border-bottom: 1px solid var(--color-border);
}



/* === Animaciones === */
@keyframes vibrate {
  0% { transform: translateX(0); }
  20% { transform: translateX(-2px); }
  40% { transform: translateX(2px); }
  60% { transform: translateX(-1px); }
  80% { transform: translateX(1px); }
  100% { transform: translateX(0); }
}
.vibrate-once {
  animation: vibrate 0.3s ease;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.6; }
  100% { opacity: 1; }
}
.bg-success[style*="opacity: 1"] {
  animation: pulse 1.5s infinite;
}

/* === Responsive === */
@media (max-width: 992px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar:not(.hidden) {
    transform: translateX(0);
  }
  #dashboard-container {
    margin-left: 0;
    padding-left: 1rem;
  }
  .top-header {
    left: 0;
  }
  
  .monitor-badge-group {
    min-width: 140px;
    padding: 0.75rem;
    font-size: 0.85rem;
  }
}

/* === Monitores compactos === */
.monitor-badge-group {
    min-width: 180px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 8px;
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    transition: all 0.2s ease;
}

.monitor-badge-group:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.12);
    transform: translateY(-2px);
}

/* === Monitores compactos en una sola línea === */
.btn-xs {
    padding: 0.15rem 0.4rem;
    font-size: 0.7rem;
    line-height: 1;
    border-radius: 4px;
}

/* Indicador de actividad pequeño */
.badge.bg-success[style*="opacity: 1"] {
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* Para pantallas pequeñas, permite que los monitores se envuelvan */
@media (max-width: 992px) {
    .monitor-badge-group {
        min-width: 140px;
        padding: 0.25rem;
        font-size: 0.85rem;
    }
}

/* === Monitores compactos en una sola línea === */
.monitors-bar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0.5rem 1.5rem;
    margin-top: 10px; /* Ajusta según la altura de tu header */
}
.monitor-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: all 0.2s ease;
}
.monitor-item:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}
.monitor-title {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-secondary);
}
.monitor-title i {
    font-size: 1.1rem;
}
.monitor-activity-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--color-success);
    opacity: 0;
    transition: opacity 0.3s ease;
}
.monitor-activity-indicator.active {
    opacity: 1;
}
.monitor-controls {
    display: flex;
    gap: 0.25rem;
}
/* Botones pequeños */
.btn-xs {
    font-size: 0.75rem;
    padding: 0.15rem 0.4rem;
    line-height: 1;
    border-radius: 4px;
}
.monitor-interval {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
}
.monitor-badge {
    min-width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 12px;
}

.monitor-spinner {
    animation: spin 1s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Alinea horizontalmente los botones de acción en la tabla de archivos */
#jobs-table .actions-cell,
#jobs-table td:last-child {
    white-space: nowrap;
}
#jobs-table .actions-cell .btn,
#jobs-table td:last-child .btn {
    margin-right: 0.25rem;
}
#jobs-table .actions-cell .btn:last-child,
#jobs-table td:last-child .btn:last-child {
    margin-right: 0;
}

/* === Botones outline con colores coherentes === */
.btn-outline-success {
    color: #16a34a !important;
    border-color: #16a34a !important;
}
.btn-outline-success:hover {
    background-color: #16a34a !important;
    color: white !important;
}
.btn-outline-danger {
    color: #dc2626 !important;
    border-color: #dc2626 !important;
}
.btn-outline-danger:hover {
    background-color: #dc2626 !important;
    color: white !important;
}
.btn-outline-warning {
    color: #d97706 !important;
    border-color: #d97706 !important;
}
.btn-outline-warning:hover {
    background-color: #d97706 !important;
    color: white !important;
}
.btn-outline-info {
    color: #0d9488 !important;
    border-color: #0d9488 !important;
}
.btn-outline-info:hover {
    background-color: #0d9488 !important;
    color: white !important;
}
.btn-outline-primary {
    color: #2563eb !important;
    border-color: #2563eb !important;
}
.btn-outline-primary:hover {
    background-color: #2563eb !important;
    color: white !important;
}

.toast .bi {
    color: white !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    filter: brightness(1.1);
}

.dropdown-menu .badge {
    display: inline-flex;
    align-items: center;
    width: 100%;
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
}
.dropdown-menu .badge i {
    color: white !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    filter: brightness(1.1);
}

.dropdown-menu .badge {
    display: inline-flex;
    align-items: center;
    width: 100%;
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
}
.dropdown-menu .badge i {
    color: white !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    filter: brightness(1.1);
}

/* === Solución para toasts de altura variable === */
.toast {
    /* Asegura que el toast se ajuste a su contenido */
    min-height: auto;
    height: auto;
    /* Permite que el contenido interno fluya libremente */
    display: flex;
    flex-direction: column;
}

.toast-header {
    /* Asegura que el encabezado no se estire */
    flex-shrink: 0;
}

.toast-body {
    /* Fuerza la expansión vertical */
    flex-grow: 1;
    /* Permite que el texto se ajuste correctamente */
    white-space: normal;
    word-wrap: break-word;
    word-break: break-word;
    /* Evita que se desborde */
    overflow-wrap: break-word;
    /* Asegura que el scroll no aparezca innecesariamente */
    max-height: none;
    overflow: visible;
}

/* === Estilos para los dropdowns de filtros === */
.btn-outline-secondary.dropdown-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.btn-outline-secondary.dropdown-toggle .badge {
    /* Asegura que la badge ocupe todo el botón y se alinee correctamente */
    flex-grow: 1;
    justify-content: flex-start;
    padding: 0.3rem 0.6rem;
}
/* Evita que el botón añada su propio padding a la badge */
.btn-outline-secondary.dropdown-toggle span.text-muted {
    flex-grow: 1;
    text-align: left;
}

/* Hacer la card "Procesados" clicable */
#processed-card,
#pending-card,
#failed-card {
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#processed-card:hover,
#pending-card:hover,
#failed-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

/* Contenedor del gráfico: ajusta la altura al espacio disponible */
/* Contenedor del gráfico: ajuste preciso */
.chart-container {
    max-height: calc(100vh - 287px); /* ✅ Valor exacto */
    min-height: 300px;
    display: flex;
    flex-direction: column;
}

.chart-container .card {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chart-container .card-body {
    flex: 1;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

/* Canvas del gráfico */
#processingChart {
    flex: 1;
    min-height: 250px;
    width: 100% !important;
    height: 100% !important;
}

.monitor-refresh-btn-now {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

/* En styles.css */
.text-decoration-line-through {
    text-decoration: line-through !important;
}

/* Indicador de ordenamiento */
th[data-sort] {
    cursor: pointer;
    user-select: none;
    position: relative;
}
th[data-sort]::after {
    content: "↕️";
    position: absolute;
    right: 0.5rem;
    opacity: 0.5;
}
th.sorted-asc::after {
    content: "🔼";
    opacity: 1;
}
th.sorted-desc::after {
    content: "🔽";
    opacity: 1;
}