/* Chat Widget Styles */
.chat-widget {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Chat Message Notifications */
@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

/* Chat Color Variables */
:root {
    --chat-primary: #192e4c;
    --chat-secondary: #f4dbab;
    --chat-sent-bubble: #ffefef;
    --chat-received-bubble: #fffce6;
}

/* Product Banner Styles */
.chat-product-banner {
    border-bottom: 1px solid #bae6fd;
    margin: 0;
    padding: 1rem;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
}

.chat-product-banner-content {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.chat-product-image {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    background: white;
    border: 1px solid #bae6fd;
}

.chat-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-product-banner-info {
    flex: 1;
    min-width: 0;
}

.chat-product-banner-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: #1e293b;
    margin-bottom: 0.5rem;
}

.chat-product-banner-link {
    font-size: 0.9375rem;
    color: #1F3A5F;
    text-decoration: none;
    font-weight: 600;
    display: block;
    margin-bottom: 0.5rem;
    line-height: 1.4;
    transition: color 0.2s;
}

.chat-product-banner-link:hover {
    color: #0f172a;
    text-decoration: underline;
}

.chat-product-banner-link svg {
    display: inline-block;
    vertical-align: middle;
    margin-left: 0.25rem;
}

/* Toggle Button */
.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
    padding: 0;
    overflow: visible;
}

.chat-toggle-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.chat-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
    display: block;
}

.chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--chat-primary);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 2px solid white;
}

/* Chat Container */
.chat-container {
    position: absolute;
    bottom: 80px;
    left: 0;
    width: 380px;
    height: 600px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Chat Header */
.chat-header {
    padding: 16px;
    background: var(--chat-primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.chat-close-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Conversations List */
.chat-conversations-list {
    flex: 1;
    overflow-y: auto;
    background: #f8f9fa;
}

.chat-conversation-item {
    padding: 12px 16px;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s;
}

.chat-conversation-item:hover {
    background: var(--chat-secondary);
}

.chat-conversation-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #495057;
    flex-shrink: 0;
}

.chat-conversation-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chat-conversation-info {
    flex: 1;
    min-width: 0;
}

.chat-conversation-name {
    font-weight: 600;
    color: #212529;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conversation-preview {
    font-size: 14px;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conversation-time {
    font-size: 12px;
    color: #adb5bd;
    margin-top: 4px;
}

.chat-conversation-unread {
    background: var(--chat-primary);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}

/* Chat Window */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
    min-height: 0;
}

.chat-window-header {
    padding: 12px 16px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--chat-secondary);
}

.chat-back-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: #495057;
}

.chat-recipient-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chat-recipient-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #495057;
}

.chat-recipient-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chat-recipient-name {
    font-weight: 600;
    color: #212529;
}

/* Messages Area */
.chat-messages-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    min-height: 0;
    max-height: 100%;
}

.chat-message {
    display: flex;
    gap: 8px;
    max-width: 75%;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #495057;
    flex-shrink: 0;
}

.chat-message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chat-message-content {
    background: var(--chat-received-bubble);
    padding: 10px 14px;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chat-message.sent .chat-message-content {
    background: var(--chat-sent-bubble);
    color: #333;
}

.chat-message-text {
    margin: 0;
    word-wrap: break-word;
    line-height: 1.5;
}

.chat-message-time {
    font-size: 11px;
    color: #6c757d;
    margin-top: 4px;
}

.chat-message.sent .chat-message-time {
    color: #6c757d;
}

.chat-message-attachment {
    margin-top: 8px;
}

.chat-message-attachment img,
.chat-message-attachment video {
    max-width: 100%;
    border-radius: 8px;
}

.chat-message-youtube {
    margin-top: 8px;
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
}

.chat-message-youtube iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

.chat-message-audio {
    margin-top: 8px;
}

.chat-message-audio audio {
    width: 100%;
}

.chat-message-file {
    margin-top: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-message.sent .chat-message-file {
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.chat-message-file a {
    color: inherit;
    text-decoration: none;
    flex: 1;
}

/* Input Area */
.chat-input-area {
    padding: 12px;
    border-top: 1px solid #e9ecef;
    background: white;
    flex-shrink: 0;
    min-height: fit-content;
}

.chat-input-tools {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-tool-btn {
    background: none;
    border: none;
    color: #6c757d;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background 0.2s;
}

.chat-tool-btn:hover {
    background: var(--chat-secondary);
}

.chat-youtube-input {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px;
    background: var(--chat-secondary);
    border-radius: 8px;
}

.chat-youtube-input input {
    flex: 1;
    padding: 6px 12px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 14px;
}

.chat-youtube-input button {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.chat-audio-recorder {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px;
    background: var(--chat-secondary);
    border-radius: 8px;
}

/* Preview Area */
.chat-preview-area {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0 16px 16px 16px;
    border: 1px solid rgba(160, 13, 38, 0.2);
    border-radius: 8px;
    background: var(--chat-secondary);
    overflow: hidden;
    max-height: 200px;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.chat-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--chat-primary);
    color: white;
    border-bottom: 1px solid rgba(160, 13, 38, 0.3);
    font-size: 12px;
    font-weight: 600;
}

.chat-preview-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.chat-preview-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-preview-content {
    padding: 8px 12px;
    max-height: 150px;
    overflow-y: auto;
}

.chat-preview-item {
    position: relative;
    margin-bottom: 8px;
}

.chat-preview-item:last-child {
    margin-bottom: 0;
}

.chat-preview-image {
    max-width: 100%;
    max-height: 120px;
    border-radius: 6px;
    display: block;
    object-fit: contain;
}

.chat-preview-video {
    max-width: 100%;
    max-height: 120px;
    border-radius: 6px;
    display: block;
}

.chat-preview-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: white;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}

.chat-preview-file-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e9ecef;
    border-radius: 4px;
    flex-shrink: 0;
}

.chat-preview-file-info {
    flex: 1;
    min-width: 0;
}

.chat-preview-file-name {
    font-size: 14px;
    font-weight: 500;
    color: #212529;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-preview-file-size {
    font-size: 12px;
    color: #6c757d;
}

.chat-preview-remove {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.chat-preview-remove:hover {
    background: #f8d7da;
}

.chat-preview-youtube {
    padding: 8px;
    background: white;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}

.chat-preview-youtube-url {
    font-size: 14px;
    color: #495057;
    word-break: break-all;
}

.chat-audio-timer {
    flex: 1;
    text-align: center;
    font-weight: 600;
    color: #495057;
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chat-message-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #dee2e6;
    border-radius: 24px;
    resize: none;
    font-size: 14px;
    font-family: inherit;
    max-height: 120px;
    min-height: 44px;
}

.chat-message-input:focus {
    outline: none;
    border-color: var(--chat-primary);
}

.chat-send-btn {
    padding: 10px 20px;
    background: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    transition: background 0.2s, opacity 0.2s;
    height: 44px;
    flex-shrink: 0;
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-send-btn:not(:disabled):hover {
    background: #8a0b20;
}

.chat-loading {
    padding: 20px;
    text-align: center;
    color: #6c757d;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    /* Widget positioning on mobile */
    .chat-widget {
        bottom: 16px;
        left: 16px;
        right: auto;
        margin: 0;
        width: auto;
        height: auto;
    }
    
    /* Ensure container is independent and centered when open */
    .chat-widget .chat-container {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        width: 100dvw !important;
        height: 100vh !important;
        height: 100dvh !important;
        margin: 0 !important;
        padding: 0 !important;
        transform: none !important;
    }
    
    /* Toggle button - larger and more accessible on mobile */
    .chat-toggle-btn {
        width: 56px;
        height: 56px;
        box-shadow: 0 4px 16px rgba(160, 13, 38, 0.4);
    }
    
    .chat-toggle-btn:active {
        transform: scale(0.95);
    }
    
    .chat-unread-badge {
        width: 22px;
        height: 22px;
        font-size: 11px;
        top: -3px;
        right: -3px;
    }
    
    /* Full screen container on mobile - perfectly centered */
    .chat-container {
        width: 100vw !important;
        width: 100dvw !important; /* Dynamic viewport width for mobile browsers */
        height: 100vh !important;
        height: 100dvh !important; /* Dynamic viewport height for mobile browsers */
        bottom: 0 !important;
        left: 0 !important;
        top: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border-radius: 0 !important;
        position: fixed !important;
        max-width: none !important;
        max-height: none !important;
        transform: none !important;
        box-sizing: border-box !important;
    }
    
    /* Header - larger touch targets */
    .chat-header {
        padding: 16px 20px;
        min-height: 56px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    .chat-header h3 {
        font-size: 20px;
    }
    
    .chat-close-btn {
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        border-radius: 50%;
        transition: background 0.2s;
    }
    
    .chat-close-btn:active {
        background: rgba(255, 255, 255, 0.2);
    }
    
    /* Conversations list - better spacing */
    .chat-conversation-item {
        padding: 16px 20px;
        min-height: 72px;
        gap: 16px;
    }
    
    .chat-conversation-item:active {
        background: var(--chat-secondary);
    }
    
    .chat-conversation-avatar {
        width: 52px;
        height: 52px;
    }
    
    .chat-conversation-name {
        font-size: 16px;
        margin-bottom: 6px;
    }
    
    .chat-conversation-preview {
        font-size: 15px;
    }
    
    .chat-conversation-time {
        font-size: 13px;
        margin-top: 6px;
    }
    
    .chat-conversation-unread {
        width: 22px;
        height: 22px;
        font-size: 12px;
    }
    
    /* Chat window header - mobile optimized */
    .chat-window-header {
        padding: 14px 16px;
        min-height: 56px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }
    
    .chat-back-btn {
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        border-radius: 50%;
        transition: background 0.2s;
    }
    
    .chat-back-btn:active {
        background: rgba(0, 0, 0, 0.1);
    }
    
    .chat-recipient-avatar {
        width: 44px;
        height: 44px;
    }
    
    .chat-recipient-name {
        font-size: 17px;
    }
    
    /* Messages area - better padding and spacing */
    .chat-messages-area {
        padding: 16px 12px;
        gap: 16px;
        /* Account for safe area on devices with notches */
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    
    /* Messages - larger on mobile, better touch targets */
    .chat-message {
        max-width: 85%;
        gap: 10px;
    }
    
    .chat-message-avatar {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }
    
    .chat-message-content {
        padding: 12px 16px;
        border-radius: 16px;
        font-size: 15px;
        line-height: 1.5;
    }
    
    .chat-message-text {
        font-size: 15px;
        line-height: 1.6;
    }
    
    .chat-message-time {
        font-size: 12px;
        margin-top: 6px;
    }
    
    /* Product banner - mobile optimized */
    .chat-product-banner {
        padding: 0.75rem !important;
    }
    
    .chat-product-image {
        width: 60px !important;
        height: 60px !important;
    }
    
    .chat-product-banner-title {
        font-size: 0.8125rem !important;
    }
    
    .chat-product-banner-link {
        font-size: 0.75rem !important;
    }
    
    /* Input area - mobile optimized */
    .chat-input-area {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        border-top: 1px solid #e9ecef;
        background: white;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
    }
    
    .chat-input-tools {
        gap: 12px;
        margin-bottom: 10px;
        flex-wrap: wrap;
    }
    
    .chat-tool-btn {
        padding: 10px;
        min-width: 44px;
        min-height: 44px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #f8f9fa;
        transition: all 0.2s;
    }
    
    .chat-tool-btn:active {
        background: var(--chat-secondary);
        transform: scale(0.95);
    }
    
    .chat-tool-btn svg {
        width: 22px;
        height: 22px;
    }
    
    /* YouTube input - mobile friendly */
    .chat-youtube-input {
        padding: 12px;
        gap: 10px;
        margin-bottom: 10px;
        flex-wrap: wrap;
    }
    
    .chat-youtube-input input {
        flex: 1;
        min-width: 0;
        padding: 10px 14px;
        font-size: 15px;
        min-height: 44px;
    }
    
    .chat-youtube-input button {
        padding: 10px 16px;
        min-height: 44px;
        font-size: 15px;
        border-radius: 8px;
    }
    
    /* Audio recorder - mobile optimized */
    .chat-audio-recorder {
        padding: 12px;
        gap: 10px;
        margin-bottom: 10px;
    }
    
    .chat-audio-timer {
        font-size: 16px;
    }
    
    .chat-audio-recorder button {
        padding: 10px 16px;
        min-height: 44px;
        font-size: 15px;
        border-radius: 8px;
    }
    
    /* Input row - better spacing */
    .chat-input-row {
        gap: 10px;
        align-items: flex-end;
    }
    
    .chat-message-input {
        padding: 12px 16px;
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 48px;
        max-height: 150px;
        border-radius: 24px;
        line-height: 1.5;
    }
    
    .chat-send-btn {
        padding: 12px 24px;
        min-width: 80px;
        min-height: 48px;
        font-size: 15px;
        border-radius: 24px;
        font-weight: 600;
    }
    
    .chat-send-btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    /* Preview area - mobile optimized */
    .chat-preview-area {
        margin: 0 12px 12px 12px;
        max-height: 180px;
        border-radius: 12px;
    }
    
    .chat-preview-header {
        padding: 10px 14px;
        font-size: 13px;
        min-height: 44px;
    }
    
    .chat-preview-close {
        padding: 6px;
        min-width: 32px;
        min-height: 32px;
        border-radius: 50%;
    }
    
    .chat-preview-content {
        padding: 10px 14px;
        max-height: 130px;
    }
    
    .chat-preview-image,
    .chat-preview-video {
        max-height: 100px;
    }
    
    /* Message attachments - better sizing */
    .chat-message-attachment img,
    .chat-message-attachment video {
        max-width: 100%;
        max-height: 250px;
        border-radius: 12px;
    }
    
    .chat-message-youtube {
        border-radius: 12px;
    }
    
    /* Loading state */
    .chat-loading {
        padding: 24px;
        font-size: 15px;
    }
    
    /* Safe area support for devices with notches */
    @supports (padding: max(0px)) {
        .chat-container {
            padding-top: env(safe-area-inset-top);
            padding-bottom: env(safe-area-inset-bottom);
            padding-left: env(safe-area-inset-left);
            padding-right: env(safe-area-inset-right);
        }
        
        .chat-header {
            padding-top: max(16px, env(safe-area-inset-top));
        }
        
        .chat-input-area {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
    }
}

/* Extra small devices (phones in portrait) */
@media (max-width: 480px) {
    .chat-toggle-btn {
        width: 52px;
        height: 52px;
        bottom: 12px;
        left: 12px;
    }
    
    .chat-message {
        max-width: 90%;
    }
    
    .chat-message-content {
        padding: 10px 14px;
        font-size: 14px;
    }
    
    .chat-input-tools {
        gap: 8px;
    }
    
    .chat-tool-btn {
        min-width: 40px;
        min-height: 40px;
        padding: 8px;
    }
    
    .chat-tool-btn svg {
        width: 20px;
        height: 20px;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-container {
        width: 100vw !important;
        width: 100dvw !important;
        height: 100vh !important;
        height: 100dvh !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .chat-header {
        min-height: 48px;
        padding: 12px 20px;
    }
    
    .chat-messages-area {
        padding: 12px;
    }
    
    .chat-input-area {
        padding: 10px 16px;
    }
    
    .chat-message-input {
        min-height: 44px;
        font-size: 15px;
    }
    
    .chat-send-btn {
        min-height: 44px;
        padding: 10px 20px;
    }
}

