/* ============================================================
 *  思福妥 / 思福诺 病人管理跟进系统 —— 全局样式
 *  主题：深蓝 + 品牌绿 + 橙黄点缀（医药风）
 * ============================================================ */

:root {
  --navy: #042C53;
  --navy-mid: #0C447C;
  --blue: #185FA5;
  --blue-light: #E6F1FB;
  --green: #1D9E75;
  --green-light: #E1F5EE;
  --amber: #BA7517;
  --amber-light: #FAEEDA;
  --gray: #5F5E5A;
  --gray-light: #F1EFE8;
  --border: #D3D1C7;
  --text: #2C2C2A;
  --danger: #A32D2D;
  --danger-light: #FCEBEB;

  /* 由 JS 按药品动态覆盖 */
  --brand: #185FA5;
  --brand-light: #E6F1FB;
  --brand-accent: #0C447C;

  /* 页面底色（表单页按药品设置浅色延伸，后台/首页保持米白） */
  --page-bg: #F7F6F3;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--page-bg, #F7F6F3);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ============ 通用 ============ */
.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px 40px; }

.card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #E8E6E0;
  padding: 18px;
  margin-bottom: 14px;
}

/* ============ 顶部品牌栏 ============ */
.topbar {
  background: linear-gradient(135deg, var(--brand-accent) 0%, var(--brand) 100%);
  color: #fff;
  padding: 20px 16px 26px;
  border-radius: 0 0 20px 20px;
  margin-bottom: 16px;
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: .5px; }
.drug-logo {
  height: 44px;
  width: auto;
  flex-shrink: 0;
  margin-bottom: 6px;
}
.topbar .sub { font-size: 12px; opacity: .85; margin-top: 4px; }
.topbar .badge {
  display: inline-block;
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.3);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  margin-top: 10px;
}

/* ============ 表单 ============ */
.field { margin-bottom: 18px; }
.field.half { width: calc(50% - 7px); display: inline-block; vertical-align: top; }
.field.half + .field.half { margin-left: 14px; }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #3C3B38;
  margin-bottom: 7px;
}
.field-label .req { color: #C0392B; margin-left: 2px; }

input[type=text], input[type=number], input[type=date],
select, textarea {
  width: 100%;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}
input::placeholder, textarea::placeholder { color: #B4B2A9; }
textarea { min-height: 84px; resize: vertical; line-height: 1.6; }

select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235F5E5A' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

/* 单选 / 多选按钮组 */
.optgroup { display: flex; flex-wrap: wrap; gap: 8px; }
.optgroup.vertical { flex-direction: column; }

.opt {
  flex: 1 1 auto;
  min-width: fit-content;
  padding: 9px 14px;
  font-size: 14px;
  text-align: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  user-select: none;
  transition: all .15s;
  color: #3C3B38;
}
.opt:active { transform: scale(.97); }
.opt.on {
  background: var(--brand-light);
  border-color: var(--brand);
  color: var(--brand-accent);
  font-weight: 500;
}
.opt.wide { flex: 1 1 100%; text-align: left; }

/* 多选（选项多、文字长）用紧凑排布，避免页面过长 */
.optgroup.compact { gap: 6px; }
.optgroup.compact .opt {
  padding: 8px 12px;
  font-size: 13.5px;
  line-height: 1.45;
  border-radius: 8px;
}
.optgroup.compact .opt::before {
  content: '';
  display: inline-block;
  width: 15px; height: 15px;
  margin-right: 8px;
  vertical-align: -2px;
  border: 1.5px solid #B4B2A9;
  border-radius: 3px;
  background: #fff;
  transition: all .15s;
}
.optgroup.compact .opt.on::before {
  background: var(--brand);
  border-color: var(--brand);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='9'%3E%3Cpath d='M1 4.5L4 7.5L10 1' stroke='%23fff' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 10px;
}

/* 错误提示 */
.field.err input, .field.err select, .field.err textarea {
  border-color: #C0392B;
  background: #FDF3F2;
}
.err-msg {
  display: none;
  font-size: 12px;
  color: var(--danger);
  margin-top: 5px;
}
.field.err .err-msg { display: block; }

/* ============ 按钮 ============ */
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 500;
  font-family: inherit;
  color: #fff;
  background: var(--brand);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.985); opacity: .9; }
.btn:disabled { background: #B4B2A9; cursor: not-allowed; }
.btn.ghost {
  background: #fff;
  color: var(--brand-accent);
  border: 1px solid var(--brand);
}
.btn.green { background: var(--green); }
.btn.small { padding: 9px 14px; font-size: 14px; width: auto; display: inline-block; }

/* ============ 提示条 ============ */
.tip {
  display: none;
  padding: 12px 14px;
  border-radius: 9px;
  font-size: 14px;
  margin-bottom: 14px;
}
.tip.show { display: block; }
.tip.ok { background: var(--green-light); color: #085041; border: 1px solid #9FE1CB; }
.tip.no { background: var(--danger-light); color: var(--danger); border: 1px solid #F7C1C1; }

/* ============ 草稿箱（本机保存，不上云） ============ */
.draft-card {
  padding: 14px 16px;
  border-left: 3px solid var(--amber);
  background: #FFFCF4;
}
.draft-now {
  font-size: 13.5px; color: #7A4E00;
  line-height: 1.65; margin-bottom: 6px;
}
.draft-now b { color: #5C3A00; }
.draft-now .t { font-size: 12px; color: #A08050; }
.draft-toggle {
  font-size: 13.5px; font-weight: 500; color: var(--amber);
  cursor: pointer; user-select: none; padding: 2px 0;
}
.draft-toggle:active { opacity: .6; }
.draft-list {
  margin-top: 8px; padding-top: 4px;
  border-top: 1px dashed #E8DCC4;
}
.draft-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 0; border-bottom: 1px solid #F2EADC;
}
.draft-item:last-child { border-bottom: none; }
.di-main { flex: 1 1 auto; min-width: 0; }
.di-name {
  font-size: 14px; color: #2C2C2A;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.draft-item.is-cur .di-name { color: var(--amber); font-weight: 600; }
.di-meta { font-size: 11.5px; color: #A08050; margin-top: 2px; }
.di-op {
  flex: 0 0 auto;
  font-size: 13px; font-family: inherit;
  padding: 5px 10px; border-radius: 7px;
  border: 1px solid #E0CFA8; background: #fff; color: #7A4E00;
  cursor: pointer; white-space: nowrap;
}
.di-op:active { transform: scale(.96); }
.di-op.del { color: var(--danger); border-color: #F0D5D5; }
.draft-foot { margin-top: 10px; }
.draft-link {
  font-size: 13px; color: var(--amber);
  cursor: pointer; font-weight: 500;
}
.draft-link:active { opacity: .6; }
.draft-warn {
  margin-top: 8px; font-size: 11.5px; color: #A08050; line-height: 1.6;
}

/* ============ 底部按钮行 / 自动保存提示 / 浮层提示 ============ */
.btn-row { display: flex; gap: 10px; margin-top: 10px; }
.btn-row .btn { flex: 1 1 0; }
.autosave {
  text-align: center; font-size: 11.5px; color: #B4B2A9;
  margin-top: 9px; min-height: 16px;
}
.toast {
  position: fixed; left: 50%; bottom: 42px;
  transform: translateX(-50%);
  max-width: 84vw;
  background: rgba(30,30,28,.92); color: #fff;
  font-size: 14px; line-height: 1.5; text-align: center;
  padding: 11px 20px; border-radius: 22px;
  z-index: 200; opacity: 0;
  transition: opacity .22s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ============ 首页药品选择 ============ */
.drug-list { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.drug-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
  background: #fff;
  border-radius: 14px;
  border: 1px solid #E8E6E0;
  text-decoration: none;
  color: inherit;
  transition: transform .12s, box-shadow .12s;
}
.drug-card:active { transform: scale(.99); }
.drug-icon {
  width: 52px; height: 52px;
  flex-shrink: 0;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; font-weight: 600;
}
.drug-meta h3 { margin: 0 0 3px; font-size: 17px; font-weight: 600; }
.drug-meta p { margin: 0; font-size: 12px; color: var(--gray); }
.drug-arrow { margin-left: auto; color: #B4B2A9; font-size: 20px; }

/* ============ 仪表盘 ============ */
.dash-head {
  background: var(--navy);
  color: #fff;
  padding: 18px 20px;
  border-radius: 0 0 16px 16px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.dash-head h1 { margin: 0; font-size: 18px; font-weight: 600; }
.dash-head .meta { font-size: 12px; opacity: .8; margin-top: 3px; width: 100%; }
.dash-head .spacer { margin-left: auto; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  padding: 8px 18px;
  border-radius: 20px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 14px;
  cursor: pointer;
  color: #3C3B38;
}
.tab.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.filters {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px; align-items: center;
}
.filters select, .filters input {
  width: auto; min-width: 130px; padding: 8px 12px; font-size: 14px;
}

.kpis { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.kpi {
  flex: 1 1 150px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid #E8E6E0;
  padding: 16px;
}
.kpi .k-label { font-size: 12px; color: var(--gray); }
.kpi .k-value { font-size: 26px; font-weight: 600; margin: 4px 0 2px; color: var(--navy); }
.kpi .k-sub { font-size: 11px; color: var(--gray); }
.kpi.g { border-left: 3px solid var(--green); }
.kpi.b { border-left: 3px solid var(--blue); }
.kpi.a { border-left: 3px solid var(--amber); }

.chart-card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #E8E6E0;
  padding: 16px;
  margin-bottom: 16px;
}
.chart-card h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
  padding-left: 9px;
  border-left: 3px solid var(--brand);
}
.chart-box { width: 100%; height: 300px; }
.chart-box.tall { height: 380px; }

.grid2 { display: flex; gap: 16px; flex-wrap: wrap; }
.grid2 > .chart-card { flex: 1 1 320px; margin-bottom: 0; }

/* 热力表 */
.heatmap { width: 100%; border-collapse: collapse; font-size: 13px; }
.heatmap th, .heatmap td {
  padding: 9px 8px;
  text-align: center;
  border: 1px solid #EFEDE8;
}
.heatmap th { background: var(--gray-light); font-weight: 500; color: #3C3B38; font-size: 12px; }
.heatmap td.rowhead { background: #FAF9F6; font-weight: 500; text-align: left; white-space: nowrap; }
.heatmap td.cell { font-weight: 500; }

/* 洞察 */
.insight-box {
  background: var(--green-light);
  border: 1px solid #9FE1CB;
  border-radius: 12px;
  padding: 18px;
}
.insight-box h3 {
  margin: 0 0 4px; font-size: 15px; font-weight: 600; color: #04342C;
}
.insight-box .sub { font-size: 12px; color: #0F6E56; margin-bottom: 12px; }
.insight-item {
  background: #fff;
  border-radius: 9px;
  padding: 12px 14px;
  margin-bottom: 9px;
  font-size: 14px;
  line-height: 1.65;
  border-left: 3px solid var(--green);
}
.insight-item .tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  background: var(--green);
  padding: 1px 8px;
  border-radius: 4px;
  margin-right: 8px;
  vertical-align: 1px;
}
.insight-item.act { border-left-color: var(--amber); }
.insight-item.act .tag { background: var(--amber); }

/* 空状态 */
.empty {
  text-align: center;
  padding: 50px 20px;
  color: var(--gray);
  font-size: 14px;
}
.empty .big { font-size: 34px; margin-bottom: 10px; color: var(--border); }

/* 设置弹层 */
.mask {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(20,20,20,.5);
  z-index: 99;
  padding: 40px 16px;
}
.modal {
  background: #fff;
  border-radius: 14px;
  padding: 22px;
  max-width: 460px;
  margin: 0 auto;
}
.modal h3 { margin: 0 0 6px; font-size: 16px; color: var(--navy); }
.modal p { font-size: 13px; color: var(--gray); margin: 0 0 14px; line-height: 1.7; }
.modal input {
  width: 100%; padding: 11px 12px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 9px; margin-bottom: 12px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.modal code {
  background: var(--gray-light); padding: 1px 6px; border-radius: 4px;
  font-size: 12px; color: var(--navy);
}

/* 表格视图 */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td {
  padding: 9px 8px; text-align: left;
  border-bottom: 1px solid #EFEDE8;
  white-space: nowrap;
}
table.data th { background: var(--gray-light); font-weight: 500; font-size: 12px; position: sticky; top: 0; }
table.data tbody tr:hover { background: #FAF9F6; }
.table-scroll { overflow-x: auto; max-height: 620px; }

.footer-note {
  text-align: center; font-size: 12px; color: #B4B2A9;
  padding: 20px 0 8px;
}

@media (max-width: 480px) {
  .field.half { width: 100%; display: block; }
  .field.half + .field.half { margin-left: 0; }
  .kpi { flex: 1 1 100%; }
  .chart-box { height: 260px; }
  .chart-box.tall { height: 320px; }
}
