/* ============================================================================
   SCL-90 心理咨询 · Web 管理后台
   设计语言：商务蓝 #1A73E8 / 字体 Montserrat · Inter · Noto Sans SC
   零依赖纯前端（无构建步骤），由 Express 以静态资源托管于 /admin/
   ============================================================================ */

:root {
  --blue: #1A73E8;
  --blue-dark: #1557b0;
  --blue-soft: #e8f0fe;
  --ink: #1f2937;
  --ink-2: #4b5563;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f5f7fa;
  --card: #ffffff;
  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --sidebar: #0f2444;
  --sidebar-hover: #1b3a66;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .05);
  --font: "Montserrat", "Inter", "Noto Sans SC", -apple-system, "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---------------------------------------------------------------- 登录页 */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1000px 520px at 15% 0%, #e8f0fe 0%, rgba(232, 240, 254, 0) 60%),
    radial-gradient(900px 500px at 100% 100%, #eef2ff 0%, rgba(238, 242, 255, 0) 55%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(16, 24, 40, .1);
  padding: 40px 36px 32px;
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  background: linear-gradient(135deg, var(--blue), #4f92f7);
  color: #fff; font-weight: 700; font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: -.5px;
}
.brand-text h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: -.2px; }
.brand-text p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 7px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; color: var(--ink); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--blue); box-shadow: 0 0 0 3px rgba(26, 115, 232, .12);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; border-radius: 9px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; transition: background .15s, opacity .15s, border-color .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn-ghost { background: #fff; color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: #f9fafb; border-color: #d1d5db; }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover:not(:disabled) { background: #fef2f2; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 7px; }
.btn-block { width: 100%; padding: 12px; }

.alert {
  padding: 11px 14px; border-radius: 9px; font-size: 13px; line-height: 1.6;
  margin-bottom: 16px; display: none;
}
.alert.show { display: block; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-info { background: var(--blue-soft); color: #1e40af; border: 1px solid #c7dbfc; }
.alert-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

.login-foot { margin-top: 22px; font-size: 12px; color: var(--muted); line-height: 1.85; }
.login-foot b { color: var(--ink-2); }
.hint-chip {
  display: inline-block; background: #f3f4f6; border-radius: 6px;
  padding: 2px 7px; font-family: var(--mono); font-size: 12px; color: var(--ink-2);
}

/* -------------------------------------------------------------- 主框架 */
.app { display: none; min-height: 100vh; }
.app.show { display: flex; }

.sidebar {
  width: 238px; flex: none; background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 20px 18px 16px; margin: 0; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .brand-mark { width: 36px; height: 36px; font-size: 15px; border-radius: 10px; }
.sidebar .brand-text h1 { color: #fff; font-size: 15px; }
.sidebar .brand-text p { color: #8fa6c4; font-size: 11px; }

.nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.nav-group { margin-bottom: 6px; }
.nav-group-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: #6b83a3; padding: 12px 10px 6px; font-weight: 700;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  border-radius: 8px; cursor: pointer; color: #cbd5e1; font-weight: 500;
  transition: background .13s, color .13s; user-select: none;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--blue); color: #fff; font-weight: 600; }
.nav-item .ico { width: 17px; text-align: center; flex: none; opacity: .95; }

.sidebar-foot {
  padding: 12px 14px 16px; border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px; color: #8fa6c4;
}
.sidebar-foot .me { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: rgba(255,255,255,.14); color: #fff; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-foot .me-name { color: #fff; font-weight: 600; font-size: 13px; }
.sidebar-foot .me-role { font-size: 11px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-size: 16px; margin: 0; font-weight: 700; letter-spacing: -.2px; }
.topbar .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.env-badge {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px;
  background: var(--blue-soft); color: var(--blue-dark); letter-spacing: .3px;
}
.env-badge.production { background: #fef2f2; color: var(--danger); }

.content { padding: 24px; flex: 1; }

/* ----------------------------------------------------------------- 卡片 */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; margin-bottom: 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.card-head h3 { font-size: 15px; margin: 0; font-weight: 700; }
.card-head .desc { font-size: 12px; color: var(--muted); margin-top: 3px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1180px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px)  { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; position: relative; overflow: hidden;
}
.stat::after {
  content: ""; position: absolute; right: -22px; top: -22px;
  width: 78px; height: 78px; border-radius: 50%; background: var(--blue-soft); opacity: .55;
}
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 8px; position: relative; }
.stat .value { font-size: 27px; font-weight: 700; letter-spacing: -.6px; position: relative; }
.stat .value small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 5px; }
.stat .foot { font-size: 12px; color: var(--muted); margin-top: 7px; position: relative; }
.stat.accent .value { color: var(--blue); }
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }
.stat.ok .value { color: var(--ok); }

/* ----------------------------------------------------------------- 表格 */
.table-wrap { overflow-x: auto; margin: 0 -22px -20px; padding: 0 22px 4px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-weight: 700; color: var(--ink-2); font-size: 12px;
  padding: 10px 9px; border-bottom: 1px solid var(--line); white-space: nowrap;
  background: #fafbfc;
}
table.data td {
  padding: 10px 9px; border-bottom: 1px solid #f3f4f6; vertical-align: middle;
}
table.data tbody tr:hover { background: #fafbfc; }
table.data td.actions { white-space: nowrap; }
/* 操作列按钮统一紧凑排布：行数多时（改角色/绑定/编辑/权限/改密/停用）
   默认内边距会把操作列撑宽、把按钮挤出可视区，故在此收窄。 */
table.data td.actions .btn { margin-right: 4px; padding: 5px 8px; }
table.data td.actions .btn:last-child { margin-right: 0; }
.mono { font-family: var(--mono); font-size: 12px; }

.tag {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.tag-admin { background: #ede9fe; color: #5b21b6; }
.tag-counselor { background: var(--blue-soft); color: var(--blue-dark); }
.tag-client { background: #f3f4f6; color: var(--ink-2); }
.tag-online { background: #ecfdf5; color: #065f46; }
.tag-draft { background: #fffbeb; color: #92400e; }
.tag-offline { background: #f3f4f6; color: var(--muted); }
.tag-on { background: #ecfdf5; color: #065f46; }
.tag-off { background: #fef2f2; color: #991b1b; }
.tag-pos { background: #fef2f2; color: #991b1b; }
.tag-border { background: #fffbeb; color: #92400e; }
.tag-normal { background: #ecfdf5; color: #065f46; }
.tag-gray { background: #f3f4f6; color: var(--muted); }
.tag-warn { background: #fffbeb; color: #92400e; }

/* --------------------------------------------------------------- 工具条 */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select {
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; outline: none; min-width: 132px;
}
.filters input:focus, .filters select:focus { border-color: var(--blue); }
.filters input.search { min-width: 190px; }

/* 地区管理：层级面包屑（全国 › 省 › 市 › 区县） */
.ds-crumb { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; margin: 0 0 14px; }
.ds-crumb a { color: var(--blue); cursor: pointer; }
.ds-crumb a:hover { text-decoration: underline; }
.ds-crumb .sep { color: #cbd5e1; }
.ds-crumb .cur { color: var(--ink-2); font-weight: 600; }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.checkbox-row input { width: 15px; height: 15px; accent-color: var(--blue); }

.section-pick {
  border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px;
  background: #fafbfc; display: flex; flex-direction: column; gap: 9px;
}
/* label 在 .field 内默认 display:block，这里必须显式改回 flex 才能横向排列 */
.section-pick .item { display: flex; align-items: flex-start; gap: 9px; cursor: pointer; }
.section-pick .item input[type=checkbox] {
  width: 15px; height: 15px; accent-color: var(--blue);
  margin: 2px 0 0; flex: 0 0 auto;
}
/* flex:1 必须搭配 min-width:0，否则长文本会把容器压成一条窄列 */
.section-pick .item .txt { flex: 1 1 auto; min-width: 0; display: block; }
.section-pick .item .txt .t {
  display: block; font-weight: 600; font-size: 13px; line-height: 1.5; color: var(--ink);
}
.section-pick .item .txt .d {
  display: block; font-size: 12px; line-height: 1.6; color: var(--muted); margin-top: 2px;
  word-break: break-word;
}

/* ----------------------------------------------------------------- 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .5);
  display: none; align-items: center; justify-content: center; padding: 24px; z-index: 100;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 540px;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(16,24,40,.25);
}
.modal.wide { max-width: 760px; }
.modal-head {
  padding: 18px 22px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.modal-head .x {
  cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1;
  border: none; background: none; padding: 2px 6px; border-radius: 6px;
}
.modal-head .x:hover { background: #f3f4f6; color: var(--ink); }
.modal-body { padding: 20px 22px; }
.modal-foot {
  padding: 14px 22px 18px; display: flex; justify-content: flex-end; gap: 10px;
  border-top: 1px solid var(--line);
}

.kv { display: grid; grid-template-columns: 108px 1fr; gap: 9px 14px; font-size: 13px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; color: var(--ink); word-break: break-word; }

/* ----------------------------------------------------------- 报告/文本区 */
.report-text {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.85;
  background: #fafbfc; border: 1px solid var(--line); border-radius: 9px;
  padding: 16px 18px; white-space: pre-wrap; max-height: 460px; overflow-y: auto;
  color: var(--ink);
}
.compare-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.compare-table th, .compare-table td {
  padding: 8px 10px; border: 1px solid var(--line); text-align: center; white-space: nowrap;
}
.compare-table th { background: #fafbfc; font-weight: 700; color: var(--ink-2); font-size: 12px; }
.compare-table th.rowhead, .compare-table td.rowhead {
  text-align: left; background: #fafbfc; font-weight: 600; position: sticky; left: 0;
}
.compare-table td.up { color: var(--danger); font-weight: 700; }
.compare-table td.down { color: var(--ok); font-weight: 700; }

/* ------------------------------------------------------------- 权限矩阵 */
.perm-matrix { overflow-x: auto; }
.perm-matrix table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.perm-matrix th, .perm-matrix td { padding: 8px 11px; border: 1px solid var(--line); }
.perm-matrix th { background: #fafbfc; font-weight: 700; color: var(--ink-2); }
.perm-matrix td.yes { color: var(--ok); font-weight: 700; text-align: center; }
.perm-matrix td.no { color: #d1d5db; text-align: center; }
.perm-matrix tr:hover td { background: #fafbfc; }
.perm-matrix .group-row td {
  background: #f3f6fb; font-weight: 700; color: var(--blue-dark); font-size: 12px;
}

.empty { text-align: center; padding: 44px 20px; color: var(--muted); font-size: 13px; }
.empty .big { font-size: 30px; opacity: .35; margin-bottom: 10px; }
.loading { text-align: center; padding: 40px; color: var(--muted); font-size: 13px; }

.toast-wrap {
  position: fixed; top: 20px; right: 20px; z-index: 300;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: #111827; color: #fff; padding: 11px 16px; border-radius: 9px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 380px;
  animation: slidein .2s ease-out;
}
.toast.ok { background: #065f46; }
.toast.err { background: #991b1b; }
@keyframes slidein { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }

.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; flex: 1; min-width: 160px; }

.help-text { font-size: 12px; color: var(--muted); line-height: 1.7; margin-top: 6px; }

.pill-row { display: flex; gap: 7px; flex-wrap: wrap; }
.pill {
  font-size: 11.5px; padding: 3px 9px; border-radius: 20px;
  background: #f3f4f6; color: var(--ink-2); font-family: var(--mono);
}
.pill.on { background: var(--blue-soft); color: var(--blue-dark); }

.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 132px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.bar {
  width: 100%; max-width: 34px; background: linear-gradient(180deg, #4f92f7, var(--blue));
  border-radius: 5px 5px 2px 2px; min-height: 3px; transition: height .35s ease;
}
.bar.zero { background: #e5e7eb; }
.bar-lbl { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.bar-val { font-size: 11px; font-weight: 700; color: var(--blue-dark); }

/* ------------------------------------------------- 报告正文模板编辑器 */
/* 「报告管理 → 报告章节与正文文本块」专用：模板文本域 / 工具条 / 变量面板 / 预览 */
.tpl-area {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.75;
  white-space: pre; overflow-x: auto; resize: vertical;
}
.tpl-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.tpl-tools .help-text { margin: 0; }
.var-panel {
  border: 1px solid var(--line); border-radius: 9px; background: #fafbfc;
  padding: 10px 12px; margin-top: 10px; display: flex; flex-direction: column; gap: 8px;
  max-height: 216px; overflow-y: auto;
}
.var-group { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.var-group-name {
  flex: 0 0 62px; font-size: 11.5px; font-weight: 600; color: var(--muted);
  line-height: 22px;
}
.var-chip {
  font-family: var(--mono); font-size: 11.5px; line-height: 1;
  padding: 5px 8px; border-radius: 6px; cursor: pointer;
  background: var(--blue-soft); color: var(--blue-dark);
  border: 1px solid #dbeafe; transition: background .15s;
}
.var-chip:hover { background: #dbeafe; }
.tpl-preview {
  font-family: var(--mono); font-size: 12px; line-height: 1.8;
  background: #fafbfc; border: 1px solid var(--line); border-radius: 9px;
  padding: 12px 14px; margin: 0; white-space: pre-wrap; word-break: break-word;
  max-height: 260px; overflow-y: auto; color: var(--ink);
}
.chk-line {
  display: flex; align-items: center; gap: 8px; font-size: 13px;
  color: var(--ink-2); line-height: 1.6; cursor: pointer;
}
.chk-line input { width: 15px; height: 15px; accent-color: var(--blue); flex: 0 0 auto; }
.chk-line.is-disabled { color: var(--muted); cursor: not-allowed; }
.muted-note { font-size: 12px; color: var(--muted); }
