/* Main layout */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
    -webkit-overflow-scrolling: touch;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    max-width: 800px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    position: relative;
}

/* Desktop styles */
@media (min-width: 769px) {
    .chat-container {
        margin: 20px auto;
        height: calc(100vh - 40px);
        height: calc(100dvh - 40px);
        border-radius: 10px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    }
    
    .chat-header {
        border-radius: 10px 10px 0 0;
    }
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    padding: 20px;
    text-align: center;
    position: relative;
}

.chat-header h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 5px;
}

.connection-status {
    font-size: 12px;
    opacity: 0.8;
    position: absolute;
    top: 10px;
    right: 20px;
    padding: 4px 8px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.2);
}

.connection-status.connected {
    background: rgba(76, 175, 80, 0.8);
}

.connection-status.disconnected {
    background: rgba(244, 67, 54, 0.8);
}

/* Messages container */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
}

/* Message styles */
.message {
    margin-bottom: 15px;
    display: flex;
    align-items: flex-start;
    animation: fadeInUp 0.3s ease-out;
}

.message.user {
    justify-content: flex-end;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message.user .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

.message.bot .message-content {
    background: white;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.message.progress .message-content {
    background: #e3f2fd;
    color: #1976d2;
    border: 1px solid #bbdefb;
    font-style: italic;
}

/* Message timestamp */
.message-time {
    font-size: 11px;
    color: #666;
    margin-top: 4px;
    text-align: right;
}

.message.bot .message-time {
    text-align: left;
}

/* Image in messages */
.message-image {
    max-width: 300px;
    max-height: 300px;
    border-radius: 8px;
    margin-top: 8px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.message-image:hover {
    transform: scale(1.02);
}

.message-image-preview {
    border: 2px solid #ddd;
    transition: border-color 0.2s ease;
}

.message-image-preview:hover {
    border-color: #4facfe;
}

/* Progress bar */
.progress-container {
    padding: 15px 20px;
    background: #f0f0f0;
    border-top: 1px solid #e0e0e0;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 3px;
}

.progress-text {
    font-size: 12px;
    color: #666;
    text-align: center;
}

/* Catalog styles */
.catalog-container {
    padding: 20px;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    max-height: 300px;
    overflow-y: auto;
}

.catalog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e0e0e0;
}

.catalog-header h3 {
    font-size: 18px;
    color: #333;
}

.close-catalog {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.close-catalog:hover {
    background: #f0f0f0;
}

.catalog-slides {
    display: flex;
    gap: 15px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 0;
    scroll-behavior: smooth;
}

.catalog-slide {
    flex: 0 0 200px; /* Fixed width, no shrink/grow */
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    min-height: 200px; /* Minimum height instead of fixed */
    max-height: 350px; /* Maximum height to prevent too tall cards */
}

.catalog-slide:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.catalog-slide-image-container {
    position: relative;
    width: 100%;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    max-height: 200px;
    overflow: hidden;
}

.catalog-slide img {
    width: 100%;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
}

.catalog-slide-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 6px;
}

.catalog-slide-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.catalog-slide-preview {
    font-size: 12px;
    color: #666;
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    flex: 1;
}

.catalog-slide-price {
    font-size: 14px;
    font-weight: 700;
    color: #e74c3c;
    margin-top: auto;
}

.catalog-slide-text {
    padding: 10px;
    font-size: 12px;
    color: #333;
    text-align: center;
    line-height: 1.3;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Image message styles */
.message-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    margin-top: 8px;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-image:hover {
    transform: scale(1.02);
}

/* Image Preview Container */
.image-preview-container {
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    padding: 15px 20px;
    max-height: 200px;
    overflow: hidden;
}

.image-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.preview-label {
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

.remove-image-btn {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: background-color 0.2s;
}

.remove-image-btn:hover {
    background: #c82333;
}

.image-preview-content {
    display: flex;
    gap: 15px;
    align-items: center;
}

.preview-image {
    max-width: 80px;
    max-height: 80px;
    border-radius: 8px;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 2px solid #e9ecef;
}

.image-info {
    flex: 1;
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}

/* Input container */
.chat-input-container {
    padding: 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.file-upload-container {
    display: flex;
    align-items: center;
}

.file-upload-btn {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.2s;
}

.file-upload-btn:hover {
    background: #e0e0e0;
}

.input-container {
    flex: 1;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    overflow-y: auto;
    outline: none;
    transition: border-color 0.2s;
    background: white;
    -webkit-appearance: none;
    -webkit-border-radius: 20px;
}

#messageInput:focus {
    border-color: #4facfe;
    box-shadow: 0 0 0 2px rgba(79, 172, 254, 0.2);
}

.send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    white-space: nowrap;
}

.send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.typing-indicator {
    animation: pulse 1.5s infinite;
}

/* Responsive design */
@media (max-width: 768px) {
    body {
        background: #f5f5f5;
    }
    
    .chat-container {
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        max-width: 100%;
        background: white;
        margin: 0;
    }
    
    .chat-header {
        border-radius: 0;
        padding: 15px 20px;
        position: sticky;
        top: 0;
        z-index: 100;
    }
    
    .chat-header h1 {
        font-size: 18px;
    }
    
    .chat-messages {
        flex: 1;
        padding: 10px 15px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .message-content {
        max-width: 85%;
        font-size: 14px;
        padding: 10px 12px;
    }
    
    .catalog-container {
        padding: 15px;
        max-height: 250px;
    }
    
    .catalog-slides {
        gap: 8px;
        padding: 5px 0;
    }
    
    .catalog-slide {
        flex: 0 0 160px;
        min-height: 180px;
        max-height: 280px;
    }
    
    .catalog-slide-image-container {
        min-height: 100px;
        max-height: 160px;
    }
    
    .chat-input-container {
        padding: 12px 15px;
        background: white;
        border-top: 1px solid #e0e0e0;
        position: sticky;
        bottom: 0;
        z-index: 100;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
    
    .input-container {
        flex: 1;
    }
    
    .input-container textarea {
        font-size: 16px !important; /* Prevent zoom on iOS */
        padding: 12px 15px;
        min-height: 44px; /* iOS touch target */
        border-radius: 18px;
        -webkit-appearance: none;
        appearance: none;
    }
    
    .send-btn {
        min-height: 44px; /* iOS touch target */
        padding: 0 16px;
        font-size: 14px;
        border-radius: 18px;
        white-space: nowrap;
    }
    
    .file-upload-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .chat-header {
        padding: 12px 15px;
    }
    
    .chat-header h1 {
        font-size: 16px;
    }
    
    .chat-messages {
        padding: 8px 12px;
    }
    
    .message-content {
        max-width: 90%;
        font-size: 13px;
        padding: 8px 10px;
    }
    
    .chat-input-container {
        padding: 10px 12px;
        gap: 8px;
    }
    
    .catalog-slide {
        flex: 0 0 140px;
        min-height: 160px;
        max-height: 240px;
    }
    
    .catalog-slide-image-container {
        min-height: 80px;
        max-height: 140px;
    }
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar,
.catalog-container::-webkit-scrollbar {
    width: 6px;
}

.catalog-slides::-webkit-scrollbar {
    height: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.catalog-container::-webkit-scrollbar-track,
.catalog-slides::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb,
.catalog-container::-webkit-scrollbar-thumb,
.catalog-slides::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.catalog-container::-webkit-scrollbar-thumb:hover,
.catalog-slides::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.chat-messages::-webkit-scrollbar-track,
.catalog-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb,
.catalog-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.catalog-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Catalog Preview Styles */
.catalog-preview {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid #e9ecef;
}

.catalog-preview-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid #dee2e6;
}

.catalog-preview-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
    border-color: #4facfe;
}

.catalog-preview-image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.catalog-preview-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.catalog-preview-title {
    font-weight: 600;
    font-size: 14px;
    color: #212529;
    line-height: 1.3;
}

.catalog-preview-description {
    font-size: 12px;
    color: #6c757d;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.catalog-preview-price {
    font-weight: 600;
    font-size: 13px;
    color: #28a745;
}

.catalog-view-all-btn {
    align-self: center;
    padding: 8px 16px;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.catalog-view-all-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 172, 254, 0.3);
}

/* Catalog Detail Modal */
.catalog-detail-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.catalog-detail-content {
    background: white;
    border-radius: 15px;
    max-width: 500px;
    max-height: 80vh;
    width: 100%;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.catalog-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e9ecef;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

.catalog-detail-header h3 {
    margin: 0;
    font-size: 18px;
    color: #212529;
    font-weight: 600;
}

.catalog-detail-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6c757d;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.catalog-detail-close:hover {
    background: #e9ecef;
    color: #495057;
}

.catalog-detail-body {
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.catalog-detail-image {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: 10px;
    margin-bottom: 15px;
}

.catalog-detail-text {
    margin-bottom: 15px;
    line-height: 1.6;
    color: #495057;
}

.catalog-detail-text ul {
    margin: 10px 0;
    padding-left: 20px;
}

.catalog-detail-text li {
    margin: 5px 0;
}

.catalog-detail-text strong {
    color: #212529;
}

.catalog-detail-price {
    font-size: 18px;
    font-weight: 700;
    color: #28a745;
    margin-bottom: 15px;
}

.catalog-detail-link-container {
    margin-top: 15px;
    padding: 12px 16px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #17a2b8;
}

.catalog-detail-link-container p {
    margin: 0;
    font-size: 14px;
    color: #495057;
}

.catalog-detail-link {
    color: #17a2b8;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.catalog-detail-link:hover {
    color: #138496;
    text-decoration: underline;
}

.catalog-detail-footer {
    padding: 20px;
    border-top: 1px solid #e9ecef;
    background: #f8f9fa;
    display: flex;
    justify-content: flex-end;
}

.catalog-detail-select {
    padding: 12px 24px;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.catalog-detail-select:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(79, 172, 254, 0.4);
}

/* Enhanced Catalog Slide Styles */
.catalog-slide-content {
    padding: 8px;
}

.catalog-slide-title {
    font-weight: 600;
    font-size: 14px;
    color: #212529;
    margin-bottom: 6px;
    line-height: 1.3;
}

.catalog-slide-preview {
    font-size: 12px;
    color: #6c757d;
    margin-bottom: 6px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.catalog-slide-price {
    font-weight: 600;
    font-size: 13px;
    color: #28a745;
}

.catalog-show-more-btn {
    flex: 0 0 150px;
    height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    text-align: center;
    line-height: 1.3;
}

.catalog-show-more-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(108, 117, 125, 0.3);
}

/* Mobile responsive for catalog elements */
@media (max-width: 768px) {
    .catalog-preview-item {
        flex-direction: column;
        text-align: center;
    }
    
    .catalog-preview-image {
        width: 80px;
        height: 80px;
        align-self: center;
    }
    
    .catalog-detail-modal {
        padding: 10px;
    }
    
    .catalog-detail-content {
        max-height: 90vh;
    }
    
    .catalog-detail-header,
    .catalog-detail-body,
    .catalog-detail-footer {
        padding: 15px;
    }
}
