/* ========================================
   在线客服系统 - 全局样式
   ======================================== */

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* ---- 按钮 ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-outline {
    background: #fff;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}
.btn-outline:hover:not(:disabled) { background: var(--gray-50); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }

/* ---- 表单 ---- */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 6px;
}
.form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}
.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

/* ---- 卡片 ---- */
.card {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* ---- 登录页 ---- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}
.login-card {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}
.login-card h1 {
    text-align: center;
    font-size: 24px;
    color: var(--gray-800);
    margin-bottom: 8px;
}
.login-card .subtitle {
    text-align: center;
    color: var(--gray-500);
    font-size: 14px;
    margin-bottom: 32px;
}
.login-card .btn-primary {
    width: 100%;
    padding: 12px;
    font-size: 16px;
}
.login-links {
    text-align: center;
    margin-top: 16px;
    font-size: 14px;
    color: var(--gray-500);
}
.error-msg {
    background: var(--danger-light);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
}
.error-msg.show { display: block; }

/* ---- 客服工作台 ---- */
.workspace {
    display: flex;
    height: 100vh;
    overflow: hidden;
}
.sidebar {
    width: 320px;
    min-width: 320px;
    background: #fff;
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
}
.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
}
.sidebar-header .user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--gray-500);
}
.session-list {
    flex: 1;
    overflow-y: auto;
}
.session-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 12px;
}
.session-item:hover { background: var(--gray-50); }
.session-item.active { background: var(--primary-light); }
.session-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
}
.session-info { flex: 1; min-width: 0; }
.session-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.session-time {
    font-size: 12px;
    color: var(--gray-400);
}
.session-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}
.status-pending {
    background: var(--warning-light);
    color: #b45309;
}
.status-active {
    background: var(--success-light);
    color: #047857;
}
.status-closed {
    background: var(--gray-100);
    color: var(--gray-500);
}

/* ---- 聊天区域 ---- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--gray-50);
}
.chat-header {
    padding: 12px 20px;
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chat-header-title {
    font-size: 15px;
    font-weight: 600;
}
.chat-header-actions {
    display: flex;
    gap: 8px;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.message {
    display: flex;
    gap: 6px;
    max-width: 80%;
}
.message.self { align-self: flex-end; flex-direction: row-reverse; }
.message-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    color: #fff;
}
.message-avatar.agent-avatar { background: var(--primary); }
.message-avatar.customer-avatar { background: var(--success); }
.message-content {
    background: #fff;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
    border: 1px solid #e8edf5;
}
.message.self .message-content {
    background: var(--primary);
    color: #fff;
    border: none;
}
.message-time {
    font-size: 10px;
    color: #bbb;
    margin-top: 1px;
}
.message.self .message-time { text-align: right; }

.system-message {
    text-align: center;
    font-size: 11px;
    color: #bbb;
    padding: 2px 0;
}

/* ---- 消息输入 ---- */
.chat-input-area {
    padding: 16px 20px;
    background: #fff;
    border-top: 1px solid var(--gray-200);
}
.chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}
.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    resize: none;
    outline: none;
    font-family: inherit;
    min-height: 42px;
    max-height: 120px;
    line-height: 1.4;
}
.chat-input:focus {
    border-color: var(--primary);
}

/* ---- 空状态 ---- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--gray-400);
    gap: 12px;
    padding: 40px;
}
.empty-icon {
    font-size: 48px;
    opacity: 0.5;
}
.empty-text {
    font-size: 15px;
}

/* ---- 管理后台 ---- */
.admin-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
    overflow: hidden;
}
.admin-sidebar {
    width: 240px;
    background: var(--gray-900);
    color: #fff;
    padding: 20px 0;
}
.admin-sidebar .logo {
    padding: 0 20px 20px;
    font-size: 18px;
    font-weight: 700;
    border-bottom: 1px solid var(--gray-700);
    margin-bottom: 8px;
}
.admin-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    font-size: 14px;
    color: var(--gray-400);
    cursor: pointer;
    transition: all 0.15s;
}
.admin-menu-item:hover { background: var(--gray-800); color: #fff; }
.admin-menu-item.active { background: var(--primary); color: #fff; }
.admin-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}
.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.admin-header h1 {
    font-size: 22px;
    font-weight: 700;
}

/* ---- 数据统计 ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
}
.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--gray-800);
}
.stat-label {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 4px;
}

/* ---- 表格 ---- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.data-table th, .data-table td {
    padding: 12px 16px;
    text-align: left;
    font-size: 14px;
    border-bottom: 1px solid var(--gray-100);
}
.data-table th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-600);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.data-table tr:hover td { background: var(--gray-50); }
.data-table .role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
}
.role-admin { background: var(--primary-light); color: var(--primary); }
.role-agent { background: var(--success-light); color: #047857; }

/* ---- 模态框 ---- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}
.modal-overlay.show { opacity: 1; visibility: visible; }
.modal {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 90%;
    max-width: 480px;
    padding: 24px;
    transform: translateY(-20px);
    transition: transform 0.2s;
}
.modal-overlay.show .modal { transform: translateY(0); }
.modal h3 {
    font-size: 18px;
    margin-bottom: 16px;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* ---- 客户聊天浮窗 ---- */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999;
}
.chat-widget-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.3s;
}
.chat-widget-btn:hover { transform: scale(1.1); background: var(--primary-hover); }
.chat-widget-window {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 380px;
    height: 520px;
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px) scale(0.95);
    transition: all 0.3s;
}
.chat-widget-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}
.chat-widget-header {
    background: var(--primary);
    color: #fff;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chat-widget-header h3 {
    font-size: 16px;
    font-weight: 600;
}
.chat-widget-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.8;
}
.chat-widget-close:hover { opacity: 1; }

/* ---- 客户聊天初始界面 ---- */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 32px;
    text-align: center;
    gap: 16px;
}
.chat-welcome-icon { font-size: 40px; }
.chat-welcome h3 { font-size: 16px; color: var(--gray-700); }
.chat-welcome p { font-size: 13px; color: var(--gray-500); }
.chat-welcome .form-input { text-align: center; margin-top: 8px; }

/* ---- 滚动条 ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ---- 侧边栏切换按钮（仅移动端显示） ---- */
.sidebar-toggle {
    display: none !important;
    visibility: hidden !important;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--gray-900);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 20px;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
}
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

/* ---- 响应式 ---- */
@media (max-width: 768px) {
    /* 客服工作台 */
    .sidebar { width: 100%; min-width: auto; }
    .workspace { flex-direction: column; }
    .chat-widget-window { width: 320px; height: 460px; }
    
    /* 通用移动端 */
    .sidebar-toggle { display: flex !important; visibility: visible !important; }
    
    /* 管理后台移动端 */
    .admin-sidebar {
        position: fixed;
        top: 0; left: -260px;
        width: 260px;
        height: 100vh;
        z-index: 100;
        transition: left 0.3s ease;
        padding-top: 60px;
    }
    .admin-sidebar.open { left: 0; }
    .admin-sidebar .logo {
        padding: 16px 20px 20px;
        font-size: 16px;
        text-align: left;
    }
    .admin-menu-item span { display: inline; }
    .admin-menu-item {
        justify-content: flex-start;
        padding: 12px 20px;
    }
    .admin-content { padding: 16px; padding-top: 60px; }
    .admin-header { flex-wrap: wrap; gap: 8px; }
    .admin-header h1 { font-size: 18px; }
    
    /* 数据表格移动端 */
    .data-table { font-size: 13px; display: block; overflow-x: auto; white-space: nowrap; }
    
    /* 统计网格移动端 */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 22px; }
    
    /* 商户后台移动端 */
    .merchant-sidebar {
        position: fixed;
        top: 0; left: -240px;
        width: 240px;
        height: 100vh;
        z-index: 100;
        transition: left 0.3s ease;
        padding-top: 60px;
    }
    .merchant-sidebar.open { left: 0; }
    .merchant-sidebar .logo {
        padding: 16px 20px 20px;
        font-size: 16px;
        text-align: left;
    }
    .merchant-sidebar .menu-item span { display: inline; }
    .merchant-sidebar .menu-item {
        justify-content: flex-start;
        padding: 12px 20px;
    }
    .merchant-content { padding: 16px; padding-top: 60px; }
    .merchant-content h1 { font-size: 18px; }
    
    /* 表单移动端 */
    .login-card, .register-card { padding: 28px 20px; }
    
    /* 按钮移动端 */
    .btn { padding: 8px 14px; font-size: 13px; }
    .btn-lg { padding: 10px 18px; font-size: 14px; }
}

/* ---- SEO 首页 ---- */
.seo-nav { display:flex; align-items:center; justify-content:space-between; padding:16px 40px; background:#fff; box-shadow:0 1px 3px rgba(0,0,0,0.08); position:sticky; top:0; z-index:100; }
.seo-nav .logo { font-size:22px; font-weight:800; color:var(--primary); }
.seo-nav .nav-links { display:flex; gap:24px; align-items:center; }
.seo-nav .nav-links a { color:var(--gray-600); font-size:14px; font-weight:500; }
.seo-nav .nav-links a:hover { color:var(--primary); }

.seo-hero { text-align:center; padding:80px 20px 60px; background:linear-gradient(135deg, #667eea 0%, #764ba2 100%); color:#fff; }
.seo-hero h1 { font-size:42px; font-weight:800; margin-bottom:16px; line-height:1.2; }
.seo-hero p { font-size:18px; opacity:0.9; max-width:600px; margin:0 auto 32px; }
.seo-hero .cta-group { display:flex; gap:16px; justify-content:center; flex-wrap:wrap; }
.seo-hero .btn { padding:14px 32px; font-size:16px; border-radius:var(--radius); }
.seo-hero .btn-white { background:#fff; color:var(--primary); font-weight:600; }
.seo-hero .btn-white:hover { background:var(--gray-100); }
.seo-hero .btn-outline-white { border:2px solid rgba(255,255,255,0.6); color:#fff; background:transparent; }
.seo-hero .btn-outline-white:hover { border-color:#fff; background:rgba(255,255,255,0.1); }

.seo-section { padding:60px 40px; max-width:1200px; margin:0 auto; }
.seo-section-title { text-align:center; margin-bottom:40px; }
.seo-section-title h2 { font-size:28px; font-weight:700; color:var(--gray-800); margin-bottom:8px; }
.seo-section-title p { color:var(--gray-500); font-size:15px; }

.feature-grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(260px, 1fr)); gap:24px; }
.feature-card { background:#fff; border-radius:var(--radius-lg); padding:28px; box-shadow:var(--shadow); text-align:center; transition:transform 0.2s, box-shadow 0.2s; }
.feature-card:hover { transform:translateY(-4px); box-shadow:var(--shadow-lg); }
.feature-card .icon { font-size:36px; margin-bottom:12px; }
.feature-card h3 { font-size:17px; font-weight:600; margin-bottom:8px; color:var(--gray-800); }
.feature-card p { font-size:13px; color:var(--gray-500); line-height:1.6; }

.steps { display:flex; gap:32px; justify-content:center; flex-wrap:wrap; }
.step { text-align:center; flex:1; min-width:200px; max-width:280px; }
.step-num { width:48px; height:48px; border-radius:50%; background:var(--primary); color:#fff; display:inline-flex; align-items:center; justify-content:center; font-size:20px; font-weight:700; margin-bottom:12px; }
.step h3 { font-size:16px; margin-bottom:6px; }
.step p { font-size:13px; color:var(--gray-500); }

.seo-faq { max-width:700px; margin:0 auto; }
.faq-item { border-bottom:1px solid var(--gray-200); padding:16px 0; }
.faq-item h4 { font-size:15px; font-weight:600; margin-bottom:6px; color:var(--gray-800); }
.faq-item p { font-size:14px; color:var(--gray-500); line-height:1.6; }

.seo-footer { background:var(--gray-900); color:var(--gray-400); padding:32px 40px; text-align:center; font-size:13px; }

/* ---- 商户后台 ---- */
.merchant-sidebar { width:220px; background:var(--gray-900); color:#fff; padding:20px 0; flex-shrink:0; }
.merchant-sidebar .logo { padding:0 20px 20px; font-size:18px; font-weight:700; border-bottom:1px solid var(--gray-700); margin-bottom:8px; color:var(--primary); }
.merchant-sidebar .menu-item { display:flex; align-items:center; gap:10px; padding:10px 20px; font-size:14px; color:var(--gray-400); cursor:pointer; transition:all 0.15s; }
.merchant-sidebar .menu-item:hover { background:var(--gray-800); color:#fff; }
.merchant-sidebar .menu-item.active { background:var(--primary); color:#fff; }

.embed-card { background:#fff; border-radius:var(--radius-lg); box-shadow:var(--shadow); padding:28px; margin-bottom:20px; }
.embed-card h3 { font-size:16px; font-weight:600; margin-bottom:12px; }
.code-block { background:var(--gray-900); color:#6ee7b7; padding:16px; border-radius:var(--radius); font-family:'Fira Code',monospace; font-size:13px; overflow-x:auto; white-space:pre-wrap; word-break:break-all; }
.copy-btn { margin-top:8px; }
.api-key-display { background:var(--gray-100); padding:12px 16px; border-radius:var(--radius); font-family:monospace; font-size:14px; display:flex; align-items:center; justify-content:space-between; }

/* 注册页 */
.register-page { display:flex; align-items:center; justify-content:center; min-height:100vh; background:linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding:20px; }
.register-card { background:#fff; border-radius:var(--radius-lg); box-shadow:var(--shadow-xl); padding:36px 40px; width:100%; max-width:460px; }
.register-card h1 { text-align:center; font-size:22px; color:var(--gray-800); margin-bottom:24px; }

/* 商户后台布局 */
.merchant-layout { display:flex; height:100vh; overflow:hidden; width:100%; }
.merchant-content { flex:1; padding:24px; overflow-y:auto; background:var(--gray-50); }
.merchant-content h1 { font-size:22px; font-weight:700; margin-bottom:20px; }
