/* ==========================================
   TEKIOT - SISTEMA MONITOREO EN TIEMPO REAL
   Dashboard 10 bodegas ESP32 + DHT22
========================================== */

:root {
    --bg: #f4f7fb;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e5e7eb;

    --green: #16a34a;
    --green-soft: #e9f8ef;

    --red: #dc2626;
    --red-soft: #fee2e2;

    --orange: #f97316;
    --gray-soft: #f3f4f6;

    --shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app {
    display: flex;
    min-height: 100vh;
}

/* =========================
   SIDEBAR SOLO LOGO
========================= */

.sidebar {
    width: 295px;
    background: #ffffff;
    border-right: 1px solid var(--border);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.logo-box {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 8px;
    padding-bottom: 30px;
}

.logo {
    width: 210px;
    max-width: 95%;
    height: auto;
    object-fit: contain;
    display: block;
}

.sidebar-info {
    width: 100%;
    margin-top: auto;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-info span,
.sidebar-info small {
    color: var(--muted);
}

.sidebar-info strong {
    font-size: 22px;
    color: var(--green);
}

/* =========================
   MAIN
========================= */

.main {
    flex: 1;
    padding: 28px 34px;
    overflow-x: hidden;
}

.header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: flex-start;
    margin-bottom: 24px;
}

.header h1 {
    margin: 0;
    font-size: 34px;
    line-height: 1.2;
    font-weight: 800;
}

.header p {
    margin: 8px 0 0 0;
    color: var(--muted);
    font-size: 16px;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 14px;
}

.header-status button {
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: 12px;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 700;
    color: var(--text);
}

.header-status button:hover {
    box-shadow: var(--shadow);
}

/* =========================
   KPI
========================= */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 22px;
    margin-bottom: 28px;
}

.kpi-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 24px 28px;
    box-shadow: var(--shadow);
    min-height: 128px;
}

.kpi-card span {
    display: block;
    color: var(--muted);
    font-size: 17px;
    margin-bottom: 10px;
}

.kpi-card strong {
    font-size: 48px;
    line-height: 1;
}

.kpi-card.online strong {
    color: var(--green);
}

.kpi-card.offline strong {
    color: #374151;
}

.kpi-card.alert strong {
    color: var(--orange);
}

/* =========================
   SENSORES
========================= */

.sensores-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}

.sensor-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px 18px;
    min-height: 255px;
    box-shadow: var(--shadow);
    position: relative;
}

.sensor-card.online {
    border-color: rgba(22, 163, 74, 0.45);
    background: linear-gradient(180deg, #ffffff 0%, #f0fdf4 100%);
}

.sensor-card.alerta {
    border-color: rgba(220, 38, 38, 0.5);
    background: linear-gradient(180deg, #ffffff 0%, #fff1f2 100%);
}

.sensor-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 18px;
}

.sensor-title {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-weight: 800;
    font-size: 21px;
    line-height: 1.15;
}

.dot {
    width: 13px;
    height: 13px;
    min-width: 13px;
    margin-top: 5px;
    border-radius: 50%;
    background: #9ca3af;
}

.dot.online {
    background: var(--green);
}

.dot.alerta {
    background: var(--red);
}

.badge {
    font-size: 14px;
    padding: 6px 10px;
    border-radius: 999px;
    font-weight: 800;
    background: var(--gray-soft);
    color: #4b5563;
    white-space: nowrap;
}

.badge.online {
    background: var(--green-soft);
    color: var(--green);
}

.badge.alerta {
    background: var(--red-soft);
    color: var(--red);
}

.sensor-data {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.data-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    font-size: 16px;
    color: var(--muted);
}

.data-row strong {
    color: var(--text);
    text-align: right;
}

.sensor-offline {
    min-height: 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    gap: 12px;
    font-size: 18px;
}

.offline-icon {
    font-size: 34px;
    opacity: 0.55;
}

/* =========================
   PANELES INFERIORES
========================= */

.bottom-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 22px;
    align-items: stretch;
}

.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 22px 26px;
    box-shadow: var(--shadow);
}

/* CORRECCIÓN IMPORTANTE DEL GRÁFICO */
.chart-panel {
    height: 340px;
    min-height: 340px;
    max-height: 340px;
    overflow: hidden;
}

.chart-box {
    position: relative;
    width: 100%;
    height: 250px;
}

#graficoBodega01 {
    width: 100% !important;
    height: 250px !important;
    max-height: 250px !important;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.panel h2 {
    margin: 0;
    font-size: 24px;
}

.panel-header span {
    color: var(--muted);
    font-size: 16px;
}

.alert-panel {
    height: 340px;
    min-height: 340px;
    max-height: 340px;
}

.alertas-box {
    margin-top: 22px;
    min-height: 230px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    color: var(--muted);
}

.alert-item {
    border: 1px solid var(--red-soft);
    background: #fff7f7;
    color: var(--red);
    border-radius: 12px;
    padding: 12px;
    font-weight: 700;
}

.ok-alertas {
    text-align: center;
    color: var(--green);
    font-weight: 800;
    font-size: 20px;
}

/* =========================
   RESPONSIVE
========================= */

@media (max-width: 1400px) {
    .sensores-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 1200px) {
    .sensores-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .bottom-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 850px) {
    .app {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-height: auto;
    }

    .logo {
        width: 180px;
    }

    .main {
        padding: 22px;
    }

    .header {
        flex-direction: column;
    }

    .sensores-grid,
    .kpi-grid,
    .bottom-grid {
        grid-template-columns: 1fr;
    }
}