:root {
  --primary: #1e3a8a; --primary-600: #1d4ed8; --primary-50: #eef2ff;
  --bg: #f5f6f8; --card: #fff; --line: #e4e7ec; --line-2: #eef0f3;
  --text: #1f2937; --muted: #6b7280; --faint: #9ca3af;
  --green: #15803d; --green-bg: #dcfce7; --yellow: #a16207; --yellow-bg: #fef3c7;
  --red: #b91c1c; --red-bg: #fee2e2; --gray-bg: #f1f2f4; --blue-bg: #dbeafe; --blue: #1d4ed8;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.05); --shadow-lg: 0 8px 30px rgba(16,24,40,.14);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Microsoft YaHei", "PingFang SC", sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-600); }

/* ---- 登入 ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 28px; }
.login-card h1 { font-size: 18px; margin: 10px 0 2px; }
.login-card .sub { color: var(--muted); margin-bottom: 18px; }
.login-card .brand-logo { margin: 14px 4px 16px; padding: 0; }
.login-card .demo { margin-top: 18px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line-2); padding-top: 12px; }
.login-card .demo code { background: var(--gray-bg); padding: 1px 5px; border-radius: 4px; }
.login-card .lang-switch { float: right; }

/* ---- 版型 ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; flex: 0 0 220px; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 12px; border-bottom: 1px solid var(--line-2); }
.brand-logo { padding: 6px 4px; }
.brand-logo img { display: block; width: 100%; height: auto; }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; background: #000; display: grid; place-items: center; flex: none; overflow: hidden; }
.brand-mark svg { width: 70%; height: 70%; }
.nav { padding: 10px 8px; flex: 1; overflow: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--text); text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: var(--gray-bg); }
.nav a.active { background: var(--primary-50); color: var(--primary); font-weight: 600; }
.nav a svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav .badge { margin-left: auto; background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; line-height: 18px; font-weight: 600; }
.user-box { border-top: 1px solid var(--line-2); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-50); color: var(--primary); display: grid; place-items: center; font-weight: 600; flex: none; }
.user-box .who { flex: 1; min-width: 0; }
.user-box .who div:first-child { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box .who div:last-child { color: var(--muted); font-size: 12px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h2 { margin: 0; font-size: 18px; flex: 1; }
.btn.menu-btn { display: none; }
.content { padding: 20px 24px 40px; }

/* ---- 按钮 / 输入 ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--gray-bg); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1b347c; }
.btn.danger { color: var(--red); }
.btn.danger.solid { background: var(--red); color: #fff; border-color: var(--red); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.lang-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.lang-switch button { border: 0; background: #fff; padding: 4px 9px; cursor: pointer; font-size: 12px; }
.lang-switch button.on { background: var(--primary); color: #fff; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=month], input[type=tel], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary-600); box-shadow: 0 0 0 3px rgba(29,78,216,.12); }
.invalid { border-color: var(--red) !important; }
textarea { resize: vertical; min-height: 70px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
label.field > span .req { color: var(--red); margin-left: 2px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.check { display: flex; align-items: center; gap: 8px; padding: 6px 0; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

/* ---- 工具列 ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .search { flex: 1 1 200px; max-width: 280px; }
.toolbar select { width: auto; min-width: 120px; }
.toolbar .spacer { flex: 1; }
.bulkbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--primary-50); border: 1px solid #c7d2fe; border-radius: 6px; padding: 8px 12px; margin-bottom: 12px; }
.bulkbar select { width: auto; }
.menu-wrap { position: relative; }
.dropdown { position: absolute; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow-lg); min-width: 150px; z-index: 20; padding: 4px; }
.dropdown button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 4px; cursor: pointer; }
.dropdown button:hover { background: var(--gray-bg); }

/* ---- 统计卡 ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat { padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--faint); font-size: 12px; }
.stat.alert .value { color: var(--red); }
.stat.click { cursor: pointer; }
.stat.click:hover { border-color: #c7d2fe; }
.section { margin-bottom: 18px; }
.section-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.section-head h3 { margin: 0; font-size: 14px; }
.section-body { padding: 14px 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.hint { color: var(--muted); font-size: 12px; }
.note-box { background: var(--yellow-bg); color: #713f12; border-radius: 6px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }
.info-box { background: var(--primary-50); color: var(--primary); border-radius: 6px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }

/* ---- 表格 ---- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 0; user-select: none; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); }
th .arrow { font-size: 10px; margin-left: 3px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f8fafc; }
tbody tr.sel { background: var(--primary-50); }
tbody tr.overdue td:first-child, tbody tr.overdue td.first { box-shadow: inset 3px 0 0 var(--red); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .main-line { font-weight: 550; }
td .sub-line { color: var(--muted); font-size: 12px; }
td.cb, th.cb { width: 36px; padding-right: 0; }
td.cb input, th.cb input { width: 16px; height: 16px; accent-color: var(--primary); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { margin: 0 0 12px; }
.more { text-align: center; padding: 12px; }
.red-text { color: var(--red); font-weight: 600; }
.green-text { color: var(--green); }

/* ---- 标签 ---- */
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 550; line-height: 20px; }
.tag.green { background: var(--green-bg); color: var(--green); }
.tag.yellow { background: var(--yellow-bg); color: var(--yellow); }
.tag.red { background: var(--red-bg); color: var(--red); }
.tag.gray { background: var(--gray-bg); color: var(--muted); }
.tag.blue { background: var(--blue-bg); color: var(--blue); }
.docs-dots { display: inline-flex; gap: 3px; }
.docs-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; }
.docs-dots i.no { background: #fca5a5; }

/* ---- 右边面板 ---- */
.panel-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.12); z-index: 30; }
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: 440px; max-width: 100%; background: #fff; box-shadow: var(--shadow-lg); z-index: 31; display: flex; flex-direction: column; transform: translateX(100%); transition: transform .18s ease; }
.panel.open { transform: none; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-head .back { display: none; }
.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 10px 6px; margin-right: 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.panel-body { flex: 1; overflow: auto; padding: 16px 18px; }
.panel-foot { border-top: 1px solid var(--line); padding: 12px 18px; display: flex; gap: 8px; justify-content: flex-end; background: #fff; }
.panel-foot .left { margin-right: auto; }
.group-title { font-size: 12px; font-weight: 600; color: var(--primary); text-transform: uppercase; letter-spacing: .02em; margin: 6px 0 10px; }
.readonly-val { padding: 7px 0; }
.call-box { border: 1px solid #c7d2fe; background: #f8faff; border-radius: 8px; padding: 12px; margin-bottom: 16px; }
.result-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.result-btns button { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 8px; cursor: pointer; }
.result-btns button.on { border-color: var(--primary); background: var(--primary); color: #fff; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--line-2); margin-left: 5px; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--faint); }
.timeline li.call::before { border-color: var(--primary-600); }
.timeline li.note::before { border-color: var(--yellow); }
.timeline .meta { font-size: 12px; color: var(--muted); }
.note-add { display: flex; gap: 8px; margin-bottom: 16px; }
.tpl-text { white-space: pre-wrap; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; padding: 12px; font-size: 13px; }

/* ---- 确认框 / 提示 ---- */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 10px; box-shadow: var(--shadow-lg); width: 100%; max-width: 380px; padding: 20px; }
.modal p { margin: 0 0 16px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; }
#toasts { position: fixed; top: 14px; right: 14px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 9px 14px; border-radius: 6px; box-shadow: var(--shadow-lg); font-size: 13px; animation: tin .15s ease; }
.toast.err { background: var(--red); }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } }

/* ---- 图表 ---- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.chart .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.bar-list .bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.bar-list .bar-row .lbl { width: 110px; flex: none; }
.bar-list .bar-row .track { flex: 1; height: 10px; background: var(--gray-bg); border-radius: 5px; overflow: hidden; }
.bar-list .bar-row .fill { height: 100%; background: var(--primary); border-radius: 5px; }
.bar-list .bar-row .n { width: 30px; text-align: right; font-variant-numeric: tabular-nums; }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.mini-list li:last-child { border-bottom: 0; }
.mini-list li:hover .t { color: var(--primary-600); }
.edit-table td, .edit-table th { padding: 5px 6px; }
.edit-table input, .edit-table select { padding: 5px 7px; }
.edit-table tbody tr { cursor: default; }
.edit-table tbody tr:hover { background: none; }

/* ---- 手机 ---- */
@media (max-width: 860px) {
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow-lg); }
  .layout.nav-open .sidebar { transform: none; }
  .layout.nav-open::after { content: ''; position: fixed; inset: 0; background: rgba(15,23,42,.3); z-index: 35; }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .topbar h2 { font-size: 16px; }
  .content { padding: 14px 16px 32px; }
  .toolbar .search { max-width: none; flex-basis: 100%; }
  .panel { width: 100%; }
  .panel-head .back { display: inline-flex; }
  .panel-head .x { display: none; }
  .row2 { grid-template-columns: 1fr; }
  .table-wrap.cards-mobile { background: none; border: 0; box-shadow: none; }
  .cards-mobile table, .cards-mobile tbody, .cards-mobile tr, .cards-mobile td { display: block; width: 100%; }
  .cards-mobile thead { display: none; }
  .cards-mobile tr { background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; padding: 8px 12px; position: relative; }
  .cards-mobile td { border: 0; padding: 3px 0; white-space: normal; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .cards-mobile td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; }
  .cards-mobile td.first { display: block; text-align: left; font-size: 15px; padding-bottom: 6px; border-bottom: 1px solid var(--line-2); margin-bottom: 4px; }
  .cards-mobile td.first::before { content: none; }
  .cards-mobile td.cb { position: absolute; right: 10px; top: 10px; width: auto; display: block; }
  .cards-mobile td.cb::before { content: none; }
  .cards-mobile td.num { text-align: right; }
}

/* 文件附件 */
.doc-row { border-bottom: 1px solid var(--line-2); padding: 2px 0 6px; }
.doc-row:last-of-type { border-bottom: 0; }
.doc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.doc-files { display: flex; flex-direction: column; gap: 4px; margin: 2px 0 4px 24px; }
.doc-file { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.doc-file a { color: var(--primary); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 0 1 auto; }
.doc-file a:hover { text-decoration: underline; }
.doc-file .sub-line { white-space: nowrap; flex-shrink: 0; }
.doc-file .btn { margin-left: auto; }
