/* =========================================================
   RESET + VARIABLES
========================================================= */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --info-color: #3498db;

    --light-color: #ecf0f1;
    --dark-color: #2c3e50;
    --gray-light: #95a5a6;
    --gray-dark: #7f8c8d;

    --border-radius: 10px;
    --box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* =========================================================
   BODY
========================================================= */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

/* =========================================================
   HEADER
========================================================= */
.header {
    background: #ffffff;
    box-shadow: var(--box-shadow);
    padding: 1rem 2rem;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-content {
    max-width: 1400px;
    margin: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo i {
    font-size: 2rem;
    color: var(--secondary-color);
}

.logo-text h1 {
    font-size: 1.6rem;
    color: var(--primary-color);
}

.subtitle {
    font-size: 0.9rem;
    color: var(--gray-dark);
}

.header-info {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.info-item {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.9rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--gray-light);
}

.status-dot.online {
    background: var(--success-color);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: .5; }
    100% { opacity: 1; }
}

/* =========================================================
   MAIN LAYOUT
========================================================= */
.main-container {
    max-width: 1400px;
    margin: 2rem auto;
    padding: 0 2rem;
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 2rem;
}

/* =========================================================
   SECTION HEADERS
========================================================= */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-header h2 {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    color: var(--primary-color);
}

/* =========================================================
   KPI CARDS
========================================================= */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: #ffffff;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    display: flex;
    gap: 1.5rem;
    box-shadow: var(--box-shadow);
    transition: var(--transition);
}

.kpi-card:hover {
    transform: translateY(-4px);
}

.kpi-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
}

.kpi-icon.temp { background: #ffeaa7; color: #e17055; }
.kpi-icon.hum { background: #a29bfe; color: #6c5ce7; }
.kpi-icon.status { background: #81ecec; color: #00cec9; }

.kpi-main-value {
    font-size: 2.6rem;
    font-weight: bold;
    color: var(--primary-color);
}

.unit {
    font-size: 1.4rem;
    color: var(--gray-light);
}

.kpi-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .5rem;
}

.stat {
    text-align: center;
}

.stat .value {
    font-weight: bold;
}

/* =========================================================
   CONTROL SECTION
========================================================= */
.control-section,
.charts-section {
    background: #ffffff;
    border-radius: var(--border-radius);
    padding: 2rem;
    box-shadow: var(--box-shadow);
    margin-bottom: 2rem;
}

.control-card {
    background: #f8f9fa;
    border-radius: var(--border-radius);
    padding: 1.5rem;
}

.control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid #eee;
}

.device-icon {
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.btn-action {
    padding: .8rem 1.5rem;
    border-radius: var(--border-radius);
    border: none;
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
}

.btn-on { background: var(--success-color); color: #fff; }
.btn-off { background: var(--danger-color); color: #fff; }

/* =========================================================
   CHARTS (🔥 SOLUCIÓN REAL DEL PROBLEMA)
========================================================= */
.charts-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.chart-card {
    position: relative;
    background: linear-gradient(180deg, #ffffff, #f3f5fb);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    height: 360px;
    box-shadow: inset 0 0 0 1px #e0e6ed;
}

.chart-card h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.chart-card canvas {
    width: 100% !important;
    height: 100% !important;
}

/* =========================================================
   SIDEBAR
========================================================= */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.devices-section,
.alerts-section,
.info-section {
    background: #ffffff;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--box-shadow);
}

/* =========================================================
   FOOTER
========================================================= */
.footer {
    background: var(--primary-color);
    color: white;
    padding: 1.5rem 2rem;
}

.footer-content {
    max-width: 1400px;
    margin: auto;
    display: flex;
    justify-content: space-between;
}

/* =========================================================
   MODAL & TOAST
========================================================= */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    align-items: center;
    justify-content: center;
}

.modal.active { display: flex; }

.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--success-color);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    display: none;
}

.toast.show { display: flex; }

/* =========================================================
   RESPONSIVE
========================================================= */
@media (max-width: 1200px) {
    .main-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .charts-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
}
