/* ============================================================
   企业微信会话存档后台 —— 蓝色主题样式
   主色 #2563EB / 深蓝侧栏渐变 / 浅蓝灰背景
   ============================================================ */

:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #dbeafe;
    --sidebar-bg1: #0b2a5b;
    --sidebar-bg2: #123e7c;
    --bg: #f1f5fb;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-sub: #64748b;
    --border: #e2e8f0;
    --danger: #dc2626;
    --ok: #16a34a;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(15, 40, 90, .08), 0 4px 16px rgba(15, 40, 90, .06);
}

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

body {
    font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
}

/* ---------- 布局骨架 ---------- */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 220px;
    background: linear-gradient(180deg, var(--sidebar-bg1), var(--sidebar-bg2));
    color: #cfe0f7;
    display: flex;
    flex-direction: column;
    transition: width .25s ease, transform .25s ease;
    z-index: 50;
}

.layout-main {
    margin-left: 220px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left .25s ease;
}

/* 折叠态：body 上加 .collapsed */
body.collapsed .sidebar { width: 64px; }
body.collapsed .layout-main { margin-left: 64px; }
body.collapsed .sidebar-logo-text,
body.collapsed .sidebar-link span:last-child,
body.collapsed .sidebar-foot { display: none; }
body.collapsed .sidebar-link { justify-content: center; }

/* ---------- 侧栏 ---------- */
.sidebar-logo {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 16px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-logo-icon {
    width: 36px; height: 36px; flex: none;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .14);
    border-radius: 10px;
    font-size: 18px;
}
.sidebar-logo-text { font-size: 15px; font-weight: 700; color: #fff; white-space: nowrap; }

.sidebar-nav { flex: 1; padding: 12px 10px; }
.sidebar-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px;
    margin-bottom: 4px;
    border-radius: 10px;
    color: #cfe0f7;
    text-decoration: none;
    white-space: nowrap;
    transition: background .15s, color .15s;
}
.sidebar-link:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.sidebar-link.active {
    background: linear-gradient(90deg, var(--primary), #3b82f6);
    color: #fff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, .4);
}
.sidebar-link-icon { font-size: 16px; }

.sidebar-foot {
    padding: 14px 16px;
    font-size: 12px;
    color: #7ea2cf;
    border-top: 1px solid rgba(255, 255, 255, .08);
    display: flex; flex-direction: column; gap: 2px;
}
.sidebar-foot-ver { color: #54749f; }

/* ---------- 顶栏 ---------- */
.topbar {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; gap: 14px;
    height: 58px;
    padding: 0 24px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(15, 40, 90, .04);
}
.topbar-toggle {
    width: 34px; height: 34px;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.topbar-toggle span { display: block; width: 16px; height: 2px; background: var(--text-sub); border-radius: 1px; }
.topbar-toggle:hover { border-color: var(--primary); }
.topbar-toggle:hover span { background: var(--primary); }

.topbar-title { font-size: 16px; font-weight: 700; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.topbar-badge {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #fef3c7;
    color: #b45309;
}
.topbar-user {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--primary), #60a5fa);
    color: #fff;
    font-size: 13px;
    border-radius: 50%;
}

/* ---------- 内容区 ---------- */
.content { flex: 1; padding: 24px; }
.page { max-width: 1200px; margin: 0 auto; }

.notice {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}
.notice-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ---------- 卡片 ---------- */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 700; }
.card-sub { font-size: 12px; color: var(--text-sub); }

/* 统计卡片 */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.card-stat {
    display: flex; align-items: center; gap: 14px;
    padding: 20px;
    margin-bottom: 0;
    transition: transform .15s, box-shadow .15s;
    cursor: default;
}
.card-stat:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(37, 99, 235, .15); }
.card-stat-icon {
    width: 48px; height: 48px; flex: none;
    display: flex; align-items: center; justify-content: center;
    border-radius: 12px;
    font-size: 22px;
}
.card-stat-value { font-size: 26px; font-weight: 800; line-height: 1.1; }
.card-stat-label { font-size: 12px; color: var(--text-sub); margin-top: 3px; }

/* 两栏 */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- 消息列表 ---------- */
.msg-list { list-style: none; padding: 8px 20px; }
.msg-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--border); }
.msg-item:last-child { border-bottom: none; }
.msg-avatar {
    width: 36px; height: 36px; flex: none;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 50%;
    font-weight: 700;
}
.msg-body { flex: 1; min-width: 0; }
.msg-line { display: flex; justify-content: space-between; margin-bottom: 3px; }
.msg-time { font-size: 12px; color: var(--text-sub); }
.msg-text { color: var(--text-sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 图表（纯 CSS 占位） ---------- */
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 8px; }
.tab {
    border: none; background: transparent;
    padding: 5px 12px; border-radius: 6px;
    font-size: 12px; color: var(--text-sub);
    cursor: pointer;
}
.tab.active { background: #fff; color: var(--primary); font-weight: 600; box-shadow: 0 1px 3px rgba(15, 40, 90, .12); }

.chart {
    height: 200px;
    padding: 20px 24px 0;
    display: flex; align-items: flex-end; justify-content: space-around;
    gap: 12px;
}
.chart-bar {
    flex: 1;
    border-radius: 6px 6px 0 0;
    background: linear-gradient(180deg, #3b82f6, var(--primary-dark));
    opacity: .85;
    transition: opacity .15s, transform .2s;
    transform-origin: bottom;
}
.chart-bar:hover { opacity: 1; transform: scaleY(1.03); }
.chart.mode-line .chart-bar { border-radius: 999px; height: 8px !important; }
.chart-legend {
    display: flex; justify-content: space-around;
    padding: 8px 24px 16px;
    font-size: 11px; color: var(--text-sub);
}

/* ---------- 筛选栏 / 表单 ---------- */
.filter-bar { display: flex; gap: 10px; padding: 14px 16px; flex-wrap: wrap; }
.input {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: #fff;
    color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.filter-bar .input:first-child { flex: 1; min-width: 220px; }

.form { padding: 20px; max-width: 560px; }
.form-item { display: block; margin-bottom: 18px; }
.form-label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.form-item .input { width: 100%; }
.form-tip { display: block; margin-top: 6px; font-size: 12px; color: var(--text-sub); }
.form-tip.ok { color: var(--ok); }
.form-actions { display: flex; align-items: center; gap: 12px; }
.form-hint { font-size: 12px; color: var(--text-sub); }

/* ---------- 按钮 ---------- */
.btn {
    padding: 9px 16px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    color: #fff;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(37, 99, 235, .35);
    transition: transform .1s, box-shadow .15s, opacity .15s;
}
.btn:hover { box-shadow: 0 4px 14px rgba(37, 99, 235, .45); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-ghost { background: #fff; color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); box-shadow: none; }

/* ---------- 表格 ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; }
.table th {
    font-size: 12px; color: var(--text-sub); font-weight: 600;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}
.table td { border-bottom: 1px solid var(--border); font-size: 13px; }
.msg-row { transition: background .12s; }
.msg-row:hover { background: #f5f9ff; }
.cell-content { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-sub); }
.cell-time { color: var(--text-sub); white-space: nowrap; }
.user-chip {
    display: inline-block;
    padding: 3px 10px;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 999px;
    font-size: 12px;
}
.type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 12px;
    background: #f1f5f9;
    color: var(--text-sub);
}
.type-badge.type-image, .type-badge.type-voice, .type-badge.type-file { background: #e0f2fe; color: #0369a1; }
.type-badge.type-text { background: #dcfce7; color: #15803d; }

.pager {
    display: flex; align-items: center; justify-content: flex-end; gap: 10px;
    padding: 14px 16px;
}
.pager-info { font-size: 12px; color: var(--text-sub); }

/* ---------- 设置页 ---------- */
.status-card { display: flex; align-items: center; gap: 14px; padding: 18px 20px; }
.status-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.status-dot.on { background: var(--ok); box-shadow: 0 0 0 4px rgba(22, 163, 74, .15); }
.status-dot.off { background: #f59e0b; box-shadow: 0 0 0 4px rgba(245, 158, 11, .15); }
.status-title { font-weight: 700; }
.status-sub { font-size: 12px; color: var(--text-sub); margin-top: 3px; }

.kv-list { padding: 8px 20px 16px; }
.kv-item {
    display: flex; justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 13px;
}
.kv-item:last-child { border-bottom: none; }
.kv-key { color: var(--text-sub); }
.kv-value { font-weight: 600; }

/* ---------- Toast / Modal ---------- */
.toast {
    position: fixed;
    top: 72px; left: 50%;
    transform: translate(-50%, -16px);
    background: #0f172a;
    color: #fff;
    padding: 11px 20px;
    border-radius: 10px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s, transform .25s;
    z-index: 200;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

.modal-mask {
    position: fixed; inset: 0;
    background: rgba(9, 20, 40, .5);
    display: flex; align-items: center; justify-content: center;
    z-index: 150;
}
/* hidden 属性必须生效，否则遮罩会一直盖在页面上关不掉 */
.modal-mask[hidden] { display: none; }
.modal {
    width: 560px; max-width: 92vw; max-height: 80vh;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(9, 20, 40, .35);
    display: flex; flex-direction: column;
    overflow: hidden;
    animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 700; }
.modal-close {
    border: none; background: none;
    font-size: 22px; line-height: 1;
    color: var(--text-sub);
    cursor: pointer;
}
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 20px; overflow: auto; }
.modal-kv { display: flex; margin-bottom: 10px; font-size: 13px; }
.modal-kv b { flex: none; width: 64px; color: var(--text-sub); font-weight: 600; }
.modal-kv div { flex: 1; word-break: break-all; }

/* ---------- 移动端 ---------- */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .layout-main { margin-left: 0; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.collapsed .layout-main { margin-left: 0; }
}

/* ============================================================
   聊天式会话界面
   ============================================================ */
.page-chat { max-width: none; }

.chat-layout {
    display: flex;
    height: calc(100vh - 140px);
    min-height: 480px;
    margin-bottom: 0;
    overflow: hidden;
}

/* ---- 左：会话列表 ---- */
.chat-list-pane {
    width: 300px;
    flex: none;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: #fff;
}
.chat-list-search { padding: 12px; border-bottom: 1px solid var(--border); }
.chat-list-search .input { width: 100%; }

.conv-list { list-style: none; flex: 1; overflow-y: auto; }
.conv-item {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    transition: background .12s;
}
.conv-item:hover { background: #f5f9ff; }
.conv-item.active { background: var(--primary-light); border-left: 3px solid var(--primary); }
.conv-avatar {
    width: 42px; height: 42px; flex: none;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: #fff;
    font-weight: 700;
}
.conv-body { flex: 1; min-width: 0; }
.conv-line { display: flex; justify-content: space-between; align-items: baseline; }
.conv-name { font-size: 14px; }
.conv-time { font-size: 11px; color: var(--text-sub); flex: none; margin-left: 8px; }
.conv-last {
    font-size: 12px; color: var(--text-sub);
    margin-top: 3px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

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

.chat-head {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: #fff;
}
.chat-head-avatar {
    width: 40px; height: 40px; flex: none;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: #fff;
    font-weight: 700;
}
.chat-head-name { font-weight: 700; }
.chat-head-sub { font-size: 11px; color: var(--text-sub); margin-top: 2px; }

.chat-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 18px 22px;
    background: linear-gradient(180deg, #eaf1fb, #f5f8fd);
}

/* 时间分隔 */
.msg-divider {
    text-align: center;
    margin: 14px 0;
}
.msg-divider span {
    display: inline-block;
    font-size: 11px;
    color: #94a3b8;
    background: rgba(255, 255, 255, .75);
    padding: 2px 10px;
    border-radius: 999px;
}

/* 一条消息（左侧对方 / 右侧我方） */
.msg-row { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 14px; }
.msg-row.me { flex-direction: row-reverse; }
.msg-ava {
    width: 34px; height: 34px; flex: none;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px;
    font-size: 12px; font-weight: 700;
    color: #fff;
    background: #64748b;
}
.msg-row.me .msg-ava { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }

.msg-wrap { max-width: 66%; display: flex; flex-direction: column; }
.msg-row.me .msg-wrap { align-items: flex-end; }
.msg-sender { font-size: 11px; color: var(--text-sub); margin-bottom: 3px; }

.bubble {
    padding: 10px 14px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 40, 90, .08);
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    position: relative;
}
.bubble.me {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: #fff;
}
.msg-time-inline {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 4px;
}
.msg-row.me .msg-time-inline { text-align: right; color: rgba(255, 255, 255, .75); }

/* 图片/语音/文件类消息的占位样式 */
.bubble .bubble-media {
    display: inline-flex; align-items: center; gap: 6px;
    background: rgba(37, 99, 235, .08);
    color: var(--primary-dark);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 13px;
}
.bubble.me .bubble-media { background: rgba(255, 255, 255, .18); color: #fff; }

/* ---- 底部输入栏 ---- */
.chat-input-bar {
    display: flex; gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: #fff;
}
.chat-input-bar .input { flex: 1; }

/* 移动端：只显示一侧 */
@media (max-width: 768px) {
    .chat-layout { height: calc(100vh - 120px); }
    .chat-list-pane { width: 100%; border-right: none; }
    body.chat-show-pane .chat-pane { display: none; }
}
