:root {
    /* New Logo Matches: Slate Blue palette */
    --brand-primary: #6e93b3;
    --brand-dark: #476a8a;
    --brand-light: #aec7db;
    --bg-page: #f0f4f8;

    --bg-panel: rgba(255, 255, 255, 0.7);
    --text-primary: #2c3e50;
    --text-secondary: #5a6c7d;

    /* Water Status Colors */
    --status-aman: #4caf50;
    --status-siaga2: #f39c12;
    /* Siaga 2 (Warning) */
    --status-siaga1: #e74c3c;
    /* Siaga 1 (Danger) */

    --water-aman: rgba(76, 175, 80, 0.85);
    --water-siaga2: rgba(243, 156, 18, 0.85);
    --water-siaga1: rgba(231, 76, 60, 0.85);

    --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.06);
    --glass-border: rgba(255, 255, 255, 0.6);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-page);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    background-image: linear-gradient(135deg, #f0f4f8 0%, #e2ebf3 100%);
    background-attachment: fixed;
}

.app-container {
    width: 100%;
    max-width: 480px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    background: #f8fafc;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.05);
}

/* Mobile: atur urutan visual — header atas, konten tengah, nav bawah */
header        { order: 0; }
.bottom-nav   { order: 2; }   /* nav ke bawah meskipun di DOM sebelum main */
.content-area { order: 1; }   /* konten di tengah */

/* Mobile: sembunyikan elemen sidebar yang hanya untuk desktop */
.sidebar-brand,
.sidebar-profile { display: none; }


/* =====================================================
   RESPONSIVE - TABLET (768px+)
   ===================================================== */
@media (min-width: 768px) {
    body {
        align-items: stretch;
    }

    .app-container {
        max-width: 100% !important;
        height: 100vh;
        flex-direction: row !important;
        flex-wrap: nowrap;
    }

    /* Reset order untuk tablet — flex-direction: row jadi urutan DOM */
    .bottom-nav   { order: 0 !important; }
    .content-area { order: 0 !important; }

    header {
        display: none !important;
    }

    /* ── SIDEBAR NAV ── */
    /* display dikontrol oleh JS (style="display:flex" atau "display:none") */
    /* kita hanya override layout properties */
    .bottom-nav {
        position: relative !important;
        bottom: auto !important;
        left: auto !important;
        top: auto !important;
        width: 220px !important;
        height: 100vh !important;
        flex-shrink: 0 !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
        align-items: stretch !important;
        padding: 0 !important;
        border-radius: 0 !important;
        border-right: 1px solid rgba(0,0,0,0.07);
        border-top: none;
        box-shadow: 2px 0 20px rgba(0, 0, 0, 0.05);
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 10;
        /* Tidak ubah display — dikontrol JS */
    }

    /* ── SIDEBAR BRAND (logo + nama app) ── */
    .sidebar-brand {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 24px 20px 20px;
        border-bottom: 1px solid rgba(0,0,0,0.07);
        flex-shrink: 0;
    }

    .sidebar-logo {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        object-fit: cover;
        box-shadow: 0 2px 8px rgba(71, 106, 138, 0.25);
        flex-shrink: 0;
    }

    .sidebar-title {
        font-size: 1.25rem;
        font-weight: 800;
        color: var(--brand-dark);
        letter-spacing: 0.5px;
    }

    /* ── SIDEBAR PROFILE (profile di bawah sidebar) ── */
    .sidebar-profile {
        display: flex;
        flex-direction: column;
        margin-top: auto;
        border-top: 1px solid rgba(0,0,0,0.07);
        flex-shrink: 0;
    }

    .sidebar-profile-trigger {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 16px 20px;
        cursor: pointer;
        transition: background 0.2s;
    }

    .sidebar-profile-trigger:hover {
        background: rgba(110, 147, 179, 0.08);
    }

    .sidebar-avatar {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: linear-gradient(135deg, #3498db, #2c3e50);
        color: #fff;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
        font-size: 0.95rem;
        flex-shrink: 0;
        box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
    }

    .sidebar-profile-info {
        display: flex;
        flex-direction: column;
        flex: 1;
        overflow: hidden;
    }

    .sidebar-profile-name {
        font-size: 0.88rem;
        font-weight: 700;
        color: var(--text-primary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar-profile-role {
        font-size: 0.75rem;
        color: var(--text-secondary);
    }

    .sidebar-chevron {
        width: 20px;
        height: 20px;
        fill: var(--text-secondary);
        flex-shrink: 0;
        transition: transform 0.2s;
    }

    .sidebar-profile-dropdown {
        display: none;
        background: rgba(110, 147, 179, 0.06);
        border-top: 1px solid rgba(0,0,0,0.05);
    }

    .sidebar-profile-dropdown.open {
        display: block;
    }

    .sidebar-dd-item {
        padding: 12px 20px;
        font-size: 0.85rem;
        cursor: pointer;
        color: var(--text-primary);
        transition: background 0.2s;
    }

    .sidebar-dd-item:hover {
        background: rgba(110, 147, 179, 0.12);
    }

    .sidebar-dd-logout {
        color: #e74c3c;
    }

    /* ── NAV ITEMS: paksa jadi horizontal list di sidebar ── */
    .nav-item {
        flex: 0 0 auto !important;       /* jangan stretch */
        width: 100% !important;
        display: flex !important;
        flex-direction: row !important;   /* icon + label sejajar */
        justify-content: flex-start !important;
        align-items: center !important;
        gap: 14px !important;
        padding: 15px 24px !important;
        font-size: 0.9rem !important;
        border-radius: 0 !important;
        color: var(--text-secondary);
        cursor: pointer;
        transition: background 0.2s, color 0.2s;
    }

    .nav-item:hover {
        background: rgba(110, 147, 179, 0.08);
        color: var(--brand-primary);
    }

    .nav-item svg {
        width: 22px !important;
        height: 22px !important;
        flex-shrink: 0 !important;
        fill: currentColor;
    }

    .nav-item span {
        font-size: 0.88rem !important;
        font-weight: 600 !important;
        white-space: nowrap;
    }

    /* Emoji icon di admin nav */
    .nav-item > span:first-child:not(:last-child) {
        font-size: 1.2rem !important;
    }

    .nav-item.active {
        background: rgba(110, 147, 179, 0.13) !important;
        color: var(--brand-primary) !important;
        border-left: 3px solid var(--brand-primary);
        padding-left: 21px !important;
    }

    .nav-item.active svg {
        transform: none !important;
    }

    /* ── CONTENT AREA ── */
    .content-area {
        flex: 1 !important;
        padding: 32px 40px !important;
        padding-bottom: 32px !important;
        overflow-y: auto;
        height: 100vh;
    }

    /* Admin navbar juga menjadi sidebar */
    #admin-navbar {
        width: 220px !important;
    }

    /* Profile wrapper di header sudah hidden */
    #profile-wrapper {
        display: none !important;
    }
}

/* =====================================================
   RESPONSIVE - DESKTOP (1024px+)
   ===================================================== */
@media (min-width: 1024px) {
    .app-container {
        max-width: 1280px;
        margin: 0 auto;
        box-shadow: 0 0 60px rgba(0, 0, 0, 0.08);
    }

    .bottom-nav {
        width: 260px !important;
    }

    #admin-navbar {
        width: 260px !important;
    }

    .content-area {
        padding: 40px 56px !important;
    }
}

/* Header */
header {
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    z-index: 10;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

h1 {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--brand-dark);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-page);
    padding: 6px 12px;
    border-radius: 20px;
}

.dot {
    width: 8px;
    height: 8px;
    background-color: #ccc;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.dot.connected {
    background-color: var(--status-aman);
}

.dot.error {
    background-color: var(--status-siaga1);
}

/* Main Content Area */
.content-area {
    flex-grow: 1;
    overflow-y: auto;
    padding: 24px 20px;
    padding-bottom: 90px;
    /* Space for bottom nav */
}

/* Views Management */
.view-section {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view-section.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-title {
    font-size: 1.25rem;
    color: var(--brand-dark);
    margin-bottom: 20px;
    font-weight: 700;
}
