@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary-color: #6366f1;
    --primary-hover: #5558e3;
    --secondary-color: #8b5cf6;
    --background-main: #202123;
    --background-secondary: #2d2d2d;
    --background-user: #3a3a3a;
    --border-color: #404040;
    --border-focus: #6366f1;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-placeholder: #606060;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh; /* Use min-height for better content adaptation */
    background-color: var(--background-main);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px; /* Add some padding around the app container */
}

#appContainer {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    background: transparent;
    position: relative;
    box-shadow: none;
    border-radius: var(--radius-lg); /* Consistent border-radius */
    overflow: hidden; /* Ensure content respects border-radius */
    background-color: var(--background-secondary); /* Give it a subtle background */
    box-shadow: var(--shadow-lg); /* Add a subtle shadow for depth */
}

/* Header */
.header {
    display: flex; /* Always display the header */
    justify-content: center;
    align-items: center;
    padding: 16px 24px;
    background-color: var(--background-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: 60px; /* Ensure a consistent height */
}

.header::after {
    /* Remove the old underline effect */
    content: none;
}

.header h1 {
    font-size: 20px; /* Slightly larger for better readability */
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Messages Area */
messages-area {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    background: var(--background-main); /* Ensure message area has a distinct background */
    position: relative;
    padding: 20px 0; /* Adjust padding for better look */
    border-radius: var(--radius-lg);
}

messages-area::-webkit-scrollbar {
    width: 8px; /* Slightly wider scrollbar for easier interaction */
}

messages-area::-webkit-scrollbar-track {
    background: var(--background-main); /* Match background */
}

messages-area::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px; /* More rounded scrollbar */
    transition: background-color 0.2s ease;
}

messages-area::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color); /* Highlight on hover */
}

messages-area #messages {
    display: flex;
    flex-direction: column;
    padding: 0;
    min-height: 100%;
}

messages-area .message {
    padding: 12px 0; /* Reduced vertical padding for denser chat */
    animation: slideIn 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); /* Slightly faster animation */
    transition: background-color 0.2s ease;
}

messages-area .message:last-child {
    margin-bottom: 10px; /* Add some space at the bottom of the last message */
}

messages-area .message:hover {
    background-color: var(--background-secondary); /* Highlight on hover */
}

messages-area .message-content {
    max-width: 720px; /* Slightly smaller max-width for content */
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    gap: 12px; /* Reduced gap */
    align-items: flex-start;
}

messages-area .avatar {
    width: 36px; /* Slightly larger avatar */
    height: 36px;
    border-radius: 50%; /* Make avatars circular */
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px; /* Slightly larger font */
    font-weight: 600; /* Bolder font */
    color: #ffffff;
    box-shadow: var(--shadow-sm); /* Add a subtle shadow to avatars */
    position: relative;
    overflow: hidden;
}

messages-area .avatar::before {
    /* Remove unnecessary ::before pseudo-element */
    content: none;
}

messages-area .user .avatar {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
}

messages-area .bot .avatar {
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
}

messages-area .bot .avatar .bot-avatar-image {
    width: 300%;
    height: 200%;
    object-fit: contain; /* Ensures the image fits without cropping */
    border-radius: 50%; /* Keep it circular */
}

messages-area .message-text {
    flex: 1;
    line-height: 1.7; /* Increased line-height for readability */
    font-size: 15px; /* Slightly larger font size */
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: normal;
    font-weight: 400;
    letter-spacing: 0;
    background-color: var(--background-main); /* Default background for message text */
    padding: 10px 15px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    /* Default LTR for generic messages */
    direction: ltr;
    text-align: left;
}

messages-area .user .message-text {
    background-color: var(--background-user); /* User message background */
    border-color: var(--primary-color);
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.3);
}

messages-area .bot .message-text {
    background-color: var(--background-secondary); /* Bot message background */
    border-color: var(--border-color);
}

/* RTL specific styles */
.rtl-content .message-text {
    direction: rtl;
    text-align: right;
}

/* Markdown Table Styles */
.message-text table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0; /* Increased margin */
    background-color: var(--background-main);
    border-radius: var(--radius-md); /* More rounded corners */
    overflow: hidden;
    box-shadow: var(--shadow-md); /* Stronger shadow for tables */
    border: 1px solid var(--border-color);
}

.message-text th,
.message-text td {
    border: 1px solid var(--border-color);
    padding: 12px 18px; /* Increased padding */
    text-align: left;
    color: var(--text-primary);
    font-size: 14px;
}

.message-text th {
    background-color: var(--background-user); /* Darker header for tables */
    font-weight: 600;
    color: var(--text-primary);
}

.message-text tr:nth-child(even) {
    background-color: var(--background-secondary); /* Alternating row colors */
}

.message-text tbody tr:hover {
    background-color: var(--border-color);
}

.message-text thead th:first-child {
    border-top-left-radius: var(--radius-md);
}

.message-text thead th:last-child {
    border-top-right-radius: var(--radius-md);
}

.message-text tbody tr:last-child td:first-child {
    border-bottom-left-radius: var(--radius-md);
}

.message-text tbody tr:last-child td:last-child {
    border-bottom-right-radius: var(--radius-md);
}

.message-text pre {
    background-color: #282c34;
    color: #abb2bf;
    padding: 15px; /* Increased padding */
    border-radius: var(--radius-md); /* More rounded corners */
    overflow-x: auto;
    margin: 15px 0;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.message-text code {
    background-color: #3e4451;
    color: #e06c75;
    padding: 3px 6px; /* Slightly larger padding */
    border-radius: 4px; /* More rounded */
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    font-size: 90%; /* Slightly larger font */
}

.message-text pre code {
    background-color: transparent;
    color: #abb2bf;
    padding: 0;
}

.message-text blockquote {
    border-left: 5px solid var(--primary-color); /* Thicker border */
    margin: 15px 0;
    padding: 10px 20px; /* Increased padding */
    color: var(--text-secondary);
    background-color: var(--background-user);
    border-radius: var(--radius-md); /* More rounded */
    box-shadow: var(--shadow-sm);
}

.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4,
.message-text h5,
.message-text h6 {
    color: var(--text-primary);
    margin-top: 25px; /* Increased top margin */
    margin-bottom: 12px; /* Increased bottom margin */
    line-height: 1.3; /* Adjusted line-height */
    font-weight: 700; /* Bolder headings */
}

.message-text h1 { font-size: 2.2em; border-bottom: 1px solid var(--border-color); padding-bottom: 5px;} /* Add underline to H1 */
.message-text h2 { font-size: 1.8em; }
.message-text h3 { font-size: 1.6em; }
.message-text h4 { font-size: 1.3em; }
.message-text h5 { font-size: 1.1em; }
.message-text h6 { font-size: 0.9em; }

.message-text p {
    margin-bottom: 12px; /* Increased bottom margin */
}

.message-text ul,
.message-text ol {
    margin: 15px 0 15px 25px; /* Adjusted margins */
    padding: 0;
}

.message-text li {
    margin-bottom: 8px; /* Increased bottom margin */
    font-size: 15px; /* Consistent font size */
}

.message-text a {
    color: var(--primary-color);
    text-decoration: underline; /* Always underline links */
    font-weight: 500;
}

.message-text a:hover {
    color: var(--primary-hover);
    text-decoration: none;
}

.message-text img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md); /* More rounded corners */
    margin: 15px 0; /* Adjusted margins */
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.message-text strong,
.message-text b {
    font-weight: 700; /* Bolder strong text */
}

.message-text em,
.message-text i {
    font-style: italic;
}

messages-area .user {
    background: transparent; /* Background on messages-area now */
}

messages-area .bot {
    background: transparent; /* Background on messages-area now */
}

.disclaimer-message {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 10px;
    margin-bottom: 5px;
    padding: 0 20px;
}

.disclaimer-message a {
    color: var(--primary-color);
    text-decoration: none;
}

.disclaimer-message a:hover {
    text-decoration: underline;
}

/* Message Input */
message-input {
    padding: 16px 24px 32px;
    background-color: var(--background-secondary); /* Match app container background */
    border-top: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    position: sticky;
    bottom: 0;
    z-index: 10;
    width: 100%;
    margin-top: auto;
}

message-input .input-container {
    max-width: 760px;
    margin: 0 auto;
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 10px; /* Add a small gap between input and send button */
}

message-input #messageInputField {
    flex: 1;
    min-height: 48px; /* Slightly taller input field */
    padding: 14px 50px 14px 18px; /* Adjusted padding */
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg); /* More rounded input field */
    font-size: 16px; /* Larger font size for input */
    font-family: inherit;
    font-weight: 400;
    background-color: var(--background-main); /* Input background color */
    color: var(--text-primary);
    resize: none;
    outline: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    line-height: 1.5;
    box-shadow: var(--shadow-sm); /* Subtle shadow */
    letter-spacing: 0;
}

message-input #messageInputField:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.3); /* Stronger focus shadow */
    transform: none;
}

message-input #messageInputField::placeholder {
    color: var(--text-placeholder);
    font-weight: 400;
}

message-input #sendButton {
    position: relative; /* Make button relative to input-container */
    right: 0;
    bottom: 0;
    width: 44px; /* Larger send button */
    height: 44px;
    border: none;
    border-radius: var(--radius-lg); /* More rounded button */
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0; /* Prevent button from shrinking */
}

message-input #sendButton:hover {
    background: linear-gradient(135deg, var(--primary-hover), var(--secondary-color));
    transform: translateY(-2px); /* Lift button on hover */
    box-shadow: var(--shadow-md);
}

message-input #sendButton:active {
    transform: scale(0.98); /* Subtle press effect */
}

message-input #sendButton:disabled {
    background-color: var(--border-color);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

message-input #sendButton svg {
    width: 20px; /* Larger icon */
    height: 20px;
    fill: #ffffff;
    transition: transform 0.2s ease; /* Add transition for icon */
    display: block;
}

message-input #sendButton:hover svg {
    transform: translateX(2px); /* Slide icon on hover */
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(15px); /* Slightly reduced slide distance */
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Typing Dots Loading Indicator */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px; /* Increased gap */
    padding: 8px 0; /* Adjusted padding */
}

.typing-indicator span {
    width: 6px; /* Slightly larger dots */
    height: 6px;
    border-radius: 50%;
    background-color: var(--primary-color);
    animation: typingDots 1.2s infinite;
    opacity: 0.5; /* Slightly more opaque */
    box-shadow: 0 0 4px currentColor; /* Stronger shadow */
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.18s; /* Adjusted delay */
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.36s; /* Adjusted delay */
}

@keyframes typingDots {
    0%, 60%, 100% {
        transform: translateY(0) scale(1);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-8px) scale(1.2); /* Increased bounce and scale */
        opacity: 1;
    }
}

.token {
    display: inline;
    opacity: 0;
    animation: fadeInToken 0.15s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards; /* Faster token animation */
    will-change: opacity, transform;
    backface-visibility: hidden;
    transform: translateZ(0);
}

@keyframes fadeInToken {
    0% {
        opacity: 0;
        transform: translateY(2px) translateZ(0); /* Slightly larger initial jump */
        filter: blur(1px); /* Stronger initial blur */
    }
    100% {
        opacity: 1;
        transform: translateY(0) translateZ(0);
        filter: blur(0);
    }
}


/* Typing indicator for generating text */
.generating-text::after {
    content: '▊';
    animation: blink 0.8s infinite;
    color: var(--primary-color);
    margin-left: 3px; /* Slightly larger margin */
    display: inline-block;
    vertical-align: middle; /* Align cursor better */
}

.message-text::after {
    content: none;
}

@keyframes blink {
    0%, 49% {
        opacity: 1;
    }
    50%, 100% {
        opacity: 0;
    }
}

/* Desktop styles */
@media (min-width: 1024px) {
    body {
        justify-content: center; /* Center content vertically on desktop */
    }

    #appContainer {
        border-radius: var(--radius-lg);
        margin: auto; /* Center with auto margins */
        height: calc(100vh - 40px);
        max-height: 900px; /* Max height for desktop */
        min-height: 600px; /* Min height for desktop */
    }

    .header {
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: var(--shadow-sm); /* Add shadow to header */
    }

    messages-area .message:hover {
        background-color: var(--background-user); /* Consistent hover effect */
    }
}

/* Tablet styles */
@media (max-width: 1023px) and (min-width: 768px) {
    body {
        padding: 15px; /* Adjust padding for tablets */
    }

    #appContainer {
        max-width: 100%;
        margin: 0;
        height: calc(100vh - 30px);
    }

    .header {
        padding: 14px 20px;
    }

    messages-area .message-content {
        padding: 0 20px;
        gap: 14px; /* Adjusted gap */
    }

    message-input {
        padding: 20px;
    }

    message-input #messageInputField {
        min-height: 50px;
    }
}

/* Mobile styles */
@media (max-width: 767px) {
    body {
        background: var(--background-main);
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
        overflow: hidden;
        position: fixed;
        width: 100%;
        padding: 0; /* Remove body padding on mobile */
    }

    #appContainer {
        max-width: 100%;
        margin: 0;
        box-shadow: none;
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
        position: relative;
        overflow: hidden;
        border-radius: 0; /* No border-radius on mobile */
    }

    .header {
        padding: 12px 16px;
        min-height: 56px;
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 100;
        background: var(--background-main);
        border-bottom: 1px solid var(--border-color);
        border-radius: 0;
    }

    .header h1 {
        font-size: 18px; /* Adjusted for mobile */
    }

    messages-area {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        padding: 0;
        position: relative;
        contain: layout style paint;
        border-radius: 0;
    }

    messages-area .message {
        padding: 14px 0; /* Adjusted padding */
        margin: 0;
        will-change: transform;
        backface-visibility: hidden;
        transform: translateZ(0);
    }

    messages-area .message-content {
        padding: 0 16px;
        gap: 14px;
        max-width: 100%;
    }

    messages-area .avatar {
        width: 36px;
        height: 36px;
        font-size: 15px;
        flex-shrink: 0;
    }

    messages-area .message-text {
        font-size: 15px;
        line-height: 1.6;
        word-wrap: break-word; /* Ensure long words break */
        overflow-wrap: break-word; /* Ensure long words break */
        word-break: break-word; /* Force words to break if necessary */
        hyphens: auto;
        padding: 12px 16px; /* Adjusted padding for mobile */
    }

    message-input {
        padding: 16px;
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        z-index: 100;
        background: var(--background-main);
        border-top: 1px solid var(--border-color);
        backdrop-filter: blur(10px);
    }

    message-input #messageInputField {
        min-height: 54px; /* Taller input for mobile */
        padding: 18px 50px 18px 18px; /* Adjusted padding */
        font-size: 16px;
        border-radius: var(--radius-lg);
        color: var(--text-primary);
        max-height: 150px; /* Allow more lines */
        resize: none;
    }

    message-input #sendButton {
        width: 48px; /* Larger button for mobile */
        height: 48px;
        right: 8px;
        bottom: 8px;
        border-radius: var(--radius-lg);
    }

    message-input #sendButton svg {
        width: 22px; /* Larger icon for mobile */
        height: 22px;
    }

    /* Prevent zoom on input focus */
    message-input #messageInputField {
        font-size: 16px;
        transform: scale(1);
    }

    /* Improve touch targets */
    .action-button {
        min-height: 48px; /* Larger touch target */
        min-width: 48px;
    }

    /* Better scrolling performance */
    messages-area {
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
}

/* Extra small mobile */
@media (max-width: 320px) {
    .header {
        padding: 10px 12px;
    }

    messages-area .message-content {
        padding: 0 12px;
        gap: 12px;
    }

    message-input {
        padding: 12px;
    }

    message-input #messageInputField {
        padding: 16px 48px 16px 16px;
    }

    message-input #sendButton {
        width: 42px;
        height: 42px;
    }
}

/* Message actions for bot responses */
.message-actions {
    display: flex;
    gap: 10px; /* Increased gap */
    margin-top: 15px; /* Increased margin */
    padding-left: 50px; /* Align with avatar */
    flex-wrap: wrap; /* Allow wrapping on small screens */
}

.action-button {
    background: var(--background-main); /* Match messages background */
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md); /* More rounded */
    padding: 10px 15px; /* Increased padding for better touch target */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    min-height: 40px; /* Ensure minimum height */
    color: var(--text-primary); /* Ensure text color is visible */
    font-size: 14px;
    box-shadow: var(--shadow-sm);
}

.action-button:hover {
    background-color: var(--primary-color); /* Highlight on hover */
    border-color: var(--primary-color);
    color: #ffffff;
    transform: translateY(-2px); /* Lift button on hover */
    box-shadow: var(--shadow-md);
}

.action-button svg {
    width: 18px; /* Slightly larger icon */
    height: 18px;
    fill: var(--text-secondary);
    margin-right: 8px; /* Space between icon and text */
    transition: fill 0.2s ease;
}

.action-button:hover svg {
    fill: #ffffff; /* White icon on hover */
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --background-main: #1a1a1c; /* Slightly darker main background */
        --background-secondary: #252527; /* Slightly darker secondary background */
        --background-user: #303032; /* Slightly darker user message background */
        --border-color: #38383a; /* Darker border */
        --text-primary: #f0f0f0; /* Lighter primary text */
        --text-secondary: #b0b0b0; /* Lighter secondary text */
        --text-placeholder: #707070; /* Lighter placeholder text */
    }

    body {
        background-color: var(--background-main);
    }

    messages-area .message:hover {
        background-color: var(--background-secondary); /* Darker hover for dark mode */
    }

    messages-area .user .message-text {
        background-color: var(--background-user);
        border-color: var(--primary-color);
    }

    messages-area .bot .message-text {
        background-color: var(--background-secondary);
        border-color: var(--border-color);
    }

    message-input #messageInputField {
        color: var(--text-primary);
        background-color: var(--background-main);
    }

    message-input #sendButton {
        background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    }

    .action-button {
        background: var(--background-main);
        color: var(--text-primary);
    }

    .action-button:hover {
        background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
        border-color: var(--primary-color);
        color: #ffffff;
    }

    .action-button svg {
        fill: var(--text-secondary);
    }

    .action-button:hover svg {
        fill: #ffffff;
    }
}

/* Focus styles for accessibility */
*:focus-visible {
    outline: 3px solid var(--primary-color); /* Thicker outline */
    outline-offset: 3px; /* More offset */
    border-radius: var(--radius-md); /* Apply radius to outline */
}

/* Custom Elements Default Display */
messages-area, message-input {
    display: block;
}

/* Product Images Styles */
.product-images {
    margin-top: 20px; /* Increased margin */
    display: flex;
    flex-wrap: wrap;
    gap: 12px; /* Increased gap */
    justify-content: center; /* Center images */
    padding: 15px; /* Increased padding */
    background: var(--background-main); /* Consistent background */
    border-radius: var(--radius-lg); /* More rounded */
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md); /* Subtle shadow */
}

.product-image {
    position: relative;
    width: 140px; /* Larger image size */
    height: 140px;
    border-radius: var(--radius-md); /* More rounded */
    overflow: hidden;
    border: 2px solid var(--border-color);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    background: var(--background-secondary);
    box-shadow: var(--shadow-sm);
}

.product-image:hover {
    transform: scale(1.08); /* More pronounced hover effect */
    border-color: var(--primary-color);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4); /* Stronger hover shadow */
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s ease;
    background: var(--background-user);
}

.product-image img:not([src]) {
    background: linear-gradient(90deg, var(--border-color) 25%, #404040 50%, var(--border-color) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

.product-image:hover img {
    transform: scale(1.15); /* More pronounced image zoom */
}

/* Image Modal Styles */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9); /* Darker overlay */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: zoom-out; /* Indicate it's clickable to close */
    animation: fadeIn 0.3s ease-out;
}

.image-modal-content {
    max-width: 95%; /* Wider modal content */
    max-height: 95%;
    position: relative;
    box-shadow: var(--shadow-lg); /* Stronger shadow */
    border-radius: var(--radius-lg);
    overflow: hidden; /* Ensure image respects border radius */
}

.image-modal img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius-lg); /* Rounded image in modal */
    animation: zoomIn 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.image-modal-close {
    position: absolute;
    top: 15px; /* Position closer to top-right */
    right: 15px;
    background: var(--background-secondary); /* Match UI background */
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px; /* Larger close button */
    height: 40px;
    font-size: 24px; /* Larger icon */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-md);
    z-index: 1001; /* Ensure it's above the image */
}

.image-modal-close:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: scale(1.1); /* Pop effect on hover */
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Mobile responsive for product images */
@media (max-width: 767px) {
    .product-image {
        width: 110px; /* Adjusted for mobile */
        height: 110px;
    }
    
    .product-images {
        gap: 10px; /* Adjusted gap for mobile */
        padding: 10px;
    }

    .image-modal-close {
        top: 10px;
        right: 10px;
        width: 36px;
        height: 36px;
        font-size: 20px;
    }
}

/* Improved scrolling on mobile */
@supports (-webkit-overflow-scrolling: touch) {
    messages-area {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* Prevent layout shifts during text generation */
.message-text {
    min-height: 1.5em; /* Increased min-height for generation */
    contain: layout;
}

/* Smooth transitions for better UX */
.message {
    transition: transform 0.2s ease-out, opacity 0.2s ease-out; /* Smoother message transitions */
    transform: translateZ(0);
    will-change: transform, opacity;
}

/* Optimize animations for mobile */
@media (max-width: 767px) {
    .token {
        animation-duration: 0.12s; /* Faster token animation on mobile */
    }
    
    .message {
        animation-duration: 0.15s; /* Faster message animation on mobile */
    }
    
    /* Reduce motion for users who prefer it */
    @media (prefers-reduced-motion: reduce) {
        .token {
            animation: none;
            opacity: 1;
        }
        
        .message {
            animation: none;
        }
        
        messages-area {
            scroll-behavior: auto;
        }
    }
}

/* Initial actions for welcome message */
.initial-actions {
    display: flex;
    justify-content: center;
    margin-top: 25px; /* Adjusted margin */
    margin-bottom: 25px;
    width: 100%;
    max-width: 760px;
    z-index: 5;
    padding: 0 24px; /* Add horizontal padding */
}

.initial-actions .who-are-you-button {
    background-color: var(--background-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg); /* More rounded button */
    padding: 12px 25px; /* Increased padding */
    font-size: 16px; /* Larger font size */
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: var(--shadow-sm);
    white-space: nowrap; /* Prevent text wrapping */
    text-overflow: ellipsis; /* Add ellipsis if text is too long */
    overflow: hidden;
}

.initial-actions .who-are-you-button:hover {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-color: var(--primary-color);
    color: #ffffff;
    transform: translateY(-2px); /* Lift button on hover */
    box-shadow: var(--shadow-md);
}

.initial-actions .who-are-you-button:active {
    transform: scale(0.98); /* Subtle press effect */
}

/* Thinking Box Styles */
.thinking-box {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(0);
    background-color: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg); /* More rounded */
    padding: 25px; /* Increased padding */
    margin: 20px auto;
    max-width: 760px;
    width: calc(100% - 48px);
    box-shadow: var(--shadow-lg); /* Stronger shadow */
    text-align: center;
    color: var(--text-primary);
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    direction: rtl;
    text-align: right;
    overflow: hidden;
    display: flex; /* Use flex for content centering */
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.thinking-box.hidden {
    transform: translateY(-20px);
    opacity: 0;
    pointer-events: none;
}

.thinking-box-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px; /* Increased gap */
}

.thinking-box-text {
    font-size: 16px; /* Larger font size */
    font-weight: 500;
    margin: 0;
    color: var(--text-secondary);
    text-align: right;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    max-width: 350px; /* Wider text area */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
    padding-right: 15px; /* Add padding for ellipsis */
}

.thinking-box-text::after {
    content: '...';
    position: absolute;
    right: 0;
    animation: ellipsis 1.4s infinite;
    color: var(--primary-color); /* Color the ellipsis */
}

.spinner {
    position: relative;
    width: 36px; /* Larger spinner */
    height: 36px;
    margin-bottom: 15px; /* Increased margin */
}

.spinner::before,
.spinner::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    width: 100%;
    height: 100%;
    border: 4px solid transparent; /* Thicker borders */
}

.spinner::before {
    border-top-color: var(--primary-color);
    animation: spin 1s cubic-bezier(0.42, 0, 0.58, 1) infinite;
}

.spinner::after {
    border-right-color: var(--secondary-color);
    animation: spin 0.8s cubic-bezier(0.42, 0, 0.58, 1) infinite reverse;
}

@keyframes ellipsis {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Skeleton Loading Animation */
.skeleton-line {
    height: 14px; /* Taller lines */
    background: linear-gradient(90deg, var(--border-color) 25%, #404040 50%, var(--border-color) 75%);
    background-size: 200% 100%;
    width: 70%; /* Slightly narrower for variety */
    border-radius: 3px; /* More rounded */
    animation: loading 1.5s infinite;
    margin-top: 10px; /* Increased margin */
}

.skeleton-line.short {
    width: 50%; /* Shorter short line */
}

@keyframes loading {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}
/* Product Cards Styles */
.products-cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin: 20px 0;
    padding: 15px;
    background: var(--background-main);
    border-radius: var(--radius-lg);
}

.product-card {
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.product-card-content {
    padding: 0;
    display: flex;
    flex-direction: column;
}

.product-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 15px 15px 10px 15px;
    text-align: right;
    direction: rtl;
    line-height: 1.4;
}

.product-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0 15px 15px 15px;
    text-align: right;
    direction: rtl;
}

.product-image-wrapper {
    width: 100%;
    height: 280px;
    overflow: hidden;
    background: var(--background-user);
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.product-card:hover .product-card-image {
    transform: scale(1.1);
}

.image-error {
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
    padding: 20px;
}

/* Mobile Responsive */
@media (max-width: 767px) {
    .products-cards-container {
        grid-template-columns: 1fr;
        gap: 15px;
        padding: 10px;
    }
    
    .product-image-wrapper {
        height: 220px;
    }
    
    .product-name {
        font-size: 15px;
    }
    
    .product-price {
        font-size: 16px;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .products-cards-container {
        grid-template-columns: repeat(2, 1fr);
    }
}