/**
 * CardChat Frontend Styles
 */

/* Base Font & Variables */
:root {
    --cardchat-primary-color: #009ace;
    --cardchat-secondary-color: #f0f4f8;
    --cardchat-text-color: #333;
    --cardchat-bot-bg: #e1f5fe; /* Lighter shade of primary */
    --cardchat-user-bg: #ffffff;
    --cardchat-font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    --cardchat-border-radius: 8px;
    --cardchat-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
    --cardchat-bg-primary: #ffffff; /* Main background */
    --cardchat-bg-secondary: #f1f1f1; /* Secondary background (e.g., input area) */
    --cardchat-text-primary: #333333; /* Main text */
    --cardchat-text-secondary: #555555; /* Secondary text (e.g., timestamps) */
    --cardchat-border-color: #e0e0e0; /* Borders */
    --cardchat-header-text: #ffffff; /* Text on primary color header */
    --cardchat-button-text: #ffffff; /* Text on primary color button */
    --cardchat-user-message-bg: var(--cardchat-primary-color); /* User message bubble */
    --cardchat-user-message-text: var(--cardchat-button-text); /* Text in user message */
    --cardchat-bot-message-bg: #e5e5ea; /* Bot message bubble */
    --cardchat-bot-message-text: #000000; /* Text in bot message */
    --cardchat-loader-color: var(--cardchat-primary-color); /* Loader dots */
    --cardchat-icon-color: #ffffff; /* Icon color on FAB */
    --cardchat-close-icon-color: #cccccc; /* Close button color (default state) */
    --cardchat-close-icon-hover-color: #aaaaaa; /* Close button color (hover state) */
    --cardchat-scrollbar-thumb: #c1c1c1;
    --cardchat-scrollbar-track: #f1f1f1;
}

/* Dark Mode Overrides */
#cardchat-container.cardchat-dark-mode {
  --cardchat-bg-primary: #1e1e1e;
  --cardchat-bg-secondary: #2a2a2a;
  --cardchat-text-primary: #e0e0e0;
  --cardchat-text-secondary: #b0b0b0;
  --cardchat-border-color: #444444;
  --cardchat-header-text: #ffffff; /* Keep white or adjust based on primary color contrast */
  --cardchat-button-text: #ffffff; /* Keep white or adjust based on primary color contrast */
  --cardchat-user-message-bg: var(--cardchat-primary-color); /* User message bubble */
  --cardchat-user-message-text: var(--cardchat-button-text); /* Text in user message */
  --cardchat-bot-message-bg: #3a3a3c; /* Bot message bubble */
  --cardchat-bot-message-text: #e0e0e0; /* Text in bot message */
  --cardchat-loader-color: var(--cardchat-primary-color);
  --cardchat-icon-color: #ffffff;
  --cardchat-close-icon-color: #777777;
  --cardchat-close-icon-hover-color: #999999;
  --cardchat-scrollbar-thumb: #555555;
  --cardchat-scrollbar-track: #2a2a2a;
}

/* Floating Action Button (FAB) */
#cardchat-fab {
    position: fixed;
    bottom: 25px;
    width: 60px;
    height: 60px;
    background-color: var(--cardchat-primary-color);
    border-radius: 50%;
    box-shadow: var(--cardchat-shadow);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 9998;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Position Specifics for FAB */
.cardchat-position-right #cardchat-fab {
    right: 25px;
    left: auto;
}

.cardchat-position-left #cardchat-fab {
    left: 25px;
    right: auto;
}

#cardchat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

/* Speech Bubble Styles */
.cardchat-speech-bubble {
    position: absolute;
    top: -50px;
    background: var(--cardchat-primary-color);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    pointer-events: none;
    max-width: 200px;
    text-align: left;
    min-width: 100px;
}

/* Position speech bubble based on chat icon position */
.cardchat-position-right .cardchat-speech-bubble {
    right: 10px;
    left: auto;
}

.cardchat-position-left .cardchat-speech-bubble {
    left: 10px;
    right: auto;
}

.cardchat-speech-bubble:after {
    content: '';
    position: absolute;
    bottom: -7px;
    width: 14px;
    height: 14px;
    background: var(--cardchat-primary-color);
    transform: rotate(45deg);
    box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.08);
    z-index: -1;
}

/* Position the triangle pointer based on chat icon position */
.cardchat-position-right .cardchat-speech-bubble:after {
    right: 15px;
    left: auto;
}

.cardchat-position-left .cardchat-speech-bubble:after {
    left: 15px;
    right: auto;
}

/* Speech Bubble Animation Styles */
@keyframes speech-bubble-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes speech-bubble-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

@keyframes speech-bubble-fade {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes speech-bubble-shake {
    /* Shake animation during the first 1.5 seconds */
    0%, 30% { transform: translateX(0); }
    3%, 9%, 15%, 21%, 27% { transform: translateX(-3px); }
    6%, 12%, 18%, 24% { transform: translateX(3px); }
    
    /* Pause for the remaining 3.5 seconds */
    30.01%, 100% { transform: translateX(0); }
}

@keyframes speech-bubble-blink {
    0%, 50%, 100% { opacity: 1; }
    25%, 75% { opacity: 0; }
}

@keyframes speech-bubble-glow {
    0%, 100% { box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2); }
    50% { box-shadow: 0 0 15px var(--cardchat-primary-color); }
}

@keyframes speech-bubble-wave {
    0% { transform: translateX(0) translateY(0); }
    25% { transform: translateX(-3px) translateY(2px); }
    50% { transform: translateX(0) translateY(-2px); }
    75% { transform: translateX(3px) translateY(2px); }
    100% { transform: translateX(0) translateY(0); }
}

@keyframes speech-bubble-dance {
    /* Start normal */
    0%, 75%, 100% { 
        transform: scale(1) rotate(0deg);
        border-radius: 20px;
    }
    /* Pop! */
    10% { 
        transform: scale(1.3) rotate(5deg); 
        border-radius: 25px;
    }
    /* Wiggle slightly */
    20% { transform: scale(1.2) rotate(-4deg); }
    30% { transform: scale(1.15) rotate(3deg); }
    40% { transform: scale(1.1) rotate(-2deg); }
    /* Settle back to normal with a tiny bounce */
    50% { transform: scale(0.95) rotate(0); }
    60% { transform: scale(1.05) rotate(0); }
}

@keyframes speech-bubble-heartbeat {
    0%, 30%, 100% { transform: scale(1); }
    15% { transform: scale(1.2); }
    45% { transform: scale(1.15); }
    60% { transform: scale(1.05); }
}

@keyframes speech-bubble-flip {
    0%, 80%, 100% { transform: perspective(400px) rotateY(0); }
    20% { transform: perspective(400px) rotateY(180deg); }
    40% { transform: perspective(400px) rotateY(0); }
    60% { transform: perspective(400px) rotateY(-180deg); }
}

@keyframes speech-bubble-rainbow {
    0%, 100% { box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2); }
    14% { box-shadow: 0 0 15px rgba(255, 0, 0, 0.7); }
    28% { box-shadow: 0 0 15px rgba(255, 165, 0, 0.7); }
    42% { box-shadow: 0 0 15px rgba(255, 255, 0, 0.7); }
    56% { box-shadow: 0 0 15px rgba(0, 128, 0, 0.7); }
    70% { box-shadow: 0 0 15px rgba(0, 0, 255, 0.7); }
    84% { box-shadow: 0 0 15px rgba(75, 0, 130, 0.7); }
}

/* Typing animation removed due to styling issues */

.speech-bubble-animate-pulse .cardchat-speech-bubble {
    animation: speech-bubble-pulse 2s infinite;
}

.speech-bubble-animate-bounce .cardchat-speech-bubble {
    animation: speech-bubble-bounce 2s infinite;
}

.speech-bubble-animate-fade .cardchat-speech-bubble {
    animation: speech-bubble-fade 2s infinite;
}

.speech-bubble-animate-shake .cardchat-speech-bubble {
    animation: speech-bubble-shake 5s infinite;
}

.speech-bubble-animate-blink .cardchat-speech-bubble {
    animation: speech-bubble-blink 3s infinite;
}

.speech-bubble-animate-glow .cardchat-speech-bubble {
    animation: speech-bubble-glow 2s infinite;
}

.speech-bubble-animate-wave .cardchat-speech-bubble {
    animation: speech-bubble-wave 3s infinite;
}

.speech-bubble-animate-dance .cardchat-speech-bubble {
    animation: speech-bubble-dance 7s infinite;
}

.speech-bubble-animate-heartbeat .cardchat-speech-bubble {
    animation: speech-bubble-heartbeat 2s infinite;
}

.speech-bubble-animate-flip .cardchat-speech-bubble {
    animation: speech-bubble-flip 8s infinite;
}

.speech-bubble-animate-rainbow .cardchat-speech-bubble {
    animation: speech-bubble-rainbow 4s infinite;
}

.speech-bubble-animate-typing .cardchat-speech-bubble {
    position: relative; /* Ensure proper positioning of the pseudo-element */
}

#cardchat-fab svg {
    width: 32px;
    height: 32px;
    fill: var(--cardchat-icon-color);
}

/* Custom Image Icon inside FAB */
#cardchat-fab img {
    max-width: 100%; /* Ensure image doesn't overflow */
    max-height: 100%;
    width: 100%; /* Try to fill the container */
    height: 100%;
    object-fit: cover; /* Cover the area, cropping if needed */
    border-radius: 50%; /* Keep the circular shape */
    display: block; /* Remove extra space below image */
}

/* Chat Window Container */
#cardchat-window {
    position: fixed;
    bottom: 100px; /* Above the FAB */
    width: 350px;
    max-width: 90vw;
    height: 500px;
    max-height: 70vh;
    background-color: var(--cardchat-bg-primary);
    border-radius: var(--cardchat-border-radius);
    box-shadow: var(--cardchat-shadow);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--cardchat-font-family);
    visibility: hidden; /* Hidden by default */
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: visibility 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
}

/* Position Specifics for Window */
.cardchat-position-right #cardchat-window {
    right: 25px;
    left: auto;
}

.cardchat-position-left #cardchat-window {
    left: 25px;
    right: auto;
}

#cardchat-window.cardchat-visible {
    visibility: visible;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Fullscreen Mode */
.cardchat-fullscreen {
    width: 100% !important;
    height: 100% !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    box-shadow: none !important;
}

/* Chat Header */
#cardchat-header {
    background-color: var(--cardchat-primary-color);
    color: var(--cardchat-header-text);
    padding: 15px;
    font-size: 0.85em;
    font-weight: 600;
    border-top-left-radius: var(--cardchat-border-radius);
    border-top-right-radius: var(--cardchat-border-radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#cardchat-close-btn {
    background: none;
    border: none;
    color: var(--cardchat-close-icon-color);
    font-size: 1.5em;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
}

#cardchat-close-btn:hover {
    color: var(--cardchat-close-icon-hover-color);
}

#cardchat-header button {
    background: none;
    border: none;
    color: var(--cardchat-header-text);
    font-size: 1.5em;
    cursor: pointer;
    padding: 10px;
    line-height: 1;
    margin-left: 5px;
    opacity: 0.8;
    transition: background-color 0.2s ease, opacity 0.2s ease;
}

#cardchat-header button:hover {
    opacity: 1;
}

#cardchat-header button:active {
    background-color: rgba(0, 0, 0, 0.2);
    opacity: 1;
}

/* Style the SVG icon inside the fullscreen button */
#cardchat-fullscreen-btn svg {
    width: 16px; /* Match font size context */
    height: 16px;
    vertical-align: middle;
    stroke-width: 2; /* Ensure stroke shows */
}

/* Message Area */
#cardchat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 0.8em;
}

/* Actions area */
#cardchat-actions {
    display: flex;
    justify-content: center;
    padding: 5px 15px;
    border-top: 1px solid var(--cardchat-border-color);
    background-color: var(--cardchat-bg-secondary);
}

#cardchat-contact-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background-color: var(--cardchat-primary-color);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

#cardchat-contact-btn:hover {
    background-color: #0080b3;
}

#cardchat-contact-btn:active {
    transform: scale(0.98);
}

#cardchat-contact-btn svg {
    width: 18px;
    height: 18px;
}

/* Individual Message Styles */
.cardchat-message {
    margin-bottom: 12px;
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--cardchat-border-radius);
    line-height: 1.5;
    position: relative;
    word-break: break-word;
}

/* Rate Limit Countdown Styles */
.cardchat-rate-limit-countdown {
    text-align: center;
    margin: 10px auto;
    padding: 8px 12px;
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
    border-radius: var(--cardchat-border-radius);
    font-size: 0.8em;
    max-width: 80%;
}

.cardchat-rate-limit-countdown span {
    font-weight: bold;
}

.cardchat-message.cardchat-bot {
    background-color: var(--cardchat-bot-message-bg);
    color: var(--cardchat-bot-message-text);
    align-self: flex-start;
    border-bottom-left-radius: 0; /* "Tail" effect */
}

.cardchat-message.cardchat-user {
    background-color: var(--cardchat-user-message-bg);
    color: var(--cardchat-user-message-text);
    align-self: flex-end;
    border-bottom-right-radius: 0; /* "Tail" effect */
}

/* Typing Indicator */
.cardchat-message.cardchat-typing-indicator {
    background-color: var(--cardchat-bot-message-bg);
    color: var(--cardchat-bot-message-text);
    align-self: flex-start;
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 5px;
}

.typing-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background-color: var(--cardchat-loader-color);
  border-radius: 50%;
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-3px);
  }
}

/* Input Area */
#cardchat-input-area {
    display: flex;
    padding: 10px;
    border-top: 1px solid var(--cardchat-border-color);
    background-color: var(--cardchat-bg-secondary);
    font-size: 0.8em;
}

#cardchat-input {
    flex-grow: 1;
    border: 1px solid var(--cardchat-border-color);
    border-radius: var(--cardchat-border-radius);
    padding: 10px 15px;
    font-size: 1em;
    margin-right: 10px;
    resize: none; /* Prevent manual resizing */
    height: 40px; /* Start with single line */
    line-height: 1.4;
    font-family: var(--cardchat-font-family);
    background-color: var(--cardchat-bg-primary);
    color: var(--cardchat-text-primary);
}

#cardchat-input:focus {
    outline: none;
    border-color: var(--cardchat-primary-color);
    box-shadow: 0 0 0 2px rgba(0, 154, 206, 0.2);
}

#cardchat-send-btn {
    background-color: var(--cardchat-primary-color);
    border: none;
    color: var(--cardchat-button-text);
    padding: 0 15px;
    border-radius: var(--cardchat-border-radius);
    cursor: pointer;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
    height: 40px;
}

#cardchat-send-btn:hover {
    background-color: #007ba7; /* Darker shade */
}

#cardchat-send-btn:disabled {
    background-color: #a0a0a0;
    cursor: not-allowed;
}

#cardchat-send-btn svg {
    width: 20px;
    height: 20px;
    fill: var(--cardchat-button-text);
}

/* Override any fullscreen classes that might be added by older code */
#cardchat-window.fullscreen:not(.cardchat-fullscreen) {
    width: 80% !important;
    height: 80% !important;
    max-width: 80vw !important;
    max-height: 80vh !important;
    top: 10% !important;
    left: 10% !important;
    right: auto !important;
    bottom: auto !important;
    border-radius: 12px !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
}

/* Prevent text field zoom on mobile devices */
input[type="text"],
input[type="search"],
input[type="email"],
input[type="url"],
input[type="number"],
input[type="password"],
input[type="tel"],
textarea,
select {
    font-size: 16px !important; /* Prevents mobile zoom */
}

/* Target the actual input field specifically */
#cardchat-input {
    font-size: 16px !important; /* Min size to prevent iOS zoom */
    max-height: 100px; /* Prevent excessive growth */
}

/* Special overrides for iOS devices */
@media (max-width: 767px) and (-webkit-min-device-pixel-ratio: 2) {
    #cardchat-window {
        width: 80% !important;
        height: 80% !important;
        max-width: 80vw !important;
        max-height: 80vh !important;
        top: 10% !important;
        left: 10% !important;
        right: auto !important;
        bottom: auto !important;
        border-radius: 12px !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
        transform: none !important;
    }
}

/* Responsive Adjustments for Mobile */
@media (max-width: 767px) {
    /* Reduced Size Chat Window (80%) - with !important to override any other styles */
    #cardchat-window {
        width: 80% !important;
        height: 80% !important;
        max-width: 80vw !important;
        max-height: 80vh !important;
        top: 10% !important;
        left: 10% !important;
        right: auto !important;
        bottom: auto !important;
        border-radius: 12px !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
        transform: none !important; /* Override animations/transforms */
        /* Force visibility if transition was interrupted */
        visibility: hidden; /* Start hidden */
        opacity: 0;
        transition: opacity 0.3s ease, visibility 0.3s ease; /* Keep transition for open/close */
        z-index: 10000; /* Ensure it's on top */
        position: fixed; /* Ensure fixed positioning */
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        overflow: hidden; /* Prevent any overflow issues */
    }
    #cardchat-window.cardchat-visible {
         visibility: visible;
         opacity: 1;
    }

    /* Hide FAB when chat window is open */
    #cardchat-window.cardchat-visible + #cardchat-fab {
        visibility: hidden;
        opacity: 0;
        transform: scale(0.8);
        transition: visibility 0.2s, opacity 0.2s linear, transform 0.2s ease;
   }

    /* Adjust Header */
    #cardchat-header {
        border-top-left-radius: 12px;
        border-top-right-radius: 12px;
        padding: 10px 15px;
        font-size: 0.95em;
        position: sticky;
        top: 0;
        z-index: 2;
        width: 100%;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    /* Reset border radius when in fullscreen mode */
    .cardchat-fullscreen #cardchat-header {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
    }
    #cardchat-close-btn {
        font-size: 1.6em;
        padding: 5px 8px;
        background: transparent;
        border: none;
        color: var(--cardchat-header-text);
        cursor: pointer;
        z-index: 3;
        position: relative;
        line-height: 1;
        margin-left: 5px;
    }
    #cardchat-fullscreen-btn {
        display: flex; /* Make fullscreen button visible on mobile */
        align-items: center;
        justify-content: center;
        margin-right: 8px;
        padding: 5px;
        background: transparent;
        border: none;
        color: var(--cardchat-header-text);
        cursor: pointer;
    }
    
    #cardchat-fullscreen-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Adjust Messages Area */
    #cardchat-messages {
        padding: 10px;
        font-size: 0.8em;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        overflow-y: auto;
        width: 100%;
        box-sizing: border-box;
        flex: 1 1 auto; /* Allow it to grow and shrink */
        position: relative;
        height: 0; /* This forces the flex item to respect the container height */
        min-height: 0; /* Allow container to shrink below content size */
        max-height: calc(80vh - 120px); /* Adjust for 80% height */
        border-radius: 0;
        
    }
    
    /* Adjust messages area in fullscreen mode */
    .cardchat-fullscreen #cardchat-messages {
        max-height: calc(100vh - 120px);
    }
    .cardchat-message {
        max-width: 85%;
        padding: 8px 12px;
        margin-bottom: 8px;
        border-radius: 12px;
        line-height: 1.4;
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }
    .cardchat-user {
        font-size: 0.8em;
    }
    .cardchat-bot {
        font-size: 0.8em;
    }
    
    /* Clickable Links in Chat Messages */
    .cardchat-message a,
    .cardchat-message .cardchat-link {
        color: var(--cardchat-primary-color);
        text-decoration: underline;
        word-break: break-word;
        transition: color 0.2s ease;
        padding: 2px 0; /* Increase tap target size */
        display: inline-block;
    }
    
    .cardchat-message a:hover,
    .cardchat-message .cardchat-link:hover {
        color: #007aa3; /* Darker shade of the primary color */
        text-decoration: underline;
    }
    
    /* Style for external links */
    .cardchat-message a[target="_blank"]::after {
        content: "\2197"; /* Unicode for north-east arrow */
        font-size: 0.8em;
        margin-left: 3px;
        display: inline-block;
    }

    /* Adjust Input Area */
    #cardchat-input-area {
        padding: 8px;
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: var(--cardchat-bg-secondary);
        z-index: 10; /* Higher z-index to ensure visibility */
        border-top: 1px solid var(--cardchat-border-color);
        width: 100%;
        box-sizing: border-box;
        flex: 0 0 auto; /* Don't allow it to grow or shrink */
        display: flex; /* Ensure flexbox is applied */
        align-items: center; /* Vertically center items */
        border-bottom-left-radius: 12px;
        border-bottom-right-radius: 12px;
    }
    
    /* Reset border radius in fullscreen mode */
    .cardchat-fullscreen #cardchat-input-area {
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
    #cardchat-input {
        padding: 8px 12px;
        font-size: 0.9em;
        height: 38px;
        margin-right: 8px;
        border-radius: 18px;
        -webkit-appearance: none; /* Remove default iOS styling */
        appearance: none; /* Standard property for cross-browser compatibility */
        flex: 1; /* Take up available space */
        min-width: 0; /* Prevent flex items from overflowing */
        box-sizing: border-box;
        border: 1px solid var(--cardchat-border-color);
    }
    #cardchat-send-btn {
        padding: 0;
        font-size: 1em;
        height: 38px;
        min-width: 38px;
        width: 38px;
        border-radius: 50%;
        flex: 0 0 auto; /* Don't grow or shrink */
        display: flex;
        align-items: center;
        justify-content: center;
        border: none;
        background-color: var(--cardchat-primary-color);
        color: var(--cardchat-button-text);
    }
    #cardchat-send-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Adjust FAB (when visible) */
    #cardchat-fab {
        bottom: 15px;
        width: 55px;
        height: 55px;
        transition: transform 0.3s ease, box-shadow 0.3s ease, visibility 0.2s, opacity 0.2s linear; /* Add visibility/opacity */
    }
    .cardchat-position-right #cardchat-fab {
        right: 15px;
        left: auto;
    }
    .cardchat-position-left #cardchat-fab {
        left: 15px;
        right: auto;
    }
    #cardchat-fab svg {
        width: 30px;
        height: 30px;
    }
    
    /* Feedback adjustments for mobile */
    .cardchat-feedback {
        margin: 2px 0 10px;
        padding: 0 5px;
    }
    .cardchat-feedback-prompt {
        font-size: 11px;
    }
    .cardchat-feedback-btn {
        font-size: 14px;
        padding: 5px;
        margin: 0 2px;
    }
}

/* Additional adjustments for very small screens */
@media (max-width: 320px) {
    #cardchat-messages {
        font-size: 0.85em;
    }
    .cardchat-message {
        max-width: 90%;
        padding: 6px 10px;
    }
    #cardchat-input {
        font-size: 0.85em;
        padding: 6px 10px;
    }
}

/* Prevent body scrolling when chat is open on mobile */
body.cardchat-no-scroll {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* CardChat Admin Settings Styles */
.cardchat-settings-section {
    margin-bottom: 20px;
}

/* Lead Capture Form Styles - Modal Version */
.cardchat-lead-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
    box-sizing: border-box;
}

.cardchat-lead-modal-overlay.active {
    opacity: 1;
}

.cardchat-lead-form-container {
    background-color: var(--cardchat-bg-primary);
    border-radius: var(--cardchat-border-radius);
    padding: 20px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 400px;
    transform: translateY(20px);
    transition: transform 0.3s ease;
    border: 1px solid var(--cardchat-border-color);
    position: relative;
}

.cardchat-lead-modal-overlay.active .cardchat-lead-form-container {
    transform: translateY(0);
}

.cardchat-lead-form-header {
    margin-bottom: 15px;
    text-align: center;
}

.cardchat-lead-form-header h4 {
    margin: 0 0 8px 0;
    color: var(--cardchat-primary-color);
    font-size: 18px;
    font-weight: 600;
}

.cardchat-lead-form-header p {
    margin: 0;
    font-size: 13px;
    color: var(--cardchat-text-secondary);
    line-height: 1.3;
}

.cardchat-form-group {
    margin-bottom: 12px;
}

.cardchat-form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--cardchat-text-primary);
}

.cardchat-form-group input {
    width: 100%;
    padding: 6px 10px;
    height: 32px;
    border: 1px solid var(--cardchat-border-color);
    border-radius: 6px;
    font-size: 14px;
    background-color: var(--cardchat-bg-primary);
    color: var(--cardchat-text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.cardchat-form-group input:focus {
    outline: none;
    border-color: var(--cardchat-primary-color);
    box-shadow: 0 0 0 3px rgba(0, 154, 206, 0.15);
}

.cardchat-form-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 15px;
}

.cardchat-lead-submit {
    background-color: var(--cardchat-primary-color);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: background-color 0.2s, transform 0.1s;
    flex: 1;
    margin-right: 8px;
}

.cardchat-lead-submit:hover {
    background-color: #0080b3;
}

.cardchat-lead-submit:active {
    transform: scale(0.98);
}

.cardchat-lead-skip {
    background-color: transparent;
    color: var(--cardchat-text-secondary);
    border: 1px solid var(--cardchat-border-color);
    padding: 8px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s, transform 0.1s;
}

.cardchat-lead-skip:hover {
    background-color: var(--cardchat-bg-secondary);
}

.cardchat-lead-skip:active {
    transform: scale(0.98);
}

/* Mobile Optimization */
@media (max-width: 480px) {
    .cardchat-lead-form-container {
        padding: 15px;
        width: 95%;
    }
    
    .cardchat-lead-form-header h4 {
        font-size: 18px;
    }
    
    .cardchat-form-actions {
        flex-direction: column;
    }
    
    .cardchat-lead-submit {
        margin-right: 0;
        margin-bottom: 10px;
    }
}

.cardchat-settings-section h3 {
    margin-bottom: 10px;
}

.cardchat-settings-section .description {
    margin-bottom: 15px;
}

#cardchat-index-status {
    margin-top: 10px;
    font-style: italic;
}

#cardchat-exclusions-ui {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #ccc;
    padding: 10px;
    margin-bottom: 10px;
}

#cardchat-exclusions-ui label {
    display: block;
    margin-bottom: 5px;
}

/* Styles for Color Picker and Theme Mode Layout */
.cardchat-color-theme-wrapper {
    display: flex;
    align-items: flex-start; /* Align items to the top */
    gap: 20px; /* Space between color picker and theme selector */
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
}

.cardchat-color-theme-wrapper .cardchat-setting-field-wrapper {
    margin-bottom: 0; /* Remove default bottom margin inside flex */
    flex: 0 1 auto; /* Allow shrinking but don't grow */
}

.cardchat-theme-mode-wrapper select {
   /* vertical-align: top; Remove if using flex align-items */
   margin-top: 5px; /* Adjust alignment slightly if needed compared to the picker */
   min-width: 100px; /* Give the dropdown some base width */
}

/* Feedback Styles */
.cardchat-feedback {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin: 5px 0 15px;
    padding: 0 10px;
    font-size: 12px;
    color: var(--cardchat-text-secondary);
}

.cardchat-feedback-prompt {
    margin-right: 10px;
}

.cardchat-feedback-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 5px;
    margin: 0 3px;
    border-radius: 50%;
    transition: background-color 0.2s, transform 0.2s;
}

.cardchat-feedback-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    transform: scale(1.1);
}

.cardchat-dark-mode .cardchat-feedback-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.cardchat-feedback-positive:hover {
    color: #4CAF50;
}

.cardchat-feedback-negative:hover {
    color: #F44336;
}

.cardchat-feedback-loading,
.cardchat-feedback-thanks,
.cardchat-feedback-error {
    padding: 5px 10px;
    border-radius: 12px;
    font-size: 12px;
}

.cardchat-feedback-thanks {
    background-color: rgba(76, 175, 80, 0.1);
    color: #4CAF50;
}

.cardchat-dark-mode .cardchat-feedback-thanks {
    background-color: rgba(76, 175, 80, 0.2);
}

.cardchat-feedback-error {
    background-color: rgba(244, 67, 54, 0.1);
    color: #F44336;
}

.cardchat-dark-mode .cardchat-feedback-error {
    background-color: rgba(244, 67, 54, 0.2);
}

/* Feedback Form Styles */
.cardchat-feedback-form {
    background-color: var(--cardchat-bg-secondary);
    border-radius: 8px;
    padding: 10px;
    margin: 5px 0;
}

.cardchat-feedback-form p {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: var(--cardchat-text-primary);
}

.cardchat-feedback-textarea {
    width: 100%;
    min-height: 80px;
    padding: 8px;
    border: 1px solid var(--cardchat-border-color);
    border-radius: 4px;
    background-color: var(--cardchat-bg-primary);
    color: var(--cardchat-text-primary);
    font-family: var(--cardchat-font-family);
    font-size: 14px;
    resize: vertical;
    margin-bottom: 10px;
}

.cardchat-feedback-form-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.cardchat-feedback-submit,
.cardchat-feedback-skip {
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    border: none;
    font-family: var(--cardchat-font-family);
}

.cardchat-feedback-submit {
    background-color: var(--cardchat-primary-color);
    color: var(--cardchat-button-text);
}

.cardchat-feedback-skip {
    background-color: var(--cardchat-bg-secondary);
    color: var(--cardchat-text-secondary);
    border: 1px solid var(--cardchat-border-color);
}

.cardchat-feedback-error-input {
    border-color: #F44336 !important;
    box-shadow: 0 0 0 1px #F44336;
}

.cardchat-color-theme-wrapper + .description.clear {
    clear: both; /* Ensure description starts below */
    padding-top: 10px; /* Add some space below the combined fields */
    width: 100%; /* Take full width */
}

/* Media Uploader Styles */
.cardchat-custom-icon-wrapper img {
    max-width: 50px;
    max-height: 50px;
    display: block;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    padding: 2px;
}
