/* =========================================================
   网帮管理后台 - 设计系统
   Light 主题 / 响应式 / 纯手写，无外部依赖
   ========================================================= */

:root {
    --bg:            #f4f6fb;
    --panel:         #ffffff;
    --panel-2:       #fafbfe;
    --border:        #e7eaf2;
    --border-strong: #d5dae6;
    --text:          #1f2937;
    --text-2:        #4b5563;
    --muted:         #8a93a5;
    --primary:       #4f46e5;
    --primary-600:   #4338ca;
    --primary-soft:  #eef1ff;
    --success:       #16a34a;
    --success-soft:  #e8f7ee;
    --warn:          #d97706;
    --warn-soft:     #fef3e2;
    --danger:        #dc2626;
    --danger-soft:   #fdecec;
    --info:          #0284c7;
    --info-soft:     #e6f4fd;
    --sidebar:       #ffffff;
    --shadow-sm:     0 1px 2px rgba(16, 24, 40, .05);
    --shadow:        0 4px 16px rgba(16, 24, 40, .06);
    --shadow-lg:     0 18px 44px rgba(16, 24, 40, .14);
    --radius:        14px;
    --radius-sm:     9px;
    --sidebar-w:     250px;
    --topbar-h:      62px;
    --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #cfd6e4; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #b6bfd2; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ 布局骨架 ============ */

.layout {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    transition: transform .26s cubic-bezier(.4, 0, .2, 1);
}

.sidebar-brand {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}

.brand-logo {
    width: 34px; height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff;
    display: grid; place-items: center;
    font-weight: 700; font-size: 16px;
    box-shadow: 0 4px 12px rgba(79, 70, 229, .35);
    flex: 0 0 auto;
}

.brand-text { overflow: hidden; }
.brand-text b { display: block; font-size: 14.5px; letter-spacing: .2px; white-space: nowrap; }
.brand-text span { display: block; font-size: 11px; color: var(--muted); white-space: nowrap; }

.sidebar-nav {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px 12px 24px;
}

.nav-group-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--muted);
    padding: 14px 12px 7px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9.5px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 13.8px;
    font-weight: 500;
    margin-bottom: 2px;
    transition: background .15s, color .15s;
    position: relative;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .82; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active {
    background: var(--primary-soft);
    color: var(--primary-600);
    font-weight: 600;
}
.nav-item.active svg { opacity: 1; }
.nav-item.active::before {
    content: "";
    position: absolute; left: -12px; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 18px;
    border-radius: 0 3px 3px 0;
    background: var(--primary);
}

.nav-count {
    margin-left: auto;
    font-size: 11px;
    background: #eef1f7;
    color: var(--muted);
    padding: 1px 7px;
    border-radius: 20px;
    font-weight: 600;
}

.main {
    flex: 1 1 auto;
    margin-left: var(--sidebar-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ============ 顶栏 ============ */

.topbar {
    height: var(--topbar-h);
    background: rgba(255, 255, 255, .88);
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 22px;
}

.burger {
    display: none;
    width: 38px; height: 38px;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 10px;
    cursor: pointer;
    align-items: center; justify-content: center;
    color: var(--text-2);
}
.burger:hover { background: var(--panel-2); }

.page-heading { min-width: 0; }
.page-heading h1 {
    font-size: 16.5px;
    margin: 0;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.page-heading .crumbs {
    font-size: 12px;
    color: var(--muted);
    margin-top: 1px;
}

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 数据库切换器 */
.db-switch {
    position: relative;
}
.db-switch-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.db-switch-btn:hover { border-color: var(--primary); }
.db-switch-btn .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 3px var(--success-soft);
    flex: 0 0 auto;
}
.db-switch-btn .db-name { font-weight: 600; white-space: nowrap; }
.db-switch-btn .caret { color: var(--muted); width: 14px; height: 14px; }

.db-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 250px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 7px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: all .16s ease;
    z-index: 70;
}
.db-menu.open { opacity: 1; visibility: visible; transform: translateY(0); }
.db-menu-title {
    font-size: 11px; color: var(--muted);
    padding: 7px 10px 5px; text-transform: uppercase; letter-spacing: .06em;
}
.db-option {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 9px;
    color: var(--text); font-size: 13px;
    transition: background .13s;
}
.db-option:hover { background: var(--panel-2); }
.db-option.current { background: var(--primary-soft); }
.db-option .ico {
    width: 30px; height: 30px; border-radius: 8px;
    display: grid; place-items: center; flex: 0 0 auto;
    background: #eef1f7; color: var(--text-2);
}
.db-option.current .ico { background: #fff; color: var(--primary); }
.db-option .meta { min-width: 0; }
.db-option .meta b { display: block; font-weight: 600; font-size: 13px; }
.db-option .meta span { display: block; font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.db-option .check { margin-left: auto; color: var(--primary); }

.user-chip {
    display: flex; align-items: center; gap: 9px;
    padding: 4px 10px 4px 4px;
    border-radius: 30px;
    border: 1px solid var(--border);
    background: #fff;
}
.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, #818cf8, #4f46e5);
    color: #fff; display: grid; place-items: center;
    font-size: 12.5px; font-weight: 700; flex: 0 0 auto;
}
.user-chip .u-name { font-size: 13px; font-weight: 600; }
.icon-btn {
    width: 38px; height: 38px;
    border: 1px solid var(--border);
    background: #fff; border-radius: 10px;
    display: grid; place-items: center;
    color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); border-color: #f6d4d4; }

/* ============ 内容区 ============ */

.content {
    padding: 22px;
    flex: 1 1 auto;
    max-width: 100%;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.page-head h2 {
    margin: 0; font-size: 20px; font-weight: 680; letter-spacing: -.2px;
}
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.page-head .actions { display: flex; gap: 9px; flex-wrap: wrap; }

/* 卡片 */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card + .card { margin-top: 18px; }
.card-head {
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 650; }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }

/* 统计卡 */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 17px 18px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: transform .18s, box-shadow .18s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card .st-top { display: flex; align-items: center; justify-content: space-between; }
.stat-card .st-label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat-card .st-ico {
    width: 38px; height: 38px; border-radius: 11px;
    display: grid; place-items: center; flex: 0 0 auto;
}
.stat-card .st-value { font-size: 27px; font-weight: 720; margin-top: 8px; letter-spacing: -.6px; line-height: 1.15; }
.stat-card .st-foot { font-size: 12px; color: var(--muted); margin-top: 5px; display: flex; align-items: center; gap: 6px; }
.trend-up { color: var(--success); font-weight: 600; }
.trend-down { color: var(--danger); font-weight: 600; }

.ico-indigo { background: var(--primary-soft); color: var(--primary); }
.ico-green  { background: var(--success-soft); color: var(--success); }
.ico-amber  { background: var(--warn-soft);    color: var(--warn); }
.ico-rose   { background: var(--danger-soft);  color: var(--danger); }
.ico-sky    { background: var(--info-soft);    color: var(--info); }

/* ============ 工具条（搜索/筛选）============ */

.toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--panel-2);
}
.field {
    display: flex; align-items: center; gap: 7px;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    padding: 0 11px;
    height: 38px;
    transition: border-color .15s, box-shadow .15s;
}
.field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field svg { width: 16px; height: 16px; color: var(--muted); flex: 0 0 auto; }
.field input, .field select {
    border: none; outline: none; background: transparent;
    font-family: inherit; font-size: 13.5px; color: var(--text);
    height: 100%; min-width: 0;
}
.field input::placeholder { color: #a9b1c2; }
.field.grow { flex: 1 1 220px; min-width: 180px; }
.field.grow input { width: 100%; }
.field.date { padding-right: 6px; }
.field.date input { width: 118px; font-size: 12.8px; }
.field .sep { color: var(--muted); font-size: 12px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: 38px; padding: 0 15px;
    border-radius: 10px;
    border: 1px solid var(--border-strong);
    background: #fff;
    color: var(--text);
    font-family: inherit; font-size: 13.5px; font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--panel-2); border-color: var(--border-strong); }
.btn-primary {
    background: var(--primary); border-color: var(--primary); color: #fff;
    box-shadow: 0 2px 8px rgba(79, 70, 229, .3);
}
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--panel-2); }
.btn-sm { height: 31px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn-danger { color: var(--danger); border-color: #f2cfcf; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); }

/* ============ 表格 ============ */

.table-scroll { overflow-x: auto; }
table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.3px;
    min-width: 720px;
}
table.data thead th {
    text-align: left;
    padding: 11px 16px;
    background: var(--panel-2);
    color: var(--muted);
    font-weight: 650;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .045em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky; top: 0;
}
table.data tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f3f8;
    color: var(--text-2);
    vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: #fafbff; }
table.data td.strong { color: var(--text); font-weight: 600; }
table.data td.nowrap, table.data th.nowrap { white-space: nowrap; }
table.data .mono { font-family: var(--mono); font-size: 12.3px; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }

.cell-main { color: var(--text); font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.ellipsis { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ 列表「用户」单元格：手机号/邮箱 + 用户名 ============ */
.user-col { max-width: 232px; }
.ucell { display: block; min-width: 0; max-width: 100%; line-height: 1.35; }
.ucell-main {
    display: block; color: var(--text); font-weight: 600; font-size: 12.9px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ucell-sub {
    display: block; color: var(--muted); font-size: 11.7px; margin-top: 1px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ucell-link {
    cursor: pointer; border-radius: 7px; margin: -4px -6px; padding: 4px 6px;
    transition: background .15s;
}
.ucell-link:hover { background: var(--primary-soft); }
.ucell-link:hover .ucell-main { color: var(--primary); }
.ucell-link:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ============ 详情「用户」字段 ============ */
.ud-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ud-contact { font-weight: 650; color: var(--text); }
.ud-name {
    font-size: 11.8px; font-weight: 600; color: var(--text-2);
    background: #eef1f7; padding: 1px 8px; border-radius: 99px;
}
.ud-id {
    margin-top: 5px; font-size: 11.5px; color: var(--muted);
    cursor: pointer; word-break: break-all; transition: color .15s;
}
.ud-id:hover { color: var(--primary); }
.ud-act { margin-top: 10px; }

/* 徽章 */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2.5px 9px;
    border-radius: 20px;
    font-size: 11.8px;
    font-weight: 650;
    white-space: nowrap;
    line-height: 1.5;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.no-dot::before { display: none; }
.badge-green  { background: var(--success-soft); color: #15803d; }
.badge-red    { background: var(--danger-soft);  color: #b91c1c; }
.badge-amber  { background: var(--warn-soft);    color: #b45309; }
.badge-blue   { background: var(--info-soft);    color: #0369a1; }
.badge-indigo { background: var(--primary-soft); color: var(--primary-600); }
.badge-gray   { background: #eef1f7;             color: #5b6474; }

/* 头像小圆 */
.mini-user { display: flex; align-items: center; gap: 9px; }
.mini-av {
    width: 30px; height: 30px; border-radius: 9px;
    background: linear-gradient(135deg, #a5b4fc, #6366f1);
    color: #fff; display: grid; place-items: center;
    font-size: 12px; font-weight: 700; flex: 0 0 auto;
}

/* 空状态 */
.empty {
    padding: 60px 20px;
    text-align: center;
    color: var(--muted);
}
.empty svg { width: 46px; height: 46px; opacity: .4; margin-bottom: 12px; }
.empty p { margin: 0; font-size: 13.5px; }

/* 分页 */
.pager {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; flex-wrap: wrap;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    background: var(--panel-2);
}
.pager .info { color: var(--muted); font-size: 12.8px; }
.pager .info b { color: var(--text); }
.pager .pages { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.pager a, .pager span.pg {
    min-width: 33px; height: 33px;
    padding: 0 9px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    background: #fff;
    color: var(--text-2);
    font-size: 13px; font-weight: 600;
}
.pager a:hover { border-color: var(--primary); color: var(--primary); }
.pager .current {
    background: var(--primary); border-color: var(--primary); color: #fff;
}
.pager .disabled { opacity: .45; pointer-events: none; }
.pager .gap { border: none; background: transparent; color: var(--muted); }

/* ============ 详情描述列表 ============ */

.desc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1px;
    background: var(--border);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.desc-item { background: #fff; padding: 13px 16px; }
.desc-item .dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.desc-item .dd { font-size: 13.8px; margin-top: 4px; color: var(--text); word-break: break-all; }
.desc-item.full { grid-column: 1 / -1; }
.desc-item pre {
    margin: 6px 0 0; padding: 11px;
    background: #f7f8fc; border: 1px solid var(--border);
    border-radius: 9px; font-family: var(--mono); font-size: 12.3px;
    white-space: pre-wrap; word-break: break-word;
    max-height: 320px; overflow: auto; color: var(--text-2);
}

/* ============ 对话流水（会话详情）============ */

.chat-tools {
    display: flex; align-items: center; gap: 8px;
    flex-wrap: wrap; margin-left: auto;
}
.chat-switch {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12.4px; color: var(--text-2); cursor: pointer;
    padding: 4px 11px; border: 1px solid var(--border);
    border-radius: 99px; background: #fff;
    user-select: none; -webkit-user-select: none;
}
.chat-switch input { accent-color: var(--primary); margin: 0; cursor: pointer; }

.chat-list { display: flex; flex-direction: column; gap: 18px; }

/* --- 对话气泡：assistant 靠左，user 靠右 --- */
.msg {
    display: flex; gap: 10px; align-items: flex-start;
    max-width: min(82%, 880px);
}
.msg-user { align-self: flex-end; flex-direction: row-reverse; }
.msg-assistant, .msg-mention { align-self: flex-start; }

.ava {
    width: 34px; height: 34px; flex: 0 0 auto; border-radius: 10px;
    display: grid; place-items: center;
    font-size: 11.5px; font-weight: 700; color: #fff; letter-spacing: .02em;
}
.ava-user { background: linear-gradient(135deg, #34d399, #10b981); }
.ava-assistant { background: linear-gradient(135deg, #818cf8, #4f46e5); }
.ava-mention { background: linear-gradient(135deg, #38bdf8, #0284c7); }

.msg-col { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.msg-user .msg-col { align-items: flex-end; }

.msg-head {
    display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
    font-size: 11.8px; color: var(--muted); padding: 0 3px;
}
.msg-head b { font-size: 12.5px; color: var(--text-2); font-weight: 650; }
.msg-head .sep { color: #cbd2e0; }

.bubble {
    max-width: 100%; overflow: hidden;
    background: #fff; border: 1px solid var(--border);
    border-radius: 14px; padding: 12px 15px;
}
.msg-user .bubble {
    background: var(--primary-soft);
    border-color: #dfe3ff;
    border-top-right-radius: 4px;
}
.msg-assistant .bubble { border-top-left-radius: 4px; }

.bubble-inner { min-width: 0; }
.bubble-inner.plain {
    white-space: pre-wrap; word-break: break-word;
    font-size: 13.6px; line-height: 1.75; color: var(--text);
}
.bubble-inner.clip { position: relative; max-height: 460px; overflow: hidden; }
.bubble-inner.clip::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 90px;
    background: linear-gradient(rgba(255, 255, 255, 0), #fff 78%);
    pointer-events: none;
}
.msg-user .bubble-inner.clip::after {
    background: linear-gradient(rgba(238, 241, 255, 0), var(--primary-soft) 78%);
}

.msg-more {
    display: inline-flex; align-items: center; gap: 4px;
    border: 1px solid var(--border); background: #fff; color: var(--primary);
    font-family: inherit; font-size: 12.3px; font-weight: 600;
    padding: 4px 13px; border-radius: 99px; cursor: pointer;
}
.msg-more:hover { background: var(--primary-soft); border-color: #dfe3ff; }
.msg-more svg { transition: transform .2s; pointer-events: none; }
.msg-more.open svg { transform: rotate(180deg); }

/* 附件卡片 */
.attach-list { display: flex; flex-wrap: wrap; gap: 8px; }
.attach-chip {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 6px 11px; border-radius: 9px;
    background: #fff; border: 1px solid var(--border);
    font-size: 12.5px; color: var(--text-2);
}
.attach-chip svg { color: var(--primary); flex: 0 0 auto; }
.attach-chip .a-id { color: var(--muted); font-size: 11.5px; }

/* --- 折叠行：system / tool_call / tool_result / editor --- */
.cmsg {
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--panel-2); overflow: hidden;
    max-width: min(96%, 1000px);
}
.cmsg-head {
    width: 100%; display: flex; align-items: center; gap: 9px;
    padding: 8px 12px; margin: 0; border: 0; background: transparent;
    font-family: inherit; text-align: left; cursor: pointer;
    font-size: 12.4px; color: var(--text-2);
}
.cmsg-head:hover { background: #f2f5fb; }
.cmsg-ico { display: inline-flex; color: var(--muted); flex: 0 0 auto; }
.cmsg-head svg { pointer-events: none; }
.cmsg-tag {
    flex: 0 0 auto; font-weight: 650; font-size: 12px;
    padding: 1px 9px; border-radius: 99px;
    background: #eef1f7; color: var(--text-2);
}
.cmsg-name {
    flex: 0 1 auto; max-width: 42%; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
    font-weight: 600; color: var(--text);
}
.cmsg-preview {
    flex: 1 1 auto; min-width: 0; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
    color: var(--muted); font-family: var(--mono); font-size: 11.8px;
}
.cmsg-meta {
    flex: 0 0 auto; color: var(--muted);
    font-size: 11.5px; font-family: var(--mono);
}
.cmsg-caret { flex: 0 0 auto; display: inline-flex; color: var(--muted); transition: transform .2s; }
.cmsg.open .cmsg-caret { transform: rotate(180deg); }
.cmsg-body { display: none; padding: 0 12px 12px; }
.cmsg.open .cmsg-body { display: block; }
.cmsg-time { font-size: 11.5px; color: var(--muted); margin-bottom: 7px; }
.cmsg-pre {
    margin: 0; padding: 11px 12px; background: #fff;
    border: 1px solid var(--border); border-radius: 9px;
    font-family: var(--mono); font-size: 12px; line-height: 1.66;
    white-space: pre-wrap; word-break: break-word;
    max-height: 520px; overflow: auto; color: var(--text-2);
}
.cmsg-system .cmsg-tag { background: var(--warn-soft); color: #b45309; }
.cmsg-tool_call .cmsg-tag { background: var(--info-soft); color: #0369a1; }
.cmsg-tool_result .cmsg-tag { background: var(--success-soft); color: #15803d; }
.cmsg-editor .cmsg-tag { background: var(--primary-soft); color: var(--primary-600); }

.chat-list .is-hide { display: none; }

.kv-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.kv {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11.8px; background: #fff;
    border: 1px solid var(--border); border-radius: 99px; padding: 3px 10px;
}
.kv i { font-style: normal; color: var(--muted); }
.kv b { color: var(--text-2); font-weight: 600; font-family: var(--mono); }

.cmsg details.extra { margin-top: 9px; }
.cmsg details.extra summary {
    cursor: pointer; font-size: 12.2px; color: var(--primary);
    font-weight: 600; list-style: none;
}
.cmsg details.extra summary::-webkit-details-marker { display: none; }
.cmsg details.extra pre {
    margin: 8px 0 0; padding: 11px; background: #fff;
    border: 1px solid var(--border); border-radius: 9px;
    font-family: var(--mono); font-size: 12px; white-space: pre-wrap;
    word-break: break-word; max-height: 320px; overflow: auto;
}

/* ============ Markdown 正文排版 ============ */

.md-body {
    font-size: 13.6px; line-height: 1.78; color: var(--text);
    word-break: break-word; overflow-wrap: anywhere;
}
.md-body > *:first-child { margin-top: 0; }
.md-body > *:last-child { margin-bottom: 0; }
.md-body p { margin: 0 0 10px; }
.md-body h1, .md-body h2, .md-body h3,
.md-body h4, .md-body h5, .md-body h6 {
    margin: 18px 0 9px; line-height: 1.42; font-weight: 650; color: #111827;
}
.md-body h1 { font-size: 19px; padding-bottom: 7px; border-bottom: 1px solid var(--border); }
.md-body h2 { font-size: 16.8px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.md-body h3 { font-size: 15.2px; }
.md-body h4 { font-size: 14.2px; }
.md-body h5, .md-body h6 { font-size: 13.6px; color: var(--text-2); }
.md-body strong { font-weight: 650; color: #111827; }
.md-body em { font-style: italic; }
.md-body del { color: var(--muted); }
.md-body a {
    color: var(--primary); word-break: break-all;
    border-bottom: 1px solid rgba(79, 70, 229, .28);
}
.md-body a:hover { border-bottom-color: var(--primary); }
.md-body a.md-img { display: inline-flex; align-items: center; }
.md-body hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.md-body ul, .md-body ol { margin: 0 0 10px; padding-left: 22px; }
.md-body li { margin: 3px 0; }
.md-body li > ul, .md-body li > ol { margin: 3px 0; }
.md-body blockquote {
    margin: 0 0 10px; padding: 8px 13px;
    border-left: 3px solid #c7cdf5; background: #f7f8fd;
    border-radius: 0 8px 8px 0; color: var(--text-2);
}
.md-body blockquote > *:last-child { margin-bottom: 0; }
.md-body .md-ic {
    font-family: var(--mono); font-size: 12.4px;
    background: #f0f2f8; border: 1px solid #e3e7f1;
    border-radius: 5px; padding: 1px 5px; color: #b03060;
    word-break: break-all;
}
.md-body .md-pre {
    margin: 0 0 12px; border: 1px solid var(--border);
    border-radius: 10px; overflow: hidden; background: #fbfcfe;
}
.md-body .md-pre-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 11px; background: #f4f6fb;
    border-bottom: 1px solid var(--border);
}
.md-body .md-lang { font-size: 11.3px; font-weight: 650; color: var(--text-2); letter-spacing: .02em; }
.md-body .md-copy {
    margin-left: auto; border: 1px solid var(--border); background: #fff;
    color: var(--text-2); font-family: inherit; font-size: 11.3px;
    padding: 2px 10px; border-radius: 6px; cursor: pointer;
}
.md-body .md-copy:hover { color: var(--primary); border-color: #d6dcf5; background: var(--primary-soft); }
.md-body .md-pre pre { margin: 0; padding: 12px 13px; overflow: auto; max-height: 460px; }
.md-body .md-pre code {
    display: block; font-family: var(--mono); font-size: 12.2px;
    line-height: 1.66; color: #1e293b; white-space: pre;
}
.md-body .md-table-wrap {
    overflow-x: auto; margin: 0 0 12px;
    border: 1px solid var(--border); border-radius: 10px;
}
.md-body .md-table { width: 100%; border-collapse: collapse; font-size: 12.8px; min-width: 420px; }
.md-body .md-table th, .md-body .md-table td {
    padding: 7px 11px; border-bottom: 1px solid var(--border);
    text-align: left; vertical-align: top;
}
.md-body .md-table th { background: #f6f8fc; font-weight: 650; color: var(--text-2); white-space: nowrap; }
.md-body .md-table tbody tr:last-child td { border-bottom: 0; }
.md-body .md-table tbody tr:hover { background: #fafbff; }
.md-body .md-td-empty { text-align: center; color: var(--muted); }

/* 抽屉内更紧凑 */
.chat-list-compact { gap: 12px; }
.chat-list-compact .msg,
.chat-list-compact .cmsg { max-width: 100%; }
.chat-list-compact .bubble { padding: 10px 13px; }
.chat-list-compact .bubble-inner { font-size: 12.9px; }

@media (max-width: 900px) {
    .msg, .cmsg { max-width: 100%; }
}
@media (max-width: 600px) {
    .chat-list { gap: 14px; }
    .msg { gap: 8px; }
    .ava { width: 28px; height: 28px; font-size: 10.5px; border-radius: 8px; }
    .bubble { padding: 10px 12px; border-radius: 12px; }
    .md-body { font-size: 13.2px; }
    .md-body h1 { font-size: 17px; }
    .md-body h2 { font-size: 15.5px; }
    .md-body .md-table { min-width: 340px; }
    .cmsg-preview { display: none; }
    .cmsg-name { max-width: 55%; }
    .chat-tools { margin-left: 0; width: 100%; }
}

/* ============ 趋势图（SVG 内联）============ */

.chart-wrap { padding: 6px 4px 0; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 18px; margin-top: 10px; flex-wrap: wrap; }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ============ 提示条 ============ */

.alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 15px; border-radius: 11px;
    font-size: 13.3px; margin-bottom: 16px;
    border: 1px solid transparent;
}
.alert svg { width: 17px; height: 17px; flex: 0 0 auto; margin-top: 1px; }
.alert-success { background: var(--success-soft); color: #15803d; border-color: #c7ebd5; }
.alert-error   { background: var(--danger-soft);  color: #b91c1c; border-color: #f5cfcf; }
.alert-warn    { background: var(--warn-soft);    color: #b45309; border-color: #f6e0bf; }
.alert-info    { background: var(--info-soft);    color: #0369a1; border-color: #c9e6f8; }

/* ============ 登录页 ============ */

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(900px 500px at 12% 8%, rgba(99, 102, 241, .18), transparent 60%),
        radial-gradient(800px 460px at 88% 92%, rgba(56, 189, 248, .16), transparent 60%),
        var(--bg);
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    padding: 34px 30px 28px;
    animation: rise .4s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.login-card .logo-lg {
    width: 52px; height: 52px; border-radius: 15px;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff; display: grid; place-items: center;
    font-size: 22px; font-weight: 750; margin: 0 auto 16px;
    box-shadow: 0 8px 20px rgba(79, 70, 229, .35);
}
.login-card h1 { text-align: center; font-size: 20px; margin: 0 0 4px; font-weight: 700; }
.login-card .tip { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.form-row { margin-bottom: 15px; }
.form-row label { display: block; font-size: 12.8px; font-weight: 650; color: var(--text-2); margin-bottom: 7px; }
.form-row .field { height: 44px; }
.form-row .field input { width: 100%; font-size: 14px; }
.login-card .btn-primary { width: 100%; height: 45px; font-size: 14.5px; margin-top: 6px; }
.login-foot { text-align: center; font-size: 11.8px; color: var(--muted); margin-top: 20px; }

/* ============ 遮罩 ============ */

.overlay {
    position: fixed; inset: 0;
    background: rgba(17, 24, 39, .42);
    backdrop-filter: blur(2px);
    z-index: 55;
    opacity: 0; visibility: hidden;
    transition: opacity .22s;
}
.overlay.show { opacity: 1; visibility: visible; }

/* ============ 错误页 ============ */

.error-page {
    min-height: 100vh; display: grid; place-items: center; padding: 24px;
    background: var(--bg);
}
.error-box {
    max-width: 560px; text-align: center;
    background: #fff; border: 1px solid var(--border);
    border-radius: 18px; padding: 44px 36px;
    box-shadow: var(--shadow);
}
.error-box .code { font-size: 54px; font-weight: 800; color: var(--primary); letter-spacing: -2px; }
.error-box h1 { font-size: 19px; margin: 8px 0 10px; }
.error-box p { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; word-break: break-word; }

/* ============ 通用工具类 ============ */

.muted { color: var(--muted); }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.ml-auto { margin-left: auto; }
.mt-0 { margin-top: 0; }
.mb-16 { margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }

/* ============ 响应式 ============ */

@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .burger { display: inline-flex; }
}

@media (max-width: 720px) {
    :root { --topbar-h: 58px; }
    .content { padding: 15px; }
    .topbar { padding: 0 12px; gap: 8px; }
    /* 移动端由页面标题承担，顶栏标题隐藏以腾出空间 */
    .page-heading { display: none; }
    .topbar-right { width: 100%; gap: 8px; }
    .user-chip .u-name { display: none; }
    .user-chip { padding: 4px; }
    .db-switch-btn .db-name { max-width: 96px; overflow: hidden; text-overflow: ellipsis; display: inline-block; }
    .db-menu { right: 0; left: auto; min-width: min(280px, calc(100vw - 24px)); }
    .page-head h2 { font-size: 17.5px; }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
    .stat-card .st-value { font-size: 22px; }
    .card-body { padding: 14px; }
    .toolbar { padding: 12px 14px; }
    .field.grow { flex: 1 1 100%; }
    .desc-grid { grid-template-columns: 1fr; }
    /* 移动端表格横向滚动 */
    table.data { min-width: 640px; }
}

@media (max-width: 480px) {
    .toolbar .btn span.lbl { display: none; }
    .pager { justify-content: center; }
    .db-switch-btn .db-name { max-width: 68px; }
    .user-chip { display: none; }
}

/* 打印 */
@media print {
    .sidebar, .topbar, .toolbar, .pager, .actions { display: none !important; }
    .main { margin-left: 0; }
    .card { box-shadow: none; border-color: #ccc; }
}
