/**
 * 私信浮窗公共样式
 * 用于 client/index.html 和 zhuotai/7272.html (通过 chat-widget.js)
 */

/* 私信浮窗统一变量（与 danmu-ui-unified.css 的 ui 变量对齐；不存在时使用 fallback） */
:root {
    --pm-fs-12: var(--ui-fs-12, 12px);
    --pm-fs-14: var(--ui-fs-14, 14px);
    --pm-fs-16: var(--ui-fs-16, 16px);

    --pm-list-pad: 10px;
    --pm-body-pad: 16px;
    --pm-input-pad-y: 8px;
    --pm-input-pad-x: 10px;
    --pm-input-gap: 8px;
    --pm-bubble-max: 68%;
    /* 键盘弹起时用于把悬浮按钮整体上移（由 JS 通过 visualViewport 动态写入） */
    --pm-btn-kb-offset: 0px;

    /* 浮标默认锚点（可被拖拽覆盖为 left/top） */
    --pm-btn-right-default: calc(16px + env(safe-area-inset-right));
    --pm-btn-bottom-default: calc(16px + env(safe-area-inset-bottom));
}

/* 私信小浮窗按钮样式 */
.pm-float-button {
    position: fixed;
    left: var(--pm-btn-left, auto);
    top: var(--pm-btn-top, auto);
    right: var(--pm-btn-right, var(--pm-btn-right-default));
    bottom: var(--pm-btn-bottom, var(--pm-btn-bottom-default));
    width: 52px;
    height: 52px;
    background: linear-gradient(45deg, #ff6699, #ee3377);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10001; /* 与弹幕输入框同层 */
    transition: transform 0.3s, box-shadow 0.3s;
    border: none;
    user-select: none;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    /* 默认叠加键盘偏移（不要在这里写 scale，否则会和 :hover/:active 叠加困难） */
    transform: translate3d(0, calc(-1 * var(--pm-btn-kb-offset)), 0);
}

.pm-float-button.dragging {
    cursor: grabbing;
    transition: none;
    box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}

.pm-float-button:hover {
    transform: translate3d(0, calc(-1 * var(--pm-btn-kb-offset)), 0) scale(1.06);
}

.pm-float-button:active {
    transform: translate3d(0, calc(-1 * var(--pm-btn-kb-offset)), 0) scale(0.95);
}

/* 浮窗打开时隐藏按钮，避免遮挡/重复入口（关闭入口在浮窗头部） */
body.pm-float-open #pm-float-button {
    opacity: 0;
    pointer-events: none;
}

.pm-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: red;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* 没有内容时不显示（避免初始化闪一下空红点） */
.pm-unread-badge:empty {
    display: none;
}

/* 与 JS 的 hidden 切换配合（显式写出，避免被其它规则覆盖） */
.pm-unread-badge[hidden] {
    display: none !important;
}

/* 私信浮窗样式 */
.pm-float-window {
    position: fixed;
    /* 避免 iOS/微信里同时指定 left/right + width 导致的 1px 横向溢出 */
    inset: 0;
    width: auto;
    height: auto;
    max-width: 100%;
    background: rgba(30, 30, 30, 0.98);
    border-radius: 0;
    box-shadow: none;
    display: none;
    flex-direction: column;
    z-index: 10001;
    backdrop-filter: blur(10px);
    border: none;
    user-select: none;
    overflow-x: hidden;
    overscroll-behavior-x: none;
}

/* 避免极端情况下 padding 叠加导致溢出；不要对所有子元素强制 max-width（可能影响布局） */
.pm-float-window {
    box-sizing: border-box;
}

.pm-float-window,
.pm-conversations-list,
.private-message-body {
    /* iOS/微信：滚动更顺滑 */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* 弹窗打开时：锁定背景滚动（配合 js/pm-float-common.js） */
body.pm-modal-open {
    overflow: hidden;
    touch-action: none;
}

/* 微信/iOS：浮窗打开态强制禁止横向溢出（避免底部左右箭头） */
html.pm-modal-open,
html.pm-modal-open body {
    overflow-x: hidden !important;
}

/* 浮窗打开态：再次兜底横向溢出（微信偶发把 fixed 元素计入 scrollWidth） */
html.pm-modal-open .pm-float-window {
    max-width: 100% !important;
    overflow-x: hidden !important;
}

/* 浮窗打开态：彻底禁止页面级滚动（对齐桌台页面的 overflow:hidden 策略） */
html.pm-modal-open,
html.pm-modal-open body {
    overflow-y: hidden !important;
}

/* 拖拽时的样式 */
.pm-float-window.dragging {
    cursor: move;
    opacity: 0.9;
    transition: none;
}

.pm-float-window.show {
    display: flex;
}

/* 浮窗头部 */
.pm-float-header {
    /* 目标：粉色头部条高度尽量“贴内容”，只保留必要安全区 */
    padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* 关键：不要整条粉红背景；粉红只出现在“返回”按钮上 */
    background: transparent;
    border-radius: 0;
    cursor: default;
    user-select: none;
    flex-shrink: 0;
    /* 不写死高度：让头部高度由标题/返回按钮自然决定 */
    height: auto;
}

.pm-float-header h3 {
    /* 头部不再是粉底时，标题用正常文本色 */
    color: var(--ui-text, #e0e0e0);
    margin: 0;
    font-size: var(--pm-fs-14);
    font-weight: 600;
    line-height: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.pm-float-title-stats {
    display: flex;
    gap: 4px;
    align-items: center;
}

.pm-float-title-unread {
    background: rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: bold;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.pm-float-title-unread.my {
    background: rgba(255, 255, 255, 0.4);
}

.pm-float-title-unread.other {
    background: rgba(173, 216, 230, 0.4);
}

.pm-float-close {
    /* 粉红背景只包裹“返回”文字 */
    background: linear-gradient(45deg, #ff6699, #ee3377);
    border: none;
    color: white;
    font-size: var(--pm-fs-14);
    font-weight: 600;
    cursor: pointer;
    padding: 2px 10px;
    height: auto;
    line-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    transition: background 0.2s;
}

.pm-float-close:hover {
    filter: brightness(1.05);
}

/* 浮窗标签 */
.pm-float-tabs {
    display: flex;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    height: 40px;
}

.pm-float-tab {
    flex: 1;
    padding: 10px 4px;
    text-align: center;
    cursor: pointer;
    color: #aaa;
    transition: all 0.3s;
    border-bottom: 2px solid transparent;
    font-size: var(--pm-fs-14);
    line-height: 20px;
    /* 允许把 tab 从 div 升级为 button（无默认样式干扰） */
    background: transparent;
    border: none;
    outline: none;
    appearance: none;
}

.pm-float-tab:focus-visible {
    outline: 2px solid rgba(255, 102, 153, 0.85);
    outline-offset: -2px;
}

.pm-float-tab.active {
    color: #ff6699;
    border-bottom-color: #ff6699;
    background: rgba(255, 102, 153, 0.1);
}

.pm-float-tab:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* 浮窗主体 */
.pm-float-body {
    flex: 1;
    overflow: hidden;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-x: hidden;
}

/* 会话列表样式 */
.pm-conversations-list {
    flex: 1;
    overflow-y: auto;
    /* 两侧包含安全区，避免贴边 */
    padding: var(--pm-list-pad);
    padding-left: calc(var(--pm-list-pad) + env(safe-area-inset-left));
    padding-right: calc(var(--pm-list-pad) + env(safe-area-inset-right));
    overflow-x: hidden;
}

/* 确保 hidden 属性的会话列表不显示 */
.pm-conversations-list[hidden] {
    display: none !important;
}

.pm-conversation-item {
    padding: 10px 12px;
    margin-bottom: 4px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    border: 1px solid transparent;
    max-width: 100%;
    overflow-x: hidden;
}

.pm-conversation-item:hover {
    background: rgba(255, 102, 153, 0.1);
    border-color: rgba(255, 102, 153, 0.3);
}

.pm-conversation-item.active {
    background: rgba(255, 102, 153, 0.15);
    border-color: #ff6699;
}

.pm-conversation-name {
    color: #e0e0e0;
    font-weight: 600;
    margin-bottom: 2px;
    font-size: var(--pm-fs-14);
    display: flex;
    align-items: center;
    gap: 8px;
    /* 允许换行，但保持右侧控件对齐 */
    flex-wrap: wrap;
    max-width: 100%;
}

/* 只让“用户名”占满剩余空间，避免在线/离线徽标被 flex 拉伸变长 */
.pm-conversation-name > .pm-conversation-name-text {
    flex: 1;
    min-width: 0;
}

/* 会话列表：在线/离线状态小徽标 */
.pm-user-status {
    /* 更紧凑：正好包裹“在线/离线”两字 */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    font-size: 9px;
    line-height: 1;
    padding: 1px 3px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: transparent;
    color: #9aa0a6;
    white-space: nowrap;
    user-select: none;
    box-sizing: border-box;
    width: fit-content;
    align-self: center;
}
.pm-user-status.online {
    color: rgba(120, 255, 180, 0.95);
    border-color: rgba(120, 255, 180, 0.25);
    background: transparent;
}
.pm-user-status.offline {
    color: #9aa0a6;
    border-color: rgba(255, 255, 255, 0.12);
    background: transparent;
}

.pm-conversation-delete-btn {
    background: rgba(231, 76, 60, 0.2);
    border: 1px solid rgba(231, 76, 60, 0.5);
    color: #e74c3c;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-left: auto; /* 尽量靠右（同一行）；若换行也保持右对齐 */
    white-space: nowrap;
}

.pm-conversation-delete-btn:hover {
    background: rgba(231, 76, 60, 0.4);
    border-color: #e74c3c;
}

.pm-conversation-delete-btn:active {
    transform: scale(0.95);
}

.pm-conversation-preview {
    color: #888;
    font-size: var(--pm-fs-14);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pm-conversation-time {
    color: #666;
    font-size: var(--pm-fs-12);
    margin-top: 2px;
}

.pm-conversation-unread-stats {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}

.pm-conversation-unread {
    background: #ff6699;
    color: white;
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: bold;
    white-space: nowrap;
}

.pm-conversation-unread-other {
    background: #4a90e2;
    color: white;
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: bold;
    white-space: nowrap;
}

/* 确认对话框样式 */
.pm-confirm-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.pm-confirm-dialog-box {
    background: rgba(30, 30, 30, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 20px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.pm-confirm-dialog-title {
    color: #e0e0e0;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
}

.pm-confirm-dialog-message {
    color: #aaa;
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 20px;
    white-space: pre-line;
}

.pm-confirm-dialog-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.pm-confirm-dialog-btn {
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-weight: 600;
}

.pm-confirm-dialog-btn-cancel {
    background: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.pm-confirm-dialog-btn-cancel:hover {
    background: rgba(255, 255, 255, 0.15);
}

.pm-confirm-dialog-btn-confirm {
    background: linear-gradient(45deg, #e74c3c, #c0392b);
    color: #fff;
    border: 1px solid rgba(231, 76, 60, 0.5);
}

.pm-confirm-dialog-btn-confirm:hover {
    background: linear-gradient(45deg, #c0392b, #a93226);
}

/* 私信消息样式 */
.private-message-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--pm-body-pad);
    padding-left: calc(var(--pm-body-pad) + env(safe-area-inset-left));
    padding-right: calc(var(--pm-body-pad) + env(safe-area-inset-right));
    min-height: 0;
}

.private-message-item {
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
}

.private-message-item.sent {
    align-items: flex-end;
}

.private-message-item.received {
    align-items: flex-start;
}

.private-message-sender {
    font-size: var(--pm-fs-12);
    color: #999;
    margin: 0 0 3px 0;
    line-height: 1.2;
    max-width: 72vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.private-message-bubble {
    max-width: var(--pm-bubble-max);
    padding: 9px 12px;
    border-radius: 14px;
    word-wrap: break-word;
    font-size: var(--pm-fs-14);
    line-height: 1.5;
}

.private-message-item.sent .private-message-bubble {
    background: linear-gradient(45deg, #ff6699, #ee3377);
    color: white;
}

.private-message-item.received .private-message-bubble {
    background: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
}

.private-message-time {
    font-size: var(--pm-fs-12);
    color: #888;
    margin-top: 2px;
}

/* 消息未读统计样式 */
.pm-messages-unread-stats {
    padding: 8px 12px;
    margin-bottom: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.pm-messages-unread-stats-content {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.pm-messages-unread-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.pm-messages-unread-badge.my {
    background: #ff6699;
    color: white;
}

.pm-messages-unread-badge.other {
    background: #4a90e2;
    color: white;
}

/* 私信输入区域样式 */
.private-message-input-area {
    padding: var(--pm-input-pad-y) var(--pm-input-pad-x);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: stretch;
    gap: var(--pm-input-gap);
    flex-shrink: 0;
    background: rgba(30, 30, 30, 0.98);
}

/* 包裹输入框的容器 */
.private-message-input-area > div[style*="flex"],
.private-message-input-area > .pm-input-wrap {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-height: 0;
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

/* 聊天视图容器：用 hidden 控制显示/隐藏 */
.pm-chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* 确保 hidden 属性的聊天视图完全不显示 */
.pm-chat-view[hidden] {
    display: none !important;
}

/* 通用加载占位（用于会话列表/等候态） */
.pm-loading {
    text-align: center;
    color: #888;
    padding: 20px;
}

.private-message-input {
    flex: 1;
    width: 100%;
    padding: 8px 14px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.35);
    color: #e0e0e0;
    font-size: var(--pm-fs-14);
    outline: none;
    margin: 0;
    line-height: 1.4;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    overflow-y: auto;
    box-sizing: border-box;
    white-space: pre-wrap;
    word-break: break-word;
}

.private-message-input:focus {
    border-color: #ff6699;
    box-shadow: 0 0 0 2px rgba(255, 102, 153, 0.2);
}

/* 私密聊天发送按钮样式已移至 /css/input-button-common.css */

/* 移动端优化 */
@media (max-width: 768px) {
    /* 移动端：避免 hover 触发导致抖动（iOS 也会模拟 hover） */
    .pm-float-button:hover {
        transform: none;
    }

    .pm-float-window {
        border-radius: 0;
    }
    
    .pm-float-header {
        padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    }
    
    .pm-float-header h3 {
        font-size: var(--pm-fs-14);
    }

    .pm-float-close {
        font-size: var(--pm-fs-14);
    }
    
    .private-message-input-area {
        padding: var(--pm-input-pad-y) var(--pm-input-pad-x);
    }
    
    .private-message-input {
        padding: 10px 12px;
        font-size: 16px; /* 防止 iOS 自动放大 */
    }
    
    /* 私密聊天发送按钮字体大小和 padding 已移至 /css/input-button-common.css */
    
    :root {
        /* 移动端：默认悬浮按钮抬高一些，避免压住输入区 */
        --pm-btn-bottom-default: calc(80px + env(safe-area-inset-bottom));
        --pm-btn-right-default: calc(16px + env(safe-area-inset-right));
    }

    .pm-float-button {
        width: 48px !important;
        height: 48px !important;
        font-size: 22px !important;
    }
}

@media (max-width: 480px) {
    :root {
        --pm-btn-bottom-default: calc(70px + env(safe-area-inset-bottom));
        --pm-btn-right-default: calc(12px + env(safe-area-inset-right));
    }

    .pm-float-button {
        width: 44px !important;
        height: 44px !important;
        font-size: 20px !important;
    }
}

