/* WeChat Style Overhaul */
.ds-ocr-chat {
    border: none;
    border-radius: 0; /* Mobile-like usually has no radius if full screen, but keep small radius for widget */
    max-width: 720px;
    margin: 20px auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f5f5f5; /* WeChat background gray */
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    position: relative; /* Context for absolute header items */
}

/* Fullscreen Mode */
.ds-ocr-chat.ds-ocr-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Use dvh for better mobile support */
    max-width: none;
    margin: 0;
    z-index: 99999;
    border-radius: 0;
    box-shadow: none;
}

.ds-ocr-chat-header {
    padding: 10px 16px; /* Slightly reduced padding to accommodate two lines */
    background: #ededed;
    color: #000;
    font-weight: 500;
    border-bottom: 1px solid #dcdcdc;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50px;
    position: relative; /* For absolute positioning of buttons */
}

.ds-ocr-header-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
}

.ds-ocr-header-status {
    font-size: 12px;
    color: #666;
    margin-top: 2px;
    height: 14px;
    line-height: 14px;
    display: none; /* Hidden by default */
}

.ds-ocr-chat-body {
    padding: 16px;
    height: 550px;
    min-height: 300px;
    overflow-y: auto;
    background: #f5f5f5;
    flex: 0 0 550px;
}

.ds-ocr-chat.ds-ocr-fullscreen .ds-ocr-chat-body {
    height: auto;
    flex: 1 1 auto;
}

/* Scrollbar styling for webkit */
.ds-ocr-chat-body::-webkit-scrollbar {
    width: 6px;
}
.ds-ocr-chat-body::-webkit-scrollbar-track {
    background: transparent;
}
.ds-ocr-chat-body::-webkit-scrollbar-thumb {
    background: #cdcdcd;
    border-radius: 3px;
}

.ds-ocr-row {
    display: flex;
    margin: 16px 0;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
}

.ds-ocr-row-user {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.ds-ocr-row-assistant {
    flex-direction: row;
    justify-content: flex-start;
}

.ds-ocr-avatar {
    width: 40px;
    height: 40px;
    border-radius: 6px; /* WeChat uses square-ish avatars with slight radius */
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.ds-ocr-msg {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
}

.ds-ocr-msg-user {
    background: #95ec69; /* WeChat Green */
    color: #000;
    border-top-right-radius: 6px;
    border: 1px solid #8ad962; /* Subtle border */
}

/* Arrow for user */
.ds-ocr-msg-user::after {
    content: "";
    position: absolute;
    right: -6px;
    top: 14px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 0 6px 6px;
    border-color: transparent transparent transparent #95ec69;
}

.ds-ocr-msg-assistant {
    background: #ffffff;
    color: #000;
    border-top-left-radius: 6px;
    border: 1px solid #ededed;
}

/* Arrow for assistant */
.ds-ocr-msg-assistant::after {
    content: "";
    position: absolute;
    left: -6px;
    top: 14px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 6px 6px 0;
    border-color: transparent #ffffff transparent transparent;
}

.ds-ocr-msg-transparent {
    background: transparent !important;
    padding: 0 !important;
    box-shadow: none !important;
    border: none !important;
}
.ds-ocr-msg-transparent::after {
    display: none;
}

.ds-ocr-typing { opacity: .7; }

/* Updated Input Area Styles to mimic WeChat */
.ds-ocr-chat-input {
    display: flex;
    gap: 10px;
    padding: 10px 12px;
    background: #f7f7f7;
    border-top: 1px solid #dcdcdc;
    align-items: center; /* Center vertically for single line look */
    min-height: 56px;
    flex-shrink: 0; /* Prevent shrinking */
}

/* Icons (Voice & Emoji) */
.ds-ocr-icon-btn {
    background: transparent;
    border: none;
    color: #181818; /* Darker outline */
    cursor: pointer;
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.ds-ocr-icon-btn:hover {
    opacity: 0.7;
}

.ds-ocr-icon-btn svg {
    width: 28px;
    height: 28px;
    display: block;
}

/* Textarea */
.ds-ocr-chat-input textarea {
    flex: 1;
    resize: none;
    height: 36px; /* Default single line height */
    min-height: 36px;
    max-height: 100px; /* Allow expansion */
    border: none; /* No border */
    border-radius: 4px;
    padding: 8px 10px;
    background: #ffffff;
    font-size: 16px;
    outline: none;
    line-height: 20px;
    /* Box shadow for subtle depth if needed, but WeChat is flat white */
}

.ds-ocr-chat-input textarea:focus {
    /* No focus ring in WeChat style usually, or very subtle */
}

/* Send Button */
.ds-ocr-chat-input button#ds-ocr-chat-send {
    padding: 0 14px;
    border: none;
    border-radius: 4px;
    background: #07c160; /* WeChat green block */
    color: #fff;
    font-weight: 500;
    height: 34px;
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 4px; /* Slight gap from emoji */
}

.ds-ocr-chat-input button#ds-ocr-chat-send:hover {
    background: #06ad56;
}

/* Emoji Container */
.ds-ocr-emoji-container {
    position: relative;
    display: flex;
    align-items: center;
}

#ds-ocr-chat-emoji {
    /* Inherits .ds-ocr-icon-btn styles */
    width: 28px;
    height: 28px;
    /* Reset any old overrides */
    border-radius: 0;
    border: none;
    font-size: inherit;
}

.ds-ocr-emoji-dropdown {
    display: none;
    position: absolute;
    bottom: 160%; /* Adjust for input height */
    right: -60px; /* Align roughly with button area */
    margin-bottom: 10px;
    width: 320px;
    height: 250px;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 1000;
    padding: 12px;
    overflow-y: auto;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.ds-ocr-emoji-dropdown.show {
    display: grid;
}

/* Arrow for emoji dropdown */
.ds-ocr-emoji-dropdown::after {
    content: "";
    position: absolute;
    bottom: -6px;
    right: 75px; /* Adjusted */
    width: 12px;
    height: 12px;
    background: #fff;
    transform: rotate(45deg);
    border-bottom: 1px solid #e5e5e5;
    border-right: 1px solid #e5e5e5;
}

.ds-ocr-emoji-item {
    cursor: pointer;
    border-radius: 8px;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    aspect-ratio: 1;
    background: #f9f9f9;
}

.ds-ocr-emoji-item:hover {
    background: #eee;
}

.ds-ocr-emoji-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.ds-ocr-typing-indicator {
    display: none !important; 
}

/* Mobile Fixes */
@media (max-width: 768px) {
    /* Only apply fixed positioning when class is present */
    .ds-ocr-chat.ds-ocr-fullscreen {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        height: 100dvh; /* Use dynamic viewport height */
        margin: 0;
        border-radius: 0;
        z-index: 99999; /* Ensure on top */
        max-width: none;
    }
    
    /* Ensure body takes available space in fixed mode */
    .ds-ocr-chat.ds-ocr-fullscreen .ds-ocr-chat-body {
        height: auto;
        flex: 1;
    }
    
    /* Always show fullscreen toggle button on mobile */
    #ds-ocr-fullscreen-btn {
        display: block;
    }
}
