/* ================= 1. 终极防裁切重置 ================= */
html, body { 
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; 
    width: 100%; overflow: hidden; margin: 0;
    overscroll-behavior: none; 
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background-color: var(--mdui-color-outline-variant); border-radius: 4px; }

mdui-layout { position: absolute; top: 0; left: 0; right: 0; bottom: 0; }

.im-main-content {
    display: flex; 
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--mdui-color-background);
    overflow: hidden; 
}

/* ================= 2. 左右核心面板 ================= */
.chat-list-panel {
    width: 320px; 
    flex-shrink: 0; 
    border-right: 1px solid var(--mdui-color-surface-variant);
    display: flex; flex-direction: column;
    background-color: var(--mdui-color-surface-container-high);
    /* 【找回】MD3 强调型非线性缓动动画，0.9秒极度丝滑 */
    transition: transform 0.9s cubic-bezier(0.2, 0, 0, 1);
    will-change: transform;
}
.chat-list-header { padding: 16px; display: flex; align-items: center; gap: 12px; }
.chat-list { flex: 1; overflow-y: auto; }

.chat-main-panel { 
    flex: 1; 
    min-width: 0; 
    display: flex; flex-direction: column; 
    background-color: var(--mdui-color-surface-container-lowest); 
}

/* 自定义原生顶部栏 */
.chat-header {
    display: flex; align-items: center; height: 64px; padding: 0 16px;
    background-color: var(--mdui-color-surface);
    border-bottom: 1px solid var(--mdui-color-surface-variant);
    flex-shrink: 0; z-index: 10;
}
.chat-header-title {
    flex: 1; font-size: 1.1rem; font-weight: 500;
    color: var(--mdui-color-on-surface);
    margin: 0 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 
}

.chat-history { 
    flex: 1; overflow-y: auto; padding: 24px; 
    display: flex; flex-direction: column;
    background-color: var(--mdui-color-surface-container-lowest); 
    scroll-behavior: smooth;
    min-height: 0; 
}

/* ================= 3. 气泡基础与富文本样式 ================= */
.msg-row { display: flex; margin-bottom: 24px; width: 100%; will-change: transform, opacity, max-height; }
.msg-row.me { justify-content: flex-end; }

.msg-bubble { 
    max-width: 75%; padding: 10px 14px; border-radius: 16px; 
    line-height: 1.5; font-size: 0.95rem; word-break: break-word; 
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); cursor: pointer; 
}
.msg-row.them .msg-bubble { background-color: #ffffff !important; color: #000000 !important; border-bottom-left-radius: 4px; transform-origin: bottom left; }
.msg-row.me .msg-bubble { background-color: var(--mdui-color-primary) !important; color: var(--mdui-color-on-primary) !important; border-bottom-right-radius: 4px; transform-origin: bottom right; }

/* 图片气泡专用修饰 */
.msg-bubble.is-image { padding: 0; background-color: transparent !important; box-shadow: none; overflow: hidden; }
.msg-bubble.is-image img { display: block; max-width: 260px; border-radius: 12px; border: 1px solid var(--mdui-color-outline-variant); }

/* 文件卡片专用修饰 */
.msg-bubble.is-file { padding: 6px; }
.msg-file-card { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 10px; text-decoration: none; }
.msg-row.them .msg-file-card { background-color: var(--mdui-color-surface); color: var(--mdui-color-on-surface); }
.msg-row.me .msg-file-card { background-color: rgba(255, 255, 255, 0.15); color: var(--mdui-color-on-primary); }

/* Telegram 风格动画 */
@keyframes msg-appear { 0% { opacity: 0; transform: scale(0.85) translateY(15px); } 100% { opacity: 1; transform: scale(1) translateY(0); } }
.msg-row.animate-in { animation: msg-appear 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }
@keyframes msg-disappear { 0% { opacity: 1; transform: scale(1); max-height: 500px; margin-bottom: 24px; } 100% { opacity: 0; transform: scale(0.8); max-height: 0; margin-bottom: 0; padding: 0; border: none; overflow: hidden; } }
.msg-row.animate-out { animation: msg-disappear 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards; }

/* ================= 4. 底部输入区 (锁底+内边距兼容) ================= */
.chat-input-panel {
    display: flex; flex-direction: column;
    background-color: var(--mdui-color-surface);
    border-top: 1px solid var(--mdui-color-surface-variant);
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom)) 16px; 
    flex-shrink: 0; box-sizing: border-box; z-index: 50; transform: translateZ(0); 
}
.chat-input-toolbar { display: flex; gap: 4px; padding-bottom: 12px; }
.chat-input-row { display: flex; align-items: flex-end; gap: 12px; }
#chat-input-field { flex: 1; background-color: var(--mdui-color-surface-container-highest); border-radius: 12px; margin-bottom: 2px; }
.send-btn-wrapper { flex-shrink: 0; display: flex; align-items: center; justify-content: center; height: 40px; }

/* ================= 5. 移动端控制 ================= */
.mobile-only { display: none; }
@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: inline-flex; }
    .chat-list-panel { width: 100%; border-right: none; position: absolute; top: 0; left: 0; bottom: 0; z-index: 10; }
    .chat-main-panel {
    position: absolute; top: 0; left: 0; bottom: 0; width: 100%; height: 100%; z-index: 20;
    background-color: var(--mdui-color-surface);
    /* 【找回】移动端聊天面板滑入滑出的 MD3 强调型动画 */
    transform: translateX(100%); 
    transition: transform 0.9s cubic-bezier(0.2, 0, 0, 1);
    will-change: transform;
    }
    .chat-main-panel::before { content: ""; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: #ffffff; z-index: -1; }
    @media (prefers-color-scheme: dark) { .chat-main-panel::before { background-color: #121212; } }
    
    .im-main-content.mobile-chat-open .chat-list-panel { transform: translateX(-30%); }
    .im-main-content.mobile-chat-open .chat-main-panel { transform: translateX(0); }
    
    .msg-bubble.is-image img { max-width: 200px; }
}

/* ================= 个人主页弹窗样式 ================= */
#dialog-profile::part(panel) {
  padding: 0;
  max-width: 500px;
  width: 100%;
  overflow: hidden;
}

.profile-header-container {
  position: relative;
  width: 100%;
  height: 200px;
  background-color: var(--mdui-color-surface-variant);
}

.profile-bg-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 150px;
  background-color: var(--mdui-color-secondary-container);
  cursor: pointer;
  overflow: hidden;
}

.profile-bg-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: filter 0.3s ease;
}

.profile-edit-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 10;
}

.profile-bg-wrapper:hover .profile-edit-overlay,
.profile-avatar-wrapper:hover .profile-edit-overlay {
  opacity: 1;
}

.profile-bg-wrapper:hover img {
  filter: blur(2px);
}

.profile-avatar-wrapper {
  position: absolute;
  bottom: 0;
  left: 24px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 4px solid var(--mdui-color-surface);
  background-color: var(--mdui-color-primary-container);
  cursor: pointer;
  overflow: hidden;
  z-index: 20;
}

.profile-avatar {
  width: 100%;
  height: 100%;
  --shape-corner: 50%;
}

.avatar-overlay {
  border-radius: 50%;
}

.nexabox-id-container {
  display: flex;
  align-items: center;
  background-color: var(--mdui-color-primary-container);
  padding: 8px 16px;
  border-radius: 8px;
  margin-bottom: 24px;
}