:root {
  --brand: #1F6FEB;
  --brand-dark: #1A5BC4;
  --brand-soft: #EAF1FE;
  --bg: #F4F6FA;
  --card: #FFFFFF;
  --line: #E8ECF2;
  --text: #1A1D24;
  --text-2: #4A5060;
  --text-3: #8A8F99;
  --green: #1B9E52;
  --red: #D93F3F;
  --orange: #E8871A;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 30, 55, .06), 0 6px 20px rgba(16, 30, 55, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--text-3); }
.nowrap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============ 登录页 ============ */
#loginView {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(150deg, #1F6FEB 0%, #4C8FF5 55%, #6FA8FF 100%);
  padding: 40px 20px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px 32px;
  box-shadow: 0 20px 60px rgba(8, 28, 66, .28);
}

.login-logo {
  width: 56px; height: 56px; border-radius: 16px;
  background: linear-gradient(150deg, #1F6FEB, #4C8FF5);
  color: #fff; font-size: 26px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 20px;
}

.login-title { font-size: 24px; font-weight: 700; margin: 0 0 6px; }
.login-sub { color: var(--text-3); font-size: 13px; margin: 0 0 26px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.field input {
  width: 100%; height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  outline: none; transition: border-color .15s, box-shadow .15s;
  background: #FBFCFE;
}
.field input:focus { border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px rgba(31,111,235,.12); }

.btn {
  height: 44px; padding: 0 20px; border: none; border-radius: var(--radius);
  background: var(--brand); color: #fff; font-size: 15px; font-weight: 600;
  transition: background .15s, opacity .15s;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-ghost { background: #fff; color: var(--text-2); border: 1px solid var(--line); }
.btn-ghost:hover { background: #F7F9FC; color: var(--brand); }
.btn-sm { height: 34px; padding: 0 14px; font-size: 13px; font-weight: 500; }
.btn-green { background: var(--green); }
.btn-green:hover { background: #168044; }

.login-err {
  margin-top: 14px; padding: 10px 14px; border-radius: var(--radius);
  background: #FDEDED; color: var(--red); font-size: 13px;
}

/* 微信扫码不可用时给中性提示，不刷成红色报错 */
.login-hint {
  margin-bottom: 18px; padding: 10px 14px; border-radius: var(--radius);
  background: #FFF8E8; color: #8A5A00; font-size: 13px; line-height: 1.6;
}

.login-switch { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-3); }
.login-switch a { font-weight: 600; }

/* ===== 微信扫码登录 ===== */
.qr-wrap { display: flex; flex-direction: column; align-items: center; }

.qr-box {
  position: relative;
  width: 212px; height: 212px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #FBFCFE;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}

.qr-img { width: 100%; height: 100%; object-fit: contain; display: block; }

.qr-hint {
  font-size: 13px; color: var(--text-3);
  padding: 0 18px; text-align: center; line-height: 1.6;
}

.qr-mask {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255, 255, 255, .95);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
}
.qr-mask-text { font-size: 13px; color: var(--text-2); }

.qr-btn {
  height: 34px; padding: 0 18px;
  border: none; border-radius: 17px;
  background: var(--brand); color: #fff;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.qr-btn:hover { background: var(--brand-dark); }

.qr-tip {
  margin-top: 16px; font-size: 13px; color: var(--text-3);
  text-align: center; line-height: 1.6;
}
.qr-tip strong { color: var(--text-2); font-weight: 600; }
.qr-tip-sub { font-size: 12px; color: var(--text-3); opacity: 0.85; }

.qr-status {
  margin-top: 10px; min-height: 18px;
  font-size: 13px; color: var(--brand); text-align: center;
}
.qr-status.err { color: var(--red); }

.login-alt {
  margin-top: 16px; padding-top: 16px;
  border-top: 1px dashed var(--line);
  text-align: center; font-size: 13px;
}
.login-alt a { color: var(--text-3); text-decoration: none; }
.login-alt a:hover { color: var(--brand); text-decoration: underline; }

/* 管局要求：ICP 备案号页脚（登录页 + 主界面共用） */
.login-footer {
  position: fixed; left: 0; right: 0; bottom: 14px;
  text-align: center; font-size: 12px;
}
.login-footer a { color: rgba(255, 255, 255, 0.92); text-decoration: none; }
.login-footer a:hover { color: #fff; text-decoration: underline; }

.site-footer {
  border-top: 1px solid var(--line);
  padding: 14px 26px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-3);
}
.sf-sep { color: var(--line); }

/* ============ 主布局 ============ */
#appView { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px; flex-shrink: 0;
  background: #0F1D33;
  color: #C6D0E0;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.sb-brand {
  padding: 22px 20px 18px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sb-logo {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(150deg, #1F6FEB, #4C8FF5);
  color: #fff; font-size: 17px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.sb-name { font-size: 15px; font-weight: 700; color: #fff; line-height: 1.25; }
.sb-name small { display: block; font-size: 11px; font-weight: 400; color: #6E7E99; margin-top: 2px; }

.sb-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.sb-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  font-size: 14px; color: #C6D0E0; cursor: pointer;
  margin-bottom: 3px; transition: background .15s, color .15s;
}
.sb-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.sb-item.active { background: var(--brand); color: #fff; font-weight: 600; }
.sb-item .ico { font-size: 15px; width: 18px; text-align: center; }
.sb-badge {
  margin-left: auto; font-size: 11px; padding: 1px 7px; border-radius: 8px;
  background: rgba(255,255,255,.14); color: #DCE4F0;
}
.sb-item.active .sb-badge { background: rgba(255,255,255,.26); color: #fff; }

.sb-foot {
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.07);
  font-size: 12px; color: #6E7E99;
}
.sb-user { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.sb-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sb-uname { color: #fff; font-size: 13px; font-weight: 600; line-height: 1.2; }
.sb-urole { font-size: 11px; color: #6E7E99; }
.sb-out {
  width: 100%; height: 30px; border-radius: 7px; border: 1px solid rgba(255,255,255,.14);
  background: transparent; color: #C6D0E0; font-size: 12px;
}
.sb-out:hover { background: rgba(255,255,255,.08); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 0 26px; height: 60px;
  display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.tb-title { font-size: 17px; font-weight: 700; }
.tb-sub { font-size: 12px; color: var(--text-3); }
.tb-spacer { flex: 1; }
.tb-cust {
  display: flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 12px; border-radius: 17px;
  background: var(--brand-soft); color: var(--brand);
  font-size: 13px; font-weight: 600; border: none;
}
.tb-cust:hover { background: #DCE8FD; }
.tb-cust select { border: none; background: transparent; color: var(--brand); font-weight: 600; outline: none; cursor: pointer; }

.content { padding: 22px 26px 40px; flex: 1; }

/* ============ 卡片 / 统计 ============ */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 15px; font-weight: 700; margin: 0 0 16px; display: flex; align-items: center; gap: 8px; }
.card-title .sub { font-size: 12px; font-weight: 400; color: var(--text-3); margin-left: auto; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat {
  background: #fff; border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow); border-left: 3px solid var(--brand);
}
.stat.green { border-left-color: var(--green); }
.stat.orange { border-left-color: var(--orange); }
.stat.red { border-left-color: var(--red); }
.stat-num { font-size: 28px; font-weight: 700; line-height: 1.15; }
.stat-num .unit { font-size: 14px; font-weight: 600; margin-left: 2px; }
.stat-label { font-size: 12px; color: var(--text-3); margin-top: 5px; }
.stat.blue .stat-num { color: var(--brand); }
.stat.green .stat-num { color: var(--green); }
.stat.orange .stat-num { color: var(--orange); }
.stat.red .stat-num { color: var(--red); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .grid-2, .grid-2-1 { grid-template-columns: 1fr; } }

/* ============ 图表 ============ */
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.tall { height: 320px; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; font-size: 13px; }
.bar-label { width: 130px; flex-shrink: 0; color: var(--text-2); }
.bar-track { flex: 1; height: 18px; background: #F1F4F9; border-radius: 9px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 9px; background: linear-gradient(90deg, #1F6FEB, #5B9BFF); transition: width .5s; }
.bar-val { width: 54px; text-align: right; color: var(--text-3); font-size: 12px; flex-shrink: 0; }

/* ============ 表格 ============ */
.table-tools {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.ti {
  height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; outline: none; color: var(--text); min-width: 0;
}
.ti:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31,111,235,.12); }
.ti-search { flex: 1; min-width: 200px; }
.ti-sm { width: 130px; }

table.data { width: 100%; border-collapse: collapse; background: #fff; font-size: 13px; }
table.data th {
  text-align: left; padding: 11px 12px; background: #F7F9FC;
  border-bottom: 1px solid var(--line); font-weight: 600; color: var(--text-2);
  white-space: nowrap; position: sticky; top: 0; z-index: 2;
}
table.data td { padding: 11px 12px; border-bottom: 1px solid #F2F5F9; vertical-align: top; }
table.data tbody tr:hover { background: #F9FBFE; }
table.data tbody tr { cursor: pointer; }
.table-scroll { max-height: 620px; overflow: auto; border-radius: var(--radius); box-shadow: var(--shadow); background: #fff; }
.t-title { font-weight: 600; color: var(--text); }
.t-title:hover { color: var(--brand); }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 5px;
  font-size: 11px; line-height: 17px; white-space: nowrap;
}
.tag-gray { background: #F0F2F5; color: #6B7280; }
.tag-blue { background: var(--brand-soft); color: var(--brand); }
.tag-green { background: #E9F7EF; color: var(--green); }
.tag-orange { background: #FFF4E5; color: var(--orange); }
.tag-red { background: #FDEDED; color: var(--red); }

.empty-box { text-align: center; padding: 60px 20px; color: var(--text-3); }
.empty-box .ico { font-size: 40px; display: block; margin-bottom: 12px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 18px; font-size: 13px; color: var(--text-2); }

/* ============ 详情抽屉 ============ */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(14, 22, 38, .42);
  z-index: 100; display: flex; justify-content: flex-end;
}
.drawer {
  width: 100%; max-width: 680px; height: 100%; background: #fff;
  display: flex; flex-direction: column; box-shadow: -8px 0 40px rgba(0,0,0,.16);
}
.drawer-head {
  padding: 20px 26px; border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; gap: 14px;
}
.drawer-title { font-size: 18px; font-weight: 700; line-height: 1.4; flex: 1; }
.drawer-close {
  width: 32px; height: 32px; border-radius: 8px; border: none; background: #F3F5F8;
  color: var(--text-2); font-size: 16px; flex-shrink: 0;
}
.drawer-close:hover { background: #E8ECF2; }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px 26px 40px; }

.d-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.d-section { margin-bottom: 24px; }
.d-section h4 {
  font-size: 13px; font-weight: 700; color: var(--text-2);
  margin: 0 0 10px; padding-left: 9px; border-left: 3px solid var(--brand);
}
.d-text {
  font-size: 13.5px; line-height: 1.85; color: var(--text-2);
  white-space: pre-wrap; word-break: break-word;
  background: #F9FBFE; border-radius: 8px; padding: 14px 16px;
}
.d-attach { display: flex; flex-wrap: wrap; gap: 10px; }
.d-attach img {
  width: 130px; height: 130px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--line); cursor: zoom-in; transition: transform .15s;
}
.d-attach img:hover { transform: scale(1.03); }

.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.86); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 40px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }

/* ============ 客户管理 ============ */
.cust-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.cust-card {
  background: #fff; border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.cust-card.off { opacity: .62; }
.cust-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.cust-avatar {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  background: linear-gradient(150deg, #1F6FEB, #4C8FF5);
  color: #fff; font-size: 18px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.cust-name { font-size: 15px; font-weight: 700; }
.cust-stats { display: flex; gap: 16px; font-size: 12px; color: var(--text-3); margin-bottom: 14px; }
.cust-stats b { color: var(--text-2); font-size: 14px; }
.cust-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed; inset: 0; background: rgba(14, 22, 38, .45); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  width: 100%; max-width: 460px; background: #fff; border-radius: 12px;
  box-shadow: 0 20px 60px rgba(8,28,66,.3); max-height: 86vh; display: flex; flex-direction: column;
}
.modal.wide { max-width: 560px; }
.modal-head { padding: 20px 24px 0; font-size: 16px; font-weight: 700; }
.modal-desc { padding: 6px 24px 0; font-size: 13px; color: var(--text-3); }
.modal-body { padding: 18px 24px; overflow-y: auto; flex: 1; }
.modal-body .field:last-child { margin-bottom: 0; }
.modal-foot { padding: 0 24px 20px; display: flex; justify-content: flex-end; gap: 10px; }

.user-pick {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 8px; border: 1px solid var(--line);
  margin-bottom: 7px; cursor: pointer; transition: all .13s;
}
.user-pick:hover { border-color: #B9CDF5; background: #FAFCFF; }
.user-pick.on { border-color: var(--brand); background: var(--brand-soft); }
.up-check {
  width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid #CBD3DF;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #fff;
}
.user-pick.on .up-check { background: var(--brand); border-color: var(--brand); }
.up-name { font-size: 13.5px; font-weight: 600; }
.up-sub { font-size: 11.5px; color: var(--text-3); }

.toast {
  position: fixed; top: 22px; left: 50%; transform: translateX(-50%);
  background: #101828; color: #fff; padding: 11px 22px; border-radius: 8px;
  font-size: 13.5px; z-index: 500; box-shadow: 0 10px 32px rgba(0,0,0,.28);
  transition: opacity .25s; max-width: 80vw; text-align: center;
}
.toast.ok { background: #14683A; }
.toast.err { background: #9C2B2B; }

.loading-row { text-align: center; padding: 40px; color: var(--text-3); font-size: 13px; }

/* ============ 侧边栏分组 ============ */
.sb-group {
  padding: 14px 12px 6px;
  font-size: 11px; letter-spacing: .06em;
  color: #5C6B84; text-transform: uppercase;
}

/* ============ 用户与角色 ============ */
.user-table tbody tr { cursor: default; }
.user-table tbody tr.row-off { opacity: .58; }
.user-table td.num { font-variant-numeric: tabular-nums; color: var(--text-2); }

.u-cell { display: flex; align-items: center; gap: 10px; }
.u-ava {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(150deg, #1F6FEB, #4C8FF5);
  color: #fff; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.u-name { font-size: 13.5px; font-weight: 600; max-width: 190px; }
.u-sub { font-size: 11.5px; color: var(--text-3); max-width: 260px; }

.role-sel {
  height: 30px; padding: 0 8px; border-radius: 7px;
  border: 1px solid var(--line); background: #fff; color: var(--text-2);
  font-size: 12.5px; outline: none; cursor: pointer;
}
.role-sel:hover { border-color: #B9CDF5; }
.role-sel:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31,111,235,.12); }
.role-sel:disabled { background: #F5F7FA; cursor: not-allowed; }

/* ============ 权限配置 ============ */
.perm-card { padding: 0; overflow: hidden; }
.perm-head { padding: 20px 22px 16px; border-bottom: 1px solid var(--line); }
.perm-title { font-size: 15px; font-weight: 700; margin-bottom: 5px; }
.perm-sub { font-size: 12.5px; color: var(--text-3); line-height: 1.7; max-width: 780px; }

.perm-scroll { overflow: auto; max-height: calc(100vh - 330px); min-height: 260px; }
.perm-table th { z-index: 3; }
.perm-table .pc-name { width: auto; min-width: 260px; }
.perm-table th.pc-role {
  width: 132px; text-align: center; font-size: 12.5px; line-height: 1.5;
}
.perm-table th.pc-role small {
  display: block; font-size: 11px; font-weight: 400; color: var(--text-3);
}
.perm-table td.pc-cell { text-align: center; vertical-align: middle; }
.perm-table tbody tr { cursor: default; }
.perm-table tbody tr:hover { background: transparent; }

.pc-pname { font-size: 13px; font-weight: 600; color: var(--text); }
.pc-pdesc { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }

.pg-row td {
  background: #F7F9FC; font-size: 11.5px; font-weight: 700;
  color: var(--text-2); letter-spacing: .04em; padding: 7px 12px;
  border-bottom: 1px solid var(--line);
}

.pc-box { position: relative; display: inline-flex; cursor: pointer; }
.pc-box input { position: absolute; opacity: 0; width: 0; height: 0; }
.pc-mark {
  width: 20px; height: 20px; border-radius: 6px;
  border: 1.5px solid #CBD3DF; background: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .13s; font-size: 12px; color: #fff; line-height: 1;
}
.pc-box:hover .pc-mark { border-color: var(--brand); }
.pc-box input:checked + .pc-mark { background: var(--brand); border-color: var(--brand); }
.pc-box input:checked + .pc-mark::after { content: "✓"; font-weight: 700; }
.pc-box input:focus-visible + .pc-mark { box-shadow: 0 0 0 3px rgba(31,111,235,.18); }
.pc-box.locked { cursor: not-allowed; }
.pc-box.locked .pc-mark { background: #EEF2F8; border-color: #D8DFEA; }
.pc-box.locked input:checked + .pc-mark { background: #A9B7CB; border-color: #A9B7CB; }
.pc-lock {
  display: block; margin-top: 3px; font-size: 10.5px; color: var(--text-3);
}

.perm-foot {
  padding: 16px 22px; border-top: 1px solid var(--line);
  background: #FBFCFE; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.pf-tip { flex: 1; min-width: 260px; font-size: 12px; color: var(--text-3); line-height: 1.7; }
.pf-actions { display: flex; align-items: center; gap: 10px; }
.pf-dirty { font-size: 12.5px; color: var(--text-3); }
.pf-dirty.on { color: var(--orange); font-weight: 600; }

@media (max-width: 900px) {
  .sidebar { width: 62px; }
  .sb-name, .sb-item span:not(.ico):not(.sb-badge), .sb-user > div, .sb-out { display: none; }
  .sb-brand { justify-content: center; padding: 18px 0; }
  .content { padding: 16px; }
  .topbar { padding: 0 14px; }
}
