:root {
    --primary: #2f6fed;
    --primary-dark: #1d5bd8;
    --primary-soft: #eaf1fe;
    --ink: #1f2733;
    --muted: #7a8699;
    --bg: #f5f7fa;
    --card: #ffffff;
    --line: #eceff4;
    --success: #16a34a;
    --warn: #f59e0b;
    --danger: #ef4444;
    --font-round: "YouYuan", "幼圆", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    background: linear-gradient(180deg, #f7f9fc 0%, var(--bg) 260px);
    color: var(--ink);
    font-size: 14px;
}

/* ============ 侧边栏（白底） ============ */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 224px;
    background: #fafbfd;
    border-right: 1px solid var(--line);
    color: var(--ink);
    padding: 16px 12px;
    z-index: 100;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; padding: 12px; background: var(--primary-soft); border-radius: 14px; }
.brand-logo {
    width: 38px; height: 38px; border-radius: 11px;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 16px; flex: none;
}
.brand-title { font-family: var(--font-round); font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    color: #465064;
    padding: 9px 12px; border-radius: 10px;
    text-decoration: none; font-size: 14px;
    border-left: 3px solid transparent;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: #f2f5fa; color: var(--ink); }
.nav-link.active {
    background: var(--primary-soft); color: var(--primary);
    font-weight: 600; border-left-color: var(--primary);
    box-shadow: 0 2px 8px rgba(47,111,237,.12);
}
.nav-ico { width: 28px; height: 28px; flex: none; border-radius: 8px; background: #eef2f7; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; }
.nav-link.active .nav-ico { background: var(--primary); color: #fff; }

/* ============ 主体 ============ */
.main { margin-left: 224px; min-height: 100vh; }
.topbar {
    height: 54px; background: var(--card);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 4px rgba(31,39,51,.05);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-family: var(--font-round); font-weight: 600; font-size: 15px; }
.topbar-user { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600;
}
.content { padding: 18px 20px; }

/* ============ 卡片 ============ */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 2px 10px rgba(31,39,51,.06);
    transition: box-shadow .18s ease;
    padding: 16px; margin-bottom: 16px;
}
.card:hover { box-shadow: 0 6px 18px rgba(31,39,51,.09); }
.card-title { position: relative; padding-left: 11px; font-family: var(--font-round); font-size: 14.5px; font-weight: 700; margin-bottom: 12px; }
.card-title::before { content: ""; position: absolute; left: 0; top: 3px; bottom: 3px; width: 3px; border-radius: 3px; background: var(--primary); }

/* ============ 统计卡片 ============ */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stat-card {
    border: 1px solid transparent; border-radius: 14px;
    padding: 16px; position: relative; overflow: hidden;
    box-shadow: 0 2px 10px rgba(31,39,51,.06);
    transition: box-shadow .18s ease, transform .18s ease;
}
.stat-card:hover { box-shadow: 0 6px 18px rgba(31,39,51,.10); transform: translateY(-2px); }
.stat-card::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--primary);
}
.stat-card::after {
    content: ""; position: absolute; right: -20px; bottom: -20px; width: 76px; height: 76px;
    border-radius: 50%; background: rgba(255,255,255,.5);
}
.stat-card:nth-child(1) { background: #eef4ff; }
.stat-card:nth-child(2) { background: #e9f7f6; }
.stat-card:nth-child(3) { background: #fdf3e3; }
.stat-card:nth-child(4) { background: #e8f6ee; }
.stat-card:nth-child(2)::before { background: #0ea5a4; }
.stat-card:nth-child(3)::before { background: var(--warn); }
.stat-card:nth-child(4)::before { background: var(--success); }
.stat-card:nth-child(1) .stat-num { color: var(--primary); }
.stat-card:nth-child(2) .stat-num { color: #0ea5a4; }
.stat-card:nth-child(3) .stat-num { color: #d97706; }
.stat-card:nth-child(4) .stat-num { color: var(--success); }
.stat-label { font-family: var(--font-round); color: var(--muted); font-size: 13px; }
.stat-num { font-family: var(--font-round); font-size: 26px; font-weight: 800; margin-top: 4px; }
.stat-trend { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ============ 表格 ============ */
.table-wrap {
    background: var(--card); border: 1px solid var(--line); border-radius: 14px;
    overflow: hidden;
}
.table { margin: 0; }
.table thead th {
    background: #f3f6fb; color: #465064; font-weight: 600; font-size: 13px;
    white-space: nowrap;
}
.table td, .table th { vertical-align: middle; padding: .55rem .75rem; font-size: 13.5px; }
.table tbody td { border-bottom: 1px solid #f1f4f8; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f7faff; }
.cell-id { color: var(--muted); font-size: 12px; }
.cell-phone { color: var(--primary); font-weight: 600; }
.dur { color: var(--ink); }
.dur-low { color: var(--warn); font-weight: 600; }
.record-link { color: var(--primary); text-decoration: none; }
.record-link:hover { text-decoration: underline; }

/* ============ 徽章 ============ */
.badge {
    display: inline-block; padding: 2px 9px; border-radius: 7px;
    font-size: 12px; line-height: 18px; white-space: nowrap;
}
.badge-grad { background: var(--primary); color: #fff; font-weight: 500; }
.badge-soft { background: #eef2f7; color: #556074; }
.badge-success { background: #e8f6ee; color: var(--success); }
.badge-warn { background: #fdf3e3; color: var(--warn); }
.badge-danger { background: #fdeaea; color: var(--danger); }

/* ============ 按钮 ============ */
.btn-grad { background: var(--primary); color: #fff; border: 1px solid var(--primary); box-shadow: 0 2px 6px rgba(47,111,237,.26); }
.btn-grad:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; box-shadow: 0 4px 10px rgba(47,111,237,.32); }
.btn-outline-light { color: #465064; border-color: var(--line); }
.btn-outline-light:hover { background: #f2f5fa; color: var(--ink); }

/* ============ 表单 ============ */
.form-label { font-size: 13px; color: #465064; margin-bottom: 4px; }
.form-control, .form-select { border-radius: 8px; padding: 5px 10px; font-size: 13px; height: 34px; }
textarea.form-control { height: auto; }
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 .2rem rgba(47,111,237,.12); }

/* ============ 规则开关卡片 + 滑块 ============ */
.rule-switch {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #f8fafd;
    height: 100%; transition: background .15s ease, border-color .15s ease;
}
.rule-switch:hover { background: #f3f7ff; border-color: #dbe7fb; }
.rule-switch-text { min-width: 0; }
.rule-switch-title { font-size: 13.5px; font-weight: 600; color: #33404f; }
.rule-switch-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.switch { position: relative; width: 42px; height: 23px; flex: none; display: inline-block; }
.switch input[type="checkbox"] { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .switch-track { position: absolute; inset: 0; background: #d3dae4; border-radius: 23px; transition: background .15s; }
.switch .switch-thumb { position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 3px rgba(31,39,51,.25); }
.switch input:checked ~ .switch-track { background: var(--primary); }
.switch input:checked ~ .switch-thumb { left: 22px; }

/* ============ 运行开关卡片 ============ */
.status-card { margin: 16px 0; }
.status-row { display: flex; flex-wrap: wrap; gap: 28px; align-items: center; }
.status-item { display: flex; align-items: center; gap: 10px; }
.status-label { font-size: 13px; color: #465064; font-weight: 600; }

/* ============ 登录页（独立） ============ */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--bg); padding: 20px;
}
.login-card {
    width: 380px; background: var(--card); border: 1px solid var(--line);
    border-radius: 18px; padding: 30px 28px;
    box-shadow: 0 12px 32px rgba(31,39,51,.10);
}
.login-logo {
    width: 52px; height: 52px; border-radius: 15px; background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 20px; margin: 0 auto 14px;
    box-shadow: 0 0 0 7px var(--primary-soft), 0 8px 20px rgba(47,111,237,.25);
}
.login-card h4 { font-family: var(--font-round); }

/* ============ 趋势条 ============ */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bar-row .bar-label { width: 84px; font-size: 13px; color: var(--muted); }
.bar-row .bar-track { flex: 1; background: #eef1f7; border-radius: 8px; height: 16px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; background: linear-gradient(90deg, #6ea3f7, var(--primary)); border-radius: 8px; }
.bar-row .bar-num { width: 64px; text-align: right; font-size: 13px; }

/* ============ 部门树（层级缩进复选列表） ============ */
.dept-tree { list-style: none; margin: 0; padding: 0; }
.dept-tree .dept-li { margin-bottom: 1px; }
.ddopt {
    display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px;
    cursor: pointer; font-size: 13px; color: #465064;
}
.ddopt:hover { background: #f2f5fa; }
.ddopt .dept-check { margin: 0; flex: none; }
.dept-children { list-style: none; margin: 0; padding: 0; }
.dept-node {
    flex: 1; display: flex; justify-content: space-between; align-items: center; gap: 8px;
    min-width: 0;
}
.dept-node.active { color: var(--primary); font-weight: 600; }
.dept-num, .dept-cnt {
    font-size: 11px; color: var(--muted); margin-left: auto;
    background: #eef2f7; border-radius: 6px; padding: 0 6px; line-height: 16px;
    white-space: nowrap;
}
.dept-cnt { background: transparent; padding: 0; }
.dept-node.active .dept-num { color: var(--primary); background: #fff; }

/* ============ 配额就地编辑 ============ */
.quota-view { cursor: pointer; min-width: 56px; display: inline-block; }
.quota-view.is-zero { color: var(--muted); }
.quota-edit { width: 74px; padding: 4px 8px; font-size: 13px; border-radius: 8px; border: 1px solid var(--primary); }

/* ============ 弹窗 ============ */
.modal-mask {
    position: fixed; inset: 0; background: rgba(31,39,51,.42); z-index: 200;
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-mask[hidden] { display: none; }
.modal-box {
    background: var(--card); border-radius: 14px; width: 520px; max-width: 100%;
    max-height: 74vh; display: flex; flex-direction: column; box-shadow: 0 16px 40px rgba(31,39,51,.18);
}
.modal-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 14.5px;
}
.modal-head .modal-sub { font-weight: 400; color: var(--muted); font-size: 12.5px; margin-left: 8px; }
.modal-x { border: 0; background: none; font-size: 20px; color: var(--muted); cursor: pointer; line-height: 1; }
.modal-body { padding: 12px 16px; overflow-y: auto; }
.modal-search { margin-bottom: 10px; }
.modal-search input { width: 100%; }

/* 弹窗内 部门/员工 树形多选 */
.modal-tree { list-style: none; margin: 0; padding: 0; }
.m-dept { margin-bottom: 2px; }
.m-dept-row {
    display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px;
    font-size: 13.5px; font-weight: 600; color: #33404f;
}
.m-dept-row:hover { background: #f2f5fa; }
.m-dept-row .m-count { margin-left: auto; font-weight: 400; font-size: 11.5px; color: var(--muted); }
.m-staffs { list-style: none; margin: 0; padding-left: 22px; }
.m-depts { list-style: none; margin: 0; padding: 0; }
.m-dept-name { font-weight: 600; }
.m-staff {
    display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px;
    font-size: 13px; color: #465064;
}
.m-staff:hover { background: #f2f5fa; }
.m-staff .m-avatar {
    width: 18px; height: 18px; flex: none; border-radius: 50%;
    background: var(--primary-soft); color: var(--primary);
    display: inline-flex; align-items: center; justify-content: center; font-size: 11px;
}
.modal-foot {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    padding: 12px 16px; border-top: 1px solid var(--line);
}
.modal-foot .foot-left { display: flex; gap: 8px; }

/* 员工页部门树：复选多选 */
.dept-tree .dept-row { padding: 3px 0; }
.dept-check { margin: 0; }
.dept-node { cursor: pointer; }
.dept-node.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

/* ============ 响应式 ============ */
@media (max-width: 900px) {
    .sidebar { width: 72px; }
    .brand-sub, .brand-title, .nav-link { font-size: 0; }
    .main { margin-left: 72px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
