/* --- 全局与重置 --- */
:root {
    --bg-color: #f4f5f7;
    --surface-color: #ffffff;
    --border-color: #e5e7eb;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --primary-color: #3b82f6;
    --primary-color-light: #eff6ff;
    --primary-color-dark: #2563eb;
    --user-msg-bg: var(--primary-color);
    --agent-msg-bg: #e5e7eb;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

html,
body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    color: var(--text-primary);
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

*,
*::before,
*::after {
    box-sizing: inherit;
}

/* --- 主布局 --- */
#chat-container {
position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface-color);
}

.app-body {
    display: flex;
    height: 100%;

    flex: 1;
    overflow: hidden;
}

/* --- 侧边栏 (客服选择) --- */
.sidebar {
    width: 300px;
    flex-shrink: 0;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--surface-color);

    height: 100%;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

/* 状态栏容器 */
.connection-status {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 4px;
}

/* 圆点基础样式 */
.connection-status .status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    transition: background 0.3s;
}

/* 文字基础样式 */
.connection-status .status-text {
    font-size: 11px;
    font-weight: normal;
}


.refresh-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.refresh-btn:hover {
    background: #f3f4f6;
    color: var(--text-primary);
}

#agent-selection {
    display: flex;
    flex-direction: column;
    height: 100%;    /* 继承 sidebar 的高度 */
    min-height: 0;   /* 允许收缩 */
    flex: 1;         /* 占据父级剩余空间 */
}

#agent-grid {
    padding: 8px;
    overflow-y: auto;

    flex: 1; 
    min-height: 0; 

    &::-webkit-scrollbar {
        display: none;
    }
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.agent-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background-color 0.2s ease;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.agent-card:hover {
    background-color: #f9fafb;
}

.agent-card.selected {
    background-color: var(--primary-color-light);
    border-color: var(--primary-color);
}

.agent-card .agent-badge {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color-light);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    flex-shrink: 0;
}

.agent-card.selected .agent-badge {
    background-color: var(--primary-color);
    color: white;
}

.agent-card .agent-info {
    overflow: hidden;
}

.agent-card .agent-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agent-card .agent-sub {
    font-size: 13px;
    color: var(--text-secondary);
}

/* --- 聊天窗格 --- */
.chat-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* 欢迎界面 */
#welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-secondary);
}

.welcome-content {
    max-width: 300px;
}

.welcome-content svg {
    color: #d1d5db;
}

.welcome-content h3 {
    margin: 16px 0 8px;
    font-size: 20px;
    color: var(--text-primary);
}

.welcome-content p {
    margin: 0;
    font-size: 15px;
}

/* 聊天窗口 */
#chat-window {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.back-btn {
    display: none;
    /* 默认隐藏，仅在移动端显示 */
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
}

.back-btn:hover {
    background: #f3f4f6;
    color: var(--text-primary);
}

.agent-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-color-light);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.agent-title .agent-name {
    font-weight: 600;
}

.agent-title .agent-status {
    display: flex;
    align-items: center; /* 垂直居中 */
    gap: 6px;            /* 圆点和文字的间距 */
    margin-top: 0px;
}

/* 小圆点样式 */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: background 0.3s;
}

/* 文字样式 */
.status-text {
    font-size: 12px;
    color: #64748b; /* 默认灰色 */
}

/* 状态颜色类 */
.status-online .status-dot { background: #22c55e; }
.status-online .status-text { color: #22c55e; }

.status-offline .status-dot { background: #94a3b8; }
.status-offline .status-text { color: #94a3b8; }

#messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: var(--bg-color);
}

.message {
    display: flex;
    flex-direction: column;
    margin-bottom: 16px;
    max-width: 85%;
}

.message .sender {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
    color: var(--text-secondary);
}

.message .text {
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message .meta {
    color: #9ca3af;
    font-size: 12px;
    margin-top: 6px;
}

/* 用户消息 */
.user-message {
    align-items: flex-end;
    margin-left: auto;
}

.user-message .text {
    background-color: var(--user-msg-bg);
    color: white;
    border-bottom-right-radius: 4px;
}

.user-message .text a {
    /* 确保 a 标签也遵循父级的换行规则 */
    word-break: break-all;
    /* 建议加上颜色和下划线，让用户知道这是链接 */
    color: white;
    text-decoration: underline;
}

.user-message .sender,
.user-message .meta {
    text-align: right;
}

/* 客服消息 */
.agent-message {
    align-items: flex-start;
}

.agent-message .text {
    background-color: var(--agent-msg-bg);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.agent-message .text a {
    /* 确保 a 标签也遵循父级的换行规则 */
    word-break: break-all;
    /* 建议加上颜色和下划线，让用户知道这是链接 */
    color: #007bff;
    text-decoration: underline;
}

/* 输入表单 */
#form {
    display: flex;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    gap: 10px;
    background: var(--surface-color);
}

#input {
    flex-grow: 1;
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    background: var(--bg-color);
}

#input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-color-light);
}

#form button {
    padding: 10px 20px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: background-color 0.2s;
}

#form button:hover {
    background-color: var(--primary-color-dark);
}

/* --- 状态与响应式 --- */
.hidden {
    display: none !important;
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 10;
        border-right: none;
        transition: transform 0.3s ease-in-out;
    }

    .sidebar.hidden-mobile {
        transform: translateX(-100%);
    }

    .chat-pane {
        width: 100%;
        height: 100%;
    }

    #welcome-screen {
        display: none;
        /* 移动端不显示欢迎页 */
    }

    .back-btn {
        display: flex;
        /* 移动端显示返回按钮 */
    }
}

/* --- 高级灰暗黑模式适配 --- */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1c1e;
        --surface-color: #242729;
        --border-color: #2f3235;
        
        --text-primary: #e2e4e7;
        --text-secondary: #94999f;
        
        --primary-color: #5394ff;
        --primary-color-light: rgba(83, 148, 255, 0.12);
        --primary-color-dark: #407cd6;
        
        --user-msg-bg: var(--primary-color);
        --agent-msg-bg: #2d3135;
    }

    .sidebar {
        background: var(--surface-color);
    }

    .agent-card {
        border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    }

    .agent-card:hover {
        background-color: #2d3135;
    }

    .agent-card.selected .agent-name {
        color: #ffffff;
    }

    #messages {
        background-color: #1a1c1e;
    }

    #input {
        background: #242729;
        color: var(--text-primary);
        border-color: var(--border-color);
    }

    .welcome-content svg {
        color: #2f3235;
    }

    .refresh-btn:hover {
        background: #2f3235;
    }

    #input::placeholder {
        color: #5a5f66;
    }

    #image-label svg {
        fill: #94999f;
    }
}
