/* =====================================================
   SISTEMA DE MONITOREO IoT - ESTILOS GLOBALES (CORREGIDO)
   ===================================================== */
/* Reset y configuración base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
:root {
    /* Paleta de colores */
    --brand-blue: #3b82c4;
    --brand-blue-light: #60a5fa;
    --brand-blue-dark: #2563eb;
    --brand-blue-soft: #dbeafe;
    --brand-blue-ultra-soft: #eff6ff;
    /* Sistema */
    --primary: #1f2937;
    --secondary: #f3f4f6;
    --accent: var(--brand-blue);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f9fafb;
    --card-bg: #ffffff;
    --text: #111827;
    --text-light: #6b7280;
    --border: #e5e7eb;
    --shadow: rgba(59, 130, 196, 0.08);
    --shadow-hover: rgba(59, 130, 196, 0.15);
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}
/* Fondo decorativo */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 300px;
    background: linear-gradient(135deg, var(--brand-blue-soft) 0%, var(--brand-blue-ultra-soft) 100%);
    z-index: -1;
    opacity: 0.3;
}
/* Contenedores */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}
.container-wide {
    max-width: 1600px;
    /* Un poco más ancho para tablas históricas */
    margin: 0 auto;
    padding: 2rem;
}
/* =====================================================
   HEADER
   ===================================================== */
.header {
    margin-bottom: 3rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}
.logo {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(59, 130, 196, 0.2));
    transition: transform 0.3s ease;
}
.logo:hover img {
    transform: scale(1.05);
}
.header-text {
    flex: 1;
}
.header-text h1 {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.25rem;
}
.header-text p {
    color: var(--text-light);
    font-size: 0.95rem;
}
.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}
/* =====================================================
   MÉTRICAS Y ESTADÍSTICAS
   ===================================================== */
.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}
.metric-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--shadow-hover);
    border-color: var(--brand-blue-soft);
}
.metric-icon {
    width: 40px;
    height: 40px;
    background: var(--brand-blue-soft);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--brand-blue);
    font-size: 1.25rem;
    margin-bottom: 1rem;
}
.metric-value {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.25rem;
}
.metric-label {
    font-size: 0.875rem;
    color: var(--text-light);
    font-weight: 500;
}
/* Stats (usado en histórico) */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}
.stat-label {
    font-size: 0.75rem;
    color: var(--text-light);
}
/* =====================================================
   CONTROLES Y BOTONES
   ===================================================== */
.controls-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 1px 3px var(--shadow);
}
.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    /* Alinea los inputs y botones abajo */
    gap: 1.5rem;
    width: 100%;
}
.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    min-width: 200px;
    /* Evita que se encojan demasiado */
}
.control-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-light);
}
/* Inputs y Selects */
.form-control,
.control-group input,
.control-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.875rem;
    background: var(--bg);
    color: var(--text);
    transition: all 0.2s ease;
}
.control-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
/* Botones Generales */
.btn {
    padding: 0.75rem 1.5rem;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    /* Evita que el texto se rompa */
}
.btn:hover {
    border-color: var(--brand-blue);
    color: var(--brand-blue-dark);
    transform: translateY(-1px);
}
.btn-primary {
    background: var(--brand-blue);
    color: white;
    border-color: var(--brand-blue);
}
.btn-primary:hover {
    background: var(--brand-blue-dark);
    color: white;
}
/* Botón Mini (Para el Header) */
.btn-mini {
    background: white;
    border: 1px solid var(--border);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.btn-mini:hover {
    border-color: var(--brand-blue);
    color: var(--brand-blue);
}
.btn-mini.active {
    background: var(--brand-blue-ultra-soft);
    border-color: var(--brand-blue);
    color: var(--brand-blue-dark);
}
/* =====================================================
   DISPOSITIVOS (GRID)
   ===================================================== */
.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}
.device-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}
.device-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 32px var(--shadow-hover);
    border-color: var(--brand-blue-soft);
}
/* Indicadores de estado */
.device-card::before {
    content: "";
    position: absolute;
    top: -20px;
    right: -20px;
    width: 60px;
    height: 60px;
    background: var(--success);
    clip-path: polygon(30% 0%, 70% 0%, 100% 50%, 70% 100%, 30% 100%, 0% 50%);
    opacity: 0.1;
}
.device-card.offline::before {
    background: var(--danger);
}
.device-card.alert::before {
    background: var(--warning);
}
.device-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}
.device-id {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--primary);
}
.device-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}
.metric {
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    background: var(--brand-blue-ultra-soft);
    border-radius: 8px;
    text-align: center;
}
.metric-name {
    font-size: 0.75rem;
    color: var(--text-light);
    text-transform: uppercase;
    font-weight: 600;
}
.metric-value {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--brand-blue-dark);
}
.device-info {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-light);
}
/* AGREGA ESTO EN style.css (después de la línea 475 aprox) */
.info-item {
    display: flex;
    /* Alinea los elementos (icono y texto) en fila */
    align-items: center;
    /* Centra verticalmente el pin con el texto */
    gap: 6px;
    /* Espacio entre el pin y el texto */
    white-space: nowrap;
    /* Evita que el texto largo se parta en dos líneas */
}
/* Badges */
.alert-badge {
    background: var(--warning);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
    margin-bottom: 1rem;
}
/* =====================================================
   TABLAS (HISTÓRICO)
   ===================================================== */
.table-card {
    background: var(--card-bg);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 1px 3px var(--shadow);
    border: 1px solid var(--border);
    margin-top: 2rem;
}
.table-container {
    max-height: 600px;
    overflow-y: auto;
    overflow-x: auto;
}
table {
    width: 100%;
    min-width: 900px;
    border-collapse: collapse;
}
thead {
    background: var(--brand-blue-ultra-soft);
    position: sticky;
    top: 0;
    z-index: 10;
}
th {
    padding: 1rem 1.5rem;
    text-align: left;
    font-weight: 600;
    color: var(--text);
    font-size: 0.875rem;
    text-transform: uppercase;
    border-bottom: 2px solid var(--brand-blue-soft);
}
td {
    padding: 1rem 1.5rem;
    text-align: left;
    font-size: 0.875rem;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}
tbody tr:hover {
    background: var(--brand-blue-ultra-soft);
}
.alert-cell {
    color: var(--warning);
    font-weight: 700;
}
.temp-cell {
    color: var(--brand-blue);
    font-weight: 600;
}
.humidity-cell {
    color: var(--brand-blue-dark);
    font-weight: 600;
}
/* =====================================================
   MENSAJES Y FOOTER
   ===================================================== */
.status-message {
    text-align: center;
    padding: 3rem;
    color: var(--brand-blue);
}
.error-message {
    background: #fee2e2;
    color: #dc2626;
    padding: 1rem;
    border-radius: 10px;
    margin: 1rem 0;
    border: 1px solid #fecaca;
    text-align: center;
}
.loading-indicator {
    display: inline-block;
    width: 40px;
    height: 40px;
    margin: 0 auto;
    border: 3px solid var(--brand-blue-soft);
    border-top-color: var(--brand-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
.footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-light);
    font-size: 0.875rem;
    border-top: 1px solid var(--border);
    margin-top: 3rem;
}
/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        text-align: center;
    }
    .header-actions {
        margin-left: 0;
        margin-top: 1rem;
        flex-direction: column;
    }
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    .control-actions {
        flex-direction: column;
    }
    .btn {
        width: 100%;
        justify-content: center;
    }
    .devices-grid {
        grid-template-columns: 1fr;
    }
    .stats {
        grid-template-columns: 1fr 1fr;
    }
}
.grafico-container {
    /* Esto evita que el gráfico se parta a la mitad */
    page-break-inside: avoid;
    break-inside: avoid;
    /* Opcional: asegura margen al imprimir */
    display: block;
    margin-bottom: 20px;
}
/* =====================================================
   INDICADOR DE ESTADO (PUNTO PARPADEANTE)
   ===================================================== */
.device-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    /* Verde por defecto (Online) */
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
    animation: pulse-success 2s infinite;
    /* Parpadeo constante */
}
/* Animación Verde (Online) */
@keyframes pulse-success {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}
/* Estado Offline (Rojo y sin parpadeo) */
.device-card.offline .device-status {
    background: var(--danger);
    animation: none;
    box-shadow: none;
}
/* Estado Alerta (Naranja y parpadeo rápido) */
.device-card.alert .device-status {
    background: var(--warning);
    animation: pulse-warning 1.5s infinite;
}
/* Animación Naranja (Alerta) */
@keyframes pulse-warning {
    0% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(245, 158, 11, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
    }
}
/* =====================================================
   FASE 3: ETIQUETAS DE CLASIFICACIÓN
   ===================================================== */
.card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    /* Espacio antes de los números */
    padding-bottom: 0.5rem;
    border-bottom: 1px dashed var(--border);
}
.area-badge {
    background: var(--brand-blue-ultra-soft);
    color: var(--brand-blue-dark);
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    border: 1px solid var(--brand-blue-soft);
    letter-spacing: 0.5px;
}
.type-badge {
    font-size: 0.7rem;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
}
/* Color especial para Crítico */
.type-badge.critico {
    color: #b91c1c;
    /* Rojo oscuro elegante */
    background: #fef2f2;
    padding: 2px 6px;
    border-radius: 4px;
}
/* =====================================================
   FASE 4: FILTROS
   ===================================================== */
.filter-container {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px dashed var(--border);
    flex-wrap: wrap;
    align-items: center;
}
.btn-filter {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    background: white;
    color: var(--text-light);
    border: 1px solid var(--border);
    border-radius: 20px;
    /* Redondos */
    cursor: pointer;
    transition: all 0.2s;
}
.btn-filter:hover {
    background: var(--bg);
    border-color: var(--brand-blue);
}
.btn-filter.active {
    background: var(--brand-blue);
    color: white;
    border-color: var(--brand-blue);
    box-shadow: 0 2px 5px rgba(59, 130, 196, 0.3);
}
.select-filter {
    padding: 0.4rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
}
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}
.modal-content {
    background-color: #fff;
    padding: 2rem;
    border-radius: 12px;
    width: 500px;
    max-width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}
.form-row {
    margin-bottom: 1rem;
}
.form-row label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}
.form-row input,
.form-row select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 6px;
}
.form-row input[readonly] {
    background-color: #e9ecef;
    color: #6b7280;
    cursor: not-allowed;
    border-color: #d1d5db;
}
.action-btn {
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    border: none;
    font-size: 0.9rem;
    margin-right: 5px;
}
.btn-edit {
    background: var(--brand-blue-soft);
    color: var(--brand-blue-dark);
}
.btn-delete {
    background: #fee2e2;
    color: #dc2626;
}
.badge-status {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
}
.activo {
    background: #d1fae5;
    color: #065f46;
}
.mantenimiento {
    background: #fef3c7;
    color: #92400e;
}
.baja {
    background: #fee2e2;
    color: #991b1b;
}
.badge-critico {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
}
.badge-ambiental {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
}
/* Estilo para grupo de calibración */
.calibration-box {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
    display: none;
    /* Oculto por defecto */
}