/**
 * 在线客服系统样式
 * 微信风格简约设计，移动端自适应
 */

/* CSS 变量 */
:root {
    --primary-color: #07c160;
    --primary-dark: #06ad56;
    --bg-color: #ededed;
    --chat-bg: #f5f5f5;
    --white: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border-color: #e5e5e5;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    --message-visitor: #95ec69;
    --message-admin: #ffffff;
    --danger-color: #fa5151;
    --header-height: 56px;
    --input-height: 56px;
}

/* 重置样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-color);
    -webkit-font-smoothing: antialiased;
}

/* 聊天容器 */
.chat-container {
    max-width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
}

/* 聊天头部 */
.chat-header {
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    justify-content: flex-start;
}

/* 提醒管理员按钮 */
.remind-admin-btn {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: linear-gradient(135deg, #ff4757 0%, #ff3838 100%);
    color: var(--white);
    border: none;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(255, 71, 87, 0.4);
    animation: pulse-remind 2s infinite;
}

.remind-admin-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 71, 87, 0.5);
}

.remind-admin-btn:active {
    transform: translateY(0);
}

.remind-admin-btn:disabled {
    background: linear-gradient(135deg, #999 0%, #888 100%);
    box-shadow: none;
    cursor: not-allowed;
    animation: none;
}

.remind-admin-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

@keyframes pulse-remind {

    0%,
    100% {
        box-shadow: 0 2px 8px rgba(255, 71, 87, 0.4);
    }

    50% {
        box-shadow: 0 2px 16px rgba(255, 71, 87, 0.7);
    }
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
}

.avatar svg {
    width: 24px;
    height: 24px;
}

.header-info h1 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-info .status {
    font-size: 12px;
    color: var(--primary-color);
}

.back-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
}

.back-btn svg {
    width: 24px;
    height: 24px;
    color: var(--text-primary);
}

/* 消息列表 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    -webkit-overflow-scrolling: touch;
}

.welcome-message {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 14px;
}

.welcome-message p {
    background: var(--white);
    padding: 12px 20px;
    border-radius: 12px;
    display: inline-block;
}

/* 消息气泡 */
.message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 80%;
}

.message.visitor {
    flex-direction: row-reverse;
    align-self: flex-end;
}

.message.admin {
    align-self: flex-start;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    background: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-avatar svg {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

.message.visitor .message-avatar {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: var(--white);
}

.message.visitor .message-avatar svg {
    color: var(--white);
}

.message.admin .message-avatar {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: var(--white);
}

.message.admin .message-avatar svg {
    color: var(--white);
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    word-break: break-word;
    position: relative;
}

.message.visitor .message-bubble {
    background: var(--message-visitor);
    border-top-right-radius: 4px;
}

.message.admin .message-bubble {
    background: var(--message-admin);
    border-top-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message-bubble.image,
.message-bubble.video {
    padding: 4px;
    background: var(--white);
}

.message-bubble img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    display: block;
}

.message-bubble video {
    max-width: 240px;
    max-height: 180px;
    border-radius: 8px;
    display: block;
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
}

.message.admin .message-time {
    text-align: left;
}

/* 输入区域 */
.chat-input-area {
    background: var(--white);
    border-top: 1px solid var(--border-color);
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.input-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.toolbar-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-color);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.toolbar-btn:active {
    background: var(--border-color);
}

.toolbar-btn svg {
    width: 22px;
    height: 22px;
    color: var(--text-secondary);
}

.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    border: none;
    background: var(--bg-color);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 16px;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    outline: none;
}

#messageInput::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn svg {
    width: 20px;
    height: 20px;
    color: var(--white);
    margin-left: 2px;
}

/* 图片预览弹窗 */
.image-preview-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}

.image-preview-modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
}

.modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
}

.modal-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 4px;
}

.close-btn {
    position: absolute;
    top: -40px;
    right: 0;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: var(--white);
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==================== 管理员页面样式 ==================== */

/* 登录页面 */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    width: 100%;
    max-width: 360px;
    background: var(--white);
    border-radius: 16px;
    padding: 40px 32px;
    box-shadow: var(--shadow);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-icon {
    width: 64px;
    height: 64px;
    color: var(--primary-color);
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
}

.login-form .form-group {
    margin-bottom: 20px;
}

.login-form input {
    width: 100%;
    height: 48px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0 16px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}

.login-form input:focus {
    border-color: var(--primary-color);
}

.login-btn {
    width: 100%;
    height: 48px;
    border: none;
    background: var(--primary-color);
    color: var(--white);
    border-radius: 12px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.login-btn:active {
    background: var(--primary-dark);
}

.error-message {
    background: #fff2f0;
    color: var(--danger-color);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    text-align: center;
}

/* 管理后台容器 */
.admin-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* 侧边栏 */
.sidebar {
    width: 100%;
    max-width: 320px;
    background: var(--white);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    height: var(--header-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.logout-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: var(--bg-color);
}

.logout-btn svg {
    width: 22px;
    height: 22px;
    color: var(--text-secondary);
}

/* 访客列表 */
.visitor-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.visitor-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid var(--border-color);
}

.visitor-item:hover {
    background: var(--bg-color);
}

.visitor-item.active {
    background: var(--bg-color);
}

.visitor-item .avatar {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
}

.visitor-item .avatar svg {
    width: 28px;
    height: 28px;
    color: var(--white);
}

.unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    background: var(--danger-color);
    color: var(--white);
    border-radius: 9px;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

.visitor-info {
    flex: 1;
    min-width: 0;
}

.visitor-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.visitor-ip {
    font-size: 12px;
    color: var(--text-muted);
}

.visitor-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.visitor-time {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* 分页 */
.pagination {
    padding: 12px;
    display: flex;
    justify-content: center;
    gap: 8px;
    border-top: 1px solid var(--border-color);
}

.page-btn {
    min-width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    background: var(--white);
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    transition: all 0.2s;
}

.page-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.page-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--white);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 主聊天区 */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    min-width: 0;
}

.no-chat-selected {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.no-chat-selected svg {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.no-chat-selected p {
    font-size: 16px;
}

/* 移动端响应式 */
@media (max-width: 768px) {
    .admin-container {
        position: relative;
    }

    .sidebar {
        max-width: none;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
    }

    .sidebar.hidden {
        display: none;
    }

    .chat-main {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    .chat-main.hidden {
        display: none;
    }

    .back-btn {
        display: flex;
    }

    .message {
        max-width: 85%;
    }
}

@media (min-width: 769px) {
    .back-btn {
        display: none;
    }
}

/* 加载动画 */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--text-muted);
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 无数据提示 */
.empty-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-message svg {
    width: 60px;
    height: 60px;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* 滚动条美化 */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}