/* Final Refined Dashboard - Modern Premium Aesthetic */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap');

:root {
    --bg-color: #F1F5F9;
    --primary: #A67347;
    --primary-light: #FDF4EB;
    --primary-glow: rgba(166, 115, 71, 0.15);
    --secondary: #1E293B;
    --accent: #3B82F6;
    --text-main: #1A1A1A;
    --text-muted: #64748B;
    --white: #FFFFFF;
    --card-bg: rgba(255, 255, 255, 0.8);
    --border-soft: rgba(0, 0, 0, 0.05);
    --border-glass: rgba(255, 255, 255, 0.5);
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 40px 100px rgba(0, 0, 0, 0.08);
    --radius-xl: 40px;
    --radius-lg: 24px;
    --radius-md: 16px;
    --font-main: 'Outfit', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: var(--font-main); }

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    display: flex; justify-content: center; align-items: center;
    padding: 10px;
    overflow: hidden;
}

.hidden { display: none !important; }

/* =============================================
   WELCOME SCREEN (ULTRA PREMIUM)
   ============================================= */
.welcome-container {
    position: fixed; inset: 0; z-index: 5000;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    background: #000; overflow: hidden;
}

.welcome-video {
    position: absolute; width: 100%; height: 100%;
    object-fit: cover; opacity: 0.7; transform: scale(1.05);
    animation: slowZoom 20s infinite alternate;
}
@keyframes slowZoom { from { transform: scale(1); } to { transform: scale(1.1); } }

.video-overlay {
    position: absolute; inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.3) 50%, rgba(0,0,0,0.6) 100%);
}

.welcome-text {
    position: relative; z-index: 10; text-align: center;
    margin-bottom: 50px; animation: fadeInUp 1s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.welcome-text h1 {
    font-size: clamp(48px, 8vw, 84px); font-weight: 800; line-height: 0.9;
    color: white; letter-spacing: -2px; margin-bottom: 15px;
}
.welcome-text h1 span {
    background: linear-gradient(135deg, #A67347 0%, #D4A373 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.welcome-subtitle {
    font-size: 18px; color: rgba(255,255,255,0.7); font-weight: 500;
    letter-spacing: 1px; text-transform: uppercase;
}

.start-btn-wrapper { position: relative; z-index: 10; display: flex; flex-direction: column; align-items: center; }

.glass-start-btn {
    background: rgba(255, 255, 255, 0.1); backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2); color: white;
    padding: 20px 40px; border-radius: 100px; font-size: 16px; font-weight: 700;
    display: flex; align-items: center; gap: 15px; cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.glass-start-btn:hover {
    background: white; color: var(--secondary); transform: translateY(-5px) scale(1.05);
    box-shadow: 0 30px 60px rgba(0,0,0,0.4);
}
.glass-start-btn svg { transition: transform 0.4s; }
.glass-start-btn:hover svg { transform: translateX(5px); }

/* =============================================
   MAIN DASHBOARD (PREMIUM GLASS)
   ============================================= */
.app-container {
    background: white;
    width: 100%; height: 100%;
    border-radius: var(--radius-xl); 
    box-shadow: 0 25px 70px rgba(0,0,0,0.1);
    display: grid; grid-template-columns: 1.2fr 1fr;
    overflow: hidden; border: 1.5px solid #E2E8F0; position: relative;
    transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes dashboardEnter {
    from { opacity: 0; transform: scale(0.95) translateY(20px); filter: blur(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); filter: blur(0); }
}

/* --- Left Panel --- */
.dashboard-visuals {
    background: linear-gradient(145deg, #F8F9FA 0%, #F1F3F5 100%);
    padding: 45px; display: flex; flex-direction: column;
    border-right: 1px solid var(--border-soft); position: relative;
}

.visual-header { 
    display: flex; align-items: center; justify-content: space-between; 
    margin-bottom: 40px; width: 100%;
}
.header-left { display: flex; align-items: center; gap: 15px; }

.back-btn {
    width: 44px; height: 44px; border-radius: 12px;
    background: var(--secondary); color: white; border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.3s;
    box-shadow: 0 4px 12px rgba(30, 41, 59, 0.2);
}
.back-btn:hover { background: var(--primary); transform: translateX(-3px); box-shadow: 0 6px 15px rgba(166, 115, 71, 0.3); }

.titles h1 { font-size: 24px; font-weight: 800; color: var(--secondary); letter-spacing: -1px; margin: 0; }

.cloud-status {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 14px; border-radius: 100px;
    background: white; border: 1px solid var(--border-soft);
    font-size: 12px; font-weight: 700; color: var(--text-muted);
    box-shadow: var(--shadow-sm);
}
.cloud-status.online { color: #10B981; border-color: #D1FAE5; background: #ECFDF5; }
.cloud-dot { width: 8px; height: 8px; background: #94A3B8; border-radius: 50%; transition: 0.3s; }
.online .cloud-dot { background: #10B981; box-shadow: 0 0 10px #10B981; }

/* Fan Viz - Re-aligned & Improved */
.fan-display {
    flex: 1; display: flex; justify-content: center; align-items: center;
    position: relative; margin-bottom: 40px;
}
.fan-glow {
    position: absolute; width: 300px; height: 300px;
    background: radial-gradient(circle, var(--primary-glow) 0%, transparent 75%);
    animation: pulseGlow 4s infinite alternate;
}

.fan-frame {
    width: 240px; height: 240px; background: white;
    border-radius: 50%; position: relative; z-index: 2;
    box-shadow: 
        0 30px 60px rgba(0,0,0,0.08), 
        inset 0 0 0 10px #F8F9FA,
        inset 0 0 20px rgba(0,0,0,0.02);
    display: flex; justify-content: center; align-items: center;
    border: 1px solid white;
}

.fan-spinner { 
    width: 100%; height: 100%; position: absolute; 
    display: flex; justify-content: center; align-items: center;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1); 
}

.fan-blade {
    position: absolute; width: 100px; height: 44px;
    background: linear-gradient(180deg, #F8FAFC 0%, #E2E8F0 100%);
    border-radius: 50% 50% 50% 50% / 100% 100% 0% 0%; /* Curvy blade shape */
    transform-origin: 0% 50%;
    left: 50%; /* Start from center */
    margin-top: -22px;
    border: 1px solid rgba(255,255,255,0.8);
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.5), 0 2px 4px rgba(0,0,0,0.05);
}

.b1 { transform: rotate(0deg); } 
.b2 { transform: rotate(120deg); } 
.b3 { transform: rotate(240deg); }

.fan-hub {
    width: 54px; height: 54px; background: white;
    border: 6px solid var(--primary); border-radius: 50%; z-index: 10;
    display: flex; justify-content: center; align-items: center;
    box-shadow: 0 6px 15px rgba(0,0,0,0.1), inset 0 2px 5px rgba(0,0,0,0.05);
    position: relative;
}

.fan-hub::after {
    content: ''; width: 12px; height: 12px; 
    background: var(--primary); border-radius: 50%;
    opacity: 0.8;
}

.spinning { animation: spin 0.5s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Controls */
.power-control-wrapper { display: flex; gap: 20px; margin-top: auto; }
.power-card {
    flex: 1; background: white; border-radius: var(--radius-lg); padding: 24px;
    display: flex; flex-direction: column; gap: 15px;
    border: 1px solid white; box-shadow: var(--shadow-md); transition: 0.3s;
}
.power-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); }

.power-info h3 { font-size: 14px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.power-info p { font-size: 16px; font-weight: 800; color: var(--secondary); }

/* Premium Toggle */
.power-switch-label { cursor: pointer; align-self: flex-start; }
.power-toggle-ui {
    width: 70px; height: 36px; background: #F1F5F9; border-radius: 100px;
    position: relative; transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border-soft);
}
.power-toggle-ui.on { background: var(--primary); border-color: var(--primary); }
.auto-ui.on { background: var(--accent); border-color: var(--accent); }

.toggle-knob {
    width: 28px; height: 28px; background: white; border-radius: 50%;
    position: absolute; top: 3px; left: 3px; transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.on .toggle-knob { transform: translateX(34px); }
.p-icon { color: #94A3B8; transition: 0.3s; }
.on .p-icon { color: var(--primary); }
.auto-ui.on .p-icon { color: var(--accent); }

/* --- Right Panel --- */
.dashboard-content {
    padding: 40px; display: flex; flex-direction: column;
    background: white; overflow: hidden; /* Prevent global scroll */
}
.side-panel-wrapper {
    display: flex; flex-direction: column; height: 100%; gap: 18px; /* Reduced gap further */
}

.section-tag { font-size: 11px; font-weight: 800; text-transform: uppercase; color: var(--text-muted); letter-spacing: 1.5px; margin-bottom: 8px; }

.panel-section { flex-shrink: 0; } /* Keep stats and settings fixed size */

.main-stats-card {
    background: #F8F9FA; border-radius: var(--radius-lg); padding: 15px;
    display: flex; align-items: center; gap: 12px; border: 1px solid var(--border-soft);
}
.stats-icon-box {
    width: 44px; height: 44px; border-radius: 14px;
    background: white; color: var(--primary);
    display: flex; justify-content: center; align-items: center;
    box-shadow: var(--shadow-sm);
}

.stats-main-info p { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: -2px; }
.stats-value-row span { font-size: 28px; font-weight: 800; color: var(--secondary); letter-spacing: -1px; }
.unit-label { font-size: 14px; color: var(--text-muted); }

.automation-card {
    background: white; border-radius: var(--radius-lg); padding: 15px;
    border: 1.5px solid var(--border-soft);
}
.auto-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.auto-title h4 { font-size: 14px; font-weight: 800; color: var(--secondary); }
.auto-title p { font-size: 11px; color: var(--text-muted); }

.auto-badge {
    background: #F8F9FA; padding: 4px 12px; border-radius: 12px;
    display: flex; align-items: center; gap: 6px; border: 1px solid var(--border-soft);
}
#thresholdInput {
    background: transparent; border: none; width: 40px; text-align: center;
    font-weight: 800; font-size: 16px; color: var(--secondary); outline: none;
}
.mini-send-btn {
    background: var(--secondary); border: none; color: white;
    width: 24px; height: 24px; border-radius: 6px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: 0.2s;
}
.mini-send-btn:hover { background: var(--primary); transform: scale(1.1); }

/* Slider */
.auto-control-box { display: flex; align-items: center; gap: 15px; }
.stepper-btn {
    width: 38px; height: 38px; border-radius: 12px; background: #F1F5F9;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.2s; color: var(--secondary);
}
.stepper-btn:hover { background: var(--secondary); color: white; }

.slider-track-box { flex: 1; position: relative; }
.premium-slider {
    width: 100%; height: 6px; -webkit-appearance: none; background: #E2E8F0;
    border-radius: 10px; outline: none;
}
.premium-slider::-webkit-slider-thumb {
    -webkit-appearance: none; width: 24px; height: 24px; background: white;
    border: 4px solid var(--primary); border-radius: 50%; cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1); transition: 0.2s;
}
.premium-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* History List Dashboard */
.history-entry { 
    flex: 1; /* Take remaining space */
    min-height: 0; /* Critical for inner scrolling */
    display: flex; flex-direction: column; 
}
.history-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; flex-shrink: 0; }
.history-count-pill {
    padding: 4px 12px; background: #F1F5F9; border-radius: 100px;
    font-size: 12px; font-weight: 800; color: var(--secondary);
}
.activity-scroll-list { 
    flex: 1; overflow-y: auto; padding-right: 8px;
    display: flex; flex-direction: column; gap: 12px;
}
/* Custom Scrollbar for activity list */
.activity-scroll-list::-webkit-scrollbar { width: 5px; }
.activity-scroll-list::-webkit-scrollbar-thumb { background: #E2E8F0; border-radius: 10px; }

.activity-card {
    background: #F8F9FA; padding: 18px; border-radius: var(--radius-md);
    display: flex; align-items: center; gap: 16px; border: 1px solid transparent; transition: 0.3s;
    flex-shrink: 0;
}
.activity-card:hover { background: white; border-color: var(--primary-light); box-shadow: var(--shadow-md); transform: translateX(5px); }

.act-icon { width: 44px; height: 44px; border-radius: 12px; display: flex; justify-content: center; align-items: center; }
.act-on { background: #ECFDF5; color: #10B981; }
.act-off { background: #FEF2F2; color: #EF4444; }
.act-settings { background: #F1F5F9; color: var(--secondary); }

.act-info h5 { font-size: 15px; font-weight: 700; color: var(--secondary); margin: 0; }
.act-info p { font-size: 13px; color: var(--text-muted); }
.act-time { margin-left: auto; font-size: 12px; font-weight: 700; color: #94A3B8; }

.riwayat-btn {
    width: 100%; padding: 18px; border-radius: var(--radius-md);
    background: var(--secondary); color: white; border: none;
    font-weight: 700; cursor: pointer; transition: 0.3s;
    display: flex; align-items: center; justify-content: center; gap: 12px;
    margin-top: 10px; flex-shrink: 0;
}
.riwayat-btn:hover { background: #0F172A; transform: translateY(-3px); box-shadow: 0 15px 30px rgba(0,0,0,0.15); }

/* =============================================
   HISTORY SCREEN OVERLAY (PREMIUM NEW DESIGN)
   ============================================= */
.history-screen {
    position: fixed; inset: 0; z-index: 2000;
    background: var(--bg-color);
    display: flex; justify-content: center; align-items: center;
    padding: 10px; animation: slideUp 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.history-screen.closing { animation: slideDown 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
@keyframes slideDown { from { transform: translateY(0); } to { transform: translateY(100%); } }

.history-page-card {
    width: 100%; height: 100%;
    background: white; border-radius: 40px;
    display: flex; flex-direction: column; overflow: hidden;
    border: 1.5px solid #E2E8F0;
    box-shadow: 0 40px 100px rgba(0,0,0,0.15);
}

.history-page-header {
    padding: 30px 40px; background: white; border-bottom: 1px solid var(--border-soft);
}
.header-top-row { display: flex; align-items: center; gap: 20px; margin-bottom: 25px; }

.history-page-title { font-size: 24px; font-weight: 800; color: var(--text-main); margin: 0; }
.history-page-title span { color: var(--accent-color); }

.date-filter-wrapper-pill {
    display: flex; align-items: center; gap: 10px;
    background: #F8F9FA; padding: 6px 12px;
    border-radius: 14px; border: 1px solid #E5E7EB;
    color: var(--text-muted); transition: all 0.3s;
    margin-left: auto;
}
.date-filter-wrapper-pill:focus-within { border-color: var(--accent-color); background: white; box-shadow: var(--shadow-sm); }

.date-input {
    border: none; background: transparent; font-size: 13px; font-weight: 600;
    font-family: 'Outfit', sans-serif; color: var(--text-main); outline: none; cursor: pointer;
    min-width: 120px;
}

.clear-btn-pill {
    background: #FEE2E2; color: #EF4444; border: none;
    padding: 4px 10px; border-radius: 8px; font-weight: 700; font-size: 11px; 
    cursor: pointer; transition: 0.2s;
}

.history-nav-tabs {
    display: inline-flex;
    background: #F4F4F5;
    padding: 4px;
    border-radius: 12px;
}
.history-tab {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 20px; border-radius: 10px; border: none;
    font-size: 13px; font-weight: 700; font-family: 'Outfit', sans-serif;
    cursor: pointer; transition: all 0.2s;
    color: #71717A;
    background: transparent;
}
.history-tab.active {
    background: white; color: var(--accent-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.history-tab-content {
    flex: 1; display: none; flex-direction: column; min-height: 0;
}
.history-tab-content.active { display: flex; }

.history-db-list {
    flex: 1; overflow-y: auto; padding: 25px 40px;
    display: flex; flex-direction: column; gap: 12px;
}
/* Custom Scrollbar for history page list */
.history-db-list::-webkit-scrollbar { width: 6px; }
.history-db-list::-webkit-scrollbar-thumb { background: #E2E8F0; border-radius: 10px; }

.db-row {
    display: flex; align-items: center; gap: 16px;
    padding: 18px 24px; border-radius: 20px;
    background: #F9FAFB; border: 1px solid #F1F1F1;
    transition: all 0.2s;
}
.db-row:hover { border-color: var(--accent-light); transform: scale(1.005); box-shadow: 0 4px 20px rgba(0,0,0,0.03); background: white; }

.db-row-icon {
    width: 44px; height: 44px; border-radius: 14px;
    display: flex; justify-content: center; align-items: center;
    flex-shrink: 0;
}
.db-row-icon.type-on { background: #ECFDF5; color: #10B981; }
.db-row-icon.type-off { background: #FEF2F2; color: #EF4444; }
.db-row-icon.type-auto { background: #EFF6FF; color: #3B82F6; }
.db-row-icon.type-threshold { background: #FFF7ED; color: #F97316; }
.db-row-icon.type-error { background: #FFF1F2; color: #E11D48; }

.db-row-info h5 { font-size: 15px; font-weight: 700; color: var(--text-main); margin: 0; }
.db-row-info p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.db-row-time { font-size: 12px; font-weight: 700; color: #94A3B8; text-align: right; min-width: 100px; }

/* Responsive System Optimized */
@media screen and (max-width: 900px) {
    body { padding: 10px; align-items: flex-start; overflow-y: auto; min-height: 100dvh; }
    
    /* App Container Mobile */
    .app-container { 
        grid-template-columns: 1fr; height: auto; 
        border-radius: 32px; width: 100%; 
        max-width: 600px; margin: 0 auto;
        box-shadow: 0 15px 40px rgba(0,0,0,0.08);
    }
    
    /* Left Panel Mobile */
    .dashboard-visuals { 
        border-right: none; border-bottom: 1px solid var(--border-soft); 
        padding: 30px 25px; 
    }
    .visual-header { margin-bottom: 30px; }
    .titles h1 { font-size: 20px; }
    .fan-frame { width: 180px; height: 180px; }
    .fan-blade { width: 75px; height: 32px; margin-top: -16px; }
    .fan-hub { width: 44px; height: 44px; }
    .fan-display { min-height: 220px; margin-bottom: 30px; }

    /* Right Panel Mobile */
    .dashboard-content { padding: 30px 20px; overflow: visible; }
    .side-panel-wrapper { height: auto; gap: 25px; }
    .activity-scroll-list { max-height: 400px; overflow-y: visible; } /* Allow natural scroll in mobile context */

    /* History Page Mobile */
    .history-screen { padding: 10px; }
    .history-page-card { 
        border-radius: 32px; 
        height: calc(100vh - 20px); 
        border: 1.5px solid #E2E8F0;
        box-shadow: 0 15px 40px rgba(0,0,0,0.1);
    }
    .history-page-header { padding: 20px; }
    .header-top-row { flex-direction: column; align-items: flex-start; gap: 15px; }
    .date-filter-wrapper-pill { width: 100%; margin-left: 0; justify-content: space-between; }
    .history-db-list { padding: 20px; }
    .db-row { padding: 15px; }
}

@media screen and (max-width: 480px) {
    .welcome-text h1 { font-size: 42px; }
    .welcome-subtitle { font-size: 14px; }
    .glass-start-btn { padding: 16px 30px; font-size: 14px; }
    
    .power-control-wrapper { flex-direction: column; }
    .main-stats-card { padding: 12px; }
    .stats-value-row span { font-size: 24px; }
    .history-nav-tabs { width: 100%; display: flex; }
    .history-tab { flex: 1; justify-content: center; padding: 10px 12px; font-size: 12px; }
}

/* =============================================
   DYNAMIC ANIMATIONS & EFFECTS
   ============================================= */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.wind-lines {
    position: absolute; inset: 0; pointer-events: none; z-index: 1;
    overflow: hidden; opacity: 0; transition: opacity 1s;
}
.app-container.active-cool .wind-lines { opacity: 0.6; }

.wind-line {
    position: absolute; background: linear-gradient(90deg, transparent, rgba(166, 115, 71, 0.2), transparent);
    height: 2px; border-radius: 10px; animation: moveWind linear infinite;
}
.w1 { width: 100px; top: 20%; left: -100px; animation-duration: 3s; }
.w2 { width: 150px; top: 40%; left: -150px; animation-duration: 2.5s; animation-delay: 0.5s; }
.w3 { width: 80px; top: 60%; left: -80px; animation-duration: 3.5s; animation-delay: 1s; }
.w4 { width: 120px; top: 80%; left: -120px; animation-duration: 2.8s; animation-delay: 0.2s; }

@keyframes moveWind {
    from { transform: translateX(0); }
    to { transform: translateX(1200px); }
}

.history-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 50px; gap: 15px; color: var(--text-muted); }
.loading-spinner { width: 30px; height: 30px; border: 3px solid #F1F5F9; border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }

.history-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px; gap: 15px; color: #94A3B8; text-align: center; }
.history-empty svg { opacity: 0.3; margin-bottom: 5px; }
