/* --- BASE & VARIABLES --- */
:root {
    --primary: #3498db; 
    --dark: #2c3e50; 
    --light: #f4f6f8;
    --success: #28a745; 
    --warning: #ffc107; 
    --danger: #dc3545;
    --radius: 8px; 
    --pill-radius: 50px;
}

/* Box Sizing Global */
* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background-color: var(--light);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

#app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* --- SIDEBAR (Escritorio) --- */
.sidebar-right {
    width: 240px;
    background-color: var(--dark);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    z-index: 100;
}

.sidebar-right.collapsed { width: 70px; }

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    color: white;
}

.logo-area { overflow: hidden; white-space: nowrap; transition: 0.2s; }
.sidebar-right.collapsed .logo-area { display: none; }
.sidebar-right.collapsed .sidebar-header { justify-content: center; padding: 20px 0; }

#toggle-sidebar {
    background: none; border: none; cursor: pointer; padding: 5px; display: flex; align-items: center; justify-content: center;
}

.nav-btn {
    background: none; border: none; color: #bdc3c7;
    padding: 15px 20px; text-align: left; cursor: pointer;
    display: flex; align-items: center; gap: 15px;
    transition: 0.2s;
    border-left: 4px solid transparent;
}
.nav-btn .nav-label { white-space: nowrap; opacity: 1; transition: 0.2s; }
.sidebar-right.collapsed .nav-label { opacity: 0; width: 0; display: none; }

.nav-btn:hover { background-color: rgba(255,255,255,0.05); color: white; }
.nav-btn.active { color: white; border-left-color: var(--primary); background: linear-gradient(90deg, rgba(52,152,219,0.1) 0%, transparent 100%); }

/* --- CONTENIDO PRINCIPAL --- */
.content {
    flex: 1;
    padding: 20px 30px;
    overflow-y: auto;
    display: none;
    position: relative;
}
.content.active { display: block; }

/* --- DASHBOARD FIXED SCROLL (NUEVO) --- */
/* Esta sección fija el buscador y scrollea solo la tabla */
#view-dashboard.active {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden; /* Anula el scroll general */
    padding: 0 !important;
}

#view-dashboard .header-actions {
    flex-shrink: 0;
    padding: 20px 30px 10px 30px; /* Mismo padding que .content original */
    background-color: var(--light);
    z-index: 10;
}

#view-dashboard .table-container-island {
    flex-grow: 1;
    overflow-y: auto; /* Scroll interno */
    padding: 0 30px 100px 30px;
    scrollbar-width: thin;
    scrollbar-color: #bdc3c7 transparent;
}

/* Scrollbar estilizado para Webkit */
#view-dashboard .table-container-island::-webkit-scrollbar { width: 8px; }
#view-dashboard .table-container-island::-webkit-scrollbar-track { background: transparent; }
#view-dashboard .table-container-island::-webkit-scrollbar-thumb { background: #bdc3c7; border-radius: 4px; }

/* --- FILTROS --- */
.filter-bar { display: flex; gap: 15px; margin-bottom: 25px; flex-wrap: wrap; }

.search-pill {
    flex: 1; min-width: 200px;
    background: white; border-radius: var(--pill-radius);
    padding: 5px 20px; display: flex; align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03); border: 1px solid #e1e4e8;
}
.search-pill input { border: none; outline: none; width: 100%; padding: 10px; font-size: 1rem; background: transparent; }

.select-pill-wrapper { flex: 1; min-width: 200px; }
.select-pill {
    width: 100%; padding: 12px 20px; border-radius: var(--pill-radius);
    border: 1px solid #e1e4e8; background: white; font-size: 1rem;
    cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.03); outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23007CB2%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat; background-position: right 1rem center; background-size: 0.65em auto;
}

/* --- TABLA ESTILO ISLA --- */
.table-container-island table { width: 100%; border-collapse: separate; border-spacing: 0 12px; }
.table-container-island th { text-align: left; color: #7f8c8d; font-weight: 600; padding: 0 15px 10px 15px; font-size: 0.9em; text-transform: uppercase; }
.table-container-island tbody tr {
    background: white; box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    transition: transform 0.2s, box-shadow 0.2s; cursor: pointer;
}
.table-container-island tbody tr:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,0,0,0.05); }
.table-container-island td { padding: 15px; vertical-align: middle; border-top: 1px solid #e1e4e8; border-bottom: 1px solid #e1e4e8; }
.table-container-island td:first-child { border-top-left-radius: var(--radius); border-bottom-left-radius: var(--radius); border-left: 4px solid transparent; border-left-style: solid; }
.table-container-island td:last-child { border-top-right-radius: var(--radius); border-bottom-right-radius: var(--radius); border-right: 1px solid #e1e4e8; }

tr.row-status-success td:first-child { border-left-color: var(--success) !important; }
tr.row-status-warning td:first-child { border-left-color: var(--warning) !important; }
tr.row-status-danger td:first-child { border-left-color: var(--danger) !important; }

.chevron-icon { color: #bdc3c7; transition: 0.2s; }
tr:hover .chevron-icon { color: var(--primary); transform: translateX(3px); }

/* --- BADGES --- */
.hospital-tag {
    font-family: monospace; font-weight: 700; color: #1a252f;
    background: #e9ecef; padding: 4px 10px; border-radius: 4px;
    border: 1px solid #ced4da; display: inline-block;
}
.status-badge { padding: 4px 12px; border-radius: 12px; font-size: 0.85em; font-weight: 700; }
.status-online { background: #d1e7dd; color: #0f5132; border: 1px solid #badbcc; }
.status-offline { background: #f8d7da; color: #842029; border: 1px solid #f5c2c7; }
/* --- SEMÁFORO DE ALERTAS --- */
.status-notice { 
    background: #fff3cd; /* Amarillo pastel */
    color: #000000; 
    border: 1px solid #ffeeba; 
}
.status-warning { 
    background: #ffe8cc; /* Naranja pastel */
    color: #000000; 
    border: 1px solid #ffd8a8; 
}
.status-critical { 
    background: #f8d7da; /* Rojo pastel */
    color: #000000; 
    border: 1px solid #f5c2c7; 
}

/* --- ALERT TABLES --- */
.table-clean { width: 100%; border-collapse: collapse; margin-bottom: 0; }
.table-clean th { text-align: left; padding: 15px; font-size: 0.85em; text-transform: uppercase; color: #7f8c8d; font-weight: 700; border-bottom: 2px solid #f0f0f0; }
.table-clean td { padding: 15px; border-bottom: 1px solid #f5f5f5; color: #2c3e50; vertical-align: middle; }
.table-clean tbody tr:last-child td { border-bottom: none; }
.table-clean.active-incidents th { background-color: #fff5f5; color: #c0392b; border-bottom: 2px solid #fadbd8; }
.table-clean.history th { background-color: #f8f9fa; color: #7f8c8d; border-bottom: 2px solid #e1e4e8; }

/* --- CONFIG TABLE --- */
.scrollable-config-table { max-height: 500px; overflow-y: auto; position: relative; border-bottom: 1px solid #e1e4e8; }
.scrollable-config-table thead th { position: sticky; top: 0; background-color: #f8f9fa; z-index: 10; box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1); }

/* --- DETAIL --- */
.detail-top-grid { 
    display: grid; 
    /* Cambiamos auto-fit por una estructura fija de 2 columnas */
    grid-template-columns: 1fr 1fr; 
    gap: 20px; 
    margin-bottom: 20px; 
}
.detail-card { background: white; border-radius: var(--radius); border: 1px solid #e1e4e8; box-shadow: 0 2px 4px rgba(0,0,0,0.02); overflow: hidden; height: 100%; }
.detail-card-header { padding: 12px 20px; font-weight: 700; color: white; text-transform: uppercase; font-size: 0.9em; letter-spacing: 0.5px; display: flex; justify-content: space-between; align-items: center; }
.detail-card-body { padding: 20px; }

.grid-2-col { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
@media (max-width: 900px) { .grid-2-col { grid-template-columns: 1fr; } }

.input-group { margin-bottom: 10px; }
.input-group label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; color: #7f8c8d; margin-bottom: 4px; display: block; }
.input-group input[readonly], .input-group input[type="number"] { background-color: #f8f9fa; border: 1px solid #e1e4e8; color: #2c3e50; font-weight: 600; width: 100%; padding: 10px; border-radius: 4px; }

.sensor-section-title { font-size: 0.75em; color: #7f8c8d; font-weight: bold; margin-top: 15px; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px dashed #eee; padding-bottom: 5px; }
.fans-grid, .sensor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.fan-chip, .sensor-chip { background: #fff; border: 1px solid #e1e4e8; border-radius: 6px; padding: 8px 12px; font-size: 0.85em; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 1px 2px rgba(0,0,0,0.02); }
.fan-chip.ok, .sensor-chip.ok { border-left: 3px solid var(--success); }
.fan-chip.fail, .sensor-chip.fail { border-left: 3px solid var(--warning); }
.fan-name, .sensor-label { font-weight: 600; color: #2c3e50; }
.fan-rpm, .sensor-value { font-family: monospace; color: #7f8c8d; }

/* --- VMs --- */
.vm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; margin-top: 20px; }
.vm-card { background: white; border-radius: var(--radius); border: 1px solid #e1e4e8; box-shadow: 0 2px 4px rgba(0,0,0,0.02); overflow: hidden; transition: transform 0.2s; }
.vm-card:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,0,0,0.05); }
.vm-body { padding: 15px; }
.progress-track { background: #ecf0f1; height: 6px; border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; transition: width 0.5s ease; }
.service-chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 20px; font-size: 0.75em; font-weight: 600; margin-right: 5px; margin-bottom: 5px; background: #f1f2f6; color: #2c3e50; }
.service-chip.running { background: #d4edda; color: #155724; }
.service-chip.stopped { background: #f8d7da; color: #721c24; }

/* --- CHART TOOLBAR --- */
.chart-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 15px; background: #f8f9fa; padding: 10px; border-radius: 8px; border: 1px solid #eee; }
.chart-selects { display: flex; gap: 10px; flex: 1; }
.chart-selects select { padding: 6px 10px; border-radius: 4px; border: 1px solid #ccc; font-size: 0.9em; cursor: pointer; }
.chart-toggles { display: flex; border: 1px solid #ccc; border-radius: 4px; overflow: hidden; }
.chart-btn { background: white; border: none; padding: 6px 12px; cursor: pointer; font-size: 0.85em; border-right: 1px solid #ccc; }
.chart-btn:last-child { border-right: none; }
.chart-btn.active { background: var(--primary); color: white; }

/* --- MISC --- */
.card { background: white; border-radius: 10px; padding: 25px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); border: 1px solid #e1e4e8; margin-bottom: 20px; width: 100%; }
.btn-action { width: 100%; padding: 15px; background-color: var(--primary); color: white; border: none; border-radius: 6px; font-size: 1em; font-weight: bold; cursor: pointer; transition: 0.2s; }
.btn-action:hover { background-color: #2980b9; }

/* --- MOBILE & RESPONSIVE --- */
.bottom-nav { display: none; position: fixed; bottom: 0; left: 0; width: 100%; background: white; box-shadow: 0 -2px 10px rgba(0,0,0,0.05); justify-content: space-around; padding: 10px 0; z-index: 1000; }
.nav-item { background: none; border: none; display: flex; flex-direction: column; align-items: center; color: #95a5a6; gap: 4px; font-size: 0.75rem; cursor: pointer; }
.nav-item.active { color: var(--primary); }

@media (max-width: 768px) {
    .sidebar-right { display: none; }
    .bottom-nav { display: flex; }
    .content { padding: 15px; }
    
    /* Mobile Dashboard Adjustment */
    #view-dashboard.active { height: calc(100vh - 60px); }
    #view-dashboard .header-actions { padding: 15px; }
    #view-dashboard .table-container-island { padding: 0 15px 80px 15px; }

    .filter-bar { flex-direction: column; gap: 10px; }
    .search-pill, .select-pill-wrapper { width: 100%; min-width: 0; }
    .chart-toolbar { flex-direction: column; align-items: stretch; }
    .chart-selects { flex-direction: column; width: 100%; }
    .chart-selects select { width: 100%; margin-bottom: 5px; }
    .chart-toggles { width: 100%; justify-content: center; }
    .chart-btn { flex: 1; }
    .table-container-island table, tbody, tr, td { display: block; width: 100%; }
    .table-container-island thead { display: none; }
    .table-container-island tbody tr { margin-bottom: 15px; border-radius: var(--radius); padding: 15px; display: grid; grid-template-columns: 1fr auto; grid-template-areas: "id status" "date date" "elems elems"; border-left: 4px solid transparent; }
    .table-container-island td { border: none; padding: 5px 0; }
    .table-container-island td:first-child { grid-area: id; border: none; font-size: 1.1em; }
    .table-container-island td:nth-child(2) { grid-area: status; text-align: right; }
    .table-container-island td:nth-child(3) { grid-area: elems; margin-top: 10px; }
    .table-container-island td:nth-child(4) { grid-area: date; color: #7f8c8d; font-size: 0.85em; margin-top: -5px; }
    .table-container-island td:nth-child(5) { display: none; }
    .detail-top-grid { grid-template-columns: 1fr; }
}

/* --- MODAL --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; display: flex; justify-content: center; align-items: center; backdrop-filter: blur(3px); }
.modal-content { background: white; padding: 30px; border-radius: 12px; width: 90%; max-width: 500px; box-shadow: 0 15px 30px rgba(0,0,0,0.2); animation: slideIn 0.3s ease; }
.modal-content input { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; }
@keyframes slideIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Botones Tabla */
.btn-small { padding: 5px 10px; font-size: 0.8em; border-radius: 4px; border: none; cursor: pointer; margin-left: 5px; color: white; }
.btn-edit { background-color: #f39c12; }
.btn-delete { background-color: #e74c3c; }
.btn-view { background-color: #3498db; color: white; }
.btn-hide { background-color: #95a5a6; color: white; }
.btn-small svg { vertical-align: middle; }

/* --- MAPA --- */
.map-tour-btn { position: absolute; bottom: 30px; right: 30px; z-index: 1000; background: white; color: var(--dark); border: 2px solid var(--primary); padding: 12px 25px; border-radius: 50px; cursor: pointer; font-weight: bold; box-shadow: 0 4px 15px rgba(0,0,0,0.1); transition: all 0.3s; font-size: 0.9em; display: flex; align-items: center; gap: 8px; }
.map-tour-btn:hover { background: var(--primary); color: white; }
.map-tour-btn.active { background: var(--danger); border-color: var(--danger); color: white; }

/* --- ANIMACIÓN ALERTA ACTIVA (PULSE) --- */
@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}

.nav-alert-active {
    animation: pulse-red 2s infinite;
    color: var(--danger) !important;
    font-weight: bold;
}

/* Ajuste sidebar */
.sidebar-right .nav-alert-active {
    border-left: 4px solid var(--danger) !important;
    background: rgba(220, 53, 69, 0.1);
}

/* Ajuste móvil */
.bottom-nav .nav-alert-active {
    border-top: 3px solid var(--danger);
}

/* --- AJUSTES PARA MÓVIL --- */
@media (max-width: 768px) {
    /* Ocultar botón de Tour en el mapa */
    .map-tour-btn {
        display: none !important;
    }
}

/* --- ARREGLO RESPONSIVO PARA TABLAS (ALERTAS E HISTORIAL) --- */
@media (max-width: 768px) {
    
    /* 1. Forzar que la tabla deje de comportarse como tabla */
    #view-alertas table, 
    #view-alertas thead, 
    #view-alertas tbody, 
    #view-alertas th, 
    #view-alertas td, 
    #view-alertas tr { 
        display: block; 
        width: 100%;
        box-sizing: border-box;
    }
    
    /* 2. Ocultar los encabezados de la tabla (ID, Detalle, etc) */
    #view-alertas thead tr { 
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    /* 3. Convertir cada fila (TR) en una Tarjeta */
    #view-alertas tr { 
        margin-bottom: 15px; 
        border: 1px solid #e1e4e8;
        border-radius: 8px;
        background: #fff;
        box-shadow: 0 2px 5px rgba(0,0,0,0.05);
        padding: 10px;
        overflow: hidden; /* Evita desbordes */
    }

    /* 4. Ajustar las celdas (TD) */
    #view-alertas td { 
        border: none;
        border-bottom: 1px solid #f0f0f0; 
        position: relative;
        padding: 8px 5px; 
        text-align: left;
        white-space: normal; /* Permitir que el texto baje */
    }
    
    /* Quitar borde a la última celda de la tarjeta */
    #view-alertas td:last-child { 
        border-bottom: none; 
    }

    /* 5. Ajustes específicos para que se vea lindo */
    
    /* El ID del Hospital más grande y destacado */
    #view-alertas td:nth-of-type(1) {
        background: #f8f9fa;
        margin: -10px -10px 10px -10px; /* Pegarlo a los bordes de arriba */
        padding: 10px 15px;
        border-bottom: 1px solid #e1e4e8;
        font-weight: bold;
    }
    
    /* El detalle del incidente con más espacio */
    #view-alertas td:nth-of-type(2) {
        font-size: 0.95em;
        padding-bottom: 10px;
    }

    /* Fechas más pequeñas y grises */
    #view-alertas td:nth-of-type(3) {
        font-size: 0.85em;
        color: #7f8c8d;
    }

    /* Tiempo/Estado alineado a la derecha o destacado */
    #view-alertas td:nth-of-type(4) {
        font-weight: bold;
        text-align: right;
        color: #c0392b; /* Rojo para alertas activas */
        padding-top: 10px;
    }
}
/* Estado colapsado para TODAS las tarjetas */
.detail-card-header, .vm-header { cursor: pointer; } 

.detail-card.collapsed .detail-card-body,
.vm-card.collapsed .vm-body { 
    display: none; 
}

.card-chevron {
    transition: transform 0.3s ease;
}

.detail-card.collapsed .card-chevron,
.vm-card.collapsed .card-chevron { 
    transform: rotate(-90deg); 
}

/* --- BARRA DE FILTRADO DE ESTADOS --- */
.status-toggle-bar {
    display: inline-flex;
    background-color: #f1f3f5; /* Fondo gris clarito del contenedor */
    border-radius: 20px;
    padding: 4px;
    gap: 5px;
}

.toggle-btn {
    border: none;
    background: transparent;
    padding: 6px 16px;
    border-radius: 16px;
    color: #555;
    font-weight: 600;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-btn:hover:not(.active) {
    background-color: #e2e6ea; /* Gris un poco más oscuro al pasar el mouse */
}

/* El botón seleccionado */
.toggle-btn.active {
    background-color: #ffffff;
    color: #2c3e50;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* --- BARRA DE NAVEGACIÓN INTERNA (DETALLE) V4 --- */
.detalle-nav-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #ffffff;
    padding: 10px 20px;
    border-bottom: 1px solid #e1e8ed;
    position: sticky;
    top: 0;
    z-index: 900;
}

/* Botón Circular de Volver */
.detail-back-btn {
    border: none;
    background-color: #f1f3f5;
    color: #2c3e50;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}
.detail-back-btn:hover {
    background-color: #3498db;
    color: white;
}

/* Pastillas de Navegación de Pestañas */
.tab-toggle-bar {
    display: inline-flex;
    background-color: #f1f3f5;
    border-radius: 20px;
    padding: 4px;
    gap: 5px;
}
.tab-btn {
    border: none;
    background: transparent;
    padding: 6px 16px;
    border-radius: 16px;
    color: #555;
    font-weight: 600;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s ease;
}
.tab-btn.active {
    background-color: #ffffff;
    color: #2c3e50;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Tarjeta de Datos del Hospital (Fondo Pastel) */
.hosp-card-badge {
    background-color: #eafaf1; /* Verde Pastel suave */
    border: 1px solid #c8f7dc;
    padding: 6px 15px;
    border-radius: 10px;
    font-family: sans-serif;
    color: #000000; /* Texto Negro para contraste */
}
.hosp-card-badge .row-1 {
    font-weight: 700;
    font-size: 1.1em;
}
.hosp-card-badge .row-2 {
    font-size: 0.8em;
    color: #555;
}

/* Contenedores de Pestañas */
.tab-content {
    display: none; /* Oculto por defecto */
}
.tab-content.active {
    display: block; /* Solo visible el activo */
}

/* --- AJUSTE RESPONSIVO BARRA DETALLE V4 --- */
@media (max-width: 768px) {
    .detalle-nav-bar {
        flex-wrap: wrap; /* Permite que los elementos bajen si no hay espacio */
        justify-content: flex-start;
        gap: 12px;
        padding: 10px 15px;
    }

    /* La flecha y las pestañas se quedan arriba */
    .detail-back-btn {
        order: 1;
    }

    .tab-toggle-bar {
        order: 2;
        flex: 1; /* Toma el espacio restante al lado de la flecha */
        justify-content: center;
    }

    /* La tarjeta del hospital baja y se estira */
    .hosp-card-badge {
        order: 3;
        width: 100%; /* Ocupa todo el ancho en la segunda fila */
        text-align: center;
        display: flex;
        flex-direction: column;
        align-items: center;
        background-color: #f8fcf9; /* Un verde un toque más sutil para el móvil */
    }

    /* Achicamos un poquito las pestañas para que entren bien en teléfonos chicos */
    .tab-btn {
        padding: 6px 10px;
        font-size: 0.8em;
    }
}

/* Ajuste extra para pantallas muy angostas (iPhone SE, etc) */
@media (max-width: 380px) {
    .tab-btn {
        padding: 6px 8px;
        font-size: 0.75em;
    }
    .tab-toggle-bar {
        gap: 3px;
    }
}

/* ========================================= */
/* --- TEMA OSCURO (DARK MODE) ACTUALIZADO --- */
/* ========================================= */
body.dark-theme {
    background-color: #0f172a !important; /* Fondo general oscuro */
    color: #f8fafc !important; /* Texto claro */
}

body.dark-theme #sidebar {
    background-color: #1e293b !important;
    border-right: 1px solid #334155 !important;
}

/* 1. Tarjetas, VMs y Contenedores Principales */
body.dark-theme .card, 
body.dark-theme .detail-card, 
body.dark-theme .detail-card-body,
body.dark-theme .vm-card,
body.dark-theme .vm-body,
body.dark-theme .detalle-nav-bar,
body.dark-theme .hosp-card-badge,
body.dark-theme .filter-container,
body.dark-theme .header-actions { /* <--- ¡Esta es la línea nueva! */
    background-color: #1e293b !important;
    border-color: #334155 !important;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2) !important;
}

/* 2. Filas de la Tabla del Dashboard */
body.dark-theme .table-container-island tbody tr { 
    background-color: #1e293b !important;
    border-color: #334155 !important;
    color: #f8fafc !important;
}
body.dark-theme .table-container-island tbody tr:hover { 
    background-color: #273549 !important; 
    box-shadow: 0 5px 15px rgba(0,0,0,0.5) !important;
}
body.dark-theme .table-container-island th { color: #94a3b8 !important; }
body.dark-theme .table-container-island td { border-color: #334155 !important; }

/* 3. Inputs, Selectores y Etiquetas */
body.dark-theme input, 
body.dark-theme select,
body.dark-theme .search-pill,
body.dark-theme .select-pill,
body.dark-theme .input-group input[readonly], 
body.dark-theme .input-group input[type="number"] {
    background-color: #0f172a !important;
    color: #f8fafc !important;
    border: 1px solid #475569 !important;
}

/* 4. Etiquetas (Badges) de Hospital y Botón Volver */
body.dark-theme .hospital-tag {
    background-color: #334155 !important;
    border-color: #475569 !important;
    color: #f8fafc !important;
}
body.dark-theme .detail-back-btn {
    background-color: #334155 !important;
    color: #f8fafc !important;
}
body.dark-theme .detail-back-btn:hover { background-color: var(--primary) !important; color: white !important;}
body.dark-theme .hosp-card-badge { color: #f8fafc !important; }
body.dark-theme .hosp-card-badge .row-2 { color: #94a3b8 !important; }

/* 5. Sensores, Ventiladores y Servicios (Chips) */
body.dark-theme .fan-chip, 
body.dark-theme .sensor-chip {
    background-color: #0f172a !important;
    border-color: #334155 !important;
}
body.dark-theme .fan-name, 
body.dark-theme .sensor-label { color: #f8fafc !important; }

body.dark-theme .service-chip {
    background-color: #0f172a !important;
    color: #f8fafc !important;
    border: 1px solid #334155 !important;
}
body.dark-theme .service-chip.running { background-color: rgba(39, 174, 96, 0.15) !important; color: #2ecc71 !important; border-color: rgba(39, 174, 96, 0.3) !important; }
body.dark-theme .service-chip.stopped { background-color: rgba(231, 76, 60, 0.15) !important; color: #e74c3c !important; border-color: rgba(231, 76, 60, 0.3) !important; }
body.dark-theme .progress-track { background-color: #334155 !important; }

/* 6. Textos y Títulos secundarios */
body.dark-theme .sensor-section-title,
body.dark-theme .input-group label {
    color: #94a3b8 !important;
    border-bottom-color: #334155 !important;
}

/* 7. Loaders de Gráficos */
body.dark-theme #chart-loader,
body.dark-theme #kpi-chart-loader {
    background-color: rgba(30, 41, 59, 0.85) !important;
}

/* 8. Botones de Gráficos y Pestañas */
body.dark-theme .chart-btn, 
body.dark-theme .kpi-btn,
body.dark-theme .tab-btn,
body.dark-theme .toggle-btn {
    background-color: #334155 !important; 
    color: #f8fafc !important; 
    border-color: #475569 !important;
}
body.dark-theme .chart-btn.active, 
body.dark-theme .kpi-btn.active,
body.dark-theme .tab-btn.active,
body.dark-theme .toggle-btn.active {
    background-color: #3498db !important; 
    color: white !important;
    border-color: #3498db !important;
}
body.dark-theme .status-toggle-bar,
body.dark-theme .tab-toggle-bar,
body.dark-theme .chart-toolbar {
    background-color: #0f172a !important;
    border-color: #334155 !important;
}

/* 9. TRUCOS MÁGICOS (Sobrescribir estilos en línea de JS sin tocar JS) */
body.dark-theme span[style*="color: #2c3e50"], 
body.dark-theme div[style*="color: #2c3e50"],
body.dark-theme span[style*="color:#2c3e50"], 
body.dark-theme div[style*="color:#2c3e50"] {
    color: #f8fafc !important;
}
/* Volúmenes RAID OK */
body.dark-theme span[style*="background:#eafaf1"],
body.dark-theme span[style*="background: #eafaf1"] {
    background-color: rgba(39, 174, 96, 0.2) !important; color: #2ecc71 !important;
}
/* Volúmenes RAID Error/NA */
body.dark-theme span[style*="background:#fadbd8"],
body.dark-theme span[style*="background: #fadbd8"] {
    background-color: rgba(231, 76, 60, 0.2) !important; color: #e74c3c !important;
}
/* Discos Físicos OK */
body.dark-theme div[style*="background:#f0fcf4"],
body.dark-theme div[style*="background: #f0fcf4"] {
    background-color: rgba(39, 174, 96, 0.1) !important; color: #f8fafc !important;
}
/* Discos Físicos Error */
body.dark-theme div[style*="background:#fdedec"],
body.dark-theme div[style*="background: #fdedec"] {
    background-color: rgba(231, 76, 60, 0.1) !important; color: #f8fafc !important;
}

.search-item:hover {
    background-color: #f8f9fa;
    color: #3498db;
}