/**
 * Save-to-List Popup — Premium Dark SaaS UI
 * Covers: Auth-gate modal + My Lists selection modal
 */

/* =============================================
   BACKDROP OVERLAY
   ============================================= */
.bfai-popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 99990;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.bfai-popup-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

/* =============================================
   MODAL CARD
   ============================================= */
.bfai-popup-card {
    position: relative;
    width: 100%;
    max-width: 480px;
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(139, 92, 246, 0.15);
    overflow: hidden;
    transform: translateY(20px) scale(0.97);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.bfai-popup-overlay.is-open .bfai-popup-card {
    transform: translateY(0) scale(1);
}

/* Top accent gradient line */
.bfai-popup-card::before {
    content: '';
    display: block;
    height: 2px;
    background: linear-gradient(90deg, #8b5cf6, #6366f1, #3b82f6);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
}

/* =============================================
   POPUP HEADER
   ============================================= */
.bfai-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 24px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.bfai-popup-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bfai-popup-header-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(99, 102, 241, 0.2));
    border: 1px solid rgba(139, 92, 246, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #a78bfa;
    flex-shrink: 0;
}

.bfai-popup-title {
    font-size: 16px;
    font-weight: 700;
    color: #f9fafb;
    margin: 0;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.bfai-popup-subtitle {
    font-size: 12px;
    color: rgba(156, 163, 175, 0.9);
    margin: 2px 0 0;
    line-height: 1.3;
}

.bfai-popup-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.07);
    color: rgba(156, 163, 175, 0.8);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.bfai-popup-close:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}

/* =============================================
   POPUP BODY
   ============================================= */
.bfai-popup-body {
    padding: 20px 24px 24px;
}

/* =============================================
   AUTH MODAL VARIANT
   ============================================= */
.bfai-auth-popup-body {
    text-align: center;
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.bfai-auth-popup-icon {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(99, 102, 241, 0.15));
    border: 1px solid rgba(139, 92, 246, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #a78bfa;
    margin-bottom: 4px;
}

.bfai-auth-popup-heading {
    font-size: 18px;
    font-weight: 700;
    color: #f9fafb;
    margin: 0;
    letter-spacing: -0.02em;
}

.bfai-auth-popup-text {
    font-size: 14px;
    color: rgba(156, 163, 175, 0.9);
    margin: 0;
    line-height: 1.55;
    max-width: 300px;
}

.bfai-auth-popup-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 280px;
}

.bfai-popup-btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: 10px;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    border: none;
    cursor: pointer;
    letter-spacing: 0.01em;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3), 0 0 0 1px rgba(99, 102, 241, 0.1);
}

.bfai-popup-btn-primary:hover {
    transform: translateY(-2px);
    background: linear-gradient(135deg, #a78bfa, #818cf8);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.45);
    color: #ffffff;
}

.bfai-popup-btn-primary:active {
    transform: translateY(0);
}

.bfai-popup-btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 24px;
    border-radius: 10px;
    background: transparent;
    color: rgba(156, 163, 175, 0.9);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    transition: all 0.25s ease;
}

.bfai-popup-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.35);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.bfai-popup-btn-secondary:active {
    transform: translateY(0);
}

/* =============================================
   LISTS SECTION (Logged-in Popup)
   ============================================= */
.bfai-save-lists-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(107, 114, 128, 1);
    margin: 0 0 12px;
}

.bfai-save-lists-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 280px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(139, 92, 246, 0.3) transparent;
    padding-right: 2px;
    margin-bottom: 16px;
}

.bfai-save-lists-grid::-webkit-scrollbar {
    width: 4px;
}

.bfai-save-lists-grid::-webkit-scrollbar-track {
    background: transparent;
}

.bfai-save-lists-grid::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.3);
    border-radius: 2px;
}

/* Loading state */
.bfai-save-lists-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 28px 0;
    color: rgba(156, 163, 175, 0.7);
    font-size: 13px;
}

.bfai-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(139, 92, 246, 0.2);
    border-top-color: #8b5cf6;
    border-radius: 50%;
    animation: bfai-spin 0.7s linear infinite;
    flex-shrink: 0;
}

@keyframes bfai-spin {
    to {
        transform: rotate(360deg);
    }
}

/* List Item Card */
.bfai-save-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.03);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
    position: relative;
    overflow: hidden;
}

.bfai-save-list-item::before {
    content: '';
    position: absolute;
    inset: 0;
    opacity: 0;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(99, 102, 241, 0.05));
    transition: opacity 0.2s;
    pointer-events: none;
}

.bfai-save-list-item:hover {
    border-color: rgba(139, 92, 246, 0.3);
    background: rgba(139, 92, 246, 0.07);
    transform: translateX(2px);
}

.bfai-save-list-item:hover::before {
    opacity: 1;
}

.bfai-save-list-item.is-loading {
    pointer-events: none;
    opacity: 0.65;
}

.bfai-save-list-item.is-added {
    border-color: rgba(16, 185, 129, 0.4);
    background: rgba(16, 185, 129, 0.07);
    cursor: default;
    transform: none;
    animation: bfai-list-added 0.4s ease;
}

@keyframes bfai-list-added {
    0% {
        transform: scale(1);
    }

    40% {
        transform: scale(1.025);
    }

    100% {
        transform: scale(1);
    }
}

.bfai-save-list-item.is-added::before {
    opacity: 0;
}

.bfai-save-list-icon {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
    background: rgba(255, 255, 255, 0.06);
}

.bfai-save-list-icon--default {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(99, 102, 241, 0.2));
    color: #a78bfa;
}

.bfai-save-list-icon--custom {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(156, 163, 175, 0.8);
}

.bfai-save-list-icon svg {
    display: block;
}

.bfai-save-list-info {
    flex: 1;
    min-width: 0;
}

.bfai-save-list-name {
    font-size: 14px;
    font-weight: 600;
    color: #e5e7eb;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.25;
}

.bfai-save-list-count {
    font-size: 11px;
    color: rgba(107, 114, 128, 0.9);
    margin: 2px 0 0;
    line-height: 1;
}

.bfai-save-list-action {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(156, 163, 175, 0.7);
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.bfai-save-list-item:hover .bfai-save-list-action {
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
    border-color: rgba(139, 92, 246, 0.3);
}

.bfai-save-list-item.is-added .bfai-save-list-action {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.3);
}

/* Spinner inside list item */
.bfai-list-item-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(139, 92, 246, 0.2);
    border-top-color: #8b5cf6;
    border-radius: 50%;
    animation: bfai-spin 0.7s linear infinite;
}

/* =============================================
   NEW LIST INLINE CREATOR
   ============================================= */
.bfai-save-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: 16px 0;
}

.bfai-new-list-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bfai-new-list-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 14px;
    border-radius: 10px;
    border: 1px dashed rgba(255, 255, 255, 0.1);
    background: transparent;
    color: rgba(139, 92, 246, 0.9);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    width: 100%;
    text-align: left;
    letter-spacing: 0.01em;
}

.bfai-new-list-trigger:hover {
    background: rgba(139, 92, 246, 0.07);
    border-color: rgba(139, 92, 246, 0.3);
}

.bfai-new-list-form {
    display: none;
    flex-direction: column;
    gap: 10px;
}

.bfai-new-list-form.is-open {
    display: flex;
    animation: bfai-slide-in 0.2s ease;
}

@keyframes bfai-slide-in {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bfai-new-list-input-row {
    display: flex;
    gap: 8px;
}

.bfai-new-list-input {
    flex: 1;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 9px;
    color: #f9fafb;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
    min-width: 0;
}

.bfai-new-list-input::placeholder {
    color: rgba(107, 114, 128, 0.8);
}

.bfai-new-list-input:focus {
    border-color: rgba(139, 92, 246, 0.5);
    background: rgba(139, 92, 246, 0.05);
}

.bfai-new-list-create-btn {
    padding: 10px 16px;
    border-radius: 9px;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.bfai-new-list-create-btn:hover {
    opacity: 0.9;
}

.bfai-new-list-create-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}

.bfai-new-list-cancel-btn {
    background: transparent;
    border: none;
    color: rgba(107, 114, 128, 0.9);
    font-size: 12px;
    cursor: pointer;
    text-align: left;
    padding: 0;
    font-family: inherit;
    transition: color 0.2s;
}

.bfai-new-list-cancel-btn:hover {
    color: #e5e7eb;
}

/* =============================================
   FEEDBACK MESSAGES
   ============================================= */
.bfai-popup-feedback {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 500;
    margin-top: 12px;
}

.bfai-popup-feedback.is-visible {
    display: flex;
    animation: bfai-slide-in 0.2s ease;
}

.bfai-popup-feedback--success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: #34d399;
}

.bfai-popup-feedback--error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #f87171;
}

/* =============================================
   TOOL PREVIEW CHIP (inside popup header)
   ============================================= */
.bfai-popup-tool-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px 16px;
    background: transparent;
}

.bfai-popup-tool-chip-logo {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #a78bfa;
}

.bfai-popup-tool-chip-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bfai-popup-tool-chip-name {
    font-size: 13px;
    font-weight: 600;
    color: rgba(209, 213, 219, 0.9);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =============================================
   LIGHT MODE OVERRIDES
   ============================================= */
@media (prefers-color-scheme: light) {
    .bfai-popup-overlay {
        background: rgba(17, 24, 39, 0.6);
    }

    .bfai-popup-card {
        background: #fff;
        border-color: rgba(0, 0, 0, 0.08);
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
    }

    .bfai-popup-title {
        color: #111827;
    }

    .bfai-popup-subtitle {
        color: #6b7280;
    }

    .bfai-popup-close {
        background: #f3f4f6;
        border-color: #e5e7eb;
        color: #6b7280;
    }

    .bfai-popup-close:hover {
        background: #fee2e2;
        color: #ef4444;
        border-color: #fca5a5;
    }

    .bfai-popup-header {
        border-bottom-color: #f3f4f6;
    }

    .bfai-auth-popup-heading {
        color: #111827;
    }

    .bfai-auth-popup-text {
        color: #6b7280;
    }

    .bfai-save-list-item {
        border-color: #e5e7eb;
        background: #f9fafb;
    }

    .bfai-save-list-item:hover {
        border-color: rgba(139, 92, 246, 0.3);
        background: rgba(139, 92, 246, 0.06);
    }

    .bfai-save-list-name {
        color: #1f2937;
    }

    .bfai-save-list-count {
        color: #9ca3af;
    }

    .bfai-save-list-action {
        background: #f3f4f6;
        border-color: #e5e7eb;
        color: #9ca3af;
    }

    .bfai-save-lists-label {
        color: #9ca3af;
    }

    .bfai-save-divider {
        background: #f3f4f6;
    }

    .bfai-new-list-trigger {
        border-color: #d1d5db;
    }

    .bfai-new-list-trigger:hover {
        background: rgba(139, 92, 246, 0.05);
    }

    .bfai-new-list-input {
        background: #f9fafb;
        border-color: #e5e7eb;
        color: #111827;
    }

    .bfai-new-list-input::placeholder {
        color: #9ca3af;
    }

    .bfai-new-list-input:focus {
        border-color: rgba(139, 92, 246, 0.5);
        background: #fff;
    }

    .bfai-popup-tool-chip-name {
        color: #374151;
    }

    .bfai-popup-btn-secondary {
        border-color: #d1d5db;
        color: #6b7280;
    }

    .bfai-popup-btn-secondary:hover {
        background: #f3f4f6;
        color: #111827;
        border-color: #9ca3af;
    }
}

/* WordPress-class based light mode (body.light-mode) */
body.light-mode .bfai-popup-card,
body.bfai-light .bfai-popup-card {
    background: #fff;
    border-color: rgba(0, 0, 0, 0.08);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

body.light-mode .bfai-popup-title,
body.bfai-light .bfai-popup-title {
    color: #111827;
}

body.light-mode .bfai-save-list-item,
body.bfai-light .bfai-save-list-item {
    border-color: #e5e7eb;
    background: #f9fafb;
}

body.light-mode .bfai-save-list-name,
body.bfai-light .bfai-save-list-name {
    color: #1f2937;
}

body.light-mode .bfai-popup-btn-secondary,
body.bfai-light .bfai-popup-btn-secondary {
    border-color: #d1d5db;
    color: #6b7280;
}

body.light-mode .bfai-popup-btn-secondary:hover,
body.bfai-light .bfai-popup-btn-secondary:hover {
    background: #f3f4f6;
    color: #111827;
    border-color: #9ca3af;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 520px) {
    .bfai-popup-card {
        max-width: 100%;
        border-radius: 16px 16px 0 0;
    }

    .bfai-popup-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .bfai-popup-overlay.is-open .bfai-popup-card {
        transform: translateY(0) scale(1);
    }

    .bfai-popup-overlay .bfai-popup-card {
        transform: translateY(100%);
    }

    .bfai-popup-body {
        padding: 16px 20px 32px;
    }

    .bfai-popup-header {
        padding: 18px 20px 14px;
    }
}