/*
 * 董氏奇穴针灸辅助工具 - 临床 UI/UX 增强包 v1.0
 * 仅做增量增强，不替代原 styles.css。
 */

:root {
  --ds-safety-height: 48px;
  --ds-clinical-red: #b42318;
  --ds-clinical-red-soft: #fff1ee;
  --ds-clinical-orange: #b54708;
  --ds-clinical-orange-soft: #fff7ed;
  --ds-clinical-green: #067647;
  --ds-clinical-green-soft: #ecfdf3;
  --ds-clinical-blue: #175cd3;
  --ds-clinical-blue-soft: #eff8ff;
  --ds-clinical-shadow: 0 16px 44px rgba(16, 24, 40, 0.15);
}

/* ---------- 全局临床安全警示 ---------- */
.ds-safety-bar {
  position: fixed;
  z-index: 10020;
  inset: 0 0 auto 0;
  min-height: var(--ds-safety-height);
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 9px 18px;
  border-bottom: 1px solid #f4b8aa;
  background: linear-gradient(90deg, #fff1ee 0%, #fff7ed 55%, #fff1ee 100%);
  color: #8a1c13;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 2px 10px rgba(180, 35, 24, 0.08);
}

.ds-safety-bar .ds-safety-icon {
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 1;
}

body.ds-clinical-authenticated .ds-safety-bar { display: flex; }
body.ds-clinical-authenticated .app-shell { padding-top: var(--ds-safety-height); }
body.ds-clinical-authenticated .sidebar {
  top: var(--ds-safety-height);
  max-height: calc(100vh - var(--ds-safety-height));
}

/* 隐藏工作台内部旧安全提示，避免重复。 */
#page-dashboard > .notice:first-child { display: none !important; }

/* ---------- 通用弹窗 ---------- */
.ds-modal-overlay {
  position: fixed;
  z-index: 12050;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
}

.ds-modal-overlay[hidden] { display: none !important; }

.ds-modal-card {
  width: min(620px, 100%);
  max-height: min(84vh, 780px);
  overflow: auto;
  border: 1px solid var(--border, #d7e3f1);
  border-radius: 18px;
  background: var(--surface, #fff);
  color: var(--text, #10213d);
  box-shadow: var(--ds-clinical-shadow);
}

.ds-modal-head,
.ds-modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 20px;
}

.ds-modal-head { border-bottom: 1px solid var(--border, #e4e7ec); }
.ds-modal-foot { border-top: 1px solid var(--border, #e4e7ec); }
.ds-modal-body { padding: 20px; }
.ds-modal-head h3 { margin: 0; font-size: 18px; }
.ds-modal-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 21px;
}
.ds-modal-close:hover { background: rgba(148, 163, 184, 0.14); }

.ds-safety-confirm-card { width: min(560px, 100%); }
.ds-safety-confirm-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin-bottom: 13px;
  border-radius: 14px;
  background: var(--ds-clinical-orange-soft);
  font-size: 24px;
}
.ds-safety-confirm-card p { margin: 8px 0; line-height: 1.75; }
.ds-safety-confirm-card .ds-legal-note {
  padding: 11px 13px;
  border-left: 4px solid #f79009;
  border-radius: 8px;
  background: #fffaeb;
  color: #7a2e0e;
  font-size: 13px;
}

/* ---------- 工作台数据卡 ---------- */
#dashboardStats.ds-stats-enhanced {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 14px;
}

#dashboardStats.ds-stats-enhanced .stat {
  min-width: 0;
  position: relative;
  overflow: hidden;
  padding: 18px;
  border: 1px solid var(--border, #d7e3f1);
  border-radius: 16px;
  background: var(--surface, #fff);
  box-shadow: 0 5px 18px rgba(15, 23, 42, 0.05);
}

#dashboardStats.ds-stats-enhanced .stat::after {
  content: none !important;
  display: none !important;
}

#dashboardStats.ds-stats-enhanced .stat .label {
  color: var(--muted, #667085);
  font-size: 13px;
  font-weight: 650;
}

#dashboardStats.ds-stats-enhanced .stat .value {
  margin-top: 8px;
  color: var(--text, #10213d);
  font-size: clamp(30px, 3.2vw, 42px) !important;
  font-weight: 820;
  line-height: 1;
  letter-spacing: -0.035em;
}

.ds-stat-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 11px;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted, #667085);
  font-size: 11px;
  font-weight: 700;
}
.ds-stat-trend.up { background: var(--ds-clinical-green-soft); color: var(--ds-clinical-green); }
.ds-stat-trend.down { background: var(--ds-clinical-red-soft); color: var(--ds-clinical-red); }
.ds-stat-trend.flat { background: #f2f4f7; color: #475467; }

#dashboardStats .ds-review-stat {
  border-color: #f4b8aa !important;
  background: linear-gradient(145deg, #fff 20%, #fff1ee 100%) !important;
}
#dashboardStats .ds-review-stat .value { color: var(--ds-clinical-red) !important; }

.ds-review-tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-top: 7px;
  padding: 3px 8px;
  border: 1px solid #f4b8aa;
  border-radius: 999px;
  background: var(--ds-clinical-red-soft);
  color: var(--ds-clinical-red);
  font-size: 11px;
  font-weight: 750;
}

/* ---------- 工作台待办 ---------- */
.ds-todo-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.ds-todo-head h3 { margin: 0; }
.ds-todo-progress { color: var(--muted, #667085); font-size: 12px; }
.ds-todo-list { display: grid; gap: 10px; }
.ds-todo-item {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border, #e4e7ec);
  border-radius: 13px;
  background: var(--surface, #fff);
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.ds-todo-item:hover { transform: translateY(-1px); border-color: #84adff; }
.ds-todo-check {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid #98a2b3;
  border-radius: 50%;
  background: #fff;
  color: transparent;
  cursor: pointer;
  font-weight: 900;
}
.ds-todo-main {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.ds-todo-main b { display: block; font-size: 14px; }
.ds-todo-main small { display: block; margin-top: 3px; color: var(--muted, #667085); line-height: 1.45; }
.ds-todo-arrow { color: var(--muted, #98a2b3); }
.ds-todo-item.completed { background: #f6fef9; border-color: #abefc6; }
.ds-todo-item.completed .ds-todo-check { border-color: #12b76a; background: #12b76a; color: #fff; }
.ds-todo-item.completed .ds-todo-main b,
.ds-todo-item.completed .ds-todo-main small { text-decoration: line-through; opacity: .66; }

/* ---------- 快捷看诊 ---------- */
.ds-quick-consult-button {
  width: calc(100% - 24px);
  margin: auto 12px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 12px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 12px;
  background: rgba(255,255,255,.12);
  color: inherit;
  cursor: pointer;
  font-weight: 750;
}
.ds-quick-consult-button:hover { background: rgba(255,255,255,.2); }
.ds-quick-modal .ds-modal-card { width: min(850px, 100%); }
.ds-quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ds-quick-grid label { display: grid; gap: 6px; font-size: 13px; font-weight: 650; }
.ds-quick-grid label.full { grid-column: 1 / -1; }
.ds-quick-result { margin-top: 16px; }

/* ---------- AI 助手抽屉 ---------- */
.ds-ai-toggle {
  position: fixed;
  z-index: 10010;
  right: 22px;
  bottom: 22px;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border: 0;
  border-radius: 999px;
  background: #175cd3;
  color: #fff;
  box-shadow: 0 12px 28px rgba(23, 92, 211, .32);
  cursor: pointer;
  font-weight: 760;
}
body.ds-clinical-authenticated .ds-ai-toggle { display: flex; }

.ds-ai-drawer {
  position: fixed;
  z-index: 11020;
  top: var(--ds-safety-height);
  right: 0;
  bottom: 0;
  width: min(420px, 92vw);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border, #d7e3f1);
  background: var(--surface, #fff);
  color: var(--text, #10213d);
  box-shadow: -18px 0 50px rgba(15, 23, 42, .16);
  transform: translateX(103%);
  transition: transform .24s ease;
}
.ds-ai-drawer.open { transform: translateX(0); }
.ds-ai-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border, #e4e7ec);
}
.ds-ai-drawer-head h3 { margin: 0; font-size: 16px; }
.ds-ai-drawer-head small { display: block; margin-top: 3px; color: var(--muted, #667085); }
.ds-ai-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 16px;
  background: linear-gradient(180deg, rgba(239,248,255,.58), transparent 140px);
}
.ds-ai-bubble {
  max-width: 92%;
  padding: 11px 13px;
  border-radius: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
}
.ds-ai-bubble.user { align-self: flex-end; background: #175cd3; color: #fff; border-bottom-right-radius: 4px; }
.ds-ai-bubble.assistant { align-self: flex-start; border: 1px solid var(--border, #e4e7ec); background: var(--surface, #fff); border-bottom-left-radius: 4px; }
.ds-ai-loading { display: inline-flex; align-items: center; gap: 5px; }
.ds-ai-loading i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .35;
  animation: dsAiDot 1s infinite ease-in-out;
}
.ds-ai-loading i:nth-child(2) { animation-delay: .15s; }
.ds-ai-loading i:nth-child(3) { animation-delay: .3s; }
@keyframes dsAiDot { 0%, 80%, 100% { transform: translateY(0); opacity: .3; } 40% { transform: translateY(-4px); opacity: 1; } }
.ds-ai-composer { padding: 14px; border-top: 1px solid var(--border, #e4e7ec); }
.ds-ai-context-switch { display: flex; align-items: center; gap: 7px; margin-bottom: 8px; color: var(--muted, #667085); font-size: 12px; }
.ds-ai-input-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.ds-ai-input-row textarea { min-height: 74px; resize: vertical; }
.ds-ai-source-list { display: grid; gap: 6px; margin-top: 10px; }
.ds-ai-source-item { padding: 7px 9px; border-radius: 9px; background: #f2f4f7; color: #475467; font-size: 11px; }

/* ---------- AI 证据与反馈 ---------- */
.ds-evidence-panel {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid #b2ddff;
  border-radius: 14px;
  background: var(--ds-clinical-blue-soft);
}
.ds-evidence-panel h4 { margin: 0 0 8px; color: #1849a9; }
.ds-evidence-list { display: grid; gap: 8px; }
.ds-evidence-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
  padding: 9px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,.72);
  font-size: 12px;
}
.ds-evidence-item b { display: block; }
.ds-evidence-item small { display: block; margin-top: 2px; color: #475467; }
.ds-evidence-empty { color: var(--ds-clinical-red); font-weight: 700; }

.ds-ai-feedback {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  margin-top: 13px;
  padding-top: 13px;
  border-top: 1px dashed var(--border, #d0d5dd);
}
.ds-ai-feedback-label { margin-right: auto; color: var(--muted, #667085); font-size: 12px; }
.ds-feedback-btn {
  padding: 8px 12px;
  border: 1px solid var(--border, #d0d5dd);
  border-radius: 10px;
  background: var(--surface, #fff);
  color: inherit;
  cursor: pointer;
  font-weight: 700;
}
.ds-feedback-btn:hover { border-color: #84adff; }
.ds-feedback-btn.adopted { border-color: #75e0a7; background: #ecfdf3; color: #067647; }
.ds-feedback-btn.rejected { border-color: #fda29b; background: #fef3f2; color: #b42318; }
.ds-feedback-status { width: 100%; color: var(--muted, #667085); font-size: 12px; }

/* ---------- 仪表盘配置 ---------- */
.ds-dashboard-config-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid var(--border, #d0d5dd);
  border-radius: 9px;
  background: var(--surface, #fff);
  color: var(--text, #344054);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}
.ds-config-list { display: grid; gap: 9px; }
.ds-config-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--border, #e4e7ec);
  border-radius: 11px;
  background: var(--surface, #fff);
  cursor: grab;
}
.ds-config-item.dragging { opacity: .45; }
.ds-config-handle { color: #98a2b3; font-size: 16px; }
.ds-config-help { margin: 0 0 12px; color: var(--muted, #667085); font-size: 12px; }

/* ---------- 表单与按钮的局部增强 ---------- */
.ds-primary-button,
.ds-secondary-button,
.ds-danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 750;
}
.ds-primary-button { border: 1px solid #175cd3; background: #175cd3; color: #fff; }
.ds-secondary-button { border: 1px solid var(--border, #d0d5dd); background: var(--surface, #fff); color: inherit; }
.ds-danger-button { border: 1px solid #fda29b; background: #fff; color: #b42318; }
.ds-primary-button:disabled,
.ds-secondary-button:disabled,
.ds-danger-button:disabled { opacity: .55; cursor: not-allowed; }
.ds-inline-form { display: grid; gap: 12px; }
.ds-inline-form label { display: grid; gap: 6px; font-size: 13px; font-weight: 650; }
.ds-inline-form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ds-inline-form input,
.ds-inline-form select,
.ds-inline-form textarea,
.ds-ai-input-row textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border, #d0d5dd);
  border-radius: 10px;
  background: var(--surface, #fff);
  color: var(--text, #101828);
  padding: 10px 11px;
  font: inherit;
}
.ds-inline-form input:focus,
.ds-inline-form select:focus,
.ds-inline-form textarea:focus,
.ds-ai-input-row textarea:focus { outline: 3px solid rgba(46, 144, 250, .16); border-color: #2e90fa; }

@media (max-width: 1200px) {
  #dashboardStats.ds-stats-enhanced { grid-template-columns: repeat(3, minmax(160px, 1fr)); }
}

@media (max-width: 760px) {
  :root { --ds-safety-height: 62px; }
  .ds-safety-bar { justify-content: flex-start; padding: 8px 12px; text-align: left; font-size: 11px; }
  body.ds-clinical-authenticated .app-shell { padding-top: var(--ds-safety-height); }
  /* 原系统手机端把侧栏改为底部导航；不要用桌面 top 偏移把它拉伸成整屏。 */
  body.ds-clinical-authenticated .sidebar { top: auto; max-height: none; }
  #dashboardStats.ds-stats-enhanced { grid-template-columns: 1fr 1fr; gap: 10px; }
  #dashboardStats.ds-stats-enhanced .stat { padding: 14px; }
  #dashboardStats.ds-stats-enhanced .stat .value { font-size: 30px !important; }
  .ds-ai-toggle { right: 14px; bottom: 78px; padding: 11px 13px; }
  .ds-ai-drawer { top: var(--ds-safety-height); width: 100vw; }
  .ds-quick-consult-button { width: auto; margin: 0; }
  .ds-quick-grid, .ds-inline-form .two { grid-template-columns: 1fr; }
  .ds-quick-grid label.full { grid-column: auto; }
  .ds-modal-overlay { padding: 10px; }
  .ds-modal-card { max-height: 92vh; border-radius: 15px; }
  .ds-todo-item { grid-template-columns: 32px 1fr; }
  .ds-todo-arrow { display: none; }
}

@media (max-width: 430px) {
  #dashboardStats.ds-stats-enhanced { grid-template-columns: 1fr; }
}
