@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700&family=Plus+Jakarta+Sans:wght@300;400;500;600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }

:root {
    --font-body: 'Montserrat', sans-serif;
    --font-display: 'Plus Jakarta Sans', sans-serif;
    --green-950: #052e16; --green-900: #14532d; --green-800: #166534; --green-700: #15803d;
    --green-600: #16a34a; --green-500: #22c55e; --green-400: #4ade80; --green-100: #dcfce7; --green-50: #f0fdf4;
    --gold: #b45309; --gold-light:#fef3c7; --red-600: #dc2626; --red-100: #fee2e2;
    --blue-600: #2563eb; --blue-100: #dbeafe;
    --gray-900: #111827; --gray-700: #374151; --gray-500: #6b7280; --gray-300: #d1d5db;
    --gray-100: #f3f4f6; --gray-50: #f9fafb; --white: #ffffff;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08); --shadow-md: 0 4px 16px rgba(0,0,0,0.10); --shadow-lg: 0 8px 32px rgba(0,0,0,0.13);
    --radius-sm: 8px; --radius-md: 12px; --radius-lg: 18px; --radius-xl: 24px;
}

/* ─── TEMA GELAP (DARK MODE) ─── */
[data-theme="dark"] {
    --white: #1e293b;
    --gray-50: #0f172a;
    --gray-100: #334155;
    --gray-300: #475569;
    --gray-500: #94a3b8;
    --gray-700: #e2e8f0;
    --gray-900: #f8fafc;
    --green-50: #064e3b;
    --green-100: #064e3b;
    --red-100: #450a0a;
    --blue-100: #1e3a8a;
    --gold-light: #451a03;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.6);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.7);
}

body { font-family: var(--font-body); background-color: var(--gray-50); color: var(--gray-700); line-height: 1.6; transition: background-color 0.3s ease, color 0.3s ease; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: var(--font-body); outline: none; }
.hidden { display: none !important; }

/* ─── LAYOUT & SIDEBAR ─── */
.topbar { background: var(--green-900); color: #ffffff; display: flex; align-items: center; justify-content: space-between; padding: 0 1.5rem; height: 60px; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow-md); }
.topbar-brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; }
.topbar-brand img { height: 32px; width: auto; object-fit: contain; }
.topbar-nav { display: flex; align-items: center; gap: 10px; }

.layout { display: flex; min-height: calc(100vh - 60px); }
.sidebar { width: 220px; background: var(--white); border-right: 1px solid var(--gray-100); padding: 1.5rem 0; flex-shrink: 0; position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto; transition: background-color 0.3s ease; }
.sidebar-section { margin-bottom: 1.5rem; }
.sidebar-label { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; color: var(--gray-500); padding: 0 1.25rem; margin-bottom: 4px; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 9px 1.25rem; font-size: 0.875rem; font-weight: 500; color: var(--gray-700); border-left: 3px solid transparent; transition: all 0.15s; }
.sidebar a:hover { background: var(--green-50); color: var(--green-700); }
.sidebar a.active { background: var(--green-50); color: var(--green-800); border-left-color: var(--green-600); font-weight: 600; }
.sidebar a .ico { font-size: 1rem; width: 20px; text-align: center; }

.main-content { flex: 1; padding: 2rem; overflow-x: hidden; min-width: 0; }
.page-header { margin-bottom: 1.5rem; }
.page-title { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; color: var(--gray-900); }
.page-subtitle { font-size: 0.875rem; color: var(--gray-500); margin-top: 2px; }

/* ─── STAT CARDS ─── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--white); border-radius: var(--radius-lg); padding: 1.25rem 1.5rem; border: 1px solid var(--gray-100); box-shadow: var(--shadow-sm); display: flex; align-items: center; gap: 1rem; transition: background-color 0.3s ease, border-color 0.3s ease; }
.stat-icon { width: 48px; height: 48px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0; }
.stat-icon.green { background: var(--green-100); } .stat-icon.red { background: var(--red-100); } .stat-icon.gold { background: var(--gold-light); } .stat-icon.blue { background: var(--blue-100); }
.stat-label { font-size: 0.75rem; color: var(--gray-500); margin-bottom: 2px; font-weight: 500; }
.stat-value { font-size: 1.35rem; font-weight: 700; color: var(--gray-900); line-height: 1; }
.stat-value.green { color: var(--green-700); } .stat-value.red { color: var(--red-600); } .stat-value.gold { color: var(--gold); }

/* ─── KARTU, TOMBOL, FORM, BADGE ─── */
.card { background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); border: 1px solid var(--gray-100); padding: 1.5rem; transition: background-color 0.3s ease, border-color 0.3s ease; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 18px; border-radius: var(--radius-sm); font-size: 0.875rem; font-weight: 600; border: none; transition: all 0.15s; }
.btn-primary { background: var(--green-700); color: #ffffff; } .btn-primary:hover { background: var(--green-800); }
.btn-danger { background: var(--red-600); color: #ffffff; } .btn-outline { background: transparent; border: 1.5px solid var(--gray-300); color: var(--gray-700); }
.btn-xs { padding: 3px 8px; font-size: 0.75rem; border-radius: 6px; }
.form-group { margin-bottom: 1rem; } .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--gray-700); margin-bottom: 5px; }
.form-control { width: 100%; padding: 9px 12px; border: 1.5px solid var(--gray-300); border-radius: var(--radius-sm); font-size: 0.875rem; background: var(--white); color: var(--gray-900); transition: background-color 0.3s ease, color 0.3s ease; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; }
.badge-green { background: var(--green-100); color: var(--green-800); } .badge-red { background: var(--red-100); color: var(--red-600); } .badge-gold { background: var(--gold-light); color: var(--gold); } .badge-blue { background: var(--blue-100); color: var(--blue-600); }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 1.25rem; }

/* ─── TABEL ─── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th { background: var(--gray-50); padding: 10px 14px; text-align: left; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--gray-500); border-bottom: 1px solid var(--gray-100); }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--gray-100); color: var(--gray-900); }

/* ─── MODAL ─── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-box { background: var(--white); border-radius: var(--radius-xl); padding: 2rem; width: 100%; max-width: 520px; box-shadow: var(--shadow-lg); transition: background-color 0.3s ease; }
.modal-title { font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; color: var(--gray-900); margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 1.25rem; }

/* ─── LOG PENGGUNA ─── */
.log-item { display: flex; gap: 15px; border-bottom: 1px solid var(--gray-100); padding-bottom: 1rem; margin-bottom: 1rem; }
.user-avatar { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 0.85rem; flex-shrink: 0; }
.avatar-masuk { background: var(--green-100); color: var(--green-800); } .avatar-keluar { background: var(--red-100); color: var(--red-600); }
.log-content { font-size: 0.9rem; font-weight: 600; color: var(--gray-800); } .log-time { font-size: 0.75rem; color: var(--gray-400); margin-top: 4px; }
.chart-container { position: relative; width: 100%; height: 220px; }

/* Default tombol garis tiga disembunyikan di Laptop */
.btn-mobile-menu { display: none; background: transparent; border: none; color: #ffffff; font-size: 1.5rem; cursor: pointer; margin-right: 15px; }

/* ========================================================
   PERBAIKAN TAMPILAN MOBILE (HP) - TUNTAS
   ======================================================== */
@media (max-width: 768px) {
    /* 0. Mencegah layar goyang/meleyot */
    html, body { overflow-x: hidden; width: 100%; position: relative; }
    
    /* 1. Sidebar & Topbar */
    .topbar { padding: 0 1rem; }
    .topbar-brand span { display: none; } /* Sembunyikan teks di HP */
    .btn-mobile-menu { display: block !important; }
    
    .sidebar { 
        position: fixed; 
        left: -260px; 
        top: 60px; 
        height: calc(100vh - 60px); 
        width: 250px; 
        transition: left 0.3s ease-in-out, background-color 0.3s ease; 
        z-index: 9999; 
        box-shadow: 4px 0 10px rgba(0,0,0,0.1); 
        display: block !important;
    }
    .sidebar.show { left: 0; }
    
    /* 2. Konten Utama */
    .main-content { padding: 15px 10px !important; width: 100%; box-sizing: border-box; }
    
    /* 3. FIX CARDS (Agar tidak kepotong seperti di foto 1) */
    .stat-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important; /* Paksa 2 kotak sebaris */
        gap: 10px !important;
    }
    .stat-card {
        padding: 12px 10px !important;
        word-wrap: break-word;
        min-width: 0;
        gap: 8px; /* Jarak ikon dan teks dikurangi */
    }
    .stat-icon { width: 38px; height: 38px; font-size: 1.1rem; } /* Ikon dikecilkan */
    .stat-value { font-size: 1.1rem !important; } /* Nominal dikecilkan */
    .stat-label { font-size: 0.7rem !important; }

    /* 4. FIX TABEL (Agar bisa digeser dan tombol tidak keluar batas seperti di foto 2) */
    .table-wrap, .card, div[style*="overflow-x: auto"] {
        width: 100% !important;
        max-width: 100vw;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 5px;
    }
    table { min-width: 500px !important; width: 100%; }
    th, td { white-space: nowrap !important; }
    
    /* 5. FIX HALAMAN PENGGUNA (Aktivitas biar tidak nyamping seperti foto 3) */
    div[style*="grid-template-columns: repeat(auto-fit"],
    div[style*="grid-template-columns: 2fr 1fr"],
    div[style*="grid-template-columns"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px !important;
    }
}