/* 处方系统全局样式 —— A4 模板按 docx 精确复刻 */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: #525659; font-family: "Microsoft YaHei", sans-serif; }

/* ===== 顶栏 ===== */
.topbar { background: #1f2937; color: #fff; padding: 0 16px; height: 48px; display: flex; align-items: center; gap: 12px; }
.topbar .brand { font-weight: 700; font-size: 15px; }
.topbar .spacer { flex: 1; }
.topbar a, .topbar button { color: #fff; text-decoration: none; background: #374151; border: 0; padding: 6px 14px; border-radius: 4px; font-size: 13px; cursor: pointer; }
.topbar a:hover, .topbar button:hover { background: #4b5563; }
.topbar .who { font-size: 13px; color: #d1d5db; }

/* ===== A4 纸（与 docx 完全对应：pgSz 11906x16838 twips，边距 864 twips = 15.24mm） ===== */
.sheet-wrap { padding: 24px 0 60px; display: flex; justify-content: center; }
.sheet {
  width: 210mm; height: 297mm;
  padding: 15.24mm;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.4);
  position: relative;
  font-family: "SimSun", "宋体", serif;
  color: #000;
  overflow: hidden;
}
.sheet .logo-img { display: block; width: 170.7mm; height: 38.2mm; margin: 1.5mm auto 0; }
.sheet .rxtitle {
  font-size: 20pt; font-weight: 700; text-align: center;
  line-height: 28pt; margin-top: 2.5mm; letter-spacing: 0.5em; text-indent: 0.5em;
}
.sheet .fline { font-size: 17pt; line-height: 28pt; white-space: nowrap; }
.sheet .fline .lbl { font-size: 15.5pt; font-weight: 700; }
.sheet .rphead { font-family: Arial, sans-serif; font-size: 34pt; font-weight: 700; line-height: 45pt; margin-top: 1.5mm; }
/* RP 药品网格：11 行 × 4 列 */
.sheet .rpgrid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  column-gap: 5pt;
  font-size: 13.5pt; line-height: 22pt;
  min-height: 242pt;
  align-content: start;
  outline: none;
}
.sheet .rpcell { white-space: nowrap; position: relative; min-height: 22pt; }
.sheet .rpgrid.editing .rpcell { border: 1px dashed #e2e5ea; border-radius: 3px; cursor: text; }
.sheet .rpgrid.editing .rpcell.active { border: 1px solid #2563eb; background: #f8fbff; box-shadow: 0 0 0 2px rgba(37,99,235,.12); }
.sheet .rpcell.filled .ddose { margin-left: 3pt; }
.sheet .dname, .sheet .ddose { outline: none; display: inline-block; }
.sheet .dunit { display: inline-block; }
.sheet .rpgrid.editing .rpcell.filled .dname, .sheet .rpgrid.editing .rpcell.filled .ddose,
.sheet .rpgrid.editing .dname:focus, .sheet .rpgrid.editing .ddose:focus { border-bottom: 1px dotted #d33; min-width: 8pt; }
.sheet .rpgrid.editing .dname, .sheet .rpgrid.editing .ddose { min-width: 8pt; }
.sheet .rpgrid:not(.editing) .dname, .sheet .rpgrid:not(.editing) .ddose { border-bottom: 1px dotted transparent; }
.sheet .dname:focus, .sheet .ddose:focus { background: transparent; }
/* 补全下拉 */
.acbox {
  position: absolute; left: 0; top: 100%; z-index: 50;
  background: #fff; border: 1px solid #cbd5e1; border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  max-height: 180px; overflow-y: auto; min-width: 150px;
}
.acitem { padding: 4px 10px; font-size: 13px; font-family: "Microsoft YaHei", sans-serif; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.acitem em { color: #94a3b8; font-style: normal; font-size: 11px; }
.acitem:hover { background: #f1f5f9; }
.acitem.on { background: #dbeafe; font-weight: 600; box-shadow: inset 3px 0 0 #2563eb; }
.sheet .note { font-size: 20pt; line-height: 33pt; white-space: nowrap; overflow: hidden; }
.sheet .note .fld { display: inline-block; white-space: nowrap; overflow: hidden; vertical-align: bottom; }
.sheet .doctorline { display: flex; justify-content: flex-end; align-items: flex-end; gap: 2mm; margin-top: 4mm; }
.sheet .doctorline .dlabel { font-size: 17pt; }
.sheet .doctorline .sigimg { width: 31.6mm; height: 17mm; object-fit: contain; }
.sheet .bottomline { font-size: 20pt; line-height: 33pt; margin-top: 6mm; display: flex; justify-content: space-between; }
.sheet .blankline { display: inline-block; min-width: 44pt; border-bottom: 1pt solid #000; }

/* ===== 可编辑字段（红圈处） ===== */
.fld {
  display: inline-block;
  min-width: 60pt;
  outline: none;
  border-bottom: 1px dotted #d33;
  min-height: 1.2em;
  padding: 0 4pt;
  vertical-align: baseline;
}
/* 行内字段统一盒模型：宽度写多少实际占多少，方便精确排版 */
.sheet .fline .fld, .sheet .note .fld { box-sizing: border-box; }
.fld:focus { background: #fff8e1; }
.sheet.editing .fld { border-bottom: 1px dotted #d33; }
.sheet:not(.editing) .fld { border-bottom: 1px solid transparent; }
.fld:empty::before { content: ""; }

/* ===== 打印 ===== */
@page { size: A4 portrait; margin: 0; }
@media print {
  html, body { background: #fff !important; }
  .topbar, .toolbar, .no-print { display: none !important; }
  .sheet-wrap { padding: 0 !important; margin: 0 !important; }
  .sheet { box-shadow: none !important; margin: 0 !important; page-break-after: avoid; }
  .fld { border-bottom-color: transparent !important; }
  .acbox { display: none !important; }
  .rpgrid .dname, .rpgrid .ddose { border-bottom-color: transparent !important; }
  .rpgrid .rpcell { border-color: transparent !important; }
  .rpgrid .dname:focus, .rpgrid .ddose:focus, .fld:focus { background: transparent !important; }
}

/* ===== 工具栏 ===== */
.toolbar { background: #fff; border-bottom: 1px solid #e5e7eb; padding: 8px 16px; display: flex; gap: 8px; align-items: center; }
.toolbar button { padding: 7px 16px; border: 1px solid #d1d5db; border-radius: 4px; background: #fff; cursor: pointer; font-size: 13px; }
.toolbar button.primary { background: #2563eb; border-color: #2563eb; color: #fff; }
.toolbar button:hover { opacity: .9; }
.toolbar .msg { font-size: 13px; color: #16a34a; }

/* ===== 列表页 ===== */
.page-body { max-width: 1100px; margin: 20px auto; background: #fff; border-radius: 6px; padding: 20px; }
.page-body h2 { font-size: 17px; margin-bottom: 12px; color: #111827; }
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar input { flex: 1; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 4px; }
.searchbar button { padding: 8px 16px; border: 0; background: #2563eb; color: #fff; border-radius: 4px; cursor: pointer; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { border-bottom: 1px solid #e5e7eb; padding: 8px 10px; text-align: left; white-space: nowrap; }
table.grid th { background: #f9fafb; color: #374151; }
table.grid td .ops button { margin-right: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer; border: 1px solid #d1d5db; background: #fff; border-radius: 3px; }
table.grid td .ops button.danger { color: #dc2626; border-color: #fca5a5; }
.empty-tip { color: #9ca3af; text-align: center; padding: 30px 0; }

/* ===== 管理后台 ===== */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid #e5e7eb; margin-bottom: 16px; }
.tabs button { padding: 9px 20px; border: 0; background: none; font-size: 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; color: #6b7280; }
.tabs button.on { color: #2563eb; border-bottom-color: #2563eb; font-weight: 600; }
.form-card { border: 1px solid #e5e7eb; border-radius: 6px; padding: 16px; margin-bottom: 16px; }
.form-card h3 { font-size: 14px; margin-bottom: 10px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.form-row label { font-size: 13px; color: #374151; display: flex; align-items: center; gap: 6px; }
.form-row input, .form-row select { padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 13px; }
.form-row button { padding: 6px 14px; border: 0; background: #2563eb; color: #fff; border-radius: 4px; cursor: pointer; }
.sig-thumb { width: 60px; height: 30px; object-fit: contain; border: 1px dashed #ccc; }
.status-on { color: #16a34a; } .status-off { color: #dc2626; }
