/* Dashboard & Widgets CSS - v3.1 Fixed Responsive */

.dashboard-container {
    padding: 1rem 0;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    /* Permitir wrap en móvil */
    gap: 1rem;
}

.dashboard-header h2 {
    margin: 0;
    color: var(--primary-teal);
}

.dashboard-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-reset-layout {
    padding: 0.5rem 1rem;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.btn-reset-layout:hover {
    background: #e0e0e0;
    border-color: #ccc;
}

/* Grid de Widgets */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (min-width: 1400px) {
    .dashboard-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Widget Base */
.widget {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    cursor: grab;
    position: relative;
    overflow: hidden;
}

.widget:active {
    cursor: grabbing;
}

.widget:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.widget.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

/* Widget Header */
.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #f0f0f0;
}

.widget-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.widget-icon {
    font-size: 1.3rem;
}

.widget-drag-handle {
    cursor: grab;
    padding: 0.25rem;
    color: #999;
    font-size: 1.2rem;
    transition: color 0.2s;
}

.widget-drag-handle:hover {
    color: #666;
}

.widget-drag-handle:active {
    cursor: grabbing;
}

/* Widget Body */
.widget-body {
    color: #666;
    line-height: 1.6;
}

/* Widget Variants */
.widget.widget-accent {
    border-left: 4px solid var(--primary-teal);
}

.widget.widget-success {
    border-left: 4px solid #4CAF50;
}

.widget.widget-warning {
    border-left: 4px solid #FF9800;
}

.widget.widget-info {
    border-left: 4px solid #2196F3;
}

/* Widget Específicos */

/* Avisos Recientes */
.widget-avisos .aviso-item {
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: #f8f9fa;
    border-left: 3px solid var(--primary-green);
    border-radius: 6px;
    transition: all 0.2s;
}

.widget-avisos .aviso-item:hover {
    background: #e8f5e9;
    transform: translateX(4px);
}

.widget-avisos .aviso-item:last-child {
    margin-bottom: 0;
}

.widget-avisos .aviso-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
}

.widget-avisos .aviso-meta {
    font-size: 0.8rem;
    color: #999;
}

/* Mensajes Sin Leer */
.widget-mensajes .contador-grande {
    font-size: 3rem;
    font-weight: bold;
    color: var(--primary-teal);
    text-align: center;
    margin: 1rem 0;
}

.widget-mensajes .mensaje-accion {
    text-align: center;
    margin-top: 1rem;
}

/* Accesos Rápidos */
.widget-accesos .accesos-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.widget-accesos .acceso-item {
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary-green), var(--primary-teal));
    color: white;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.widget-accesos .acceso-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(42, 172, 162, 0.3);
}

.widget-accesos .acceso-icon {
    font-size: 1.8rem;
}

.widget-accesos .acceso-label {
    font-size: 0.85rem;
    font-weight: 600;
}

/* Calendario CAPA */
.widget-capa .capa-evento {
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: #fff3e0;
    border-left: 3px solid #FF9800;
    border-radius: 6px;
}

.widget-capa .capa-evento:last-child {
    margin-bottom: 0;
}

.widget-capa .capa-fecha {
    font-weight: 600;
    color: #FF9800;
    font-size: 0.9rem;
}

.widget-capa .capa-descripcion {
    font-size: 0.85rem;
    color: #666;
    margin-top: 0.25rem;
}

/* Vehículos Alerta */
.widget-vehiculos .vehiculo-alerta {
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: #ffebee;
    border-left: 3px solid #e74c3c;
    border-radius: 6px;
}

.widget-vehiculos .vehiculo-alerta:last-child {
    margin-bottom: 0;
}

.widget-vehiculos .vehiculo-matricula {
    font-weight: 600;
    color: #e74c3c;
}

.widget-vehiculos .vehiculo-problema {
    font-size: 0.85rem;
    color: #666;
    margin-top: 0.25rem;
}

/* Estadísticas */
.widget-stats .stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.widget-stats .stat-item {
    text-align: center;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
}

.widget-stats .stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-teal);
}

.widget-stats .stat-label {
    font-size: 0.8rem;
    color: #999;
    margin-top: 0.25rem;
}

/* Empty State */
.widget-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: #999;
}

.widget-empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

/* Dark Mode Support */
body.dark-mode .widget {
    background: var(--card-color);
    border-color: var(--border-color);
}

body.dark-mode .widget-header {
    border-bottom-color: var(--border-color);
}

body.dark-mode .widget-title {
    color: var(--text-primary);
}

body.dark-mode .widget-body {
    color: var(--text-secondary);
}

body.dark-mode .widget-avisos .aviso-item,
body.dark-mode .widget-stats .stat-item,
body.dark-mode .widget-accesos .accesos-grid {
    background: var(--surface-color);
}

body.dark-mode .widget-avisos .aviso-title {
    color: var(--text-primary);
}

/* Loading State */
.widget-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 150px;
    color: #999;
}

.widget-loading::after {
    content: "⏳";
    font-size: 2rem;
    animation: spin 2s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* =========================================
   RESPONSIVE & MOBILE FIXES (v3.1)
   ========================================= */

/* --- RESPONSIVE DIRECTORIO --- */
.grid-responsive {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    /* Tarjetas flexibles */
    gap: 1rem;
    width: 100%;
}

@media (max-width: 768px) {
    .grid-responsive {
        grid-template-columns: 1fr !important;
    }
}

.expand-collapse-container {
    margin: 1rem 0;
    text-align: right;
}

/* Botón responsivo */
.btn-expand-collapse {
    padding: 0.6rem 1rem;
    background: linear-gradient(135deg, var(--primary-green), var(--primary-teal));
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    width: 100%;
    /* Full width en móvil */
    margin-bottom: 0.5rem;
}

@media (min-width: 768px) {
    .btn-expand-collapse {
        width: auto;
        /* Ancho auto en escritorio */
    }
}

/* --- RESPONSIVE TABLES & SCROLLING --- */
/* Contenedor con scroll horizontal para tablas */
.table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Scroll suave iOS */
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin-top: 1rem;
}

/* Tabla mínima forzada para activar scroll */
.data-table {
    width: 100%;
    min-width: 600px;
    /* <--- CLAVE: Fuerza scroll si la pantalla es menor a 600px */
    border-collapse: collapse;
}

/* Ajustes de celdas para móvil */
.data-table th,
.data-table td {
    white-space: nowrap;
    /* Evita saltos de línea feos en celdas pequeñas */
    padding: 0.8rem 1rem;
}

/* Excepción para columnas de descripción o contenido largo */
.data-table td.wrap-text {
    white-space: normal;
    min-width: 200px;
}

/* Scroll lateral para pestañas (Tabs) en móvil */
/* (Soluciona que "Roles y Permisos" o "Plantillas Tarifas" se corten) */
.submenu-tabs {
    display: flex;
    flex-wrap: nowrap;
    /* Mantiene una línea */
    overflow-x: auto;
    /* Scroll horizontal */
    width: 100%;
    gap: 0.5rem;
    padding-bottom: 0.5rem;
    /* Espacio para scrollbar */
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    -webkit-overflow-scrolling: touch;
}

.submenu-tab {
    white-space: nowrap;
    /* No partir texto */
    flex: 0 0 auto;
    /* No encoger pestañas */
}

/* Mobile Adjustments */
@media (max-width: 600px) {
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .dashboard-actions,
    .btn-reset-layout {
        width: 100%;
    }

    .btn-reset-layout {
        text-align: center;
    }
}