:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --border: #e5e7eb;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    --chat-bg: #f9fafb;
    --msg-agent-bg: #e0edff;
    --msg-visitor-bg: #ffffff;
}

* {
    box-sizing: border-box;
}

html, body, #app {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* -------- 加载提示 -------- */
.app-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    gap: 16px;
}
.loader {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: loader-spin 0.8s linear infinite;
}
@keyframes loader-spin {
    to { transform: rotate(360deg); }
}

/* -------- 登录页 -------- */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: linear-gradient(135deg, #eff6ff 0%, #e0e7ff 100%);
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
}
.login-card h1 {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 600;
    text-align: center;
    color: var(--text);
}
.login-card .subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 24px;
}
.login-card .field {
    margin-bottom: 16px;
}
.login-card .field label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-size: 13px;
}
.login-card .field input {
    width: 100%;
}
.login-card .submit-btn {
    width: 100%;
    margin-top: 8px;
}
.login-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}
.login-logo .logo-box {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 24px;
    font-weight: bold;
}

/* -------- 主布局 -------- */
.main-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}
.app-header .brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px;
    font-weight: 600;
}
.app-header .brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
}
.app-header .user-box {
    display: flex;
    align-items: center;
    gap: 12px;
}
.app-header .user-info {
    text-align: right;
    line-height: 1.2;
}
.app-header .user-info .name {
    font-size: 13px;
    font-weight: 500;
}
.app-header .user-info .email {
    font-size: 12px;
    color: var(--text-secondary);
}
.sidebar-toggle {
    display: none;
}

.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}
.sidebar {
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px 0;
    overflow-y: auto;
    flex-shrink: 0;
}
.sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--text-secondary);
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all 0.15s;
    font-size: 14px;
}
.sidebar .nav-item:hover {
    background: #f3f4f6;
    color: var(--text);
}
.sidebar .nav-item.active {
    background: #eff6ff;
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 500;
}
.sidebar .nav-item i {
    font-size: 16px;
}
.content {
    flex: 1;
    overflow: auto;
    padding: 20px;
    min-height: 0;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 4px;
}
.page-desc {
    color: var(--text-secondary);
    margin: 0 0 20px;
    font-size: 13px;
}
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

/* -------- 统计卡片 -------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.stat-card .label {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.stat-card .value {
    font-size: 28px;
    font-weight: 600;
    color: var(--text);
    line-height: 1;
}
.stat-card .icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    margin-left: auto;
}
.stat-card .top {
    display: flex;
    align-items: flex-start;
    margin-bottom: 4px;
}
.stat-card .sub {
    color: var(--text-light);
    font-size: 12px;
    margin-top: 8px;
}

/* -------- 面板/表格 -------- */
.panel {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-bottom: 16px;
}
.panel h2 {
    margin: 0 0 16px;
    font-size: 16px;
    font-weight: 600;
}
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.panel-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

/* -------- 聊天界面 -------- */
.chat-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 0;
    height: calc(100vh - 56px - 40px - 100px);
    min-height: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.chat-sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: #fafbfc;
    min-width: 0;
}
.chat-sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--surface);
}
.chat-sidebar-header .title {
    font-weight: 600;
    font-size: 14px;
}
.chat-list {
    flex: 1;
    overflow-y: auto;
}
.chat-list-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    position: relative;
}
.chat-list-item:hover {
    background: #f3f4f6;
}
.chat-list-item.active {
    background: #eff6ff;
}
.chat-list-item .conv-info {
    flex: 1;
    min-width: 0;
}
.chat-list-item .conv-name {
    font-weight: 500;
    font-size: 13px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chat-list-item .conv-time {
    font-size: 11px;
    color: var(--text-light);
    flex-shrink: 0;
    margin-left: 6px;
}
.chat-list-item .conv-last {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-list-item .conv-tags {
    margin-top: 4px;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.chat-list-empty {
    padding: 40px 16px;
    text-align: center;
    color: var(--text-light);
    font-size: 13px;
}

.chat-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--chat-bg);
}
.chat-main-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.chat-main-header .title {
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-main-header .meta {
    color: var(--text-secondary);
    font-size: 12px;
    margin-top: 2px;
}
.chat-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chat-empty {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 72%;
    align-items: flex-start;
}
.message.mine {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.message .msg-avatar {
    flex-shrink: 0;
}
.message .msg-bubble-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.message .msg-head {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    gap: 8px;
    align-items: center;
}
.message.mine .msg-head {
    justify-content: flex-end;
}
.message .msg-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.message.visitor .msg-bubble {
    background: var(--msg-visitor-bg);
    border: 1px solid var(--border);
    border-top-left-radius: 4px;
}
.message.mine .msg-bubble {
    background: var(--msg-agent-bg);
    border-top-right-radius: 4px;
}
.message .msg-time {
    font-size: 11px;
    color: var(--text-light);
}

.typing-indicator {
    align-self: flex-start;
    color: var(--text-secondary);
    font-size: 12px;
    padding: 8px 14px;
    background: var(--msg-visitor-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    border-top-left-radius: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.typing-dots span {
    display: inline-block;
    width: 5px;
    height: 5px;
    background: var(--text-light);
    border-radius: 50%;
    margin: 0 1px;
    animation: typing-bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.chat-input {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}
.chat-input textarea {
    width: 100%;
    resize: none;
    min-height: 40px;
    max-height: 160px;
}
.chat-input-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.chat-input-status {
    font-size: 12px;
    color: var(--text-light);
}

/* -------- 访客详情 -------- */
.visitor-detail .row {
    display: flex;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.visitor-detail .row:last-child { border-bottom: none; }
.visitor-detail .label {
    width: 120px;
    color: var(--text-secondary);
    font-size: 13px;
    flex-shrink: 0;
}
.visitor-detail .value {
    flex: 1;
    font-size: 13px;
    color: var(--text);
    word-break: break-all;
}

/* -------- 代码块（嵌入代码） -------- */
.code-block {
    background: #0f172a;
    color: #e2e8f0;
    padding: 14px 16px;
    border-radius: 8px;
    font-family: "SF Mono", Consolas, Monaco, "Courier New", monospace;
    font-size: 12.5px;
    line-height: 1.6;
    overflow: auto;
    white-space: pre;
    margin: 0;
    max-height: 260px;
}

/* -------- 表格样式优化 -------- */
.p-datatable .p-column-header-content {
    font-weight: 600;
}

/* -------- 表单栅格 -------- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}
.form-grid .col-full {
    grid-column: 1 / -1;
}
.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.form-field label {
    font-size: 13px;
    color: var(--text-secondary);
}
.form-field .req::after {
    content: " *";
    color: var(--danger);
}

/* -------- 角色/状态 Tag -------- */
.cell-tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    line-height: 1.5;
}
.role-admin { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.role-agent { background: #eff6ff; color: #2563eb; border: 1px solid #bfdbfe; }
.status-active { background: #ecfdf5; color: #059669; border: 1px solid #a7f3d0; }
.status-inactive { background: #f3f4f6; color: #6b7280; border: 1px solid #e5e7eb; }
.status-open { background: #eff6ff; color: #2563eb; border: 1px solid #bfdbfe; }
.status-closed { background: #f3f4f6; color: #6b7280; border: 1px solid #e5e7eb; }
.conv-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 11px;
    line-height: 1.6;
    min-width: 18px;
    text-align: center;
}

/* -------- 表格操作按钮 -------- */
.cell-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    background: transparent;
    color: #3b82f6;
    transition: all 0.15s;
}
.cell-btn:hover {
    background: #eff6ff;
}
.cell-btn .pi {
    margin: 0;
}

/* -------- 在线指示 -------- */
.online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    display: inline-block;
    margin-right: 6px;
}
.offline-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-light);
    display: inline-block;
    margin-right: 6px;
}

/* -------- 响应式：移动端 -------- */
@media (max-width: 960px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 56px;
        height: calc(100vh - 56px);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 20;
        width: 240px;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 12px rgba(0, 0, 0, 0.1);
    }
    .sidebar-toggle {
        display: inline-flex;
    }
    .sidebar-mask {
        position: fixed;
        inset: 56px 0 0 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 15;
    }
    .content {
        padding: 14px;
    }
    .form-grid {
        grid-template-columns: 1fr;
    }
    .chat-layout {
        grid-template-columns: 1fr;
        height: calc(100vh - 84px);
        position: relative;
    }
    .chat-layout.mobile-show-list .chat-sidebar {
        display: flex;
    }
    .chat-layout.mobile-show-list .chat-main {
        display: none;
    }
    .chat-sidebar {
        display: none;
        border-right: none;
    }
    .chat-main {
        display: flex;
    }
    .chat-back-btn {
        display: inline-flex !important;
    }
    .message {
        max-width: 88%;
    }
    .app-header .user-info .email {
        display: none;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .stat-card .value {
        font-size: 22px;
    }
}

.chat-back-btn {
    display: none;
}

/* -------- 滚动条优化 -------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* 聊天输入文本域（替代 PrimeVue InputTextarea） */
.chat-textarea {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    resize: vertical;
    outline: none;
    box-sizing: border-box;
    line-height: 1.5;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.chat-textarea:disabled {
    background: var(--chat-bg);
    color: var(--text-light);
    cursor: not-allowed;
}
.chat-textarea::placeholder {
    color: var(--text-light);
}
