/* =============================================================================
   后台页面样式（窗口 5 自研，不依赖任何 CDN / 旧系统 CSS）
   -----------------------------------------------------------------------------
   设计口径：
   - 只用 CSS 变量管色板与圆角，改主题只改 :root；
   - 布局用 flex + grid，不用 float；移动端 960px 断点把侧边栏收成抽屉；
   - 表格横向滚动**只发生在 .table-wrap 内部**，页面本身在 375px 不许横向滚动；
   - 所有图标用 CSS 形状/文字，不引图标字体（断网也要能看）。
   ========================================================================== */

:root {
    --brand: #2B3A8F;
    --brand-2: #3D4FBD;
    --accent: #F26A21;
    --bg: #F4F6FB;
    --surface: #FFFFFF;
    --line: #E5E8F0;
    --line-strong: #D2D7E4;
    --text: #1F2937;
    --muted: #6B7280;
    --muted-2: #9AA1AF;
    --ok: #12B76A;
    --ok-bg: #E8F8F0;
    --warn: #B54708;
    --warn-bg: #FEF6E7;
    --danger: #D92D20;
    --danger-bg: #FDECEA;
    --info-bg: #EEF1FD;
    --radius: 10px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
    --sidebar-w: 232px;
    --topbar-h: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-2); text-decoration: none; }
a:hover { color: var(--accent); }

/* ---------------------------------------------------------------- 布局 */
.app { display: flex; min-height: 100vh; }

/* ============================ 侧边栏（参考图：白底 / 60px 行高 / 选中态 / 可折叠） ============================ */
.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: #fff;
    color: #374151;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    border-right: 1px solid #edf0f5;
    transition: width .18s ease;
}

/* 品牌区：60px 高，logo 32px，名字超长省略 */
.sidebar .brand {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;   /* 只有 logo 没有文字，居中比靠左稳 */
    gap: 10px;
    padding: 0 18px;
    flex: 0 0 auto;
    overflow: hidden;
}
/* 横版 logo（711×245）：按高度定，宽度自适应；塞进 32×32 方框会缩成一条缝。
   品牌区现在只有 logo（没有文字），所以高度放到 30px，视觉上填满 60px 的条 */
.sidebar .brand img { height: 30px; width: auto; flex: 0 0 auto; }

.nav { padding: 6px 10px 24px; overflow-y: auto; overflow-x: hidden; flex: 1 1 auto; }
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: #dce1ea; border-radius: 3px; }
.nav::-webkit-scrollbar-thumb:hover { background: #c8cfdb; }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav-group { margin-bottom: 2px; }

/* 一级菜单：60px 高，图标 20px，右侧 chevron */
.nav-group-head {
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px;
    border: 0;
    border-radius: 10px;
    background: none;
    color: #374151;
    font: inherit;
    font-size: 14.5px;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    text-align: left;
    transition: background .15s, color .15s;
}
.nav-group-head:hover { background: #f5f7fb; }
.nav-group-head .ico { width: 20px; height: 20px; flex: 0 0 auto; color: #6b7280; }
.nav-group-head .txt { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-group-head .chev {
    width: 16px; height: 16px; flex: 0 0 auto; color: #b6bcc8;
    transition: transform .18s ease;
}
.nav-group.open > .nav-group-head .chev { transform: rotate(180deg); }

/* 一级菜单选中：浅蓝底 + 左侧蓝条 + 蓝字（参考图的 60px 选中块） */
.nav-group.current > .nav-group-head {
    background: #eef4ff;
    color: #2f6bff;
    font-weight: 600;
}
.nav-group.current > .nav-group-head .ico { color: #2f6bff; }
.nav-group.current > .nav-group-head::before {
    content: "";
    position: absolute;
    left: 0; top: 14px; bottom: 14px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: #2f6bff;
}

/* 子菜单：50px 行高，缩进对齐文字（12 padding + 20 icon + 12 gap = 44） */
/* 「工作台」固定入口：和一级菜单同高同款，选中态同「当前分组」 */
.nav-home {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 60px;
    padding: 0 12px;
    margin-bottom: 2px;
    border-radius: 10px;
    color: #374151;
    font-size: 14.5px;
    font-weight: 500;
    position: relative;
    transition: background .15s, color .15s;
}
.nav-home:hover { background: #f5f7fb; }
.nav-home .ico { width: 20px; height: 20px; flex: 0 0 auto; color: #6b7280; }
.nav-home.active { background: #eef4ff; color: #2f6bff; font-weight: 600; }
.nav-home.active .ico { color: #2f6bff; }
.nav-home.active::before {
    content: "";
    position: absolute;
    left: 0; top: 14px; bottom: 14px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: #2f6bff;
}
body.sb-collapsed .nav-home { justify-content: center; padding: 0; gap: 0; }
body.sb-collapsed .nav-home .txt { display: none; }

.nav-sub { display: none; padding: 2px 0 6px; }
.nav-group.open > .nav-sub { display: block; }
.nav-sub a {
    display: flex;
    align-items: center;
    height: 50px;
    padding: 0 12px 0 44px;
    border-radius: 10px;
    color: #4b5563;
    font-size: 13.5px;
    position: relative;
    transition: background .15s, color .15s;
}
.nav-sub a:hover { background: #f5f7fb; color: #111827; }
.nav-sub a.active {
    background: #eef4ff;
    color: #2f6bff;
    font-weight: 600;
}

/* ---------------- 折叠态：80px 图标栏 + 悬停飞出子菜单 ---------------- */
body.sb-collapsed .sidebar { width: 80px; flex-basis: 80px; }
body.sb-collapsed .main { margin-left: 80px; }
body.sb-collapsed .sidebar .brand { padding: 0; justify-content: center; }
/* 折叠后品牌区只剩 80px：横版 logo（711×245）按**高度**收。
   按宽度定 52px 时高度只有 18px，看起来像一条模糊的色块（实测）。 */
body.sb-collapsed .sidebar .brand img { height: 22px; width: auto; max-width: 64px; }
body.sb-collapsed .nav { padding: 6px 10px; overflow: visible; }
body.sb-collapsed .nav-group-head { justify-content: center; padding: 0; gap: 0; }
body.sb-collapsed .nav-group-head .txt,
body.sb-collapsed .nav-group-head .chev { display: none; }
/* ⚠️ 必须比 `.nav-group.open > .nav-sub`（特异性 0,3,0）更高：
   折叠时如果只是 `display:none`，会被"已展开分组"的规则盖掉，
   子菜单就挤在 80px 的图标栏里，竖排成一条字（实测截图就是这样）。 */
body.sb-collapsed .nav-group > .nav-sub { display: none; }

/* 折叠态：白卡从图标右侧飞出。
   🔴 两个都必须有，否则"鼠标往卡片上挪，卡片就消失"（实测）：
     ① 只由 `.show-sub` 控制显隐（JS 在 mouseenter 加上、mouseleave 后延迟 220ms 移除），
        不再用 `:hover` —— 两套机制并存时，鼠标离开的过渡期里会出现"同一份菜单两张"的观感；
     ② `.nav-sub::before` 是一条透明桥（宽 20px），把命中区域往左延伸到图标上，
        鼠标横移时不会掉进缝里。 */
body.sb-collapsed .nav-group { position: relative; }
body.sb-collapsed .nav-group.show-sub > .nav-sub {
    display: block;
    position: absolute;
    left: 84px;
    top: 0;
    width: 184px;
    padding: 8px;
    background: #fff;
    border: 1px solid #edf0f5;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(16, 24, 40, .12);
    z-index: 40;
}
body.sb-collapsed .nav-group.show-sub > .nav-sub::after {
    content: "";
    position: absolute;
    left: -22px;
    top: 0;
    bottom: 0;
    width: 22px;
    background: transparent;
}
/* 折叠态飞出卡片顶部补一个分组标题，否则只有一堆子项、不知道属于哪个模块 */
body.sb-collapsed .nav-group.show-sub > .nav-sub::before {
    content: attr(data-title);
    display: block;
    padding: 4px 10px 8px;
    font-size: 12px;
    font-weight: 600;
    color: #8a94a6;
    letter-spacing: .3px;
}
body.sb-collapsed .nav-group.show-sub > .nav-sub a {
    height: 40px;
    padding: 0 10px;
    font-size: 13px;
}

.main {
    flex: 1 1 auto;
    min-width: 0;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar .hamburger { display: none; }
.topbar .crumb { color: var(--muted); font-size: 13px; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.topbar .who b { color: var(--text); font-weight: 600; }

.content { padding: 20px; max-width: 1440px; width: 100%; }

/* ---------------------------------------------------------------- 通用块 */
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 19px; font-weight: 650; letter-spacing: .2px; }
.page-head .desc { color: var(--muted); font-size: 13px; flex: 1 1 240px; min-width: 0; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-title .sub { font-weight: 400; color: var(--muted); font-size: 12.5px; }

/* 统计卡（工作台） */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
    min-width: 0;
}
.stat .k { color: var(--muted); font-size: 12.5px; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.5px; margin-top: 4px; }
.stat .v small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; }

/* 工具条 */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1 1 auto; }

/* ---------------------------------------------------------------- 表单控件 */
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=search], select, textarea {
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    outline: none;
    min-width: 0;
}
textarea { height: auto; min-height: 72px; padding: 8px 10px; line-height: 1.6; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(61, 79, 189, .12); }
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input[disabled], select[disabled], textarea[disabled] { background: #F7F8FB; color: var(--muted); cursor: not-allowed; }
select { padding-right: 26px; appearance: none; background-image: linear-gradient(45deg, transparent 50%, #8A90A2 50%), linear-gradient(135deg, #8A90A2 50%, transparent 50%); background-position: calc(100% - 14px) 14px, calc(100% - 10px) 14px; background-size: 4px 4px, 4px 4px; background-repeat: no-repeat; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12.5px; color: var(--muted); }
.field > label .req { color: var(--danger); margin-left: 2px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }

/* 按钮 */
.btn {
    height: 34px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.btn:hover { border-color: var(--brand-2); color: var(--brand-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.danger { color: var(--danger); border-color: #F3C4BF; }
.btn.danger:hover { background: var(--danger-bg); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.link { border: none; background: none; color: var(--brand-2); padding: 0 6px; height: 26px; }
.btn.link:hover { color: var(--accent); }
.btn.link.danger { color: var(--danger); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-group { display: inline-flex; gap: 4px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- 表格 */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    -webkit-overflow-scrolling: touch;
}
table.tb { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
table.tb th, table.tb td { padding: 10px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
table.tb th { background: #FAFBFE; color: var(--muted); font-weight: 600; font-size: 12.5px; white-space: nowrap; }
table.tb tbody tr:hover { background: #FAFBFF; }
table.tb tbody tr:last-child td { border-bottom: none; }
table.tb td.actions { white-space: nowrap; }
table.tb td.num, table.tb th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tb .empty-row td { text-align: center; color: var(--muted); padding: 36px 12px; }

/* 徽标 */
.badge { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: 12px; line-height: 20px; background: var(--info-bg); color: var(--brand-2); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: #067647; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.mute { background: #F2F4F7; color: var(--muted); }

/* 分页 */
.pager { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 12px; font-size: 13px; color: var(--muted); }
.pager .total { margin-right: auto; }
.pager .pages { display: flex; gap: 4px; align-items: center; }
.pager button {
    min-width: 30px; height: 30px; padding: 0 8px;
    border: 1px solid var(--line-strong); background: #fff; border-radius: 7px;
    color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
}
.pager button.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager button[disabled] { opacity: .45; cursor: not-allowed; }
.pager select { height: 30px; }

/* 空态 / 加载 */
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.empty .big { font-size: 15px; color: var(--text); margin-bottom: 6px; }
.loading { text-align: center; color: var(--muted); padding: 24px 12px; }

/* 表单弹层 */
.modal-mask {
    position: fixed; inset: 0; background: rgba(17, 24, 39, .45);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 48px 16px; z-index: 60; overflow-y: auto;
}
.modal {
    background: #fff; border-radius: 12px; box-shadow: 0 24px 64px rgba(16, 24, 40, .24);
    width: 100%; max-width: 560px; overflow: hidden;
}
.modal.wide { max-width: 760px; }
.modal .m-head { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal .m-head h3 { font-size: 15px; font-weight: 600; flex: 1 1 auto; }
.modal .m-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.modal .m-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #FCFCFE; }
.modal .m-close { border: none; background: none; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.modal .m-close:hover { color: var(--text); }

/* 提示条 */
.toast-wrap { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: #1F2937; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, .2); max-width: 520px;
}
.toast.ok { background: #067647; }
.toast.err { background: #B42318; }

/* 标签页 */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button {
    border: none; background: none; padding: 8px 14px; font: inherit; font-size: 13.5px;
    color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* 开关（状态列） */
.switch { position: relative; display: inline-block; width: 38px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: #D2D7E4; border-radius: 999px; transition: .18s; cursor: pointer; }
.switch i::after { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .18s; }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(18px); }

/* 提示框（表单校验/说明） */
.hint { font-size: 12.5px; color: var(--muted); }
.hint.danger { color: var(--danger); }

/* 品牌页预览 */
.logo-preview { width: 64px; height: 64px; border: 1px dashed var(--line-strong); border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #FAFBFE; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* 侧边栏遮罩（移动端） */
.nav-mask { display: none; position: fixed; inset: 0; background: rgba(17, 24, 39, .4); z-index: 25; }

/* ---------------------------------------------------------------- 响应式 */
@media (max-width: 1100px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
    /* 手机上是抽屉，折叠态（80px 图标栏）不适用，两条都要压回去 */
    body.sb-collapsed .sidebar { width: var(--sidebar-w); flex-basis: var(--sidebar-w); }
    body.sb-collapsed .main { margin-left: 0; }
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
    body.nav-open .sidebar { transform: translateX(0); }
    body.nav-open .nav-mask { display: block; }
    .main { margin-left: 0; }
    .topbar .hamburger { display: inline-flex; }
    .topbar .sb-toggle { display: none; }
    .content { padding: 14px; }
    .grid-2 { grid-template-columns: minmax(0, 1fr); }
    .modal-mask { padding: 16px 10px; align-items: flex-start; }
}

@media (max-width: 560px) {
    .stats { grid-template-columns: minmax(0, 1fr); }
    .page-head h1 { font-size: 17px; }
    .stat .v { font-size: 22px; }
    .btn { padding: 0 11px; }
    table.tb th, table.tb td { padding: 8px 10px; }
}

/* ---------------------------------------------------------------- 侧边栏折叠按钮 */
/* 桌面常显、只放图标；手机在 @media 里已被隐藏（手机用「菜单」抽屉） */
.topbar .sb-toggle { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 30px; padding: 0; }
.topbar .sb-toggle svg { display: block; }

/* ---------- 顶栏通知铃铛 ---------- */
.bell-wrap { position: relative; display: inline-block; }
.bell { position: relative; display: inline-flex; align-items: center; justify-content: center; }
.bell-dot {
    position: absolute; top: 2px; right: 2px; min-width: 15px; height: 15px; padding: 0 3px;
    border-radius: 8px; background: #e5484d; color: #fff; font-size: 10px; line-height: 15px;
    text-align: center; font-weight: 600;
}
.bell-panel {
    position: absolute; right: 0; top: 38px; width: 320px; max-height: 420px; overflow: auto;
    background: #fff; border: 1px solid #e6e8ec; border-radius: 10px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, .12); z-index: 60;
}
.bell-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; border-bottom: 1px solid #f0f1f4; font-size: 13px;
}
.bell-all { color: #2b3a8f; text-decoration: none; font-size: 12px; }
.bell-list { padding: 6px; }
.bell-empty { padding: 18px 10px; text-align: center; color: #9aa0aa; font-size: 13px; }
.bell-item {
    display: block; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: inherit;
}
.bell-item:hover { background: #f7f8fa; }
.bell-item .t { font-size: 13px; color: #1f2430; }
.bell-item .c { font-size: 12px; color: #6b7280; margin-top: 2px; }
.bell-item .d { font-size: 11px; color: #9aa0aa; margin-top: 4px; }
.bell-item.unread .t { font-weight: 600; }
.bell-item.unread::after {
    content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
    background: #e5484d; margin-left: 6px; vertical-align: middle;
}
