/* 聊天室全局样式 */
:root {
    --message-bg-self: #e0f2fe;
    --message-bg-other: #f8fafc;
    --message-border-radius: 1rem;
}

/* 禁用横向滚动 */
html, body {
    overflow-x: hidden;
    max-width: 100%;
}

/* Apply overflow-x hidden to the main content area container */
.drawer-content > .flex-1.flex.flex-col.relative {
    overflow-x: hidden !important;
}

/* Also apply to the drawer content itself */
.drawer-content {
     overflow-x: hidden !important;
}

/* 确保聊天容器不会横向溢出 */
.chat-container, 
.chat-messages,
.markdown-content {
    max-width: 100%;
    /* Keep overflow-x hidden on chat-messages just in case */
    overflow-x: hidden !important; 
}

/* 确保图片和其他内容不会导致横向溢出 */
.markdown-content img,
.markdown-content pre,
.markdown-content code,
.chat-bubble {
    max-width: 100%;
    box-sizing: border-box;
}

/* 聊天气泡样式 */
.chat-bubble {
    position: relative;
    padding: 0.75rem 1rem;
    border-radius: var(--message-border-radius);
    max-width: 80%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    margin-bottom: 0.5rem;
    color: hsl(var(--bc) / 0.9);
    box-sizing: border-box;
    overflow: hidden;
}

.chat-bubble.self {
    background-color: var(--message-bg-self);
    margin-left: auto;
    border-bottom-right-radius: 0;
}

.chat-bubble.other {
    background-color: var(--message-bg-other);
    margin-right: auto;
    border-bottom-left-radius: 0;
}

/* 消息时间样式 */
.message-time {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 4px;
    text-align: right;
}

.chat-bubble.self .message-time {
    text-align: right;
}

.chat-bubble.other .message-time {
    text-align: left;
}

/* 聊天容器 */
.chat-container {
    /* height: calc(100vh - 12rem); */ /* 由 Tailwind Flexbox 处理 */
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden !important; /* Force disable horizontal scroll */
    padding: 1rem;
}

.chat-input {
    padding: 1rem;
    background-color: #fff;
    border-top: 1px solid #e5e7eb;
}

/* 在线状态指示器 */
.online-indicator,
.offline-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.online-indicator {
    background-color: #22c55e;
}

.offline-indicator {
    background-color: #d1d5db;
}

/* 消息已读/未读状态 */
.message-status {
    font-size: 0.7rem;
    margin-left: 6px;
    padding: 1px 4px;
    border-radius: 4px;
}

.message-status.sent {
    color: #6b7280;
    background-color: #f3f4f6;
}

.message-status.read {
    color: #15803d;
    background-color: #dcfce7;
}

/* 自定义滚动条 */
::-webkit-scrollbar {
    width: 0.5rem;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c5c5c5;
    border-radius: 0.25rem;
}

::-webkit-scrollbar-thumb:hover {
    background: #a3a3a3;
}

/* Markdown样式 */
.markdown-content {
    overflow-wrap: break-word;
    word-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
}

.markdown-content p {
    margin: 0;
}

.markdown-content p > a {
    display: block;
    max-width: 100%;
    line-height: 0;
}

.markdown-content pre {
    background-color: #f1f5f9;
    padding: 0.75rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.markdown-content code {
    font-family: monospace;
    background-color: #f1f5f9;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-all;
    white-space: normal;
}

.markdown-content blockquote {
    border-left: 4px solid #cbd5e1;
    padding-left: 1rem;
    color: #64748b;
    font-style: italic;
}

/* 用户搜索结果 */
.user-search-result {
    transition: all 0.2s ease;
}

.user-search-result:hover {
    background-color: #f1f5f9;
}

/* 动画效果 */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

/* 群组标签 */
.group-tag {
    background-color: #dbeafe;
    color: #2563eb;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* 未读消息计数器 */
.unread-counter {
    background-color: #ef4444;
    color: white;
    border-radius: 9999px;
    padding: 0.125rem 0.375rem;
    font-size: 0.75rem;
    font-weight: bold;
}

/* 响应式调整 */
/* 移除旧的 @media 块，drawer 组件自带响应式处理 */

/* 表单样式增强 */
.form-control:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.5);
}

/* 明暗主题切换 */
[data-theme="dark"] {
    --message-bg-self: #1e40af;
    --message-bg-other: #1f2937;
}

[data-theme="dark"] .chat-bubble.self {
    color: white;
}

[data-theme="dark"] .markdown-content pre {
    background-color: #374151;
}

[data-theme="dark"] .markdown-content code {
    background-color: #374151;
}

/* Emoji选择器 */
.emoji-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* 确保emoji选择器正常显示 */
.dropdown-top .dropdown-content {
    z-index: 100;
    visibility: visible;
    opacity: 1;
    transform: none;
}

.emoji-item {
    cursor: pointer;
    font-size: 1.5rem;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.emoji-item:hover {
    background-color: var(--fallback-b2, oklch(var(--b2) / 0.1));
}

/* Message Input Max Height */
#message-input {
    max-height: 150px;
    overflow-y: auto;
    resize: none;
}

/* 聊天输入区域优化 */
#chat-input-area form {
    margin-bottom: 0;
}

#chat-input-area .btn {
    min-height: 2.5rem;
    height: auto;
}

/* 移动端输入区域优化 */
@media (max-width: 640px) {
    #chat-input-area {
        padding: 0.75rem;
    }
    
    #chat-input-area form {
        gap: 0.5rem;
    }
    
    .emoji-picker {
        max-height: 150px;
    }
    
    /* 修改dropdown位置样式 */
    .dropdown.dropdown-top .dropdown-content {
        position: absolute;
        bottom: 100%;
        left: 0;
        width: 16rem !important;
        max-width: 90vw;
        margin-bottom: 0.5rem;
        transform-origin: bottom;
        border-radius: 0.5rem;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }

    /* Mobile dropdown position fixes */
    .message-actions .dropdown .dropdown-content {
        /* Ensure dropdown fits screen width */
        max-width: 80vw; 
    }

    /* Force left alignment for 'other' bubbles on mobile */
    .chat-bubble.other .message-actions .dropdown.dropdown-right .dropdown-content {
        left: 0 !important; /* Important to override daisy default */
        right: auto !important;
        transform: translateX(0) !important; /* Reset any horizontal transform */
    }

    /* Adjust position slightly for 'self' bubbles if needed */
     .chat-bubble.self .message-actions .dropdown.dropdown-left .dropdown-content {
        right: 0 !important;
        left: auto !important;
        transform: translateX(0) !important;
    }
}

/* Markdown 内容中的图片样式 */
.markdown-content img {
    display: block;
    max-width: 100%;
    max-height: 250px;
    height: auto;
    object-fit: contain;
    border-radius: 0.375rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
    margin-left: auto;
    margin-right: auto;
}

/* 添加 sm 断点样式 */
@media (min-width: 640px) {
    .emoji-picker {
        grid-template-columns: repeat(8, 1fr); /* sm及以上屏幕8列 */
    }
}

/* 图片限制最大尺寸 */
.markdown-content img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 0.5rem;
    margin: 0.25rem auto;
    object-fit: contain;
}

/* 消息操作按钮样式 */
.message-actions {
    margin-top: 2px;
    min-height: 20px;
    position: relative;
}

/* Align action button to the left for other user's messages */
.chat-bubble.other .message-actions {
    text-align: left;
}

.message-actions .dropdown {
    position: static;
}

.message-actions .btn-circle {
    width: 1.5rem;
    height: 1.5rem;
    min-height: 1.5rem;
    padding: 0;
}

.message-actions .dropdown .dropdown-content {
    /* Adjust width: auto min, limit max */
    min-width: auto;
    max-width: 9rem; /* Limit maximum width */
    width: max-content; /* Make width fit content */
    z-index: 9999 !important; /* Increase z-index significantly and use !important */
    position: absolute; 
    /* Ensure padding doesn't make it too wide */
    padding: 0.25rem; 
}

/* Adjust menu item padding */
.message-actions .dropdown-content ul.menu li > * {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

/* Ensure dropdown alignment */
.chat-bubble.self .message-actions .dropdown.dropdown-top.dropdown-right .dropdown-content,
.chat-bubble.other .message-actions .dropdown.dropdown-top.dropdown-right .dropdown-content {
    left: 0;
    right: auto;
    transform-origin: top left;
}

@media (min-width: 640px) {
    .emoji-picker {
        max-height: 250px;
    }
}

/* Restore basic message actions styles */
.chat-bubble .message-actions {
    min-height: 20px; /* Restore min height */
    margin-top: 2px; /* Restore margin */
    text-align: initial; /* Reset align, specific align below */
    position: relative; /* Needed for inner absolute elements? maybe static */
    position: static; /* Let's try static first */
}

/* Align action button based on bubble type */
.chat-bubble.other .message-actions {
    text-align: left;
}
.chat-bubble.self .message-actions {
    text-align: right;
}

/* Remove positioning rules for the moved container */
/* Remove .message-actions-container rules */

/* Keep dropdown content styles */
.message-actions .dropdown-content { /* Use the original selector path */
    min-width: auto;
    max-width: 9rem; 
    width: max-content; 
    z-index: 9999 !important; /* Keep high z-index */
    position: absolute; /* Keep absolute */
    padding: 0.25rem; 
}

/* Adjust menu item padding */
.message-actions .dropdown-content ul.menu li > * {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

/* Attempt to force menu visibility slightly outside */
/* This might not work due to overflow:hidden, but worth a try */
.message-actions .dropdown-top .dropdown-content {
    /* margin-bottom: -5px; */ /* Negative margin might pull it slightly out */
    /* transform: translateY(-5px); */ /* Transform might also work */
}

/* Remove previous alignment attempts that might conflict */

@media (max-width: 640px) {
   /* Remove mobile specific positioning for moved container */
}

@media (min-width: 640px) {
    .emoji-picker {
        max-height: 250px;
    }
} 