/* Import Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

:root {
    --primary-color: #4f46e5; /* Indigo Modern */
    --primary-hover: #4338ca;
    --secondary-color: #64748b;
    --background-color: #f1f5f9;
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --text-dark: #1e293b;
    --text-light: #64748b;
    --border-color: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 12px;
    --table-stripe: #f1f5f9; /* Warna baris genap tabel */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
    text-decoration: none;
    list-style: none;
}

body {
    background-color: var(--background-color);
    color: var(--text-dark);
    height: 100vh;
    display: flex;
    transition: background-color 0.3s, color 0.3s; /* Animasi halus saat ganti tema */
}

/* --- Dark Mode Variables --- */
body.dark-mode {
    --background-color: #0f172a;
    --sidebar-bg: #1e293b;
    --card-bg: #1e293b;
    --text-dark: #f1f5f9;
    --text-light: #94a3b8;
    --border-color: #334155;
    --table-stripe: #253045; /* Warna baris genap tabel gelap */
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5);
}

/* --- Utility Classes --- */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: 0.3s;
    font-size: 14px;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-success:hover {
    background-color: #059669;
}

.btn-wa {
    background-color: #25D366;
    color: white;
}

.btn-wa:hover {
    background-color: #128C7E;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-dark);
    font-weight: 500;
    font-size: 14px;
}

.form-control {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    outline: none;
    transition: 0.3s;
    font-size: 14px;
}

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* --- Login Page Styles --- */
.login-container {
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #4f46e5 0%, #818cf8 100%);
}

.login-card {
    background: white;
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-header h2 {
    color: var(--text-dark);
    margin-bottom: 10px;
}

.login-header p {
    color: var(--text-light);
    margin-bottom: 30px;
    font-size: 14px;
}

.login-btn {
    width: 100%;
    margin-top: 10px;
}

/* --- Dashboard Layout --- */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px;
    position: fixed;
    height: 100%;
}

.brand {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between; /* Pisahkan teks dan tombol */
    gap: 10px;
}

.brand-text {
    background: linear-gradient(to right, var(--primary-color), #8b5cf6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.desktop-toggle {
    -webkit-text-fill-color: var(--text-dark);
    font-size: 22px;
    cursor: pointer;
    display: block;
}

@media (max-width: 768px) {
    .desktop-toggle { display: none; }
}

.nav-links li {
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    color: var(--text-light);
    border-radius: 8px;
    transition: 0.3s;
}

.nav-links a:hover, .nav-links a.active {
    background-color: #eff6ff;
    color: var(--primary-color);
}

/* --- Sidebar Collapsed (Minimized) --- */
.sidebar.collapsed {
    width: 80px;
}

.sidebar.collapsed .brand-text,
.sidebar.collapsed .link-text {
    display: none; /* Sembunyikan teks */
}

.sidebar.collapsed .brand {
    justify-content: center; /* Tengahkan icon toggle */
}

.sidebar.collapsed .nav-links a {
    justify-content: center; /* Tengahkan icon menu */
}

.main-content.expanded {
    margin-left: 80px;
    width: calc(100% - 80px);
}

.main-content {
    margin-left: 260px;
    flex: 1;
    padding: 30px;
    width: calc(100% - 260px);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
}

/* --- Dashboard Cards --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 20px;
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    background-color: #eff6ff;
    color: var(--primary-color);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
}

.stat-info h3 {
    font-size: 24px;
    color: var(--text-dark);
}

.stat-info p {
    color: var(--text-light);
    font-size: 14px;
}

/* --- Input Form & Table Section --- */
.content-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 20px;
}

.card {
    background: var(--card-bg);
    padding: 25px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
}

.card-header h3 {
    font-size: 18px;
    color: var(--text-dark);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

th {
    color: var(--text-light);
    font-weight: 600;
}

/* Zebra Striping & Hover Effect (Desktop) */
@media (min-width: 769px) {
    tbody tr:nth-child(even) {
        background-color: var(--table-stripe); /* Gunakan variabel agar berubah saat dark mode */
    }
    tbody tr:hover {
        background-color: #eef2ff; /* Warna indigo muda saat hover */
        transition: background-color 0.2s;
    }
}

/* Hover effect khusus Dark Mode */
body.dark-mode tbody tr:hover {
    background-color: #312e81; /* Indigo gelap */
}

/* --- Mobile Utilities --- */
body.no-scroll {
    overflow: hidden;
}

/* --- Mobile Elements --- */
.menu-toggle, .sidebar-overlay {
    display: none;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

/* Responsive */
@media (max-width: 768px) {
    .menu-toggle {
        display: block;
        font-size: 24px;
        margin-right: 15px;
        cursor: pointer;
        color: var(--text-dark);
    }

    .sidebar { 
        left: -260px; /* Sembunyikan di kiri */
        transition: 0.3s;
        z-index: 1000;
        box-shadow: 4px 0 10px rgba(0,0,0,0.1);
    }
    
    .sidebar.active {
        left: 0; /* Munculkan */
    }

    .sidebar-overlay.active {
        display: block;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }

    .main-content { margin-left: 0; width: 100%; }
    .content-grid { grid-template-columns: 1fr; }

    /* Mobile Optimizations */
    .header h1 { display: none; } /* Sembunyikan judul halaman di HP */
    .header > div:first-child::after {
        content: "BascameWifi";
        font-size: 22px;
        font-weight: 800;
        letter-spacing: -1px;
        background: linear-gradient(to right, var(--primary-color), #8b5cf6);
        -webkit-background-clip: text;
        background-clip: text;
        -webkit-text-fill-color: transparent;
    }
    .user-info span { display: none; } /* Sembunyikan nama user di HP agar rapi */
    
    .login-card {
        padding: 25px;
        width: 90%;
    }

    /* --- Mobile Table (Card View) --- */
    /* Matikan scroll horizontal */
    .table-responsive {
        overflow-x: visible;
    }

    /* Ubah tabel menjadi blok (tumpuk ke bawah) */
    table, thead, tbody, th, td, tr, tfoot { 
        display: block; 
    }
    
    /* Sembunyikan header tabel asli */
    thead tr { 
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    /* Style untuk setiap baris data (seperti kartu) */
    tbody tr { 
        margin-bottom: 15px; 
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: #fff;
        background: var(--card-bg); /* Support Dark Mode */
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        padding: 10px;
    }
    
    /* Style untuk setiap sel data */
    td { 
        border: none;
        border-bottom: 1px solid #eee; 
        position: relative;
        padding-left: 50% !important; /* Ruang untuk label */
        text-align: right;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        min-height: 35px;
    }
    
    /* Membuat Label Judul Kolom di sebelah kiri */
    td:before { 
        position: absolute;
        left: 10px;
        width: 45%; 
        white-space: nowrap;
        text-align: left;
        font-weight: 600;
        color: var(--text-light);
        font-size: 13px;
    }

    /* Label Otomatis untuk Tabel Laporan (Dashboard) */
    #laporanTable tbody td:nth-of-type(1):before { content: "Reseller"; }
    #laporanTable tbody td:nth-of-type(2):before { content: "Periode"; }
    #laporanTable tbody td:nth-of-type(3):before { content: "Total"; }
    #laporanTable tbody td:nth-of-type(4):before { content: "Fee Reseller"; }
    #laporanTable tbody td:nth-of-type(5):before { content: "Fee Admin"; }

    /* Label Otomatis untuk Tabel Reseller */
    #resellerTable tbody td:nth-of-type(1):before { content: "Nama"; }
    #resellerTable tbody td:nth-of-type(2):before { content: "No. HP"; }
    #resellerTable tbody td:nth-of-type(3):before { content: "Alamat"; }
    #resellerTable tbody td:nth-of-type(4):before { content: "Persentase"; }
    #resellerTable tbody td:nth-of-type(6):before { content: "Aksi"; }

    /* Penyesuaian Kolom Aksi (Tombol) */
    td:last-child {
        border-bottom: none;
        padding-left: 10px !important;
        justify-content: center;
        margin-top: 10px;
    }
    td:last-child:before { content: "" !important; }

    /* Penyesuaian Footer Tabel (Total) */
    tfoot tr { border: none; box-shadow: none; background: transparent !important; }
    tfoot td { padding-left: 10px !important; text-align: right; justify-content: space-between; }
    tfoot td:last-child { display: none; } /* Sembunyikan sel kosong */
}

/* --- Modal Styles --- */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
    padding: 15px; /* Tambahkan padding untuk mobile */
}

/* Definisi Keyframes untuk Animasi */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

.modal.active {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.modal.active .modal-content {
    animation: slideUp 0.3s ease-out;
}

.modal-content {
    background-color: var(--card-bg);
    padding: 25px;
    border-radius: var(--radius);
    width: 90%;
    max-width: 550px; /* Sedikit lebih lebar */
    position: relative;
    max-height: 90vh; /* Sedikit lebih tinggi */
    overflow-y: auto;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.2); /* Shadow lebih tegas */
}

/* --- Perbaikan Header Modal --- */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 18px;
    color: var(--text-dark);
    margin: 0; /* Hapus margin default */
}

.modal-close {
    background: var(--background-color);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-light);
    transition: 0.2s;
}

.modal-close:hover {
    background: var(--border-color);
    color: var(--text-dark);
}

/* --- Perbaikan Summary Box di Modal --- */
.modal-summary {
    background-color: var(--background-color);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.modal-summary-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 14px;
}

.modal-summary-row span:first-child {
    color: var(--text-light);
}

.modal-summary-row span:last-child {
    font-weight: 600;
    color: var(--text-dark);
}

.modal-summary-total {
    border-top: 1px dashed #cbd5e1;
    margin-top: 12px;
    padding-top: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-summary-total span:first-child {
    font-weight: 600;
    color: var(--text-dark);
}

.modal-summary-total span:last-child {
    font-weight: 700;
    font-size: 18px;
    color: var(--primary-color);
}

.modal-summary-action {
    margin-top: 15px;
    border-top: 1px solid var(--border-color);
    padding-top: 15px;
}

/* --- Perbaikan Tabel di Modal --- */
.modal-content .table {
    width: 100%;
    border-collapse: collapse;
}

.modal-content .table th,
.modal-content .table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

.modal-content .table th {
    color: var(--text-light);
    font-weight: 600;
}

.modal-content .table tbody tr:last-child td {
    border-bottom: none;
}

/* --- Footer --- */
.footer {
    margin-top: 40px;
    text-align: center;
    color: var(--text-light);
    font-size: 13px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

/* Desktop Optimizations: Mencegah kolom Periode turun baris */
@media (min-width: 769px) {
    #laporanTable td:nth-child(2) {
        white-space: nowrap;
    }
}
