/* 基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f5f7fa;
    color: #333;
}

/* ============ 登录页面 ============ */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 400px;
}

.login-box h2 {
    text-align: center;
    margin-bottom: 30px;
    color: #333;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: #666;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-primary:hover {
    background: #5a67d8;
}

.error-message {
    color: #e53e3e;
    margin-top: 10px;
    text-align: center;
}

/* ============ 管理后台 ============ */
.admin-wrapper {
    display: flex;
    height: 100vh;
    flex-direction: column;
}

.admin-topbar {
    background: #2d3748;
    color: white;
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.admin-topbar h1 {
    font-size: 20px;
    margin: 0;
}

.admin-topbar .user-info {
    display: flex;
    align-items: center;
    gap: 20px;
}

.admin-topbar .user-info .status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
}

.status-badge.online {
    background: #48bb78;
    color: white;
}

.status-badge.offline {
    background: #fc8181;
    color: white;
}

.btn-logout {
    background: #e53e3e;
    color: white;
    border: none;
    padding: 6px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.btn-logout:hover {
    background: #c53030;
}

.admin-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.admin-sidebar {
    width: 200px;
    background: #f7fafc;
    border-right: 1px solid #e2e8f0;
    padding: 20px 0;
    flex-shrink: 0;
}

.admin-sidebar .menu-item {
    padding: 12px 24px;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    color: #4a5568;
    font-size: 14px;
}

.admin-sidebar .menu-item:hover {
    background: #edf2f7;
}

.admin-sidebar .menu-item.active {
    background: #ebf8ff;
    border-left-color: #667eea;
    color: #667eea;
    font-weight: 600;
}

.admin-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background: #f7fafc;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

/* 统计卡片 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-card .stat-label {
    color: #718096;
    font-size: 14px;
    margin-bottom: 8px;
}

.stat-card .stat-value {
    font-size: 32px;
    font-weight: bold;
    color: #2d3748;
}

/* ============ 会话列表 ============ */
.sessions-panel {
    display: flex;
    gap: 20px;
    height: calc(100% - 60px);
}

.session-list {
    flex: 1;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    min-width: 300px;
}

.session-list .list-header {
    padding: 15px 20px;
    background: #f7fafc;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 600;
    color: #2d3748;
}

.session-list .list-items {
    overflow-y: auto;
    max-height: 500px;
}

.session-item {
    padding: 15px 20px;
    border-bottom: 1px solid #f7fafc;
    cursor: pointer;
    transition: background 0.2s;
}

.session-item:hover {
    background: #f7fafc;
}

.session-item.active {
    background: #ebf8ff;
    border-left: 3px solid #667eea;
}

.session-item .session-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.session-item .visitor-id {
    font-weight: 600;
    color: #2d3748;
    font-size: 14px;
}

.session-item .unread-badge {
    background: #fc8181;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
}

.session-item .last-msg {
    color: #718096;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-item .time {
    color: #a0aec0;
    font-size: 12px;
}

/* ============ 聊天窗口 ============ */
.chat-panel {
    flex: 2;
    background: white;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    min-width: 400px;
}

.chat-panel .chat-header {
    padding: 15px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f7fafc;
    border-radius: 10px 10px 0 0;
    flex-shrink: 0;
}

.chat-panel .chat-header .chat-title {
    font-weight: 600;
    color: #2d3748;
}

.chat-panel .chat-header .chat-actions {
    display: flex;
    gap: 10px;
}

.btn-end {
    background: #fc8181;
    color: white;
    border: none;
    padding: 6px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.btn-end:hover {
    background: #f56565;
}

/* ============ 消息样式 - 关键修复 ============ */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 400px;
    max-height: 500px;
    background: #f7fafc;
}

/* 消息基础样式 */
.message {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 10px;
    word-wrap: break-word;
    position: relative;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message .message-content {
    font-size: 14px;
    line-height: 1.5;
}

.message .msg-time {
    font-size: 11px;
    margin-top: 4px;
}

/* 客服消息 - 显示在左边 */
.message.admin {
    align-self: flex-start;
    background: #ffffff;
    color: #2d3748;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message.admin .msg-time {
    color: #a0aec0;
}

/* 访客消息 - 显示在右边 */
.message.visitor {
    align-self: flex-end;
    background: #667eea;
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 2px rgba(102, 126, 234, 0.3);
}

.message.visitor .msg-time {
    color: rgba(255, 255, 255, 0.7);
}

/* 系统消息 - 居中 */
.message.system {
    align-self: center;
    background: #edf2f7;
    color: #718096;
    font-size: 13px;
    max-width: 80%;
    text-align: center;
    border-radius: 20px;
    padding: 6px 16px;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #a0aec0;
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 10px;
}

/* ============ 聊天输入区 ============ */
.chat-input-area {
    padding: 15px 20px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 10px;
    background: white;
    border-radius: 0 0 10px 10px;
    flex-shrink: 0;
}

.chat-input-area textarea {
    flex: 1;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 5px;
    resize: none;
    font-size: 14px;
    font-family: inherit;
    min-height: 50px;
    transition: border-color 0.2s;
}

.chat-input-area textarea:focus {
    outline: none;
    border-color: #667eea;
}

.chat-input-area .btn-send {
    padding: 10px 30px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    align-self: flex-end;
    transition: background 0.2s;
}

.chat-input-area .btn-send:hover {
    background: #5a67d8;
}

.chat-input-area .btn-send:disabled {
    background: #a0aec0;
    cursor: not-allowed;
}

/* ============ 设置页面 ============ */
.settings-container {
    max-width: 800px;
}

.settings-container .setting-group {
    background: white;
    padding: 24px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.settings-container .setting-group h3 {
    margin-bottom: 15px;
    color: #2d3748;
    font-size: 16px;
}

.settings-container .setting-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 5px;
    font-size: 14px;
    resize: vertical;
    font-family: inherit;
    min-height: 80px;
}

.settings-container .setting-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.settings-container .setting-group .toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.settings-container .setting-group .toggle-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.btn-save {
    background: #48bb78;
    color: white;
    border: none;
    padding: 10px 30px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
}

.btn-save:hover {
    background: #38a169;
}

/* ============ 链接生成 ============ */
.link-generator {
    background: white;
    padding: 24px;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    max-width: 600px;
}

.link-generator .link-display {
    display: flex;
    gap: 10px;
    margin: 20px 0;
}

.link-generator .link-display input {
    flex: 1;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 5px;
    font-size: 14px;
}

.link-generator .link-display input:focus {
    outline: none;
    border-color: #667eea;
}

.btn-copy {
    background: #4299e1;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
}

.btn-copy:hover {
    background: #3182ce;
}

.btn-generate {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 30px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
}

.btn-generate:hover {
    background: #5a67d8;
}

.btn-status {
    padding: 10px 30px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
}

.link-history {
    margin-top: 30px;
}

.link-history .history-item {
    padding: 10px 0;
    border-bottom: 1px solid #f7fafc;
    display: flex;
    justify-content: space-between;
    font-size: 14px;
}

.link-history .history-item .link-url {
    color: #667eea;
    word-break: break-all;
}

.link-history .history-item .link-time {
    color: #a0aec0;
    white-space: nowrap;
    margin-left: 20px;
}

/* ============ 客户聊天窗口 ============ */
.chat-container {
    max-width: 500px;
    margin: 50px auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    overflow: hidden;
}

.chat-container .chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    flex-shrink: 0;
}

.chat-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-online {
    color: #48bb78;
}

.status-offline {
    color: #fc8181;
}

/* 客户聊天消息样式 */
.chat-container .chat-messages {
    height: 400px;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f7fafc;
}

/* 客户聊天 - 客服消息在左边 */
.chat-container .message.admin {
    align-self: flex-start;
    background: #ffffff;
    color: #2d3748;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

/* 客户聊天 - 访客消息在右边 */
.chat-container .message.visitor {
    align-self: flex-end;
    background: #667eea;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.chat-container .message.system {
    align-self: center;
    background: #edf2f7;
    color: #718096;
    font-size: 13px;
    max-width: 80%;
    text-align: center;
    border-radius: 20px;
    padding: 6px 16px;
}

.chat-container .chat-input-area {
    padding: 15px 20px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 10px;
    background: white;
}

.chat-container .chat-input-area textarea {
    flex: 1;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 5px;
    resize: none;
    font-family: inherit;
}

.chat-container .chat-input-area textarea:focus {
    outline: none;
    border-color: #667eea;
}

.chat-container .chat-input-area button {
    padding: 10px 25px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.chat-container .chat-input-area button:hover {
    background: #5a67d8;
}

/* ============ 响应式 ============ */
@media (max-width: 768px) {
    .admin-body {
        flex-direction: column;
    }
    
    .admin-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
        padding: 10px 0;
        display: flex;
        overflow-x: auto;
    }
    
    .admin-sidebar .menu-item {
        white-space: nowrap;
        border-left: none;
        border-bottom: 3px solid transparent;
    }
    
    .admin-sidebar .menu-item.active {
        border-left: none;
        border-bottom-color: #667eea;
    }
    
    .sessions-panel {
        flex-direction: column;
        height: auto;
    }
    
    .session-list {
        min-width: unset;
        max-height: 300px;
    }
    
    .chat-panel {
        min-width: unset;
        min-height: 400px;
    }
    
    .chat-messages {
        max-height: 300px;
        min-height: 200px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .chat-container {
        margin: 20px;
        max-width: unset;
    }
}