/* Base & Typography */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

body { 
    font-family: 'Inter', sans-serif; 
    background-color: #383838; 
    margin: 0; 
    padding: 10px; 
    color: #1e293b; 
}

.container { 
    background: #aab4b4; 
    padding: 20px; 
    border-radius: 12px; 
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); 
    max-width: 1200px; 
    margin: 0 auto; 
}

h2, h3 { margin-top: 0; color: #0f172a; }

/* === ANTI AUTO ZOOM === */
input, select, textarea { 
    font-size: 16px !important; 
    width: 100%; 
    padding: 12px 15px; 
    margin-bottom: 12px; 
    border: 1px solid #cbd5e1; 
    border-radius: 8px; 
    box-sizing: border-box; 
    outline: none;
    background-color: #f8fafc;
}
input:focus { border-color: #3b82f6; background-color: #ffffff; }

/* Buttons */
button { 
    padding: 10px 12px; 
    background: #3b82f6; 
    color: white; 
    border: none; 
    border-radius: 8px; 
    cursor: pointer; 
    font-weight: 600; 
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
button:disabled { background: #94a3b8; cursor: not-allowed; }
.btn-primary { background: #3b82f6; }
.btn-warning { background: #f59e0b; }
.btn-danger { background: #ef4444; }
.btn-success { background: #10b981; }
.btn-info { background: #0ea5e9; }

/* Header & Pencarian */
.header-actions { margin-bottom: 20px; }
.header-actions h2 { margin-bottom: 15px; text-align: center; }

#searchInput { margin-bottom: 20px; border-radius: 20px; padding-left: 20px; }

/* === STYLING TABEL DESKTOP === */
.table-wrapper { width: 100%; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 16px 12px; text-align: left; border-bottom: 1px solid #e2e8f0; font-size: 12px; }
th { background: #f8fafc; color: #475569; font-weight: 600; text-transform: uppercase; font-size: 10px; }

/* Badges */
.badge { padding: 4px 8px; border-radius: 6px; font-weight: 600; font-size: 11px; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* Terminal */
.log-container { background-color: #0f172a; border-radius: 8px; margin-top: 5px; overflow: hidden; }
.log-header { background: #1e293b; color: #94a3b8; padding: 10px 15px; font-size: 10px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.btn-clear-log { background: #334155; color: #ef4444; padding: 4px 10px; font-size: 10px; border-radius: 6px; }
.log-content { max-height: 150px; overflow-y: auto; padding: 12px; font-size: 10px; color: #4ade80; font-family: monospace; line-height: 1.6; }
.log-content div { border-bottom: 1px dashed #334155; padding-bottom: 4px; margin-bottom: 4px; }

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15,23,42,0.7); backdrop-filter: blur(4px); z-index: 1000; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #fff; padding: 25px; border-radius: 16px; width: 90%; max-width: 400px; z-index: 1001; display: none; box-sizing: border-box; }
.modal-buttons { display: flex; gap: 10px; margin-top: 15px; }
.modal-buttons button { flex: 1; }

/* Floating Window / Iframe */
/* === PERBAIKAN POSISI ISI TOPUP AGAR TIDAK TERTUTUP HEADER === */
.floating-window { 
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 92% !important;
    max-width: 420px !important;
    height: 85vh !important;
    max-height: 580px !important;
    background: #ffffff !important;
    border-radius: 16px !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4) !important;
    border: none !important;
    z-index: 1002 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

.window-header { 
    background: #0f172a !important; 
    padding: 10px 14px !important; 
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    flex-shrink: 0 !important; /* Mencegah header menyusut */
    z-index: 10 !important;
}

/* Memastikan iframe turun ke bawah dan tidak tertutup header gelap */
.floating-window .window-content {
    width: 100% !important;
    height: calc(100% - 40px) !important;
    flex: 1 !important;
    border: none !important;
    background: #ffffff !important;
    overflow: hidden !important;
}

.floating-window .window-content iframe {
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    display: block !important;
}

/* =========================================================
   MAGIC MOBILE RESPONSIVE (Card UI Layout & Button Grid)
   ========================================================= */
@media (max-width: 768px) {
    body { padding: 5px; }
    .container { 
        background: transparent; /* Membuat container transparan di mobile agar menyatu dengan body */
        box-shadow: none;
        padding: 10px; 
    }
    
    /* Tombol Header HP (Grid 2 Kolom) */
    .header-actions div { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
    .header-actions div button { width: 100%; font-size: 11px; padding: 10px 5px; }
    .header-actions div button:nth-child(3) { grid-column: span 2; } /* Refresh Ceklist Full Width */
    .header-actions div button:nth-child(4) { grid-column: span 2; } /* Logout Full Width */

    /* Menghilangkan format Tabel Klasik */
    table, thead, tbody, th, td, tr { display: block; }
    thead tr { display: none; } /* Sembunyikan Header Kolom di HP */

    /* Desain Kartu (Row Utama) */
    tr {
        background: #fff;
        margin-bottom: 15px;
        border-radius: 12px;
        border: 1px solid #e2e8f0;
        box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
        padding: 15px;
    }

    /* List Isi Data (Kiri Label, Kanan Value) */
    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border: none;
        padding: 8px 0;
        border-bottom: 1px dashed #e2e8f0;
    }
    
    td:last-child { border-bottom: none; } /* Hilangkan garis pada Kolom Aksi */
    
    /* Memunculkan Nama Kolom di Sebelah Kiri Data */
    td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #64748b;
        font-size: 11px;
        min-width: 70px;
    }

    /* Khusus Checkbox HP */
    td[data-label="Pilih"] { justify-content: flex-end; }
    td[data-label="Pilih"]::before { margin-right: auto; }
    td[data-label="Pilih"] input { width: 20px; height: 20px; margin: 0;}

    /* === GRID TOMBOL AKSI DI HP === */
    .action-buttons {
        display: grid !important;
        grid-template-columns: 1fr 1fr; /* Membagi tombol jadi Kiri Kanan */
        gap: 10px;
        margin-top: 15px;
        width: 100%;
    }
    .action-buttons::before { display: none; } /* Hilangkan label 'Aksi' */
    
    .action-buttons button { margin: 0; width: 100%; padding: 12px 0; font-size: 11px; }
    .action-buttons .btn-terminal { grid-column: span 1; } /* Tombol Terminal Full Lebar */

/* Perbaikan Row Log Terminal agar menyatu di Mobile */
    tr.terminal-open {
        border-bottom-left-radius: 0 !important;
        border-bottom-right-radius: 0 !important;
        border-bottom: none !important;
        margin-bottom: 0 !important; 
    }

    tr.log-row-card {
        background: #fff;
        padding: 0 15px 15px 15px; 
        margin-top: 0; 
        margin-bottom: 15px; 
        border: 1px solid #e2e8f0;
        border-top: none; 
        border-radius: 0 0 12px 12px; 
        box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); 
    }

    /* Tambahkan baris ini di bawahnya */
    tr.log-row-card[style*="table-row"] {
        display: block !important;
    }

    tr.log-row-card td { padding: 0; border: none; }
    tr.log-row-card td::before { display: none; }
    
    .log-container { margin-top: 10px; }
}

/* Tampilan Desktop & Tablet Lebar */
@media (min-width: 769px) {
    .header-actions { display: flex; justify-content: space-between; align-items: center; }
    .header-actions h2 { margin-bottom: 0; }
    .action-buttons button { margin-right: 4px; margin-bottom: 4px; }
}

/* Styling Khusus Checkbox Mobile */
.mobile-action-bar { 
    display: none; 
    margin-bottom: 15px; 
    background: #fff; 
    padding: 12px 15px; 
    border-radius: 12px; 
    border: 1px solid #e2e8f0; 
    font-weight: 600; 
    font-size: 12px; 
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

.mobile-action-bar input { 
    width: 20px !important; 
    height: 20px; 
    margin: 0 10px 0 0 !important; 
    vertical-align: middle; 
}

.mobile-action-bar label {
    display: flex;
    align-items: center;
    cursor: pointer;
    color: #475569;
}

/* Munculkan di semua layar (Hapus max-width) */
.mobile-action-bar { display: block; }

/* === STYLING DROPDOWN AKSI MASSAL === */
#bulkActions {
    background: #ffffff;
    padding: 12px 15px;
    margin-bottom: 15px;
    border-radius: 12px;
    border: 1px solid #cbd5e1;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    gap: 15px;
}

#bulkActions select {
    margin-bottom: 0; /* Mencegah turun ke bawah */
    max-width: 250px;
    cursor: pointer;
    background-color: #ffffff;
}

/* Responsif untuk layar HP */
@media (max-width: 768px) {
    #bulkActions {
        flex-direction: column;
        align-items: stretch;
    }
    #bulkActions select {
        max-width: 100%;
    }
}

/* =========================================================
   PERBAIKAN FINAL: EFEK LOADING & PESAN (ANTI-BREAK TABLE)
   ========================================================= */

/* 1. DESKTOP: Matikan efek pada TR agar kolom tabel tidak rusak */
/* =========================================================
   PERBAIKAN FINAL: EFEK LOADING & PESAN (UNIFIED)
   ========================================================= */

/* 1. Posisi relative pada TR Utama (Card) */
.card-main.loading-overlay-active, 
.card-main.overlay-message-active {
    position: relative !important;
    pointer-events: none;
}

/* 2. Efek Blur Latar Belakang */
.card-main.loading-overlay-active::before, 
.card-main.overlay-message-active::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(4px);
    z-index: 10;
    border-radius: inherit; /* Supaya blur mengikuti lengkungan kotak */
    display: block !important;
}

/* 3. Efek Spinner Loading */
.card-main.loading-overlay-active::after {
    content: "";
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 35px; height: 35px;
    border: 4px solid #cbd5e1;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 11;
    display: block !important;
}

/* 4. Efek Notifikasi Pesan (Fix Teks & Rounded Mobile/Desktop) */
.card-main.overlay-message-active::after {
    content: attr(data-msg) !important; /* Ambil teks dari TR */
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 11;
    
    font-weight: 700;
    font-size: 13px;
    color: white;
    text-align: center;
    
    /* Fix lengkungan & padding */
    padding: 12px 24px;
    border-radius: 30px !important; /* Paksa lengkung sempurna */
    width: max-content;
    min-width: 200px; /* Minimal lebar di desktop */
    max-width: 90%;
    box-sizing: border-box;
    
    line-height: 1.5;
    white-space: normal; /* Biarkan teks turun jika panjang */
    word-wrap: break-word;
    
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: flex !important;
    align-items: center;
    justify-content: center;
}

.card-main.msg-success::after { background: #10b981 !important; }
.card-main.msg-error::after { background: #ef4444 !important; }

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* =========================================
   FIX LAYOUT: HEADER, PHONE, & ACTION BUTTONS
   ========================================= */

/* 1. Header Desktop Layout */
.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}
.header-action-group {
    display: flex;
    gap: 10px;
}

/* 2. Container No HP & Reff Desktop */
.phone-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.reff-wrapper {
    font-size: 12px;
    color: #64748b;
    margin-top: 4px;
    display: flex;
    align-items: center;
}
.btn-copy {
    padding: 2px 6px;
    font-size: 10px;
    background: #64748b;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin: 0;
}
.btn-copy:hover {
    background: #475569;
}

/* 3. Action Buttons Desktop (Memaksa 1 Baris Penuh) */
.action-buttons {
    display: flex;
    flex-wrap: nowrap !important; /* Mencegah tombol turun (wrap) */
    gap: 5px;
    align-items: center;
    white-space: nowrap; /* Mencegah teks dalam tombol turun */
}
.action-buttons button {
    margin: 0 !important; /* Menghilangkan margin jika ada bawaan template */
}

/* =========================================
   MOBILE RESPONSIVE TWEAKS (Maks 768px)
   ========================================= */
@media (max-width: 768px) {
    /* Header Mobile: Logout di atas, Tambah & Register di bawah */
    .header-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .header-actions .btn-logout {
        width: 100%;
    }
    .header-action-group {
        width: 100%;
        justify-content: space-between;
    }
    .header-action-group button {
        flex: 1; /* Membagi dua rata ukuran tombol */
    }

    /* Merapikan posisi No HP di Mobile (Rata Kanan) */
    td[data-label="Phone"] {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
    }
    .phone-wrapper {
        align-items: flex-end; /* Memaksa teks rata kanan dari label flexbox */
        text-align: right;
    }
    .reff-wrapper {
        justify-content: flex-end; /* Memaksa label Reff rata kanan */
    }

    /* Action buttons di mobile: biarkan turun baris (wrap) agar layar tidak kepanjangan */
    .action-buttons {
        flex-wrap: wrap !important;
        justify-content: flex-end;
    }
}

/* =========================================================
   PERBAIKAN LAYOUT CARD UI (MENIMPA STYLE LAMA)
   ========================================================= */

/* Hapus Header Tabel & Format Ulang Tabel */
thead { display: none !important; }
table, tbody { display: block !important; width: 100% !important; background: transparent !important; }

/* --- BARIS UTAMA (COLLAPSED) --- */
.card-main { 
    display: block !important; 
    position: relative;
    background: #ffffff !important; 
    border-radius: 12px !important; 
    margin-bottom: 12px !important; 
    box-shadow: 0 7px 7px rgba(0,0,0,0.06) !important; 
    border: 1px solid #e2e8f0 !important; 
    transition: all 0.1s;
}
.card-main.expanded { 
    border-bottom-left-radius: 0 !important; 
    border-bottom-right-radius: 0 !important; 
    border-bottom: none !important; 
    margin-bottom: 0 !important; 
}

.card-td-main { 
    display: block !important; 
    padding: 10px 15px !important; /* Diperbesar agar di Desktop tidak terlalu tipis/gepeng */
    border: none !important; 
    cursor: pointer; 
}
.card-td-main::before { display: none !important; }

.card-header { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.card-title { display: flex; align-items: center; gap: 12px; font-weight: 500; color: #1e293b; font-size: 12px; }
.card-title input[type="checkbox"] { margin: 0 !important; width: 18px !important; height: 18px !important; cursor: pointer; }

.card-status { display: flex; align-items: center; gap: 12px; }
.badge-online { font-size: 12px; font-weight: 700; color: #10b981; }
.badge-offline { font-size: 12px; font-weight: 600; color: #64748b; }
.toggle-icon { font-size: 8px; color: #94a3b8; font-weight: bold; }

/* --- BARIS DETAIL (EXPANDED) --- */
.card-detail { 
    display: block; 
    background: #f8fafc !important; 
    border-radius: 0 0 12px 12px !important; 
    margin-bottom: 12px !important; 
    border: 1px solid #e2e8f0 !important; 
    border-top: 1px dashed #cbd5e1 !important; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.06) !important;
}
.card-td-detail { 
    display: block !important; 
    padding: 5px 5px !important; /* Diperbesar agar rapi di layat lebar */
    border: none !important; 
}
.card-td-detail::before { display: none !important; }
.card-td-detail::before { display: none !important; }

/* Informasi Saldo, Poin & Reff */
.detail-stats { display: flex; flex-wrap: wrap; gap: 15px; margin-bottom: 15px; font-size: 12px; align-items: center; color: #475569; }
.reff-box { margin-left: auto; display: flex; align-items: center; gap: 6px; }

/* Tombol Aksi */
.action-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 15px; }
.action-grid button { margin: 0 !important; flex: 1 1 auto; justify-content: center; padding: 10px 12px; font-size: 12px; }

/* Perbaikan Terminal Overlap */
.log-container { margin-top: 0 !important; border: 1px solid #334155; width: 100%; box-sizing: border-box; }

/* --- RESPONSIVE MOBILE TWEAKS --- */
@media (max-width: 768px) {
    /* Menipiskan frame utama di Mobile */
    .card-td-main {
        padding: 10px 10px !important; 
    }
    
    /* Menipiskan padding sisi kiri/kanan di dalam detail (Mobile) */
    .card-td-detail {
        padding: 5px 5px !important; 
    }

    .card-title { font-size: 13px; gap: 8px; }
    .card-status { gap: 8px; }
    
    .detail-stats { flex-direction: column; align-items: flex-start; gap: 10px; }
    .reff-box { margin-left: 0; width: 100%; }
    
    /* Tombol grid 2 kolom rapi di HP */
    .action-grid { display: grid !important; grid-template-columns: 1fr 1fr; width: 100%; gap: 6px; }
    
    /* Menipiskan sedikit tombol agar hemat ruang vertikal */
    .action-grid button { width: 100% !important; padding: 8px 8px !important; font-size: 12px; } 
}

/* =========================================
   UI PROXY MINIMALIS & RESPONSIVE
   ========================================= */
.proxy-wrapper {
    background: #ffffff;
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}
.proxy-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}
.proxy-title {
    font-weight: 700;
    color: #1e293b;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.proxy-status {
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    background: #f8fafc;
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
}
.proxy-body {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.proxy-input {
    flex: 1;
    min-width: 250px;
    padding: 10px 15px !important; 
    margin-bottom: 0 !important; /* Mencegah bentrok dengan margin input default */
    background: #f8fafc;
}
.proxy-btn {
    padding: 10px 20px;
    font-size: 12px;
    margin: 0 !important; /* Mencegah bentrok dengan margin tombol default */
}

/* Responsif Proxy untuk Layar HP */
@media (max-width: 768px) {
    .proxy-body { flex-direction: column; }
    .proxy-input, .proxy-btn { width: 100%; flex: none; }
}