:root {
    --sidebar-bg: #0f172a;
    --sidebar-fg: #cbd5e1;
    --sidebar-fg-active: #ffffff;
    --sidebar-active: rgba(99, 102, 241, .25);
    --brand: #6366f1;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    background: #f5f7fb;
    color: #0f172a;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
    font-size: 14px;
}

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

.sidebar {
    width: 230px;
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    flex-shrink: 0;
    padding: 16px 0;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand {
    padding: 8px 20px 20px;
    font-size: 17px; font-weight: 600;
    color: #fff; display: flex; align-items: center; gap: 8px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand i { color: var(--brand); }
.sidebar .nav-link {
    color: var(--sidebar-fg); padding: 9px 20px; border-radius: 0;
    font-size: 13.5px; display: flex; align-items: center; gap: 10px;
    border-left: 3px solid transparent;
}
.sidebar .nav-link:hover { color: #fff; background: rgba(255,255,255,.04); }
.sidebar .nav-link.active { color: var(--sidebar-fg-active); background: var(--sidebar-active); border-left-color: var(--brand); }
.sidebar .nav-section {
    padding: 14px 20px 6px;
    font-size: 11px; color: #64748b; letter-spacing: 1px; text-transform: uppercase;
}

.content { flex: 1; min-width: 0; }
.topbar {
    background: #fff; border-bottom: 1px solid #e2e8f0;
    padding: 8px 20px; display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.btn-sidebar { border: none; background: transparent; font-size: 22px; padding: 4px 8px; }
.account-switcher .dropdown-toggle { font-size: 13.5px; }
.account-switcher .dropdown-toggle i { color: var(--brand); margin-right: 4px; }
.account-switcher .dropdown-menu { min-width: 240px; }
.account-switcher .dropdown-item.active { background: #eef2ff; color: #4338ca; font-weight: 600; }
.account-switcher .dropdown-item i { width: 18px; }

.page { padding: 20px; max-width: 1400px; }
.page-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 18px;
}
.page-header h2 { margin: 0; font-size: 22px; font-weight: 600; }

.card { border: 1px solid #e5e7eb; box-shadow: 0 1px 2px rgba(0,0,0,.02); }
.card-header { background: #fafbfc; font-weight: 600; }

.stat-card {
    background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
    padding: 16px 18px;
}
.stat-label { color: #64748b; font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; }

/* ====== 仪表盘 v2 ====== */
body { background: linear-gradient(180deg, #fafbff 0%, #f5f7fb 320px) fixed; }

.page-header h2 { letter-spacing: -.4px; }

/* 顶部摘要横幅 */
.dash-banner {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: #fff;
    border-radius: 16px;
    padding: 20px 24px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    box-shadow: 0 20px 40px -20px rgba(99,102,241,.4);
    position: relative;
    overflow: hidden;
}
.dash-banner::before {
    content: '';
    position: absolute;
    right: -40px; top: -40px;
    width: 200px; height: 200px;
    border-radius: 50%;
    background: rgba(255,255,255,.08);
}
.dash-banner::after {
    content: '';
    position: absolute;
    right: 60px; bottom: -80px;
    width: 160px; height: 160px;
    border-radius: 50%;
    background: rgba(255,255,255,.05);
}
.dash-banner h3 { font-size: 20px; font-weight: 600; margin: 0 0 4px; position: relative; }
.dash-banner p { font-size: 13.5px; opacity: .9; margin: 0; position: relative; }
.dash-banner .banner-stats { display: flex; gap: 28px; position: relative; }
.dash-banner .banner-stat { text-align: right; }
.dash-banner .banner-stat .num { font-size: 28px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.dash-banner .banner-stat .lbl { font-size: 11.5px; opacity: .85; margin-top: 2px; }

/* KPI 卡片 */
.dashboard-kpis .kpi {
    position: relative;
    background: #fff;
    border: none;
    border-radius: 14px;
    padding: 20px 22px;
    overflow: hidden;
    transition: transform .2s cubic-bezier(.4,0,.2,1), box-shadow .2s;
    box-shadow: 0 1px 2px rgba(15,23,42,.04), 0 4px 12px rgba(15,23,42,.03);
}
.dashboard-kpis .kpi:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(15,23,42,.08), 0 4px 8px rgba(15,23,42,.04);
}
.dashboard-kpis .kpi::before {
    content: ''; position: absolute; inset: 0;
    border-radius: 14px;
    background: linear-gradient(180deg, var(--kpi-tint, transparent) 0%, transparent 60%);
    opacity: .5;
    pointer-events: none;
}
.dashboard-kpis .kpi-primary { --kpi-tint: rgba(99,102,241,.10); }
.dashboard-kpis .kpi-success { --kpi-tint: rgba(16,185,129,.10); }
.dashboard-kpis .kpi-warning { --kpi-tint: rgba(245,158,11,.10); }
.dashboard-kpis .kpi-info    { --kpi-tint: rgba(6,182,212,.10); }

.dashboard-kpis .kpi-icon {
    position: absolute; right: -10px; top: -10px;
    width: 80px; height: 80px;
    border-radius: 16px;
    display: flex; align-items: flex-end; justify-content: flex-start;
    padding: 12px;
    font-size: 32px; color: #fff;
    opacity: .18;
    transform: rotate(-8deg);
    transition: transform .25s, opacity .25s;
}
.dashboard-kpis .kpi:hover .kpi-icon { opacity: .28; transform: rotate(-8deg) scale(1.08); }
.dashboard-kpis .kpi-primary .kpi-icon { background: linear-gradient(135deg, #6366f1, #4f46e5); color: #6366f1; }
.dashboard-kpis .kpi-success .kpi-icon { background: linear-gradient(135deg, #10b981, #059669); color: #10b981; }
.dashboard-kpis .kpi-warning .kpi-icon { background: linear-gradient(135deg, #f59e0b, #d97706); color: #f59e0b; }
.dashboard-kpis .kpi-info    .kpi-icon { background: linear-gradient(135deg, #06b6d4, #0891b2); color: #06b6d4; }
.dashboard-kpis .kpi-icon i { color: #fff; }

.dashboard-kpis .kpi-label {
    position: relative;
    font-size: 12.5px;
    color: #64748b;
    font-weight: 500;
    letter-spacing: .2px;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.dashboard-kpis .kpi-value {
    position: relative;
    font-size: 32px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1;
    letter-spacing: -.8px;
    font-variant-numeric: tabular-nums;
    margin: 0 0 8px;
}
.dashboard-kpis .kpi-foot {
    position: relative;
    font-size: 12px;
    color: #94a3b8;
    line-height: 1.4;
}

.trend {
    display: inline-flex; align-items: center; gap: 2px;
    padding: 2px 9px; border-radius: 999px;
    font-size: 11px; font-weight: 600;
    letter-spacing: .2px;
}
.trend-up   { background: #d1fae5; color: #047857; }
.trend-down { background: #fee2e2; color: #b91c1c; }
.trend-flat { background: #f1f5f9; color: #64748b; }

/* 卡片 */
.dashboard-card {
    border: none;
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba(15,23,42,.03), 0 4px 12px rgba(15,23,42,.04);
    overflow: hidden;
    transition: box-shadow .2s;
}
.dashboard-card:hover { box-shadow: 0 4px 16px rgba(15,23,42,.05), 0 12px 32px rgba(15,23,42,.05); }
.dashboard-card .card-header {
    background: #fff;
    border-bottom: none;
    padding: 18px 22px 12px;
    font-size: 14.5px;
    font-weight: 600;
    color: #0f172a;
    letter-spacing: -.1px;
}
.dashboard-card .card-header i {
    color: var(--brand);
    margin-right: 8px;
    font-size: 15px;
}
.dashboard-card .card-body { padding: 8px 22px 22px; }

/* 排行表格 */
.ranking-table { border: none; }
.ranking-table td { padding: 14px 22px; vertical-align: middle; border: none; }
.ranking-table tr { transition: background .15s; }
.ranking-table tr:hover { background: #fafbfc; }
.ranking-table .progress {
    height: 6px;
    background: #f1f5f9;
    border-radius: 999px;
    overflow: hidden;
}
.ranking-table .progress-bar {
    border-radius: 999px;
    transition: width .6s cubic-bezier(.4,0,.2,1);
}
.dot {
    display: inline-block;
    width: 9px; height: 9px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
    box-shadow: 0 0 0 3px rgba(0,0,0,0);
}

/* 最近消息表 */
.dashboard-card table.table-hover tbody tr { transition: background .15s; }
.dashboard-card table.table-hover tbody tr:hover { background: #fafbfc; }
.dashboard-card table.table-hover td { padding: 12px 22px; border-color: #f1f5f9; }
.dashboard-card table.table-hover th { padding: 12px 22px; border-color: #f1f5f9; font-weight: 600; color: #64748b; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; background: #fafbfc; }

/* KPI 内迷你折线 */
.kpi-spark {
    margin-top: 10px;
    margin-left: -22px;
    margin-right: -22px;
    margin-bottom: -20px;
    height: 40px;
    opacity: .9;
}
.kpi-spark canvas { display: block; width: 100%; height: 40px; }

.dashboard-kpis .kpi {
    padding-bottom: 0;
    min-height: 138px;
}
.dashboard-kpis .kpi-foot {
    margin-bottom: 8px;
}

/* 排名徽章 */
.rank-badge {
    display: inline-flex; align-items: center; justify-content: center;
    width: 24px; height: 24px;
    border-radius: 6px;
    background: #f1f5f9;
    color: #64748b;
    font-weight: 700;
    font-size: 11.5px;
}
.ranking-table tr:nth-child(1) .rank-badge { background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #fff; }
.ranking-table tr:nth-child(2) .rank-badge { background: linear-gradient(135deg, #d1d5db, #9ca3af); color: #fff; }
.ranking-table tr:nth-child(3) .rank-badge { background: linear-gradient(135deg, #fb923c, #ea580c); color: #fff; }

/* 渠道分布卡片图例 */
.scene-legend > div {
    font-size: 12.5px;
    padding: 4px 0;
}

/* Banner 二级布局 */
.dash-banner .banner-left h3 { letter-spacing: -.3px; }
.dash-banner .banner-stats { gap: 32px; }
@media (max-width: 768px) {
    .dash-banner { flex-direction: column; align-items: flex-start; }
    .dash-banner .banner-stats { gap: 20px; width: 100%; justify-content: space-between; }
    .dash-banner .banner-stat { text-align: left; }
}

.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.avatar-xl { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; }
.avatar-placeholder { display: inline-block; width: 36px; height: 36px; background: #e5e7eb; border-radius: 50%; }

.msg-bubble {
    margin: 8px 0; padding: 8px 12px; border-radius: 10px;
    max-width: 75%;
}
.msg-bubble.msg-in { background: #eef2ff; }
.msg-bubble.msg-out { background: #ecfdf5; margin-left: auto; }
.msg-meta { font-size: 11px; color: #64748b; margin-bottom: 4px; }

.material-thumb { height: 140px; object-fit: cover; background: #f1f5f9; }
.material-placeholder { display: flex; align-items: center; justify-content: center; font-size: 36px; color: #94a3b8; }

/* Menu builder */
.mb-row { background: #f8fafc; border: 1px dashed #cbd5e1; padding: 10px; border-radius: 6px; margin-bottom: 10px; }
.mb-btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.mb-btn {
    padding: 6px 12px; background: #fff; border: 1px solid #cbd5e1; border-radius: 4px; cursor: pointer;
    display: inline-flex; gap: 4px; align-items: center;
}
.mb-btn.active { border-color: var(--brand); background: #eef2ff; color: var(--brand); }
.mb-sub-row { padding-left: 12px; margin-top: 8px; border-left: 2px dashed #cbd5e1; }
.mb-add { background: transparent; border: 1px dashed #94a3b8; color: #64748b; }

.menu-preview {
    display: flex; border: 1px solid #e5e7eb; border-radius: 6px; overflow: hidden;
    background: #f8fafc;
}
.menu-preview .mp-item {
    flex: 1; padding: 10px 6px; text-align: center; font-size: 13px;
    border-right: 1px solid #e5e7eb; position: relative;
}
.menu-preview .mp-item:last-child { border-right: none; }

/* Login */
.login-body { background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%); min-height: 100vh; display: flex; align-items: center; }
.login-wrap { width: 100%; }
.login-card { max-width: 400px; margin: 0 auto; background: #fff; padding: 36px 32px; border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.login-brand { text-align: center; margin-bottom: 24px; }
.login-logo { font-size: 38px; color: var(--brand); }

@media (max-width: 767px) {
    .sidebar { position: fixed; transform: translateX(-100%); transition: .25s; z-index: 200; }
    body.sidebar-open .sidebar { transform: translateX(0); }
}

/* ====== UI 弹窗系统 ====== */
.ui-toast {
    color: #fff;
    min-width: 280px;
    max-width: 420px;
    box-shadow: 0 10px 30px rgba(15,23,42,.18);
    border-radius: 10px;
    overflow: hidden;
    backdrop-filter: blur(8px);
}
.ui-toast .toast-body {
    padding: 12px 12px 12px 0;
    font-size: 14px;
    line-height: 1.45;
    word-break: break-word;
}
.ui-toast-icon {
    padding: 0 12px;
    font-size: 22px;
    display: flex;
    align-items: center;
}
.ui-toast .btn-close {
    filter: invert(1) brightness(2);
    opacity: .8;
}
.ui-toast-success { background: linear-gradient(135deg, #10b981, #059669); }
.ui-toast-danger  { background: linear-gradient(135deg, #ef4444, #dc2626); }
.ui-toast-warning { background: linear-gradient(135deg, #f59e0b, #d97706); }
.ui-toast-info    { background: linear-gradient(135deg, #6366f1, #4f46e5); }

.ui-modal .modal-content {
    border: none;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(15,23,42,.25);
}
.ui-modal .modal-header {
    border-bottom: 1px solid #f1f5f9;
    padding: 16px 20px;
}
.ui-modal .modal-title { font-size: 16px; font-weight: 600; }
.ui-modal .modal-body { padding: 20px; line-height: 1.6; color: #334155; }
.ui-modal .modal-footer { border-top: 1px solid #f1f5f9; padding: 12px 20px; }

/* ====== 多消息回复编辑器 ====== */
.mp-card {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    margin: 0;
}
.mp-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    border-radius: 10px 10px 0 0;
}
.mp-badge {
    font-size: 12px;
    color: #475569;
    font-weight: 600;
    background: #e0e7ff;
    color: #4338ca;
    padding: 3px 10px;
    border-radius: 999px;
}
.mp-card:first-child .mp-badge {
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff;
}
.mp-actions .btn { padding: 2px 8px; }
.mp-card-body { padding: 14px; }

.mp-delay {
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 10px;
    min-height: 48px;
}
.mp-delay-line {
    flex: 1;
    border-top: 1px dashed #cbd5e1;
}
.mp-delay-input {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #fef3c7;
    color: #92400e;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 13px;
    white-space: nowrap;
}
.mp-delay-input input { font-size: 13px; padding: 2px 6px; }

.mp-add-wrap {
    text-align: center;
    padding: 14px 0;
}
.mp-add-wrap .btn {
    border-style: dashed;
}
