:root {
  --bg: #f4f6f9;
  --card: #fff;
  --text: #1f2933;
  --muted: #6b7785;
  --border: #e1e6ec;
  --primary: #1f6feb;
  --primary-dark: #1859bd;
  --danger: #d1343a;
  --ok: #1a8f4c;
  --warn: #c77700;
  --radius: 8px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
input, select, textarea {
  font: inherit; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: inherit; max-width: 100%;
}
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd4fb; border-color: var(--primary); }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 56px;
  background: #13233a; color: #dfe7f1; position: sticky; top: 0; z-index: 10;
}
.topbar a { color: #dfe7f1; }
.brand { font-weight: 600; font-size: 16px; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 6px; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.16); color: #fff; }
.user-menu { display: flex; align-items: center; gap: 14px; white-space: nowrap; }
.user-menu .muted { color: #aebbc9; }
.user-menu .link { color: #dfe7f1; }

.container { max-width: 1280px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.card.narrow { max-width: 480px; margin: 24px auto; }
.card.narrow label, .login-box label { display: block; margin-bottom: 12px; }
.card.narrow label input:not([type=checkbox]), .card.narrow label select,
.login-box label input:not([type=checkbox]) { display: block; width: 100%; margin-top: 4px; }
.login-box { max-width: 380px; margin: 12vh auto; padding: 32px; }
.login-box h1 { margin-bottom: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .card { margin-bottom: 16px; }

/* 按钮 */
.btn {
  display: inline-block; padding: 6px 14px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--text); cursor: pointer; font: inherit; white-space: nowrap;
}
.btn:hover { background: #f0f3f7; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f0c4c6; }
.btn.block { width: 100%; padding: 9px; }
button.link { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; }
.danger, button.link.danger { color: var(--danger); }
form.inline { display: inline; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.alert-success { background: #e9f7ef; border-color: #b6e2c6; color: #155d35; }
.alert-danger { background: #fdecec; border-color: #f3c0c2; color: #9b1c21; }
.alert-warning { background: #fff6e5; border-color: #f4d9a4; color: #7a4a00; }
.alert-info { background: #eaf2fe; border-color: #c2d8fb; color: #174a99; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 16px 0; margin: 0; }
.ml-auto { margin-left: auto; }
.more { display: inline-block; margin-top: 8px; }

/* 徽标 */
.badge {
  display: inline-block; padding: 0 8px; border-radius: 10px; font-size: 12px; line-height: 20px;
  background: #eef1f5; color: #46525e; font-weight: normal; margin-left: 4px; vertical-align: middle;
}
.badge.status-planned { background: #eef1f5; color: #46525e; }
.badge.status-in_progress, .badge.visit-scheduled { background: #e3eefe; color: #1859bd; }
.badge.status-paused { background: #fff3dc; color: #8a5300; }
.badge.status-done, .badge.visit-done { background: #e2f5ea; color: #1a7440; }
.badge.visit-cancelled { background: #f1f1f1; color: #888; text-decoration: line-through; }
.badge.overdue { background: #fde4e4; color: var(--danger); }
.badge.role-admin { background: #f4e4fb; color: #7a2d9c; }
.badge.role-supervisor { background: #fff0d6; color: #8a5300; }
.badge.role-member { background: #e3eefe; color: #1859bd; }

/* 统计卡片 */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; color: var(--text); }
.stat:hover { text-decoration: none; border-color: #b9c7d8; }
.stat b { display: block; font-size: 26px; line-height: 1.2; }
.stat span { color: var(--muted); }
.stat.warn b { color: var(--danger); }

/* 表格 */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 13px; background: #fafbfc; }
.table tbody tr:hover { background: #fafcff; }
tr.disabled td { color: #a0a9b3; }

/* 进度条 */
.progress { position: relative; height: 18px; background: #edf1f5; border-radius: 9px; overflow: hidden; min-width: 100px; }
.progress div { height: 100%; background: linear-gradient(90deg, #4f8ff7, #1f6feb); }
.progress span { position: absolute; inset: 0; text-align: center; font-size: 12px; line-height: 18px; color: #1d2733; }
.big-progress .progress { height: 26px; border-radius: 13px; margin: 8px 0 16px; }
.big-progress .progress span { line-height: 26px; font-size: 13px; font-weight: 600; }

/* 表单 */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 16px; }
.filters input[name=q] { min-width: 260px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; margin-bottom: 20px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; color: #3d4954; }
.form-grid .span-2 { grid-column: span 2; }
.row-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-form .grow { flex: 1; min-width: 160px; }
.sub-form { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
label.check { display: flex; align-items: center; gap: 6px; }

dl.info { display: grid; grid-template-columns: 96px 1fr; gap: 6px 12px; margin: 0; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; }
.desc { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); white-space: pre-wrap; }

/* 列表 */
ul.list { list-style: none; margin: 0; padding: 0; }
ul.list li { padding: 10px 0; border-bottom: 1px solid var(--border); }
ul.list li:last-child { border-bottom: 0; }
.clip { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: pre-wrap; }

/* 日志 */
.log-form { background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 16px; }
.log-form textarea { margin-bottom: 8px; }
.file-input { position: relative; overflow: hidden; cursor: pointer; padding: 6px 12px; border: 1px dashed #9db6d8; border-radius: 6px; color: var(--primary); background: #fff; }
.file-input input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.log { border-bottom: 1px solid var(--border); padding: 14px 0; }
.log:last-child { border-bottom: 0; }
.log header { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.log-content { white-space: pre-wrap; word-break: break-word; }
.gallery { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.gallery img { width: 140px; height: 105px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background: #f0f2f5; }
.gallery img:hover { border-color: var(--primary); }
ul.files { list-style: none; padding: 0; margin: 10px 0 0; }
ul.files li { display: flex; gap: 10px; align-items: center; padding: 4px 0; }

/* 日历 */
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav b { min-width: 110px; text-align: center; font-size: 16px; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); padding: 0; overflow: hidden; }
.cal-head { padding: 8px; text-align: center; background: #fafbfc; color: var(--muted); border-bottom: 1px solid var(--border); }
.cal-day { min-height: 110px; padding: 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day.other { background: #fafbfc; color: #aab3bd; }
.cal-day.today .cal-date { background: var(--primary); color: #fff; border-radius: 50%; width: 24px; text-align: center; }
.cal-date { font-size: 13px; margin-bottom: 4px; height: 24px; line-height: 24px; }
.cal-item {
  display: block; font-size: 12px; padding: 2px 6px; margin-bottom: 3px; border-radius: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: #e3eefe; color: #174a99;
}
.cal-item.visit-done { background: #e2f5ea; color: #1a7440; }
.cal-item.visit-cancelled { background: #f1f1f1; color: #999; text-decoration: line-through; }
.cal-item:hover { text-decoration: none; filter: brightness(.95); }

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 8px 16px; }
  .container { padding: 16px; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .card { overflow-x: auto; }
  .cal-day { min-height: 70px; }
  .cal-item { font-size: 11px; padding: 1px 3px; }
}
