:root {
  --primary: #0e7c66;
  --primary-dark: #0a5c4b;
  --primary-soft: #e3f2ee;
  --accent: #e8993a;
  --accent-soft: #fdf1e1;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1f2d2a;
  --muted: #6b7a76;
  --border: #e3e9e7;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --shadow: 0 6px 24px rgba(14, 60, 50, 0.08);
  --shadow-lg: 0 12px 40px rgba(14, 60, 50, 0.14);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 10px; cursor: pointer;
  font-size: 14px; font-weight: 600; font-family: inherit;
  padding: 10px 18px; transition: all 0.18s ease;
  white-space: nowrap;
}
.btn:focus-visible { outline: 3px solid rgba(14,124,102,0.35); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-soft); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(14,124,102,0.08); color: var(--primary-dark); }
.btn-sm { padding: 4px 12px; font-size: 12px; white-space: nowrap; }
.pagination { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.pagination button { padding: 4px 12px; font-size: 13px; border: 1.5px solid var(--border); background: #fff; color: var(--text); border-radius: 8px; cursor: pointer; }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination .pg-info { font-size: 13px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.record-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; }
.record-table th, .record-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 13px; }
.record-table th { background: #f7f8fa; color: var(--muted); font-weight: 600; white-space: nowrap; }
.record-table tbody tr { cursor: pointer; }
.record-table tbody tr:hover { background: #fafbfc; }
.record-table .cell-img img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
.record-table .cell-content { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-table .nowrap { white-space: nowrap; }
.record-table .no-photo-sm { color: var(--muted); font-size: 12px; }
.btn-danger { background: #fff; color: var(--danger); border: 1.5px solid var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- 输入框 ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.field label .req { color: var(--danger); }
.input, .textarea, select.input {
  width: 100%; padding: 11px 13px; font-size: 14px; font-family: inherit;
  border: 1.5px solid var(--border); border-radius: 10px;
  background: #fff; color: var(--text); transition: border 0.15s, box-shadow 0.15s;
}
.input:focus, .textarea:focus, select.input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,124,102,0.12);
}
.textarea { min-height: 110px; resize: vertical; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- 提示条 ---------- */
.alert { padding: 10px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid #f2c3c3; }
.alert-success { background: #e5f7ee; color: var(--primary-dark); border: 1px solid #b9e6cf; }

/* 查重提示 */
.dup-panel { margin-top: 8px; }
.dup-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; margin-bottom: 8px;
  background: var(--accent-soft); border: 1px solid #f0d5ad;
  border-radius: 10px; font-size: 13px;
}
.dup-item .badge {
  flex-shrink: 0; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px;
}
.dup-item .meta { color: var(--muted); margin-top: 2px; }
/* 可正常拜访（已达间隔）样式 */
.dup-item.dup-ok {
  background: #e8f6ee; border-color: #b9e6cf;
}
.dup-item.dup-ok .badge { background: var(--primary); }
/* 未达间隔，无法选择样式 */
.dup-item.dup-block {
  background: #fdecec; border-color: #f3b6b6;
}
.dup-item.dup-block .badge { background: var(--danger); }

/* ---------- 卡片 ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }

/* ---------- 顶部导航 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,0.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 20px;
  height: 62px; display: flex; align-items: center; gap: 22px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; color: var(--primary-dark); }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.nav { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  border: none; background: transparent; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; font-family: inherit; transition: all 0.15s;
}
.nav-btn:hover { background: var(--primary-soft); color: var(--primary-dark); }
.nav-btn.active { background: var(--primary); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.user-menu { position: relative; }
.user-chip .caret { font-size: 10px; color: var(--muted); transition: transform .15s; }
.user-menu.open .caret { transform: rotate(180deg); }
.user-dropdown { position: absolute; right: 0; top: calc(100% + 6px); min-width: 130px; background: #fff; border: 1px solid var(--border, #e4e7ec); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); overflow: hidden; z-index: 60; }
.user-dropdown .dd-item { display: block; width: 100%; padding: 10px 14px; text-align: left; background: none; border: none; font-size: 14px; color: var(--text); cursor: pointer; }
.user-dropdown .dd-item:hover { background: #f5f6f7; }
.user-dropdown .dd-item.danger { color: var(--danger); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700;
}

/* ---------- 主布局 ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 26px 20px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.page-sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; }

/* ---------- 看板统计卡 ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.stat-card .num { font-size: 30px; font-weight: 800; color: var(--primary-dark); }
.stat-card .lbl { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ---------- 记录列表 ---------- */
.records-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.records-head .search { flex: 1; min-width: 200px; position: relative; }
.toolbar { display: flex; gap: 10px; margin-left: auto; align-items: center; }
.search-bar { display: flex; gap: 8px; flex-wrap: nowrap; align-items: center; flex: 1; min-width: 0; background: #f3f5f7; border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.export-clear { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.export-clear input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.seg { display: inline-flex; background: #e7ecea; border-radius: 9px; padding: 3px; }
.seg button { border: none; background: transparent; padding: 6px 14px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit; }
.seg button.active { background: #fff; color: var(--primary-dark); box-shadow: 0 1px 4px rgba(0,0,0,0.08); }

.record-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.record-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; transition: transform 0.18s, box-shadow 0.18s; cursor: pointer;
}
.record-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.record-thumb { height: 150px; background: var(--primary-soft); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.record-thumb img { width: 100%; height: 100%; object-fit: cover; }
.record-thumb .no-photo { color: var(--primary); font-size: 40px; opacity: 0.5; }
.record-body { padding: 14px 16px; }
.record-body .org { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.tag-pharmacy { background: var(--primary-soft); color: var(--primary-dark); }
.tag-clinic { background: var(--accent-soft); color: #a85c14; }
.record-body .meta { color: var(--muted); font-size: 13px; margin-top: 6px; }
.record-body .preview { color: var(--text); font-size: 13px; margin-top: 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.record-body .who { font-size: 12px; color: var(--muted); margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .icon { font-size: 44px; opacity: 0.35; margin-bottom: 12px; }

/* ---------- 模态框 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,30,26,0.5); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-mask.show { opacity: 1; pointer-events: auto; }
.modal {
  background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  padding: 26px; transform: translateY(12px); transition: transform 0.2s;
}
.modal-mask.show .modal { transform: translateY(0); }
.modal h3 { font-size: 19px; font-weight: 800; margin-bottom: 18px; }
.modal-close { float: right; border: none; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); }

/* ---------- 登录页 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0a5c4b 0%, #0e7c66 55%, #12997e 100%); padding: 20px; }
.login-card { width: 100%; max-width: 400px; }
.login-logo { display: flex; flex-direction: column; align-items: center; margin-bottom: 22px; color: #fff; }
.login-logo .logo {
  width: 62px; height: 62px; border-radius: 18px; background: #fff; color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center; font-size: 34px; margin-bottom: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.login-logo h1 { font-size: 20px; font-weight: 800; }
.login-logo p { font-size: 13px; opacity: 0.85; }

/* ---------- 统计页 ---------- */
.rank-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.rank-row:last-child { border-bottom: none; }
.rank-row .rank { width: 26px; height: 26px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.rank-row .rank.top { background: var(--primary); color: #fff; }
.rank-row .bar { height: 8px; border-radius: 6px; background: var(--primary); opacity: 0.85; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.section-title { font-size: 16px; font-weight: 800; margin: 26px 0 12px; }

/* ---------- 详情 ---------- */
.detail-photo { width: 100%; max-height: 360px; object-fit: contain; border-radius: 12px; background: #f0f4f2; margin-bottom: 16px; }
.detail-row { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.detail-row .k { color: var(--muted); width: 90px; flex-shrink: 0; }

/* ---------- 用户管理 ---------- */
.user-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.user-row .role-pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.role-pill.admin { background: var(--accent-soft); color: #a85c14; }
.role-pill.user { background: var(--primary-soft); color: var(--primary-dark); }
.role-pill.pharmacy { background: #e8f1fd; color: #1d5fa8; } /* 药店 */
.role-pill.clinic { background: #e8f6ee; color: #1e7d52; } /* 诊所 */

/* ---------- 可搜索下拉 ---------- */
.combobox { position: relative; }
.combobox-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 30;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  max-height: 240px; overflow-y: auto; box-shadow: var(--shadow-lg);
  display: none; margin-top: 4px;
}
.combobox-list .opt { padding: 9px 12px; cursor: pointer; font-size: 14px; }
.combobox-list .opt:hover, .combobox-list .opt.active { background: var(--primary-soft); }
.combobox-list .opt .sub { color: var(--muted); font-size: 12px; }
.combobox-list .opt-empty { padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }

/* 任务进度条 */
.progress { height: 10px; background: #eef0f3; border-radius: 5px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 5px; transition: width .3s; }
.progress-fill.done { background: #1e9e5a; }

/* 批量选择 */
.batch-bar { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; flex-wrap: wrap; }
.check-col { width: 30px; flex-shrink: 0; }
.org-check { display: flex; align-items: center; cursor: pointer; }
.org-check input { width: 17px; height: 17px; cursor: pointer; accent-color: var(--primary); }

/* ---------- 照片上传 ---------- */
.photo-upload {
  border: 2px dashed var(--border); border-radius: 12px; padding: 16px;
  text-align: center; color: var(--muted); cursor: pointer; transition: border 0.15s, background 0.15s;
}
.photo-upload:hover { border-color: var(--primary); background: var(--primary-soft); }
.photo-preview { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.photo-preview img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; border: 2px solid var(--border); }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--primary-dark); color: #fff; padding: 12px 22px; border-radius: 10px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: all 0.25s; z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .topbar-inner { padding: 0 14px; gap: 10px; }
  .brand span.text { display: none; }
  .nav { overflow-x: auto; }
  .nav-btn { padding: 8px 10px; font-size: 13px; }
  .container { padding: 18px 14px 60px; }
}

/* ---------- 移动端适配 ---------- */
@media (max-width: 600px) {
  html, body { max-width: 100vw; overflow-x: hidden; }
  .container { max-width: 100%; padding: 16px 12px 60px; }
  .modal-mask { padding: 12px; }
  .modal {
    max-width: 92vw;
    width: 92%;
    max-height: 90vh;
    max-height: 90dvh;
    -webkit-overflow-scrolling: touch;
  }
}
