:root {
  --bg: #f6f3ec;
  --card: #ffffff;
  --ink: #3a3328;
  --muted: #8a8172;
  --line: #e6e0d3;
  --accent: #8c6a3f;
  --accent-dark: #6f5230;
  --accent-soft: #efe6d6;
  --green: #4a7c59;
  --red: #b04a3e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: linear-gradient(135deg, #6f5230, #8c6a3f);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .logo { font-size: 22px; }
.brand .title { font-size: 18px; font-weight: 700; letter-spacing: 1px; }
.brand .subtitle { font-size: 12px; opacity: .8; }

.tabs { display: flex; gap: 6px; }
.tab {
  border: none;
  background: transparent;
  color: rgba(255,255,255,.8);
  padding: 8px 18px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
  transition: all .15s;
}
.tab:hover { background: rgba(255,255,255,.15); }
.tab.active { background: #fff; color: var(--accent-dark); font-weight: 600; }

.container { max-width: 1100px; margin: 24px auto; padding: 0 20px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* 卡片 */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.card h3 { margin: 0 0 12px; font-size: 15px; color: var(--accent-dark); }

/* 工具栏 */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
}
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.filters input {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
}
.filters input[type="text"] { width: 150px; }
.filters input[type="date"] { width: 140px; }
.sep { color: var(--muted); }
.export-btns { display: flex; gap: 8px; }

/* 按钮 */
.btn {
  padding: 8px 16px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
}
.btn:hover { background: var(--accent-dark); }
.btn.primary { background: var(--green); border-color: var(--green); }
.btn.primary:hover { background: #3d6a4a; }
.btn.ghost {
  background: #fff;
  color: var(--accent);
  border-color: var(--line);
}
.btn.ghost:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn.danger { background: #fff; color: var(--red); border-color: var(--line); }
.btn.danger:hover { background: #fbeae8; border-color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* 表格 */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.data-table th, .data-table td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.data-table th {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 600;
  white-space: nowrap;
}
.data-table tbody tr:hover { background: #faf7ef; }
.data-table td { vertical-align: top; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  background: #eef2ee;
  color: var(--green);
}
.tag.followup { background: #fdf1e7; color: var(--accent); }
.tag.photo { background: #e9eef7; color: #4a6c9b; }
.tag.warn { background: #fbeae8; color: var(--red); }
.cell-note { color: var(--muted); font-size: 12px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
  font-size: 14px;
}

/* 表单 */
.entry-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.entry-head h2 { margin: 0; font-size: 18px; color: var(--accent-dark); }
.entry-mode { color: var(--muted); font-size: 13px; }

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 5px; font-size: 13px; color: var(--accent-dark); font-weight: 500; }
.field label .req { color: var(--red); }
.field input[type="text"], .field input[type="date"], .field input[type="number"],
.field select, .field textarea, .patient-pick select {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.field textarea { resize: vertical; }
.field.inline { display: flex; align-items: flex-end; }
.checkbox { display: flex; align-items: center; gap: 6px; cursor: pointer; font-weight: normal; color: var(--ink); margin-bottom: 9px; }
.checkbox input { width: auto; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
.span2 { grid-column: span 2; }
@media (max-width: 760px) { .grid2, .grid3 { grid-template-columns: 1fr; } .span2 { grid-column: auto; } }

.patient-pick { display: flex; align-items: center; gap: 12px; }
.patient-pick label { font-weight: 600; color: var(--accent-dark); white-space: nowrap; }

/* 上传区 */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
  background: #faf9f5;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.photo-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.photo-item { position: relative; }
.photo-item img { width: 110px; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.photo-item .del {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--red); color: #fff; border: none; cursor: pointer; font-size: 13px; line-height: 1;
}
.actions { display: flex; gap: 10px; margin-top: 8px; }

/* 统计 */
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; text-align: center; }
.stat-card .num { font-size: 32px; font-weight: 700; color: var(--accent); }
.stat-card .label { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stat-cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .stat-cols, .stat-cards { grid-template-columns: 1fr; } }

.stat-list { list-style: none; padding: 0; margin: 0; }
.stat-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.stat-list li .bar-wrap { flex: 1; margin-left: 12px; height: 8px; background: #f0ebe0; border-radius: 4px; overflow: hidden; }
.stat-list li .bar { height: 100%; background: linear-gradient(90deg, #a8814f, #8c6a3f); border-radius: 4px; }
.stat-list li .cnt { width: 32px; text-align: right; color: var(--muted); }
.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-chart .row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.bar-chart .row .m { width: 56px; color: var(--muted); }
.bar-chart .row .b { flex: 1; height: 16px; background: var(--accent-soft); border-radius: 4px; overflow: hidden; }
.bar-chart .row .b i { display: block; height: 100%; background: var(--green); }
.bar-chart .row .v { width: 24px; text-align: right; color: var(--muted); }

/* 弹窗 */
.modal {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 100;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 40px 20px;
}
.modal.show { display: flex; }
.modal-box {
  background: #fff; border-radius: 14px; padding: 22px 24px;
  width: 520px; max-width: 100%;
  box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
.modal-box.wide { width: 720px; }
.modal-box h3 { margin: 0 0 16px; color: var(--accent-dark); }

/* 详情打印区 */
.detail-block { margin-bottom: 14px; }
.detail-block .k { font-weight: 600; color: var(--accent-dark); margin-bottom: 4px; }
.detail-block .v { white-space: pre-wrap; }
.detail-photos { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.detail-photos img { width: 160px; height: 160px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

/* 提示 */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: #3a3328; color: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 200;
}
.toast.show { opacity: 1; }

/* 用户框 */
.userbox { display: flex; align-items: center; gap: 8px; }
.user-name { color: rgba(255,255,255,.95); font-size: 13px; margin-right: 4px; }
.userbox .btn { color: #fff; border-color: rgba(255,255,255,.4); background: transparent; }
.userbox .btn:hover { background: rgba(255,255,255,.15); border-color: #fff; }

/* 登录覆盖层 */
.login-overlay {
  display: none;
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #6f5230, #8c6a3f);
  z-index: 300;
  align-items: center; justify-content: center;
}
.login-overlay.show { display: flex; }
.login-box {
  background: #fff; border-radius: 16px; padding: 36px 34px;
  width: 360px; max-width: 92%;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.login-brand { text-align: center; font-size: 20px; font-weight: 700; color: var(--accent-dark); margin-bottom: 6px; }
.login-brand .logo { font-size: 24px; }
.login-tip { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.login-box input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; margin-bottom: 12px; font-family: inherit;
}
.login-btn { width: 100%; margin-bottom: 8px; padding: 11px; font-size: 15px; }
.login-switch { text-align: center; margin-top: 10px; }
.login-switch a { color: var(--accent); font-size: 13px; }

/* 患者档案 */
.profile-visit {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 14px; background: #fcfaf5;
}
.pv-head { font-weight: 700; color: var(--accent-dark); margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }

/* 打印 */
@media print {
  .topbar, .toolbar, .actions, .no-print, .modal-box > .actions, .userbox, .login-overlay { display: none !important; }
  body { background: #fff; }
  .modal { position: static; display: block; padding: 0; background: #fff; overflow: visible; }
  .modal-box { width: 100%; box-shadow: none; padding: 0; }
  .profile-visit { break-inside: avoid; }
  .detail-photos img { width: 120px; height: 120px; }
}

/* 登录 tab 切换 */
.login-tabs {
  display: flex;
  gap: 4px;
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 18px;
}
.login-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--accent-dark);
  padding: 8px 0;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
  transition: all .15s;
}
.login-tab.active { background: #fff; font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* 患者搜索联想 */
.patient-search { flex: 1; position: relative; }
.patient-search input {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.patient-search-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.12);
  max-height: 260px;
  overflow-y: auto;
  z-index: 60;
}
.ps-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.ps-item:last-child { border-bottom: none; }
.ps-item:hover { background: var(--accent-soft); }
.ps-name { font-weight: 600; color: var(--ink); }
.ps-extra { color: var(--muted); font-size: 12px; white-space: nowrap; }
.ps-empty { padding: 14px 12px; color: var(--muted); font-size: 13px; text-align: center; }
