/* 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: #f1f5f9; 
    margin: 0; 
    padding: 10px; 
    color: #1e293b; 
}

.container { 
    background: #ffffff; 
    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: 14px;
    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: 14px; }
th { background: #f8fafc; color: #475569; font-weight: 600; text-transform: uppercase; font-size: 12px; }

/* Badges */
.badge { padding: 4px 8px; border-radius: 6px; font-weight: 600; font-size: 13px; }
.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: 12px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.btn-clear-log { background: #334155; color: #ef4444; padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.log-content { max-height: 150px; overflow-y: auto; padding: 12px; font-size: 12px; 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 { padding: 15px; }
    
    /* 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: 13px; padding: 12px 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: 13px;
        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: 13px; }
    .action-buttons .btn-terminal { grid-column: span 1; } /* Tombol Terminal Full Lebar */

    /* Perbaikan Row Log Terminal agar rapi di Mobile */
    tr.log-row-card {
        padding: 0;
        margin-top: -20px; /* Menempel ke Kartu atasnya */
        border-top-left-radius: 0;
        border-top-right-radius: 0;
        border-top: none;
        box-shadow: none;
    }
    tr.log-row-card td { padding: 0; }
    tr.log-row-card td::before { display: none; } /* Hilangkan Label buatan CSS */
}

/* 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: 14px; 
    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 hanya di mode HP */
@media (max-width: 768px) {
    .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 */
.loading-overlay-active, .overlay-message-active {
    position: static !important;
    transform: none !important;
    pointer-events: none;
}

.loading-overlay-active::before, .overlay-message-active::before,
.loading-overlay-active::after, .overlay-message-active::after {
    display: none !important;
}

/* 2. DESKTOP: Terapkan Blur per Sel (TD) secara terpisah */
.loading-overlay-active td, .overlay-message-active td {
    position: relative;
}

.loading-overlay-active td::before, .overlay-message-active td::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;
}

/* 3. DESKTOP: Tampilkan Spinner khusus di atas Kolom Aksi (TD Terakhir) */
.loading-overlay-active td:last-child::after {
    content: "";
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 30px; height: 30px;
    border: 4px solid #cbd5e1;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 11;
    display: block !important;
}

/* 4. DESKTOP: Tampilkan Teks Pesan khusus di atas Kolom Aksi */
.overlay-message-active td:last-child::after {
    content: attr(data-msg); /* Membaca teks dari TD */
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 11;
    font-weight: 700;
    font-size: 13px;
    padding: 8px 16px;
    border-radius: 8px;
    color: white;
    white-space: normal;
    text-align: center;
    width: max-content;
    max-width: 95%;
    line-height: 1.5;
    word-wrap: break-word;
    display: block !important;
}

.msg-success td:last-child::after { background: #10b981; }
.msg-error td:last-child::after { background: #ef4444; }


/* =========================================================
   MODE MOBILE (KEMBALI MENGGUNAKAN TR OVERLAY)
   ========================================================= */
@media (max-width: 768px) {
    /* Di Mobile, TR berbentuk Card, jadi aman dipasangi position relative */
    .loading-overlay-active, .overlay-message-active {
        position: relative !important;
    }
    
    /* Aktifkan kembali blur & pesan penuh di TR untuk mobile */
    .loading-overlay-active::before, .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;
        display: block !important;
    }

    .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;
    }

    .overlay-message-active::after {
        content: attr(data-msg); /* Di mobile, membaca langsung dari atribut parent TR */
        position: absolute;
        top: 50%; left: 50%;
        transform: translate(-50%, -50%);
        z-index: 11;
        font-weight: 700;
        font-size: 13px;
        padding: 8px 16px;
        border-radius: 8px;
        color: white;
        white-space: normal;
        text-align: center;
        width: max-content;
        max-width: 90%;
        line-height: 1.5;
        word-wrap: break-word;
        display: block !important;
    }

    .msg-success::after { background: #10b981 !important; }
    .msg-error::after { background: #ef4444 !important; }
}


/* =========================================
   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: 11px;
    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;
    }
}