/* css/styles.css */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Header */
header {
    background: white;
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
    margin-bottom: 25px;
    text-align: center;
}

header h1 {
    font-size: 2.5em;
    color: #2d3748;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.refresh-info {
    font-size: 0.9em;
    color: #718096;
    font-style: italic;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.stat-card {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    border-left: 5px solid #667eea;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f7fafc;
}

.device-name {
    font-size: 1.3em;
    font-weight: bold;
    color: #2d3748;
}

.status-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8em;
    font-weight: bold;
    text-transform: uppercase;
}

.status-online {
    background: #c6f6d5;
    color: #276749;
}

.status-offline {
    background: #fed7d7;
    color: #9b2c2c;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 8px 0;
}

.stat-label {
    color: #718096;
    font-size: 0.95em;
}

.stat-value {
    font-weight: bold;
    font-size: 1.05em;
}

.stat-value.temp {
    color: #e53e3e;
}

.stat-value.hum {
    color: #3182ce;
}

.stat-value.lux {
    color: #d69e2e;
}

/* Sections */
.readings-section, .charts-section {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
    margin-bottom: 25px;
}

.section-title {
    font-size: 1.8em;
    color: #2d3748;
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 15px;
    border-bottom: 3px solid #f7fafc;
}

/* Table */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

thead {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    font-size: 0.95em;
}

tbody tr {
    border-bottom: 1px solid #e2e8f0;
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: #f7fafc;
}

tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

tbody tr:nth-child(even):hover {
    background-color: #edf2f7;
}

td {
    padding: 15px;
    color: #4a5568;
}

td.temp {
    color: #e53e3e;
    font-weight: bold;
}

td.hum {
    color: #3182ce;
    font-weight: bold;
}

td.lux {
    color: #d69e2e;
    font-weight: bold;
}

/* No Data */
.no-data {
    text-align: center;
    padding: 40px;
    color: #a0aec0;
    font-style: italic;
    font-size: 1.1em;
}

/* Device Selector */
.device-selector {
    margin-bottom: 20px;
}

.device-selector select {
    padding: 12px 20px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    font-size: 1em;
    color: #4a5568;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 200px;
}

.device-selector select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Nuevos estilos para gráficos separados */
.charts-section {
    background: white;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.period-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.period-btn {
    padding: 8px 16px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
}

.period-btn:hover {
    background: #667eea;
    color: white;
}

.period-btn.active {
    background: #667eea;
    color: white;
}

.chart-grid {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.chart-wrapper {
    width: 100%;
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid;
}

.chart-wrapper.temperature {
    border-left-color: #e74c3c;
}

.chart-wrapper.humidity {
    border-left-color: #3498db;
}

.chart-wrapper.luminosity {
    border-left-color: #f39c12;
}

.chart-wrapper.combined {
    border-left-color: #9b59b6;
}

.chart-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 15px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-container-full {
    height: 300px;
    width: 100%;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    header h1 {
        font-size: 2em;
        flex-direction: column;
        gap: 10px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-card {
        padding: 20px;
    }
    
    .readings-section, .charts-section {
        padding: 20px;
    }
    
    .section-title {
        font-size: 1.5em;
    }
    
    table {
        font-size: 0.9em;
    }
    
    th, td {
        padding: 10px 8px;
    }
    
    .period-selector {
        justify-content: center;
    }
    
    .period-btn {
        flex: 1;
        min-width: 80px;
        text-align: center;
    }
    
    .chart-container-full {
        height: 250px;
    }
    
    .device-selector select {
        min-width: 150px;
        width: 100%;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.6em;
    }
    
    .stat-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    .stat-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    table {
        font-size: 0.8em;
    }
    
    th, td {
        padding: 8px 5px;
    }
    
    .chart-title {
        font-size: 16px;
    }
    
    .chart-container-full {
        height: 200px;
    }
}

/* Animaciones */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-card, .readings-section, .charts-section {
    animation: fadeIn 0.6s ease-out;
}

/* Scroll personalizado */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #5a6fd8, #6a4190);
}

/* Estados de carga */
.loading {
    opacity: 0.7;
    pointer-events: none;
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Mejoras de accesibilidad */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible para mejor accesibilidad */
button:focus-visible,
select:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .stat-card {
        border: 2px solid #000;
    }
    
    table {
        border: 2px solid #000;
    }
    
    th {
        background: #000;
        color: #fff;
    }
}