/* Phase 10.AM — Buy confirm modal. Vanilla, no framework. */

.bm-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.bm-backdrop.is-open { opacity: 1; pointer-events: auto; }

.bm-modal {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -48%) scale(0.96);
    /* Tăng width 520→760 để hiển thị credentials đầy đủ (refresh_token + cookie long string) */
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - 40px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 30px 80px rgba(0,0,0,0.25);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
    display: flex; flex-direction: column;
}
.bm-modal.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

/* ── Header ─────────────────────────────────────── */
.bm-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #F1F5F9;
}
.bm-head h3 {
    margin: 0;
    font: 600 16px/1.2 'Be Vietnam Pro', system-ui, sans-serif;
    color: #111827;
    display: inline-flex; align-items: center; gap: 8px;
}
.bm-head h3 i { color: #13A459; font-size: 18px; }
.bm-close {
    width: 30px; height: 30px; border: 0; background: #F3F4F6;
    border-radius: 50%; cursor: pointer; color: #6B7280;
    display: inline-flex; align-items: center; justify-content: center;
    transition: 0.15s;
}
.bm-close:hover { background: #E5E7EB; color: #111827; }

/* Detail link in header (open SEO product page) */
.bm-detail-link {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 5px 10px;
    background: #ECFDF5;
    color: #047857;
    border-radius: 6px;
    font: 500 11px 'Be Vietnam Pro', sans-serif;
    text-decoration: none;
    margin-right: 4px;
    transition: 0.15s;
}
.bm-detail-link:hover { background: #D1FAE5; color: #065F46; }
.bm-detail-link[hidden] { display: none; }
.bm-detail-link i { font-size: 10px; }

/* ── Body ───────────────────────────────────────── */
.bm-body { padding: 18px 20px 8px; overflow-y: auto; }

.bm-product {
    display: flex; gap: 14px; align-items: flex-start;
    padding: 14px;
    background: #F9FAFB;
    border-radius: 12px;
    margin-bottom: 14px;
}
.bm-product-img {
    width: 96px; height: 96px; border-radius: 12px;
    background: #fff; overflow: hidden;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    border: 1px solid #E5E7EB;
}
.bm-product-img img { width: 100%; height: 100%; object-fit: cover; }
.bm-product-img i { font-size: 36px; color: #9CA3AF; }
.bm-product-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.bm-product-name {
    font: 600 15px/1.35 'Be Vietnam Pro', system-ui, sans-serif;
    color: #1F2937;
    margin: 0;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
}
.bm-product-meta {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    font: 500 12px 'Be Vietnam Pro', sans-serif;
}
.bm-product-meta .bm-brand { display: inline-flex; align-items: center; gap: 4px; color: #374151; }
.bm-product-meta .bm-brand i { font-size: 13px; }
.bm-product-meta .bm-flag { width: 22px; height: 16px; object-fit: cover; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,0.1); }
.bm-product-meta .bm-quality {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 99px;
    font: 600 11px 'Be Vietnam Pro', sans-serif;
}
.bm-product-meta .bm-stock {
    display: inline-flex; align-items: center; gap: 4px;
    font: 500 11px 'Be Vietnam Pro', sans-serif;
    padding: 2px 8px; border-radius: 6px;
}
.bm-product-meta .bm-stock i { font-size: 6px; }
.bm-product-meta .bm-stock.ok { background: #ECFDF5; color: #047857; }
.bm-product-meta .bm-stock.low { background: #FFFBEB; color: #B45309; }
.bm-product-meta .bm-stock.empty { background: #FEF2F2; color: #B91C1C; }
.bm-product-price { font: 500 12px 'Be Vietnam Pro', sans-serif; color: #6B7280; margin-top: auto; }
.bm-product-price strong { color: #DC2626; font-weight: 700; font-size: 14px; }

.bm-product-chips {
    display: flex; flex-wrap: wrap; gap: 5px;
    margin: 0 0 12px;
}
.bm-product-chips .bm-chip {
    font: 500 11px 'Be Vietnam Pro', sans-serif;
    padding: 3px 9px;
    border-radius: 6px;
    background: #ECFDF5;
    color: #047857;
}
.bm-product-desc {
    font: 400 12px/1.5 'Be Vietnam Pro', sans-serif;
    color: #6B7280;
    background: #F9FAFB;
    border-left: 3px solid #E5E7EB;
    padding: 8px 12px;
    border-radius: 0 6px 6px 0;
    margin-bottom: 14px;
}

/* Qty stepper */
.bm-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 0;
}
.bm-row + .bm-row { border-top: 1px dashed #F1F5F9; }
.bm-label { font: 500 13px 'Be Vietnam Pro', sans-serif; color: #4B5563; }
.bm-qty {
    display: inline-flex; align-items: center; gap: 0;
    border: 1px solid #E5E7EB; border-radius: 8px; overflow: hidden;
}
.bm-qty button {
    width: 34px; height: 34px; border: 0; background: #fff;
    cursor: pointer; color: #4B5563; font-size: 16px; font-weight: 600;
    transition: 0.15s;
}
.bm-qty button:hover:not(:disabled) { background: #F3F4F6; color: #111827; }
.bm-qty button:disabled { opacity: 0.4; cursor: not-allowed; }
.bm-qty input {
    width: 64px; height: 34px; border: 0; text-align: center;
    font: 600 14px 'Be Vietnam Pro', sans-serif; color: #1F2937;
    border-left: 1px solid #E5E7EB; border-right: 1px solid #E5E7EB;
    background: #fff;
    -moz-appearance: textfield;
}
.bm-qty input::-webkit-outer-spin-button,
.bm-qty input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.bm-qty-hint { font: 400 11px 'Be Vietnam Pro', sans-serif; color: #9CA3AF; margin-left: 8px; }

/* Total amount highlight */
.bm-total {
    margin: 12px 0 8px;
    padding: 14px 16px;
    border-radius: 12px;
    background: linear-gradient(135deg, #ECFDF5 0%, #D1FAE5 100%);
    display: flex; align-items: center; justify-content: space-between;
    transition: background 0.25s;
}
.bm-total .lbl { font: 500 12px 'Be Vietnam Pro', sans-serif; color: #047857; text-transform: uppercase; letter-spacing: 0.4px; }
.bm-total .val {
    font: 800 22px/1.1 'Be Vietnam Pro', sans-serif;
    background: linear-gradient(135deg, #065F46 0%, #10B981 100%);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}
.bm-modal.is-insufficient .bm-total {
    background: linear-gradient(135deg, #FEF2F2 0%, #FEE2E2 100%);
}
.bm-modal.is-insufficient .bm-total .lbl { color: #B91C1C; }
.bm-modal.is-insufficient .bm-total .val {
    background: linear-gradient(135deg, #991B1B 0%, #EF4444 100%);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Balance row */
.bm-balance {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-radius: 10px;
    background: #F9FAFB;
    margin-top: 4px;
    font: 500 13px 'Be Vietnam Pro', sans-serif;
}
.bm-balance .lbl { color: #6B7280; display: inline-flex; align-items: center; gap: 6px; }
.bm-balance .lbl i { color: #9CA3AF; }
.bm-balance .val { color: #047857; font-weight: 700; }
.bm-balance.is-insufficient { background: #FEF2F2; }
.bm-balance.is-insufficient .val { color: #DC2626; }
.bm-balance.is-insufficient .lbl i { color: #DC2626; }

.bm-warn {
    margin-top: 8px;
    padding: 10px 14px;
    background: #FEF2F2;
    border-left: 3px solid #DC2626;
    border-radius: 6px;
    font: 500 12px/1.4 'Be Vietnam Pro', sans-serif;
    color: #B91C1C;
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.bm-modal.is-insufficient .bm-warn { display: flex; }
.bm-warn a {
    color: #fff; background: #DC2626;
    padding: 5px 12px; border-radius: 6px;
    text-decoration: none; font-weight: 600; font-size: 11px;
    white-space: nowrap;
    transition: 0.15s;
}
.bm-warn a:hover { background: #B91C1C; }

/* ── Footer ─────────────────────────────────────── */
.bm-foot {
    display: flex; gap: 10px;
    padding: 14px 20px 18px;
    border-top: 1px solid #F1F5F9;
    background: #FAFBFC;
}
.bm-btn {
    flex: 1;
    height: 44px;
    border-radius: 10px;
    border: 0;
    cursor: pointer;
    font: 600 14px 'Be Vietnam Pro', sans-serif;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    transition: 0.15s;
}
.bm-btn-cancel { background: #F3F4F6; color: #4B5563; }
.bm-btn-cancel:hover { background: #E5E7EB; color: #1F2937; }
.bm-btn-confirm {
    background: linear-gradient(135deg, #13A459 0%, #10B981 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(19, 164, 89, 0.25);
}
.bm-btn-confirm:hover:not(:disabled) {
    box-shadow: 0 6px 18px rgba(19, 164, 89, 0.35);
    transform: translateY(-1px);
}
.bm-btn-confirm:disabled {
    background: #D1D5DB; color: #fff;
    box-shadow: none; cursor: not-allowed; transform: none;
}
.bm-btn .spinner {
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: bm-spin 0.7s linear infinite;
    display: none;
}
.bm-btn.is-loading .spinner { display: inline-block; }
.bm-btn.is-loading .label { opacity: 0.85; }
.bm-btn.is-loading i { display: none; }
@keyframes bm-spin { to { transform: rotate(360deg); } }

/* ── State switching ────────────────────────────── */
.bm-state-confirm, .bm-state-processing, .bm-state-success, .bm-state-error { display: none; }
.bm-modal[data-bm-state="confirm"]    .bm-state-confirm    { display: flex; flex-direction: column; min-height: 0; }
.bm-modal[data-bm-state="processing"] .bm-state-processing { display: block; }
.bm-modal[data-bm-state="success"]    .bm-state-success    { display: flex; flex-direction: column; min-height: 0; }
.bm-modal[data-bm-state="error"]      .bm-state-error      { display: flex; flex-direction: column; min-height: 0; }

/* ── Processing state ──────────────────────────── */
.bm-processing {
    padding: 36px 24px 24px;
    text-align: center;
}
.bm-spinner-big {
    width: 64px; height: 64px;
    margin: 0 auto 18px;
    border: 5px solid #E5E7EB;
    border-top-color: #13A459;
    border-radius: 50%;
    animation: bm-spin 0.9s linear infinite;
}
.bm-processing h4 {
    font: 700 17px/1.3 'Be Vietnam Pro', sans-serif;
    color: #111827;
    margin: 0 0 6px;
}
.bm-proc-status {
    font: 500 13px 'Be Vietnam Pro', sans-serif;
    color: #047857;
    margin-bottom: 10px;
    transition: opacity 0.15s;
}
.bm-proc-order {
    font: 600 12px 'JetBrains Mono', ui-monospace, monospace;
    background: #F3F4F6;
    padding: 5px 10px;
    border-radius: 6px;
    display: inline-block;
    color: #374151;
    margin-bottom: 20px;
}
.bm-warn-banner {
    background: #FFFBEB;
    border: 1px solid #FCD34D;
    color: #92400E;
    padding: 12px 16px;
    border-radius: 10px;
    font: 500 12px/1.5 'Be Vietnam Pro', sans-serif;
    display: flex; align-items: center; gap: 10px;
    margin: 0 4px;
    text-align: left;
}
.bm-warn-banner i { font-size: 16px; color: #D97706; flex-shrink: 0; }

/* ── Result states ─────────────────────────────── */
.bm-result {
    padding: 28px 24px 18px;
    text-align: center;
    overflow-y: auto;
    flex: 1; min-height: 0;
}
.bm-result-icon {
    width: 64px; height: 64px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 28px;
    margin-bottom: 12px;
    animation: bm-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.bm-result-icon.success { background: #D1FAE5; color: #047857; }
.bm-result-icon.error { background: #FEE2E2; color: #DC2626; }
@keyframes bm-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
.bm-result h4 {
    font: 700 17px/1.3 'Be Vietnam Pro', sans-serif;
    color: #111827;
    margin: 0 0 8px;
}
.bm-result-order, .bm-result-msg {
    font: 500 12px 'Be Vietnam Pro', sans-serif;
    color: #6B7280;
    margin-bottom: 16px;
}
.bm-result-order .bm-order-id {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    background: #F3F4F6;
    padding: 3px 8px;
    border-radius: 4px;
    color: #374151;
    font-weight: 600;
}

/* ── PR5: Account credentials list — UX redesign ─────────────── */
.bm-accounts {
    text-align: left;
    margin-top: 14px;
    max-height: 50vh;
    overflow-y: auto;
    padding: 2px 4px;
}

/* Action bar trên list */
.bm-acc-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin: 14px 0 8px 0;
    padding: 10px 12px;
    background: linear-gradient(135deg, #F0FDF4 0%, #ECFDF5 100%);
    border: 1px solid #BBF7D0;
    border-radius: 10px;
}
.bm-act-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 12px;
    background: #fff;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    font: 600 12.5px 'Be Vietnam Pro', sans-serif;
    color: #1F2937; text-decoration: none;
    cursor: pointer;
    transition: 0.15s;
}
.bm-act-btn:hover { background: #F9FAFB; border-color: #9CA3AF; transform: translateY(-1px); }
.bm-act-btn i.fa-copy { color: #2563EB; }
.bm-act-btn i.fa-download { color: #059669; }
.bm-act-btn i.fa-list { color: #6B7280; }

.bm-act-dl-wrap { position: relative; }
.bm-act-dl-menu {
    position: absolute; top: calc(100% + 4px); left: 0;
    background: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    min-width: 200px;
    padding: 4px;
    z-index: 10001;
    display: flex; flex-direction: column; gap: 2px;
}
.bm-act-dl-menu button {
    background: transparent; border: 0;
    padding: 8px 12px;
    text-align: left;
    border-radius: 6px;
    font: 500 12.5px 'Be Vietnam Pro', sans-serif;
    color: #1F2937;
    cursor: pointer;
}
.bm-act-dl-menu button:hover { background: #F3F4F6; }

/* PR5 — Format picker row */
.bm-fmt-row { display: flex; align-items: center; gap: 8px; width: 100%; flex-wrap: wrap; margin-bottom: 8px; }
.bm-fmt-lbl { font: 600 12px 'Be Vietnam Pro', sans-serif; color: #374151; white-space: nowrap; }
.bm-fmt-sel { flex: 1; min-width: 220px; padding: 6px 10px; border: 1px solid #D1D5DB; border-radius: 6px; background: #fff; font: 500 13px 'Be Vietnam Pro', sans-serif; cursor: pointer; }
.bm-fmt-custom { flex-basis: 100%; padding: 6px 10px; border: 1px solid #D1D5DB; border-radius: 6px; font: 500 12px ui-monospace, monospace; margin-top: 4px; }
.bm-fmt-buttons { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; width: 100%; }

/* Account card */
.bm-acc {
    background: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    padding: 10px 12px 12px;
    margin-bottom: 10px;
    font: 400 12px/1.5 'Be Vietnam Pro', sans-serif;
    color: #1F2937;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.bm-acc-head {
    display: flex; justify-content: space-between; align-items: center;
    font-weight: 600; color: #111827;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px dashed #E5E7EB;
}
.bm-acc-num {
    background: #DBEAFE; color: #1E40AF;
    padding: 3px 10px;
    border-radius: 999px;
    font: 700 11px 'Be Vietnam Pro', sans-serif;
}
.bm-acc-copy-line {
    display: inline-flex; align-items: center; gap: 5px;
    background: #1E40AF;
    color: #fff;
    border: 0;
    padding: 4px 10px;
    border-radius: 6px;
    font: 600 11px 'Be Vietnam Pro', sans-serif;
    cursor: pointer;
    transition: 0.15s;
}
.bm-acc-copy-line:hover { background: #1D4ED8; }

/* Credential grid: row per field */
.bm-cred-grid {
    display: flex; flex-direction: column; gap: 5px;
}
.bm-cred-row {
    display: grid;
    grid-template-columns: 110px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}
.bm-cred-label {
    display: inline-flex; align-items: center; gap: 6px;
    font: 600 11.5px 'Be Vietnam Pro', sans-serif;
    color: #6B7280;
}
.bm-cred-label i { width: 14px; color: #9CA3AF; }
.bm-cred-value-wrap { min-width: 0; overflow: hidden; }
.bm-cred-value {
    display: inline-block;
    background: #F3F4F6;
    border: 1px solid #E5E7EB;
    padding: 3px 8px;
    border-radius: 5px;
    font: 500 12px 'JetBrains Mono', ui-monospace, monospace;
    color: #111827;
    user-select: all;
    max-width: 100%;
    overflow: auto;
    white-space: nowrap;
    vertical-align: middle;
}
.bm-cred-value.is-secret.bm-hidden {
    color: #9CA3AF;
    letter-spacing: 2px;
    user-select: none;
}
.bm-cred-actions { display: inline-flex; gap: 4px; flex-shrink: 0; }
.bm-cred-mini {
    background: #fff;
    border: 1px solid #D1D5DB;
    border-radius: 5px;
    width: 26px; height: 26px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: #4B5563;
    transition: 0.15s;
}
.bm-cred-mini:hover { background: #F3F4F6; border-color: #9CA3AF; color: #111827; }
.bm-cred-mini.bm-cred-copy:hover { background: #DBEAFE; border-color: #93C5FD; color: #1E40AF; }
.bm-cred-mini i.fa-check { color: #059669 !important; }

/* Toast */
.bm-toast {
    position: absolute; bottom: 80px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1F2937; color: #fff;
    padding: 8px 16px;
    border-radius: 999px;
    font: 600 12px 'Be Vietnam Pro', sans-serif;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 10002;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}
.bm-toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.bm-acc-empty {
    font: 500 13px 'Be Vietnam Pro', sans-serif;
    color: #6B7280;
    background: #F9FAFB;
    padding: 18px;
    border-radius: 10px;
    text-align: center;
}

.bm-btn-copy {
    flex: 0 0 auto !important;
    background: #F3F4F6;
    color: #374151;
}
.bm-btn-copy:hover { background: #E5E7EB; }

/* ── Mobile ─────────────────────────────────────── */
@media (max-width: 480px) {
    .bm-modal {
        width: 100vw; max-width: 100vw;
        bottom: 0; top: auto;
        left: 0; right: 0;
        transform: translateY(100%);
        border-radius: 16px 16px 0 0;
        max-height: 90vh;
    }
    .bm-modal.is-open { transform: translateY(0); }
}
