:root {
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --text-color: #333;
    --text-secondary: #666;
    --text-muted: #888;
    --primary-color: #007bff;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --border-radius: 12px;
    --color-bueno: #28a745;
    --color-regular: #ffc107;
    --color-malo: #dc3545;
    --color-info: #17a2b8;
    --border-color: #ddd;
    --table-header-bg: #f8f9fa;
    --logout-btn-hover: #e2e6ea;
    --status-log-bg: #fff3cd;
    --status-log-border: #ffeeba;
    --status-log-text: #856404;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --card-bg: #2d2d2d;
        --text-color: #e0e0e0;
        --text-secondary: #b0b0b0;
        --text-muted: #888;
        --primary-color: #4a9eff;
        --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        --color-bueno: #4caf50;
        --color-regular: #ffa726;
        --color-malo: #ef5350;
        --color-info: #29b6f6;
        --border-color: #444;
        --table-header-bg: #383838;
        --logout-btn-hover: #3a3a3a;
        --status-log-bg: #3d3820;
        --status-log-border: #5a5330;
        --status-log-text: #ffdb70;
    }
    
    .login-card {
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    }
    
    .form-control {
        background-color: #383838;
        color: var(--text-color);
        border-color: var(--border-color);
    }
    
    .form-control::placeholder {
        color: #999;
    }
    
    .logout-btn {
        border-color: var(--border-color);
        color: var(--text-color);
    }
    
    .social-icons a {
        background-color: #383838;
        color: var(--primary-color);
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    }
    
    .social-icons a:hover {
        background-color: var(--primary-color);
        color: #1a1a1a;
    }
    
    .filter-container {
        background: var(--card-bg);
    }
    
    .btn-filter {
        background: #383838;
        border-color: var(--primary-color);
    }
    
    .btn-filter:hover,
    .btn-filter.active {
        background: var(--primary-color);
        color: #1a1a1a;
    }
    
    .risk-icon {
        background: #383838;
    }
    
    .connection-badge.status-online {
        background-color: #1b3a1b;
        color: #81c784;
        border-color: #2d5a2d;
    }
    
    .connection-badge.status-offline {
        background-color: #3a1b1b;
        color: #e57373;
        border-color: #5a2d2d;
    }
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Login Styles */
#login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: var(--bg-color);
    z-index: 1000;
    transition: opacity 0.5s ease;
    padding: 20px;
    box-sizing: border-box;
}

.login-card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-header i {
    font-size: 3rem;
    color: var(--primary-color);
    margin-bottom: 15px;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-control {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-sizing: border-box;
}

.btn {
    width: 100%;
    padding: 12px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s;
    margin-bottom: 10px;
}

.btn:hover {
    background-color: #0056b3;
}

.btn-secondary {
    background-color: #6c757d;
}

.btn-secondary:hover {
    background-color: #545b62;
}

/* Dashboard Styles */
#dashboard-container {
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

header {
    text-align: center;
    margin-bottom: 30px;
    position: relative;
}

.logout-btn {
    position: absolute;
    top: 0;
    right: 0;
    background: transparent;
    border: 1px solid #aaa;
    color: #555;
    padding: 6px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: var(--logout-btn-hover);
}

/* Grid Responsive */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    max-width: 1600px;
    margin: 0 auto;
}

.card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 25px;
    transition: transform 0.2s;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-2px);
}

.card-full-width {
    grid-column: 1 / -1;
}

/* Risk Cards */
.risk-card {
    border-left: 5px solid #ddd;
}

.risk-high {
    border-left-color: var(--color-malo);
}

.risk-med {
    border-left-color: var(--color-regular);
}

.risk-low {
    border-left-color: var(--color-bueno);
}

.risk-header {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.risk-icon {
    font-size: 1.5rem;
    margin-right: 10px;
    width: 40px;
    height: 40px;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    border-radius: 50%;
}

/* Estilos para el indicador de conexión */
.connection-badge {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: bold;
    transition: all 0.3s ease;
    margin-right: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.status-online {
    background-color: #e6f4ea;
    color: #1e7e34;
    border: 1px solid #c3e6cb;
}

.status-offline {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    animation: pulse-red 2s infinite;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
    background-color: currentColor;
}

@keyframes pulse-red {
    0% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
    }
}

/* Tabla Responsive */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

#tablaInterpretacion {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    white-space: nowrap;
}

#tablaInterpretacion th,
#tablaInterpretacion td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

#tablaInterpretacion th {
    background-color: var(--table-header-bg);
}

.badge {
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.85rem;
    font-weight: bold;
    color: white;
    display: inline-block;
}

.bg-bueno {
    background-color: var(--color-bueno);
}

.bg-regular {
    background-color: var(--color-regular);
    color: #333;
}

.bg-malo {
    background-color: var(--color-malo);
}

.chart-container {
    position: relative;
    height: 250px;
    width: 100%;
}

canvas {
    width: 100% !important;
    height: 100% !important;
}

#statusLog {
    margin-top: 10px;
    padding: 10px;
    background: var(--status-log-bg);
    border: 1px solid var(--status-log-border);
    border-radius: 5px;
    font-size: 0.85rem;
    color: var(--status-log-text);
    display: none;
}

.info-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

main {
    padding-bottom: 20px;
}

/* --- NUEVOS ESTILOS PARA EL FOOTER --- */
.site-footer {
    margin-top: 50px;
    padding: 30px 0;
    border-top: 1px solid var(--border-color);
    text-align: center;
    color: var(--text-secondary);
}

.social-icons {
    margin-bottom: 15px;
}

.social-icons a {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    margin: 0 5px;
    border-radius: 50%;
    background-color: #fff;
    color: var(--primary-color);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    text-decoration: none;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.social-icons a:hover {
    background-color: var(--primary-color);
    color: white;
    transform: translateY(-3px);
}

.footer-text {
    font-size: 0.9rem;
}

/* Estilos para el filtro de tiempo */
.filter-container {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
    background: var(--card-bg);
    padding: 10px 20px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.filter-label {
    font-weight: bold;
    color: var(--text-color);
    margin-right: 10px;
}

.btn-filter {
    padding: 6px 15px;
    border: 1px solid var(--primary-color);
    background: var(--card-bg);
    color: var(--primary-color);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 0.9rem;
}

.btn-filter:hover,
.btn-filter.active {
    background: var(--primary-color);
    color: white;
}

/* Landscape Optimization */
@media (min-width: 769px) and (max-width: 1200px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .card-full-width {
        grid-column: 1 / -1;
    }
    
    .filter-container {
        grid-column: 1 / -1;
    }
}

@media (min-width: 1201px) {
    .dashboard-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    /* Las tarjetas de riesgo ocupan 2 columnas en pantallas grandes */
    .card.risk-card {
        grid-column: span 1;
    }
}

/* Landscape Mobile (teléfonos en horizontal) */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        padding: 10px;
    }
    
    header {
        margin-bottom: 15px;
    }
    
    #banner {
        max-height: 80px;
        width: auto !important;
    }
    
    .logout-btn {
        position: fixed;
        top: 10px;
        right: 10px;
        z-index: 100;
        background: white;
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    }
    
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .card {
        padding: 15px;
    }
    
    .chart-container {
        height: 180px;
    }
    
    .connection-badge {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
    
    .filter-container {
        padding: 8px 15px;
        gap: 8px;
    }
    
    .btn-filter {
        padding: 5px 12px;
        font-size: 0.85rem;
    }
}

/* Tablet Landscape */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .dashboard-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
    }
    
    .card-full-width {
        grid-column: 1 / -1;
    }
    
    .filter-container {
        grid-column: 1 / -1;
        justify-content: center;
    }
    
    .chart-container {
        height: 220px;
    }
    
    header {
        margin-bottom: 20px;
    }
}

@media (max-width: 768px) {
    .filter-container {
        flex-direction: column;
    }

    .btn-filter {
        width: 100%;
        margin-bottom: 5px;
    }
}

/* Mobile Portrait Styles */
@media (max-width: 768px) and (orientation: portrait) {
    body {
        padding: 10px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .card {
        padding: 15px;
    }

    .logout-btn {
        position: relative;
        display: inline-block;
        margin-bottom: 10px;
    }

    h1 {
        font-size: 1.5rem;
        margin-top: 10px;
    }
}

/* Mobile Landscape Styles */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        padding: 8px;
    }

    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .card {
        padding: 12px;
    }
    
    .card-full-width {
        grid-column: 1 / -1;
    }
}
