:root {
    --bg: #f0f2f5;
    --panel: #ffffff;
    --border: #e4e6eb;
    --text: #1c1e21;
    --muted: #65676b;
    --brand: #25d366;
    --brand-dark: #128c7e;
    --in-bubble: #ffffff;
    --out-bubble: #dcf8c6;
    --badge: #fa3e3e;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--text);
    background: var(--bg);
}

.inbox {
    display: flex;
    flex-direction: column;
    height: 100vh;
}
.inbox-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}
.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.sidebar-head h1 {
    font-size: 18px;
    margin: 0;
}
.dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: #bbb; display: inline-block;
}
.dot.on { background: var(--brand); }
.dot.off { background: var(--badge); }

.conv-list {
    list-style: none;
    margin: 0; padding: 0;
    overflow-y: auto;
    flex: 1;
}
.conv-item {
    position: relative;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.conv-item:hover { background: #f5f6f7; }
.conv-item.active { background: #eef6f1; }
.conv-name { font-weight: 600; font-size: 14px; }
.conv-preview {
    color: var(--muted);
    font-size: 13px;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 240px;
}
.conv-meta {
    position: absolute;
    top: 12px; right: 12px;
    color: var(--muted);
    font-size: 11px;
}
.badge {
    position: absolute;
    bottom: 12px; right: 12px;
    background: var(--badge);
    color: #fff;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
}
.empty { padding: 24px; color: var(--muted); text-align: center; }

/* Chat */
.chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}
.chat-title { font-weight: 600; }
.close-btn {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
}
.close-btn:disabled { color: var(--muted); cursor: default; }

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
}
.bubble.in {
    align-self: flex-start;
    background: var(--in-bubble);
    border: 1px solid var(--border);
}
.bubble.out {
    align-self: flex-end;
    background: var(--out-bubble);
}
.bubble .media {
    max-width: 240px;
    max-height: 320px;
    border-radius: 6px;
    display: block;
    margin-bottom: 4px;
    background: #000;
}
.bubble .media-link {
    display: inline-block;
    margin-bottom: 4px;
    color: inherit;
    text-decoration: underline;
    font-size: 13px;
}
.bubble .text { white-space: pre-wrap; }

/* ---- 坐席管理页 ---- */
.page {
    max-width: 860px;
    margin: 0 auto;
    padding: 24px 20px 48px;
}
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}
.page-head h1 { font-size: 20px; font-weight: 600; }
.page-head-actions a { color: var(--brand, #4a7fd4); text-decoration: none; font-size: 13px; }
.sec-title {
    font-size: 14px;
    font-weight: 600;
    color: #46536a;
    margin: 26px 0 10px;
}
.list { border: 1px solid #e3e8f0; border-radius: 8px; overflow: hidden; }
.list .row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #fff;
    border-bottom: 1px solid #eef2f7;
}
.list .row.sub { background: #fafbfd; padding-top: 8px; padding-bottom: 8px; }
.list .row input[type=text] { width: 130px; }
.list .row .email { flex: 1; font-size: 13px; }
.list .row button {
    background: #4a7fd4;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 5px 14px;
    font-size: 13px;
    cursor: pointer;
}
.list .row button.ghost {
    background: transparent;
    color: #6b7789;
    border: 1px solid #ccd6e6;
}
.switch { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: #6b7789; }
.card-form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    background: #fff;
    border: 1px solid #e3e8f0;
    border-radius: 8px;
    padding: 16px;
}
.card-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #6b7789; }
.card-form input, .card-form select { min-width: 150px; }
.card-form button {
    background: #4a7fd4;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 18px;
    font-size: 13px;
    cursor: pointer;
}
.alert.ok { background: #eaf6ee; color: #1f7a3d; }
.admin-link { margin-left: 12px; font-size: 13px; color: #4a7fd4; text-decoration: none; }

/* ---- 模板管理页 ---- */
.hint {
    background: #f5f8fc;
    border-left: 3px solid #4a7fd4;
    padding: 9px 12px;
    border-radius: 6px;
    font-size: 12.5px;
    color: #4d5a6e;
    line-height: 1.6;
}
.tpl-card {
    display: block;
    background: #fff;
    border: 1px solid #e3e8f0;
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 8px;
}
.tpl-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.tpl-name {
    font-family: Consolas, Menlo, monospace;
    font-size: 13px;
    font-weight: 600;
    color: #2c3a4f;
}
.tpl-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.tpl-grid label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: #6b7789;
}
.tpl-grid .wide { grid-column: 1 / -1; }
.tpl-grid input, .tpl-grid select, .tpl-grid textarea {
    font-size: 13px;
    font-family: inherit;
}
.tpl-actions { margin-top: 10px; }
.tpl-actions button {
    background: #4a7fd4;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 16px;
    font-size: 13px;
    cursor: pointer;
}
.tpl-delete { margin: -2px 0 18px; }
.tpl-delete button.danger {
    background: transparent;
    color: #b3453c;
    border: 1px solid #e3b7b2;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 12px;
    cursor: pointer;
}
.empty-tip {
    border: 1px dashed #d7dfea;
    border-radius: 8px;
    padding: 18px;
    text-align: center;
    color: #8a94a6;
    font-size: 13px;
}
@media (max-width: 720px) {
    .tpl-grid { grid-template-columns: 1fr; }
}

/* AI 回复草案面板 */
.ai-draft-panel {
    margin: 0 16px 8px;
    border: 1px solid #d8e3f7;
    border-left: 3px solid #4a7fd4;
    background: #f4f8ff;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
}
.ai-draft-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #2c5aa0;
    margin-bottom: 6px;
}
.ai-draft-model {
    font-weight: 400;
    font-size: 11px;
    color: #7d8ba1;
    background: #e6eefb;
    border-radius: 4px;
    padding: 1px 6px;
}
.ai-draft-content {
    white-space: pre-wrap;
    color: #24303f;
    line-height: 1.55;
    max-height: 180px;
    overflow-y: auto;
    margin-bottom: 8px;
}
.ai-draft-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-draft-actions button {
    background: #4a7fd4;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 12px;
    cursor: pointer;
}
.ai-draft-actions button:hover { background: #3a6cbe; }
.ai-draft-actions button.ghost {
    background: transparent;
    color: #7d8ba1;
    border: 1px solid #c9d5e8;
}
.ai-draft-tip {
    color: #8a94a6;
    font-size: 11px;
    margin-left: auto;
}
.bubble-meta {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
    text-align: right;
}

.composer {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    background: var(--panel);
    border-top: 1px solid var(--border);
}
#msg-input {
    flex: 1;
    resize: none;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
    outline: none;
}
#send-btn {
    background: var(--brand-dark);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0 22px;
    font-weight: 600;
    cursor: pointer;
}
#send-btn:hover { background: var(--brand); }

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}
.topbar .me { font-size: 14px; }
.role-tag {
    margin-left: 8px;
    font-size: 11px;
    padding: 1px 8px;
    border-radius: 10px;
    background: #eef1f5;
    color: var(--muted);
}
.logout-btn {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 6px;
    padding: 5px 14px;
    cursor: pointer;
}

/* 会话归属与认领 */
.conv-owner {
    font-size: 11px;
    color: var(--muted);
    margin-top: 3px;
}
.claim-btn {
    margin-top: 6px;
    border: none;
    background: var(--brand-dark);
    color: #fff;
    border-radius: 5px;
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
}

/* 登录页 */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}
.login-card {
    width: 340px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 28px;
}
.login-card h1 {
    font-size: 20px;
    margin: 0 0 18px;
}
.login-card label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 12px;
}
.login-card input[type="email"],
.login-card input[type="password"] {
    width: 100%;
    margin-top: 5px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 9px 11px;
    font: inherit;
    outline: none;
}
.login-card .remember {
    display: flex;
    align-items: center;
    gap: 6px;
}
.login-card button {
    width: 100%;
    background: var(--brand-dark);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-weight: 600;
    cursor: pointer;
}
.alert {
    background: #fdecec;
    color: #a12b2b;
    border-radius: 6px;
    padding: 8px 11px;
    font-size: 13px;
    margin-bottom: 14px;
}

/* 工具栏与模板面板 */
.composer-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--panel);
    border-top: 1px solid var(--border);
}
.composer-tools button {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
}
.composer-tools button:disabled { color: #bbb; cursor: default; }
.window-tip { font-size: 12px; color: var(--muted); }
.window-tip.closed { color: #a12b2b; }

.template-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
    padding: 10px 16px;
    background: #f7f9f8;
    border-top: 1px solid var(--border);
}
.template-panel label {
    display: flex;
    flex-direction: column;
    font-size: 11px;
    color: var(--muted);
    gap: 3px;
}
.template-panel select,
.template-panel input {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 9px;
    font: inherit;
    font-size: 13px;
    outline: none;
}
.template-panel button {
    background: var(--brand-dark);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 7px 16px;
    font-weight: 600;
    cursor: pointer;
}
.composer textarea:disabled { background: #f2f3f5; }
.composer button:disabled { background: #c9ced2; cursor: default; }
