:root {
    /* Palette Warna Baru */
    --bg-navy: #1e293b;       /* Deep Navy Background Utama */
    --bg-card: #1e293b;       /* Sama dengan body agar menyatu, atau sedikit terang */
    --bg-card-hover: #334155; /* Sedikit lebih terang saat hover */
    
    --text-main: #f1f5f9;     /* Hampir Putih */
    --text-muted: #94a3b8;    /* Abu-abu terang */
    
    --primary: #3b82f6;       /* Electric Blue */
    --secondary: #2dd4bf;     /* Cyan */
    --gradient: linear-gradient(135deg, #3b82f6 0%, #2dd4bf 100%);
    
    --success: #22c55e;       /* Hijau (ON) */
    --warning: #eab308;       /* Kuning Emas (OFF/Standby) */
    --offline: #64748b;       /* Abu-abu (MQTT Offline) */
    
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --glow-blue: 0 0 15px rgba(59, 130, 246, 0.4);
    --glow-green: 0 0 15px rgba(34, 197, 94, 0.4);
    --glow-yellow: 0 0 15px rgba(234, 179, 8, 0.4);
    
    --radius: 12px;
    --font-head: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-body: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* --- RESET & BODY --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { 
    font-family: var(--font-body); 
    background: var(--bg-navy); 
    color: var(--text-main); 
    line-height: 1.6; 
    transition: background 0.3s ease;
}
a { text-decoration: none; color: inherit; transition: 0.3s; }
button, input, select, textarea { font-family: inherit; }
img { max-width: 100%; height: auto; display: block; }

/* --- LAYOUT --- */
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* --- HEADER & NAVBAR --- */
header { 
    background: rgba(30, 41, 59, 0.95); /* Transparan Navy */
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #334155;
    position: sticky; top: 0; z-index: 1000; 
}
.nav-container { display: flex; justify-content: space-between; align-items: center; height: 70px; }
.logo { font-size: 1.5rem; font-weight: 800; color: white; display: flex; align-items: center; gap: 10px; text-transform: uppercase; letter-spacing: 1px;}
.logo i { color: var(--primary); }
.nav-links { display: flex; align-items: center; gap: 20px; }
.nav-links a { font-weight: 500; color: var(--text-muted); font-size: 0.95rem; }
.nav-links a:hover, .nav-links a.active { color: var(--primary); }

/* Tombol dengan Gradasi Electric Blue -> Cyan */
.btn-login { 
    background: var(--gradient); 
    color: white; 
    padding: 8px 24px; 
    border-radius: 50px; 
    font-weight: 600; border: none; cursor: pointer; 
    box-shadow: var(--glow-blue);
}
.btn-login:hover { opacity: 0.9; transform: translateY(-2px); }

/* Mobile Menu Toggle */
.menu-toggle { display: none; font-size: 1.5rem; color: white; cursor: pointer; background: none; border: none; }

/* --- HERO SECTION --- */
.hero { 
    background: var(--gradient); /* Gradasi penuh pada hero */
    padding: 80px 0; 
    text-align: center; 
    color: white;
    position: relative;
    overflow: hidden;
}
/* Efek pola halus di background hero */
.hero::before {
    content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background-image: radial-gradient(rgba(255,255,255,0.1) 1px, transparent 1px);
    background-size: 30px 30px; opacity: 0.3;
}
.hero h1 { font-size: 3rem; margin-bottom: 20px; line-height: 1.2; text-shadow: 0 2px 10px rgba(0,0,0,0.2); }
.hero p { font-size: 1.2rem; margin-bottom: 40px; max-width: 700px; margin-left: auto; margin-right: auto; opacity: 0.9; }
.hero-img { 
    margin: 40px auto 0; 
    border-radius: var(--radius); 
    box-shadow: 0 20px 40px rgba(0,0,0,0.3); 
    border: 2px solid rgba(255,255,255,0.2);
}

/* --- GRID SYSTEM --- */
.grid-responsive { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 25px; }
.section-title { text-align: center; margin-bottom: 40px; font-size: 2rem; color: white; text-transform: uppercase; letter-spacing: 2px; }
.blog-section { padding: 60px 0; }

/* --- BLOG CARDS (Dark Mode) --- */
.blog-card { 
    background: var(--bg-card); 
    border-radius: var(--radius); 
    overflow: hidden; 
    box-shadow: var(--shadow); 
    border: 1px solid #334155; 
    display: flex; flex-direction: column; 
    transition: 0.3s;
}
.blog-card:hover { transform: translateY(-5px); border-color: var(--primary); }
.blog-img { width: 100%; height: 200px; object-fit: cover; background: #0f172a; }
.blog-content { padding: 20px; flex: 1; display: flex; flex-direction: column; }
.blog-title { font-size: 1.2rem; margin-bottom: 10px; font-weight: 700; color: white; }
.blog-excerpt { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 20px; flex: 1; }
.read-more { color: var(--secondary); font-weight: 600; margin-top: auto; }

/* --- DASHBOARD LAYOUT --- */
.dashboard-wrapper { display: flex; min-height: 100vh; }
.sidebar { 
    width: 250px; 
    background: #0f172a; /* Lebih gelap dari body */
    color: white; 
    padding: 20px; 
    flex-shrink: 0; 
    border-right: 1px solid #334155;
    transition: 0.3s; 
}
.sidebar h2 { font-size: 1.4rem; margin-bottom: 30px; padding-bottom: 15px; border-bottom: 1px solid #334155; color: var(--primary); }
.sidebar-menu a { display: block; padding: 12px; color: var(--text-muted); border-radius: 8px; margin-bottom: 5px; transition: 0.2s; }
.sidebar-menu a:hover, .sidebar-menu a.active { background: rgba(59, 130, 246, 0.1); color: var(--primary); border-left: 3px solid var(--primary); }

.main-content { flex: 1; padding: 30px; overflow-y: auto; background: var(--bg-navy); }

/* --- DASHBOARD CARDS --- */
.card { 
    background: var(--bg-card); 
    padding: 25px; 
    border-radius: var(--radius); 
    box-shadow: var(--shadow); 
    margin-bottom: 25px; 
    border: 1px solid #334155; 
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; border-bottom: 1px solid #334155; padding-bottom: 15px; }
.card-header h3 { font-size: 1.2rem; color: white; display: flex; align-items: center; gap: 10px; }

/* --- SENSOR CARDS --- */
.sensor-card { 
    background: #1e293b; border-radius: var(--radius); padding: 20px; 
    box-shadow: var(--shadow); border: 1px solid #334155; 
    position: relative; overflow: hidden; transition: 0.3s;
}
.sensor-card:hover { border-color: var(--primary); transform: translateY(-3px); }
.sensor-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 15px; }
.sensor-icon-box { 
    width: 50px; height: 50px; background: rgba(59, 130, 246, 0.1); 
    border-radius: 12px; display: flex; align-items: center; justify-content: center; 
    color: var(--primary); font-size: 1.4rem; border: 1px solid rgba(59, 130, 246, 0.3);
}
.sensor-title { font-weight: 600; color: var(--text-muted); font-size: 0.9rem; text-transform: uppercase; }
.sensor-val-box { text-align: right; }
.sensor-val { font-size: 2rem; font-weight: 800; color: white; font-family: var(--font-head); }
.sensor-unit { font-size: 0.9rem; color: var(--text-muted); font-weight: 500; }

/* --- SWITCH CARDS (LOGIKA WARNA BARU) --- */
.switch-card { 
    background: rgba(234, 179, 8, 0.1); /* Background Kuning Transparan */
    border: 1px solid var(--warning); /* Border Kuning (Standby/OFF) */
    color: var(--warning); /* Teks Kuning */
    border-radius: var(--radius); padding: 20px; 
    display: flex; flex-direction: row !important; 
    align-items: center; justify-content: space-between; gap: 15px;
    transition: all 0.4s ease; /* Transisi halus warna */
}

.switch-info { display: flex; align-items: center; gap: 15px; flex: 1; min-width: 0; }
.switch-icon-box { 
    width: 45px; height: 45px; border-radius: 50%; background: #000; 
    color: var(--warning); /* Ikon Kuning */
    display: flex; align-items: center; justify-content: center; font-size: 1.2rem; 
    flex-shrink: 0; transition: 0.3s;
    border: 1px solid var(--warning);
}
.switch-name { font-weight: 700; font-size: 1.1rem; color: var(--warning); transition: 0.3s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.switch-controls { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; flex-shrink: 0; }

/* 1. STATUS ON (Hijau Menyala) */
.switch-card.active {
    background: rgba(34, 197, 94, 0.15); /* Background Hijau Transparan */
    border-color: var(--success); /* Border Hijau */
    color: var(--success); /* Teks Hijau */
    box-shadow: var(--glow-green); /* Efek Glow Hijau */
}

.switch-card.active .switch-icon-box {
    background: var(--success);
    color: white;
    border-color: var(--success);
    box-shadow: 0 0 10px var(--success);
}

.switch-card.active .switch-name { color: var(--success); }

/* 2. STATUS MQTT OFFLINE (Abu-abu & Mati) */
/* Catatan: Class ini aktif jika body memiliki class 'mqtt-offline' */
body.mqtt-offline .switch-card {
    background: #334155; /* Abu-abu Gelap */
    border-color: #64748b; /* Abu-abu Terang */
    color: #94a3b8; /* Teks Abu-abu Pudar */
    box-shadow: none;
    opacity: 0.7;
}

body.mqtt-offline .switch-icon-box {
    background: #475569;
    border-color: #64748b;
    color: #94a3b8;
}

body.mqtt-offline .switch-name { color: #94a3b8; }


/* --- TOGGLE SWITCH SWITCH --- */
.toggle-switch { position: relative; display: inline-block; width: 52px; height: 28px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #475569; transition: .4s; border-radius: 34px; border: 2px solid #64748b;}
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 2px; bottom: 2px; background-color: white; transition: .4s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.5); }
input:checked + .slider { background-color: var(--success); border-color: var(--success); }
input:checked + .slider:before { transform: translateX(24px); }

/* --- BUTTONS & FORMS --- */
.btn-primary { background: var(--gradient); color: white; border: none; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-weight: 600; box-shadow: var(--glow-blue); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-icon { padding: 6px 10px; border-radius: 6px; border: none; cursor: pointer; font-size: 0.9rem; transition: 0.2s; }
.btn-edit { background: #f59e0b; color: white; }
.btn-delete { background: #ef4444; color: white; }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 600; font-size: 0.9rem; color: var(--text-muted); }
.form-control { width: 100%; padding: 10px; border: 1px solid #475569; background: #0f172a; color: white; border-radius: 8px; font-size: 1rem; }
.form-control:focus { border-color: var(--primary); outline: none; }

/* --- MODALS --- */
.modal { display: none; position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.8); align-items: center; justify-content: center; }
.modal-content { background-color: #1e293b; padding: 25px; border-radius: var(--radius); width: 90%; max-width: 500px; position: relative; max-height: 90vh; overflow-y: auto; border: 1px solid #334155; }
.modal-content h3 { color: white; margin-bottom: 20px; }
.close { position: absolute; right: 20px; top: 15px; font-size: 28px; font-weight: bold; cursor: pointer; color: #94a3b8; }
.close:hover { color: white; }

/* --- MQTT STATUS INDICATOR --- */
.mqtt-status { 
    position: fixed; bottom: 20px; right: 20px; padding: 10px 20px; 
    border-radius: 50px; font-size: 0.9rem; font-weight: 600; 
    display: flex; align-items: center; gap: 10px; z-index: 9999; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.5); backdrop-filter: blur(5px); 
    color: white;
}
.mqtt-status.online { background: rgba(34, 197, 94, 0.2); border: 1px solid #22c55e; box-shadow: var(--glow-green); }
.mqtt-status.offline { background: rgba(100, 116, 139, 0.3); border: 1px solid #64748b; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.online .dot { box-shadow: 0 0 8px currentColor; background: #22c55e; }
.offline .dot { background: #64748b; }

/* --- MOBILE RESPONSIVE --- */
@media (max-width: 768px) {
    .nav-container { position: relative; }
    .menu-toggle { display: block; color: white; }
    .nav-links { position: absolute; top: 100%; left: 0; width: 100%; background: #0f172a; flex-direction: column; padding: 20px; box-shadow: 0 10px 10px rgba(0,0,0,0.5); display: none; border-bottom: 1px solid #334155; }
    .nav-links.active { display: flex; }
    .nav-links a { width: 100%; text-align: center; padding: 10px; color: #cbd5e1; }
    .nav-links a:hover { color: white; background: rgba(255,255,255,0.05); }

    .dashboard-wrapper { flex-direction: column; }
    .sidebar { width: 100%; padding: 10px 20px; flex-direction: row; justify-content: space-between; align-items: center; height: auto; position: relative; border-bottom: 1px solid #334155; }
    .sidebar h2 { margin: 0; border: none; font-size: 1.1rem; white-space: nowrap; }
    
    /* Mobile Hamburger in Dashboard */
    .mobile-menu-btn {
        display: block; background: rgba(255,255,255,0.1); border: none; color: white; font-size: 1.5rem; cursor: pointer; padding: 5px 10px; border-radius: 5px;
    }
    .sidebar-menu { 
        display: none; position: absolute; top: 100%; left: 0; width: 100%; background: #0f172a; 
        flex-direction: column; padding: 15px 0; box-shadow: 0 10px 10px rgba(0,0,0,0.5); 
        z-index: 50; border-bottom: 1px solid #334155;
    }
    .sidebar-menu.active { display: flex; }
    .sidebar-menu a { padding: 12px 20px; text-align: left; color: #94a3b8; }
    .sidebar-menu a:hover, .sidebar-menu a.active { color: var(--primary); background: rgba(59, 130, 246, 0.1); padding-left: 25px; }

    .hero h1 { font-size: 1.8rem; }
    .grid-responsive { grid-template-columns: 1fr; }
    .switch-card { flex-direction: column !important; align-items: flex-start; gap: 15px; }
    .switch-info { width: 100%; }
    .switch-controls { width: 100%; align-items: flex-start; flex-direction: row; justify-content: space-between; }
}

/* =========================================
   STYLING KHUSUS HALAMAN ARTIKEL (BLOG)
   ========================================= */

.article-wrapper {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px 0;
    line-height: 1.8;
}

/* 1. Judul (H1, H2, H3) dengan Gradasi Electric Blue -> Cyan */
.article-wrapper h1, 
.article-wrapper h2, 
.article-wrapper h3 {
    font-weight: 800; /* Bold */
    margin-bottom: 20px;
    line-height: 1.3;
    
    /* CSS untuk Text Gradient */
    background: linear-gradient(135deg, #3b82f6 0%, #2dd4bf 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent; /* Membuat teks transparan agar background gradient terlihat */
    background-clip: text;
}

/* Judul Utama (H1) lebih besar */
.article-wrapper h1 {
    font-size: 2.5rem; /* Ukuran besar */
    margin-bottom: 10px;
}

/* 2. Isi Artikel (Body Text): Light Slate (#CBD5E1) */
.article-content p, 
.article-content ul, 
.article-content ol {
    color: #CBD5E1;
    font-size: 1.1rem;
    margin-bottom: 20px;
    text-align: justify;
}

.article-content li { margin-bottom: 8px; }

/* 3. Teks Pendukung (Meta/Caption): Slate (#94A3B8) */
.article-meta, 
.img-caption {
    color: #94A3B8;
    font-size: 0.9rem;
    margin-bottom: 30px;
    display: block;
    font-style: italic;
}

/* =========================================
   SKEMA VISUAL ELEMEN ARTIKEL
   ========================================= */

/* Link (Tautan): Electric Blue dengan Underline saat Hover */
.article-content a {
    color: #3b82f6;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    border-bottom: 1px solid transparent;
}

.article-content a:hover {
    color: #2dd4bf; /* Berubah cyan saat hover */
    border-bottom: 1px solid #2dd4bf; /* Efek underline */
}

/* Blockquote: Garis Vertikal Gradasi */
.article-content blockquote {
    border-left: 5px solid; /* Persiapan untuk gradient border */
    /* Membuat border gradasi */
    border-image: linear-gradient(to bottom, #3b82f6, #2dd4bf) 1; 
    
    padding-left: 20px;
    margin: 25px 0;
    font-style: italic;
    color: #E2E8F0; /* Sedikit lebih terang dari body text */
    background: rgba(255, 255, 255, 0.02); /* Background sangat tipis */
    padding: 15px 20px;
    border-radius: 0 8px 8px 0;
}

/* Highlight Teks: Background Transparan Biru Muda */
.article-content mark {
    background: rgba(59, 130, 246, 0.2); /* Biru transparan */
    color: #ffffff; /* Teks tetap cerah/putih */
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

/* Ikon IoT: Warna Cyan (#2dd4bf) */
.article-content i.fas, 
.article-content i.fab {
    color: #2dd4bf;
    margin: 0 5px;
    vertical-align: middle;
    text-shadow: 0 0 5px rgba(45, 212, 191, 0.4); /* Efek glow halus pada ikon */
}

/* Responsif untuk Judul di Mobile */
@media (max-width: 768px) {
    .article-wrapper h1 { font-size: 1.8rem; }
    .article-content p { font-size: 1rem; }
}

/* =========================================
   NAVIGASI ARTIKEL
   ========================================= */

/* 1. Short Link "Kembali ke Beranda" di dalam konten */
.back-home-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #3b82f6; /* Electric Blue */
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 15px;
    transition: all 0.3s ease;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
}

.back-home-link i { transition: transform 0.3s; }

.back-home-link:hover {
    color: #2dd4bf; /* Cyan saat hover */
    transform: translateX(-5px); /* Geser sedikit ke kiri */
}

/* 2. Tombol "Back to Top" (Floating Button) */
#backToTop {
    display: none; /* Sembunyi secara default */
    position: fixed;
    bottom: 30px; /* Posisi 30px dari bawah */
    right: 30px;  /* Posisi 30px dari kanan */
    width: 50px;
    height: 50px;
    
    /* Styling Sesuai Tema */
    background: linear-gradient(135deg, #3b82f6 0%, #2dd4bf 100%);
    color: white;
    border-radius: 50%; /* Bentuk Bulat */
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.5); /* Glow Effect */
    z-index: 9999;
    
    /* Center Icon */
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.4s ease;
}

/* State saat tombol muncul (diatur via JS) */
#backToTop.show {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

#backToTop:hover {
    transform: translateY(-5px); /* Naik sedikit saat hover */
    box-shadow: 0 8px 25px rgba(45, 212, 191, 0.6);
}

/* Responsif Mobile */
@media (max-width: 768px) {
    #backToTop {
        bottom: 20px;
        right: 20px;
        width: 45px;
        height: 45px;
        font-size: 1.2rem;
    }
}