/* 全站样式：只用本地资源，不内联（CSP 不允许内联样式）。 */
:root {
  --brand: #2c5ed7;
  --brand-soft: #edf3ff;
  --text: #233047;
  --muted: #66758b;
  --line: #e2e8f1;
  --surface: #ffffff;
  --page: #f3f6fb;
  --nav: #172a48;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --success: #067647;
  --success-soft: #e7f6ec;
  --warning: #b54708;
  --warning-soft: #fff4e5;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(31, 52, 88, .05);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", Arial, sans-serif;
  color: var(--text);
  background: var(--page);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.4; margin: 0; font-weight: 600; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
:where(a, button, input, select, textarea):focus-visible { outline: 3px solid #b8ccfa; outline-offset: 2px; }
[hidden] { display: none !important; }

/* 按钮与表单 */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; line-height: 1.4; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.button:hover { border-color: #bccbe0; background: #f8faff; }
.button:disabled { opacity: .55; cursor: default; }
.button-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.button-primary:hover { background: #214fc2; border-color: #214fc2; }
.button-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button-danger:hover { background: #b42318; border-color: #b42318; }
.button-small { min-height: 32px; padding: 5px 11px; font-size: 13px; }
.button-text { border: 0; background: none; color: var(--brand); padding: 5px 6px; min-height: 32px; }
.field { display: grid; gap: 7px; margin-bottom: 18px; min-width: 0; }
.field > span { font-size: 13px; color: #47566c; font-weight: 500; }
.field input[type="text"], .field input[type="search"], .field input[type="datetime-local"], .field select, .field textarea, .toolbar select, .toolbar input {
  width: 100%; min-width: 0; min-height: 40px; padding: 8px 11px; border: 1px solid #d6dfeb; border-radius: 8px;
  font: inherit; color: inherit; background: #fff;
}
.field textarea { min-height: 120px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .toolbar input:focus, .toolbar select:focus { border-color: var(--brand); }
.field input::placeholder, .field textarea::placeholder, .toolbar input::placeholder { color: #909caf; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0; min-height: 32px; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); flex-shrink: 0; }
.check-group { display: grid; gap: 2px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; max-height: 220px; overflow: auto; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 8px 10px; border-radius: 8px; margin: 0 0 12px; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }

/* 登录页 */
.login-shell { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 32px 20px; background: radial-gradient(ellipse at 50% 0, #e6eeff, transparent 65%), var(--page); }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid rgba(226, 232, 241, .85); border-radius: 20px; box-shadow: 0 12px 48px rgba(31, 52, 88, .08); padding: 32px; }
.login-card header { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.brand-mark { display: inline-grid; place-items: center; width: 40px; height: 40px; flex-shrink: 0; border-radius: 11px; background: var(--brand); color: #fff; font-weight: 600; }
.login-card h1 { font-size: 20px; }
.login-card .org { color: var(--muted); font-size: 13px; }
.login-status { min-height: 24px; margin: 8px 0 22px; color: var(--muted); line-height: 1.8; overflow-wrap: anywhere; }
.login-status.error { color: var(--danger); }
.demo-users { display: grid; gap: 8px; margin-top: 8px; }
.demo-user { display: flex; justify-content: space-between; gap: 12px; text-align: left; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font: inherit; cursor: pointer; }
.demo-user:hover { border-color: var(--brand); }
.demo-user small { color: var(--muted); }
.demo-apps { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.demo-apps a { padding: 2px 10px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; font-size: 13px; color: var(--text); }
.demo-apps a.active { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* 应用外壳 */
.app-header { position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; min-height: 68px; padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--line); }
.app-title { display: flex; align-items: center; gap: 12px; min-width: 0; font-size: 17px; font-weight: 600; }
.app-title .brand-mark { width: 34px; height: 34px; font-size: 14px; }
.app-user { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; font-size: 13px; color: var(--muted); }
.app-user strong { color: var(--text); font-weight: 500; }
.app-user .role { padding: 3px 9px; border-radius: 6px; background: var(--page); font-size: 12px; }
.app-body { display: grid; grid-template-columns: 204px minmax(0, 1fr); min-height: calc(100vh - 68px); }
.app-nav { padding: 24px 14px; background: var(--nav); }
.app-nav a { display: block; padding: 11px 16px; border-radius: 8px; color: #c9d5e8; text-decoration: none; margin-bottom: 5px; font-size: 14px; transition: background-color .15s, color .15s; }
.app-nav a:hover { background: #233b5f; color: #fff; }
.app-nav a.active { background: #2b4e81; color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 #76a7ff; }
.app-nav .nav-group { margin: 22px 16px 9px; font-size: 11px; font-weight: 500; color: #95a9c5; letter-spacing: .06em; }
.app-nav .nav-group:first-child { margin-top: 0; }
.app-main { padding: 30px 32px 40px; min-width: 0; width: 100%; max-width: 1680px; margin: 0 auto; }
.demo-banner { margin-bottom: 16px; padding: 8px 12px; border-radius: 8px; background: var(--warning-soft); color: var(--warning); font-size: 13px; }
.view-switcher { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.view-switcher > span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.view-switcher select { min-height: 34px; max-width: 160px; padding: 5px 28px 5px 10px; border: 1px solid var(--line); border-radius: 7px; background: #f8faff; color: var(--text); font-size: 13px; cursor: pointer; }
.view-notice { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-bottom: 20px; padding: 12px 16px; border: 1px solid #d8e4fa; border-radius: 10px; background: var(--brand-soft); color: #526682; font-size: 12px; }
.view-notice strong { color: #284f95; font-size: 13px; font-weight: 600; }
.view-notice .button { margin-left: auto; }

/* 页面内容 */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px 24px; margin-bottom: 24px; }
.page-head > div:first-child { flex: 1 1 320px; min-width: 0; }
.page-head h1 { font-size: 24px; letter-spacing: -.02em; }
.page-head p { max-width: 880px; margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.75; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.toolbar select, .toolbar input { width: auto; min-width: 140px; max-width: 100%; }
.toolbar input[type="search"] { flex: 1 1 180px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card h2 { font-size: 17px; margin-bottom: 10px; }
.card-link { display: block; color: inherit; text-decoration: none; }
.card-link:hover { border-color: #c9ced8; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 13px; }
.prewrap { white-space: pre-wrap; word-break: break-word; }
.section-title { font-size: 16px; margin: 26px 0 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.back { display: inline-block; margin-bottom: 12px; text-decoration: none; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--page); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge-brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.empty-state { padding: 56px 24px; text-align: center; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.empty-state p { max-width: 560px; margin: 10px auto; }
.error-state p { color: var(--danger); }
.loading { padding: 32px; text-align: center; color: var(--muted); }

/* 表格：窄屏时变成卡片 */
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 13px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; font-size: 14px; line-height: 1.6; }
.table th { background: #f8faff; color: #52627a; font-weight: 500; font-size: 12px; white-space: nowrap; }
.table tbody tr:hover { background: #fbfcff; }
.table tr:last-child td { border-bottom: 0; }
.more { display: flex; justify-content: center; margin: 14px 0; }

/* 弹窗与提示 */
dialog { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); border: 1px solid var(--line); border-radius: 16px; padding: 0; color: var(--text); box-shadow: 0 24px 72px rgba(16, 30, 55, .2); }
dialog::backdrop { background: rgba(18, 32, 56, .4); }
.dialog-form { padding: 26px; }
.dialog-form h2 { font-size: 20px; margin-bottom: 22px; }
.dialog-body { max-height: 60vh; max-height: 60dvh; overflow: auto; padding: 3px 4px; margin: 0 -4px; overscroll-behavior: contain; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
#toast-region { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 10px; background: #1f2633; color: #fff; box-shadow: var(--shadow); }
.toast-error { background: var(--danger); }
.site-footer { text-align: center; font-size: 12px; padding: 12px; color: var(--muted); }
.site-footer a { color: var(--muted); }

@media (max-width: 760px) {
  .app-header { min-height: 58px; padding: 12px 16px; gap: 10px 12px; }
  .app-title { gap: 8px; font-size: 16px; }
  .app-title .brand-mark { width: 30px; height: 30px; border-radius: 9px; }
  .app-user { gap: 8px; margin-left: auto; }
  .app-user .role { display: none; }
  .view-switcher { gap: 5px; }
  .view-switcher > span { display: none; }
  .view-switcher select { min-height: 36px; max-width: 150px; font-size: 16px; }
  .view-notice { padding: 11px 12px; margin-bottom: 18px; gap: 5px 10px; }
  .view-notice > span { flex: 1 1 220px; }
  .app-body { display: block; }
  .app-nav { display: flex; gap: 6px; overflow-x: auto; padding: 10px 14px; border: 0; scrollbar-width: thin; scrollbar-color: #657c9f transparent; }
  .app-nav a { flex-shrink: 0; padding: 9px 14px; font-size: 13px; white-space: nowrap; margin: 0; }
  .app-nav a.active { box-shadow: none; background: #315b95; }
  .app-nav .nav-group { display: none; }
  .app-main { padding: 22px 16px max(28px, env(safe-area-inset-bottom)); }
  .page-head { gap: 14px; margin-bottom: 18px; }
  .page-head > div:first-child { flex-basis: 100%; }
  .page-head h1 { font-size: 21px; }
  .page-head p { margin-top: 6px; font-size: 12px; line-height: 1.75; }
  .toolbar { gap: 10px; padding: 12px; margin-bottom: 16px; }
  .toolbar select, .toolbar input { flex: 1 1 130px; min-width: 0; }
  .toolbar input[type="search"] { flex-basis: 100%; }
  .button { min-height: 42px; padding: 9px 14px; }
  .button-small { min-height: 34px; padding: 6px 11px; font-size: 12px; }
  .button-text { min-height: 34px; padding: 6px; }
  .card { padding: 18px; }
  .card h2 { font-size: 16px; }
  .login-card { padding: 28px 24px; }
  .login-status { font-size: 14px; }
  .field input[type], .field select, .field textarea { font-size: 16px; }
  .table { border: 0; background: transparent; overflow: visible; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 0; margin-bottom: 12px; background: var(--surface); }
  .table td { border: 0; padding: 5px 16px; overflow-wrap: anywhere; }
  .table td[data-label] { position: relative; padding-left: 100px; min-height: 32px; }
  .table td[data-label]::before { content: attr(data-label); position: absolute; left: 16px; top: 6px; width: 72px; color: var(--muted); font-size: 12px; font-weight: 400; text-align: left; }
  .table td.cell-num { text-align: left !important; }
  .table .cell-actions { white-space: normal; }
  .table .cell-actions .button { margin: 2px 2px 2px 0; }
  .table td.empty-cell { padding: 26px 16px !important; }
  .dialog-form { padding: 22px 18px; }
  .dialog-form h2 { font-size: 19px; margin-bottom: 18px; }
  .dialog-actions .button { flex: 1; }
}
fieldset.field { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
.toolbar a { text-decoration: none; }
.app-main:focus { outline: none; }
@media (max-width: 760px) { .table td[data-label]:empty { display: none; } }

/* ---------- 内部管理报表 ---------- */
.form-error { white-space: pre-line; }
dialog.dialog-wide { width: min(880px, calc(100vw - 32px)); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; align-items: start; }
.form-grid .field { align-content: start; }
.field input[type="date"], .field input[type="number"] {
  width: 100%; min-width: 0; min-height: 40px; padding: 8px 11px; border: 1px solid #d6dfeb; border-radius: 8px; font: inherit; color: inherit; background: #fff;
}
.field .field-error { color: var(--danger); font-size: 13px; }
.field.invalid input, .field.invalid select { border-color: var(--danger); background: var(--danger-soft); }
.field.warned input, .field.warned select { border-color: var(--warning); background: var(--warning-soft); }
.field.warned .field-error { color: var(--warning); }
.head-actions { margin-top: 0; align-items: center; }
.muted { color: var(--muted); }
.sub { color: var(--muted); font-size: 12px; line-height: 1.55; margin-top: 4px; word-break: break-word; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.num.neg { color: var(--danger); }
.num.zero { color: #98a2b3; }
.cell-num { text-align: right !important; }
.cell-actions { white-space: nowrap; }
.danger-text { color: var(--danger); }
.empty-cell { text-align: center !important; color: var(--muted); padding: 28px 12px !important; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
.notice { padding: 16px 18px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); margin-bottom: 18px; line-height: 1.7; }
.notice p { margin: 6px 0 0; }
.notice .actions { margin-top: 10px; }
.notice-error { background: var(--danger-soft); border-color: #f4c7c3; }
.notice-warning { background: var(--warning-soft); border-color: #f5d7b0; }
.notice-success { background: var(--success-soft); border-color: #b7e2c4; }
.issues .row-error td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.issues .row-warning td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; flex-shrink: 0; }
.segmented a { display: inline-flex; align-items: center; justify-content: center; padding: 8px 18px; min-height: 40px; color: var(--text); text-decoration: none; }
.segmented a.active { background: var(--brand); color: #fff; }
.empty-state h2 { color: var(--text); font-size: 18px; margin-bottom: 8px; }

/* 钉钉通讯录：筛选与成员列表 */
.directory-panel .page-head { margin-bottom: 18px; }
.directory-panel .page-head h2 { margin-bottom: 0; }
.directory-toolbar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; align-items: end; gap: 14px; }
.directory-toolbar .field { margin-bottom: 0; }
.directory-toolbar > .button { min-height: 40px; }
.directory-status { min-height: 22px; margin: 16px 0 0; overflow-wrap: anywhere; }
.directory-warning { margin: 12px 0; padding: 10px 12px; border: 1px solid #f5d7b0; border-radius: 8px; color: var(--warning); font-size: 13px; line-height: 1.65; overflow-wrap: anywhere; }
.directory-list { margin-top: 14px; }
.directory-person { display: flex; align-items: center; gap: 16px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.directory-person:first-child { border-top: 1px solid var(--line); }
.directory-person-info { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.directory-person-info strong { display: block; font-size: 14px; font-weight: 600; line-height: 1.5; }
.directory-person-info .hint { margin-top: 4px; font-size: 12px; }
.directory-person > .button { flex-shrink: 0; }
.directory-pagination { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

/* 汇总表：表头和前两列固定，单元格可点开看明细 */
.report-wrap { overflow: auto; max-height: calc(100vh - 260px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-top: 12px; overscroll-behavior-x: contain; }
.report { border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 100%; }
.report th, .report td { border-bottom: 1px solid var(--line); border-right: 1px solid #eef1f6; padding: 9px 12px; background: var(--surface); }
.report thead th { position: sticky; top: 0; z-index: 2; background: #edf2fa; color: #52627a; font-weight: 500; text-align: center; height: 40px; white-space: nowrap; }
.report thead tr.second th { top: 40px; }
.report .sticky { position: sticky; z-index: 1; text-align: left; }
.report thead .sticky { z-index: 3; }
.report .c1 { left: 0; min-width: 64px; width: 64px; color: var(--muted); font-weight: 400; }
.report .c2 { left: 64px; min-width: 220px; font-weight: 400; box-shadow: 1px 0 0 var(--line); }
.report td.cell-num { min-width: 112px; }
.report tr.line-group th, .report tr.line-calc th, .report tr.line-group td, .report tr.line-calc td { font-weight: 600; }
.report tr.depth-0 th, .report tr.depth-0 td { background: #f8faff; }
.report tr.line-calc th, .report tr.line-calc td { background: #fffaf2; }
.report tr.line-audit th, .report tr.line-audit td { background: #fafbfc; }
.report .cell-audit { text-align: center; white-space: nowrap; }
.report .indent { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.report .indent-1 { padding-left: 14px; }
.report .indent-2 { padding-left: 28px; }
.report .indent-3 { padding-left: 42px; }
.report .indent-4 { padding-left: 56px; }
.toggle { border: 0; background: none; color: var(--brand); cursor: pointer; width: 20px; min-height: 24px; flex-shrink: 0; padding: 0; font: inherit; }
.toggle-space { display: inline-block; width: 18px; }
.cell-link { border: 0; background: none; padding: 0; font: inherit; cursor: pointer; color: inherit; }
.cell-link:hover .num, .cell-link:focus-visible .num { text-decoration: underline; color: var(--brand); }

@media (max-width: 760px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .field input[type="date"], .field input[type="number"] { font-size: 16px; }
  .head-actions { width: 100%; }
  .head-actions .button-primary { flex: 1; }
  .directory-toolbar { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .directory-toolbar > .button { width: 100%; min-height: 42px; }
  .directory-person { gap: 12px; padding: 14px 0; }
  .directory-person > .button { min-height: 38px; }
  .report-wrap { max-height: none; }
  .report .c1 { display: none; }
  .report .c2 { left: 0; min-width: 164px; width: 164px; max-width: 164px; }
  .report .indent { white-space: normal; line-height: 1.5; }
  .report th, .report td { padding: 9px; }
  .report .indent-1 { padding-left: 8px; }
  .report .indent-2 { padding-left: 16px; }
  .report .indent-3 { padding-left: 24px; }
  .report .indent-4 { padding-left: 32px; }
  .table-wrap { overflow-x: visible; }
}

@media (prefers-reduced-motion: reduce) {
  .button, .app-nav a { transition: none; }
}

@media (max-width: 480px) {
  .app-user { flex-basis: 100%; }
  .app-user strong { margin-right: auto; overflow: hidden; text-overflow: ellipsis; max-width: 120px; white-space: nowrap; }
  .view-switcher select { max-width: 144px; }
  .view-notice .button { margin-left: 0; }
}
