/* -------------------------------------------------------------
 * 1. Global Reset & Variables
 * ------------------------------------------------------------- */
:root {
    --bg-dark: #0a0e1a;
    --bg-gradient: linear-gradient(135deg, #090e1d 0%, #151b30 100%);
    --card-bg: rgba(20, 26, 48, 0.45);
    --card-border: rgba(255, 255, 255, 0.08);
    --card-highlight: rgba(255, 255, 255, 0.03);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;

    /* Theme colors */
    --temp-color: #ff5722;
    --temp-gradient: linear-gradient(135deg, #ff8c00 0%, #ff3c00 100%);
    --temp-glow: rgba(255, 92, 0, 0.35);

    --humidity-color: #00bcd4;
    --humidity-gradient: linear-gradient(135deg, #00e5ff 0%, #00838f 100%);
    --humidity-glow: rgba(0, 229, 255, 0.3);

    --pressure-color: #3f51b5;
    --pressure-gradient: linear-gradient(135deg, #3d5afe 0%, #1a237e 100%);
    --pressure-glow: rgba(61, 90, 254, 0.3);

    --online-color: #10b981;
    --offline-color: #ef4444;
    --loading-color: #f59e0b;

    --font-thai: 'Prompt', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-eng: 'Plus Jakarta Sans', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-dark);
    background-image: var(--bg-gradient);
    color: var(--text-primary);
    font-family: var(--font-thai);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* -------------------------------------------------------------
 * 2. Background Effects (Premium Vibe)
 * ------------------------------------------------------------- */
.stars-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(white 1px, transparent 1px);
    background-size: 50px 50px;
    opacity: 0.05;
    pointer-events: none;
    z-index: 1;
}

.glow-bg {
    position: fixed;
    top: -10%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, rgba(99, 102, 241, 0) 70%);
    pointer-events: none;
    z-index: 1;
    filter: blur(80px);
}

/* -------------------------------------------------------------
 * 3. Layout Container
 * ------------------------------------------------------------- */
.dashboard-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem;
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
    min-height: 100vh;
}

/* -------------------------------------------------------------
 * 4. Header Section
 * ------------------------------------------------------------- */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
    width: 50px;
    height: 50px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.3);
    color: white;
}

.logo-icon i {
    width: 24px;
    height: 24px;
}

.logo-text h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #ffffff, #c7d2fe);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: var(--font-eng);
    letter-spacing: 0.5px;
}

/* Status Indicator */
.status-panel {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.4rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0.4rem 0.9rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--loading-color);
    position: relative;
}

/* Pulsing effect when online */
.status-indicator.online .status-dot {
    background-color: var(--online-color);
    box-shadow: 0 0 10px var(--online-color);
    animation: pulse 1.8s infinite ease-in-out;
}

.status-indicator.offline .status-dot {
    background-color: var(--offline-color);
    box-shadow: 0 0 10px var(--offline-color);
}

.status-indicator.loading .status-dot {
    background-color: var(--loading-color);
    box-shadow: 0 0 10px var(--loading-color);
    animation: flash 1s infinite alternate;
}

.last-updated {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-eng);
}

/* -------------------------------------------------------------
 * 5. Stats Cards Grid
 * ------------------------------------------------------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    position: relative;
    border-radius: 24px;
    border: 1px solid var(--card-border);
    background-color: var(--card-bg);
    padding: 1.8rem;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 180px;
}

.card-glass {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.02) 0%, rgba(255, 255, 255, 0) 100%);
    z-index: -1;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, transparent 100%);
    pointer-events: none;
    z-index: 1;
}

.stat-card:hover {
    transform: translateY(-6px);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

/* Custom glow on hover for each type */
.stat-card.temp-card:hover {
    box-shadow: 0 15px 30px var(--temp-glow), 0 5px 15px rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 87, 34, 0.3);
}

.stat-card.humidity-card:hover {
    box-shadow: 0 15px 30px var(--humidity-glow), 0 5px 15px rgba(0, 0, 0, 0.2);
    border-color: rgba(0, 188, 212, 0.3);
}

.stat-card.pressure-card:hover {
    box-shadow: 0 15px 30px var(--pressure-glow), 0 5px 15px rgba(0, 0, 0, 0.2);
    border-color: rgba(61, 90, 254, 0.3);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.2rem;
    position: relative;
    z-index: 2;
}

.card-title {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.card-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.card-icon i {
    width: 20px;
    height: 20px;
}

.temp-icon {
    background: var(--temp-gradient);
    box-shadow: 0 4px 15px rgba(255, 87, 34, 0.3);
}

.humidity-icon {
    background: var(--humidity-gradient);
    box-shadow: 0 4px 15px rgba(0, 188, 212, 0.3);
}

.pressure-icon {
    background: var(--pressure-gradient);
    box-shadow: 0 4px 15px rgba(61, 90, 254, 0.3);
}

.card-body {
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
    margin-bottom: auto;
    position: relative;
    z-index: 2;
}

.stat-value {
    font-size: 2.8rem;
    font-weight: 800;
    font-family: var(--font-eng);
    letter-spacing: -1px;
}

.stat-unit {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.card-footer {
    display: flex;
    align-items: center;
    font-size: 0.78rem;
    color: var(--text-muted);
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    padding-top: 0.8rem;
    margin-top: 1rem;
    position: relative;
    z-index: 2;
}

.mini-icon {
    width: 14px;
    height: 14px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 4px;
}

/* -------------------------------------------------------------
 * 6. Charts Section
 * ------------------------------------------------------------- */
.chart-section {
    width: 100%;
}

.chart-card {
    position: relative;
    border-radius: 28px;
    border: 1px solid var(--card-border);
    background-color: var(--card-bg);
    padding: 2rem;
    overflow: hidden;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1.2rem;
    margin-bottom: 2rem;
    position: relative;
    z-index: 2;
}

.chart-title-area h2 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
}

.chart-title-area p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.chart-controls {
    display: flex;
    gap: 0.6rem;
    align-items: center;
}

.btn-control {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 12px;
    font-family: var(--font-thai);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-control:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.btn-control.active {
    background: #6366f1;
    border-color: #6366f1;
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
}

.btn-refresh {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-refresh:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.btn-refresh:active i {
    transform: rotate(180deg);
}

.btn-refresh i {
    width: 18px;
    height: 18px;
    transition: transform 0.4s ease;
}

.chart-body-container {
    width: 100%;
    min-height: 350px;
    position: relative;
    z-index: 2;
}

/* ApexCharts customization */
.apexcharts-canvas {
    font-family: var(--font-eng) !important;
}
.apexcharts-tooltip.apexcharts-theme-dark {
    background: rgba(15, 23, 42, 0.8) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(10px) !important;
    border-radius: 12px !important;
    box-shadow: 0 10px 20px rgba(0,0,0,0.3) !important;
}

/* -------------------------------------------------------------
 * 7. Footer Section
 * ------------------------------------------------------------- */
.main-footer {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* -------------------------------------------------------------
 * 8. Animations
 * ------------------------------------------------------------- */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

@keyframes flash {
    0% {
        opacity: 0.4;
    }
    100% {
        opacity: 1;
    }
}

/* -------------------------------------------------------------
 * 9. Responsive Adjustments
 * ------------------------------------------------------------- */
@media (max-width: 768px) {
    .dashboard-container {
        padding: 1.5rem 1rem;
        gap: 1.5rem;
    }
    .main-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    .status-panel {
        align-items: flex-start;
        width: 100%;
    }
    .chart-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .chart-controls {
        width: 100%;
        justify-content: space-between;
    }
    .btn-control {
        flex: 1;
        text-align: center;
        padding: 0.5rem 0.2rem;
        font-size: 0.78rem;
    }
    .stat-value {
        font-size: 2.3rem;
    }
}
