/* ==========================================================================
   Cardman Chatbot & Card Image CSS Override
   ========================================================================== */

/* 1. Progressive Card Image Loader Styles */
.card-image-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1.58;
    border-radius: 16px;
    overflow: hidden;
    background: #0f172a;
    box-shadow: 0 16px 32px rgba(15, 23, 42, 0.16);
    display: flex;
    align-items: center;
    justify-content: center;
}

.css-card-fallback {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

.card-real-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    border-radius: 16px;
    opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 2;
    pointer-events: none;
}

.card-real-image.loaded {
    opacity: 1;
}

.card-image-wrap-large {
    width: min(100%, 420px);
    margin: 0 auto;
}

/* 2. Cardman Floating Launcher */
.cardman-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0f766e, #0d9488, #115e59);
    box-shadow: 0 8px 30px rgba(13, 148, 136, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.cardman-launcher:hover {
    transform: scale(1.08) rotate(5deg);
    box-shadow: 0 12px 35px rgba(13, 148, 136, 0.5);
}

.cardman-launcher:active {
    transform: scale(0.95);
}

.cardman-launcher-icon {
    width: 30px;
    height: 30px;
    fill: #ffffff;
    transition: transform 0.3s ease;
}

.cardman-launcher.active .cardman-launcher-icon {
    transform: rotate(90deg);
}

/* Pulse Notification Indicator */
.cardman-launcher::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid #ffffff;
    animation: launcherPulse 2s infinite;
}

.cardman-launcher.active::after {
    display: none;
}

@keyframes launcherPulse {
    0% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
    100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* 3. Chatbot Window Container */
.cardman-chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    height: 580px;
    border-radius: 20px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.165, 0.84, 0.44, 1), opacity 0.3s ease;
}

.cardman-chat-window.active {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* Chat Header */
.cardman-chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(13, 148, 136, 0.9), rgba(15, 118, 110, 0.9));
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cardman-header-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cardman-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    font-size: 1.3rem;
}

.cardman-profile-info {
    color: #ffffff;
}

.cardman-profile-info h4 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.cardman-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    display: inline-block;
    box-shadow: 0 0 8px #10b981;
}

.cardman-profile-info span {
    font-size: 0.72rem;
    opacity: 0.85;
    display: block;
}

.cardman-header-close {
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 1.4rem;
    cursor: pointer;
    opacity: 0.75;
    transition: opacity 0.2s, transform 0.2s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.cardman-header-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
}

/* Chat Messages Content Area */
.cardman-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

/* Scrollbar Styles */
.cardman-chat-messages::-webkit-scrollbar {
    width: 5px;
}

.cardman-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.cardman-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
}

/* Bubble Styling */
.cardman-msg-row {
    display: flex;
    width: 100%;
}

.cardman-msg-row.bot {
    justify-content: flex-start;
}

.cardman-msg-row.user {
    justify-content: flex-end;
}

.cardman-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.88rem;
    line-height: 1.45;
    word-wrap: break-word;
    color: #f1f5f9;
}

.cardman-msg-row.bot .cardman-bubble {
    background: rgba(30, 41, 59, 0.8);
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.cardman-msg-row.user .cardman-bubble {
    background: #0f766e;
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(15, 118, 110, 0.2);
}

/* Bot recommendations or bullet items */
.cardman-bubble ul {
    margin: 8px 0 0 0;
    padding-left: 20px;
}

.cardman-bubble li {
    margin-bottom: 4px;
}

/* Chat Input Bar */
.cardman-chat-input-bar {
    padding: 14px 20px;
    background: rgba(15, 23, 42, 0.98);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 12px;
}

.cardman-input-form {
    display: flex;
    width: 100%;
    gap: 8px;
    align-items: center;
}

.cardman-input {
    flex: 1;
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 10px 16px;
    color: #ffffff;
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.2s, background-color 0.2s;
}

.cardman-input:focus {
    border-color: #0d9488;
    background: rgba(30, 41, 59, 0.9);
}

.cardman-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.cardman-send-btn {
    background: #0d9488;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #ffffff;
    transition: background-color 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.cardman-send-btn:hover {
    background: #0f766e;
    transform: scale(1.05);
}

.cardman-send-btn:active {
    transform: scale(0.95);
}

.cardman-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    margin-left: 2px;
}

/* 4. Chat Quick Replies Options */
.cardman-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
    max-width: 100%;
}

.cardman-qr-btn {
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid rgba(13, 148, 136, 0.3);
    color: #0d9488;
    border-radius: 18px;
    padding: 6px 14px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cardman-qr-btn:hover {
    background: #0d9488;
    color: #ffffff;
    border-color: #0d9488;
    transform: translateY(-1px);
}

.cardman-qr-btn:active {
    transform: translateY(0);
}

/* 5. Chat Card Recommendations Bubble */
.cardman-recommended-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 8px;
    width: 100%;
}

.cardman-compact-card {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.cardman-cc-header {
    display: flex;
    gap: 12px;
    padding: 10px 12px;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.cardman-cc-preview {
    width: 70px;
    height: 44px;
    border-radius: 4px;
    background: linear-gradient(135deg, var(--issuer-primary, #334155), var(--issuer-secondary, #475569));
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.cardman-cc-preview img {
    width: 100%;
    height: 100%;
    object-fit: fill;
}

.cardman-cc-fallback-logo {
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: 700;
}

.cardman-cc-info {
    flex: 1;
    min-width: 0;
}

.cardman-cc-info h5 {
    margin: 0 0 2px 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: #f8fafc;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cardman-cc-info p {
    margin: 0;
    font-size: 0.68rem;
    color: rgba(255, 255, 255, 0.6);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cardman-cc-fees {
    padding: 6px 12px;
    background: rgba(15, 23, 42, 0.3);
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.75);
    display: flex;
    justify-content: space-between;
}

.cardman-cc-actions {
    display: flex;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.cardman-cc-btn {
    flex: 1;
    padding: 8px;
    font-size: 0.76rem;
    font-weight: 600;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
}

.cardman-cc-btn.details {
    color: rgba(255, 255, 255, 0.7);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.cardman-cc-btn.details:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #ffffff;
}

.cardman-cc-btn.apply {
    color: #ffffff;
    background: #0d9488;
}

.cardman-cc-btn.apply:hover {
    background: #0f766e;
}

/* Typing Indicator Animation */
.cardman-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
}

.cardman-typing span {
    width: 6px;
    height: 6px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.cardman-typing span:nth-child(1) { animation-delay: -0.32s; }
.cardman-typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* Responsive Window Scaling */
@media (max-width: 480px) {
    .cardman-chat-window {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        z-index: 10000;
    }
    .cardman-launcher {
        display: none; /* Hide floating button when full screen on mobile */
    }
    .cardman-chat-window.active {
        transform: translateY(0) scale(1);
    }
}
