/* ============================================================
   clinic-ui-5.css — ชั้นที่ 3 (รอบ 3)
   ครอบคลุม: ยืนยันก่อนลบ + เลิกทำ · กรองคิว · ค้นหาบนแถบนำทาง
             เมนูยุบ · ปุ่มกดไม่ได้/กำลังบันทึก · เลย์เอาต์ 3 หน้างานหลัก
             QR พร้อมเพย์ + โหมดหันจอให้คนไข้
   โหลดต่อท้าย: style.css → clinic-ui-2.css → clinic-ui-3.css → clinic-ui-5.css
   ⛔ ไม่แก้ไฟล์เดิม
   ============================================================ */

/* ---------- 0. พื้นตัวอักษรขั้นต่ำ 12px ---------- */
:where(.muted, .stat .lbl, th, .badge, label, .hint, .sub, .dt, .lbl) { font-size: max(12px, 1em); }
:where(.badge) { font-size: 12px; }

/* ---------- 1. ยืนยันก่อนลบ ---------- */
.confirm-bg {
  position: fixed; inset: 0; background: rgba(24,28,18,.5); backdrop-filter: blur(2px);
  z-index: 60; display: none; align-items: center; justify-content: center; padding: 20px;
}
.confirm-bg.open { display: flex; }
.confirm {
  background: #fff; border-radius: 14px; width: 100%; max-width: 420px;
  box-shadow: var(--sh-modal); padding: 20px 22px;
}
.confirm .q { font-size: 16.5px; font-weight: 700; line-height: 1.45; }
.confirm .why { font-size: 13.5px; color: var(--muted); margin-top: 7px; }
.confirm .warn {
  background: var(--danger-soft); border: 1px solid #f4cccc; color: var(--danger-ink);
  border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 12px;
}
.confirm .type-lock { margin-top: 13px; }
.confirm .type-lock label { font-size: 12.5px; }
.confirm-acts { display: flex; gap: 9px; margin-top: 18px; }
/* ปุ่มยกเลิกเป็นปุ่มหลัก (ให้พลาดยาก) ปุ่มลบเป็นกรอบแดงพื้นขาว */
.confirm-acts .keep { flex: 1; }
.confirm-acts .del {
  background: #fff; color: var(--danger); border-color: #f4cccc;
}
.confirm-acts .del:hover { background: var(--danger-soft); }
.confirm-acts .del[aria-disabled="true"] { opacity: .45; pointer-events: none; }

/* ---------- 2. toast แบบมีปุ่มเลิกทำ ---------- */
.toast-undo {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 55;
  background: var(--text); color: #fff; border-radius: 12px; padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(31,36,25,.3); display: flex; align-items: center; gap: 14px;
  font-size: 14px; max-width: calc(calc(100vw / var(--zf, 1)) - 32px); overflow: hidden;
}
.toast-undo .msg { flex: 1; min-width: 0; }
.toast-undo .undo {
  background: transparent; border: 1px solid rgba(255,255,255,.45); color: #fff;
  min-height: 34px; padding: 6px 13px; border-radius: 9px; font-weight: 600; font-size: 13px;
}
.toast-undo .undo:hover { background: rgba(255,255,255,.14); }
.toast-undo .bar {
  position: absolute; left: 0; bottom: 0; height: 3px; background: #c8cfa8;
  animation: undobar 6s linear forwards;
}
@keyframes undobar { from { width: 100%; } to { width: 0; } }

/* ---------- 3. แถบกรองคิว ---------- */
.queue-filter { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 9px; }
.queue-filter .chip { padding: 6px 11px; font-size: 12.5px; gap: 5px; }
.queue-filter .chip .n {
  background: var(--border); color: var(--muted); border-radius: 99px;
  padding: 0 6px; font-size: 11.5px; font-weight: 700; min-width: 18px; text-align: center;
}
.queue-filter .chip.on .n { background: #fff; color: var(--primary-dark); }
.queue-hidden {
  font-size: 12px; color: var(--faint); padding: 7px 2px;
  display: flex; align-items: center; gap: 7px;
}

/* ---------- 4. ค้นหาบนแถบนำทาง ---------- */
.nav-search { position: relative; min-width: 240px; flex: 0 1 300px; }
.nav-search input {
  width: 100%; min-height: 36px; padding: 7px 11px 7px 32px; font-size: 13.5px;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.28);
  border-radius: 9px; color: #fff;
}
.nav-search input::placeholder { color: #cfd6bd; }
.nav-search input:focus {
  background: #fff; color: var(--text); border-color: #fff;
  box-shadow: 0 0 0 3px rgba(255,255,255,.22);
}
.nav-search .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-size: 13px; opacity: .8; pointer-events: none; }
.nav-search .kbd {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  font-size: 11px; color: #cfd6bd; border: 1px solid rgba(255,255,255,.3);
  border-radius: 5px; padding: 1px 5px; pointer-events: none;
}
.nav-search input:focus ~ .kbd { display: none; }

.ns-results {
  position: absolute; top: calc(100% + 6px); left: 0; width: 420px; max-width: calc(86vw / var(--zf, 1));
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--sh-modal); max-height: 420px; overflow-y: auto; z-index: 48; display: none;
}
.ns-results.open { display: block; }
.ns-group { font-size: 11.5px; font-weight: 700; color: var(--muted); padding: 9px 13px 5px; background: #fbfcf8; }
.ns-item {
  display: flex; gap: 10px; align-items: center; padding: 9px 13px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.ns-item:hover, .ns-item.sel { background: var(--primary-soft); }
.ns-item .av {
  width: 32px; height: 32px; border-radius: 50%; background: #e8eae1; color: var(--muted);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none;
}
.ns-item .tx { flex: 1; min-width: 0; }
.ns-item .tx b { font-size: 14px; }
.ns-item .tx .s { display: block; font-size: 12px; color: var(--muted); }
.ns-item .acts { display: flex; gap: 5px; }
.ns-empty { padding: 20px 14px; text-align: center; color: var(--faint); font-size: 13.5px; }
@media (max-width: 980px) {
  .nav-search { min-width: 0; flex: 0 0 40px; }
  .nav-search input { padding-left: 30px; }
  .nav-search input::placeholder { color: transparent; }
  .nav-search .kbd { display: none; }
}

/* ---------- 5. เมนูยุบ "เพิ่มเติม" ---------- */
.nav-more { position: relative; }
.nav-more > .more-btn {
  background: transparent; border: 0; color: #dfe3cd; font-size: 13.5px;
  padding: 12px 11px; min-height: 0; border-radius: 0; position: relative;
}
.nav-more > .more-btn:hover { background: rgba(255,255,255,.1); }
.nav-more > .more-btn .pin {
  position: absolute; top: 9px; right: 4px; width: 7px; height: 7px;
  border-radius: 50%; background: #fca5a5;
}
.nav-more-menu {
  position: absolute; top: 100%; right: 0; min-width: 210px; background: #fff;
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--sh-modal);
  padding: 6px; display: none; z-index: 47;
}
.nav-more-menu.open { display: block; }
.nav-more-menu a {
  display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: 9px;
  font-size: 14px; color: var(--text);
}
.nav-more-menu a:hover { background: var(--primary-soft); }
.nav-more-menu a .n {
  margin-left: auto; background: var(--amber-soft); color: var(--amber-ink);
  border-radius: 99px; padding: 0 7px; font-size: 11.5px; font-weight: 700;
}
/* ถ้าเมนูในกลุ่มถูกซ่อนตามสิทธิ์จนหมด ให้ซ่อนปุ่มทั้งก้อน */
.nav-more:not(:has(.nav-more-menu a)) { display: none; }

/* ---------- 6. ปุ่มกดไม่ได้ + เหตุผล + กำลังบันทึก ---------- */
button[aria-disabled="true"], .btn[aria-disabled="true"] {
  background: #e8eae1; color: var(--faint); border-color: transparent;
  cursor: not-allowed; pointer-events: none;
}
.btn-reason { font-size: 12px; color: var(--amber); margin-top: 5px; display: block; }
.btn-wrap { display: inline-flex; flex-direction: column; }

.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 17px; height: 17px;
  margin: -8.5px 0 0 -8.5px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.45); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
.btn-outline.is-loading::after, .btn-gray.is-loading::after {
  border-color: rgba(31,36,25,.25); border-top-color: var(--text);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* tooltip สั้น ๆ */
.tip { position: relative; }
.tip::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%); background: var(--text); color: #fff; font-size: 12px;
  padding: 6px 9px; border-radius: 7px; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: .12s;
}
.tip:hover::after { opacity: 1; }

/* ---------- 7. เลย์เอาต์หน้างานหลัก ---------- */
/* ต้อนรับ: ซ้ายค้นหา/คนไข้ · กลางฟอร์มวัด · ขวาคิว+นัด */
.work-3 { display: grid; grid-template-columns: 330px minmax(0,1fr) 320px; gap: 16px; align-items: start; }
.work-2 { display: grid; grid-template-columns: 300px minmax(0,1fr); gap: 16px; align-items: start; }
@media (max-width: 1240px) { .work-3 { grid-template-columns: 300px minmax(0,1fr); } .work-3 > .col-side { grid-column: 1 / -1; } }
@media (max-width: 900px) { .work-3, .work-2 { grid-template-columns: 1fr; } }

/* หัวชีทที่ต้องเห็นเสมอ */
.sticky-head {
  position: sticky; top: 0; z-index: 4; background: #fff;
  border-bottom: 1px solid var(--border); padding: 13px 16px; margin: -18px -20px 14px;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.sticky-head .who { display: flex; align-items: center; gap: 11px; flex-wrap: wrap; }
.sticky-head .nm { font-size: 17px; font-weight: 700; }
.sticky-head .allergy-pill {
  background: var(--danger-soft); border: 1px solid #f4cccc; color: var(--danger-ink);
  border-radius: 99px; padding: 5px 12px; font-size: 12.5px; font-weight: 700;
}
.sticky-head .allergy-pill.none { background: var(--line); border-color: var(--border); color: var(--muted); font-weight: 500; }

/* แถบ Vital */
.vitals { display: grid; grid-template-columns: repeat(auto-fit,minmax(104px,1fr)); gap: 9px; }
.vital {
  background: #fbfcf8; border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 10px; text-align: center;
}
.vital .k { font-size: 12px; color: var(--muted); }
.vital .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.3; }
.vital.warn { background: var(--amber-soft); border-color: #f6dfb8; }
.vital.warn .v, .vital.warn .k { color: var(--amber-ink); }
.vital.bad { background: var(--danger-soft); border-color: #f4cccc; }
.vital.bad .v, .vital.bad .k { color: var(--danger-ink); }
/* ช่องกรอกที่ค่าผิดปกติ */
input.val-warn { border-color: var(--amber); background: var(--amber-soft); }
input.val-bad { border-color: var(--danger); background: var(--danger-soft); }

/* ขั้นตอนในชีทตรวจ */
.steps { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 14px; }
.steps button {
  background: #fff; border: 1px solid var(--border); color: var(--muted);
  border-radius: 10px; padding: 9px 14px; font-size: 13.5px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 7px;
}
.steps button .no {
  width: 20px; height: 20px; border-radius: 50%; background: var(--line);
  color: var(--muted); font-size: 11.5px; font-weight: 700; display: grid; place-items: center;
}
.steps button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.steps button.on .no { background: rgba(255,255,255,.25); color: #fff; }
.steps button.done .no { background: var(--green); color: #fff; }

/* แถบปุ่มท้ายชีท ติดล่างเสมอ */
.action-bar {
  position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--border);
  padding: 12px 16px; margin: 14px -20px -18px; border-radius: 0 0 var(--r-lg) var(--r-lg);
  display: flex; gap: 9px; align-items: center; flex-wrap: wrap;
}
.action-bar .sum { margin-left: auto; font-size: 13px; color: var(--muted); }
.action-bar .sum b { font-size: 19px; color: var(--text); font-variant-numeric: tabular-nums; }

/* แถวรายการยาในชีท */
.rx-row { border: 1px solid var(--border); border-radius: 12px; padding: 11px 12px; margin-bottom: 9px; background: #fff; }
.rx-row.alert { border-color: #f4cccc; background: var(--danger-soft); }
.rx-row .top { display: flex; gap: 9px; align-items: flex-start; }
.rx-row .qty-box { display: flex; align-items: center; gap: 3px; border: 1px solid #d9ddcf; border-radius: 10px; padding: 2px 3px; background: #fff; }
.rx-row .qty-box button { width: 34px; min-height: 34px; padding: 0; background: #fff; color: var(--muted); border: 0; font-size: 17px; }
.rx-row .qty-box input { width: 54px; border: 0; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; padding: 6px 2px; }

/* แผงคิดเงิน */
.pay-panel { background: #fff; border: 1px solid var(--border); border-radius: var(--r-lg); padding: 16px 18px; }
.pay-panel .due-lbl { font-size: 12.5px; color: var(--muted); }
.pay-panel .due { font-size: 34px; font-weight: 700; letter-spacing: -.8px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.pay-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.pay-modes button {
  border: 1.5px solid var(--border); background: #fff; color: var(--muted);
  border-radius: 11px; padding: 13px 10px; font-size: 14px; font-weight: 500; min-height: 56px;
  flex-direction: column; gap: 3px;
}
.pay-modes button.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); font-weight: 700; }
.cash-box { margin-top: 12px; border: 1px solid var(--border); border-radius: 12px; padding: 13px; background: #fbfcf8; }
.cash-box .big { font-size: 19px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.quick-cash { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.change-row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--border); }
.change-row .amt { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.change-row .amt.short { color: var(--danger); }

/* ---------- 8. QR พร้อมเพย์ ---------- */
.qr-stage {
  background: #fff; border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 22px; text-align: center;
}
.qr-frame {
  width: 280px; height: 280px; margin: 0 auto; background: #fff;
  border: 1px solid var(--border); border-radius: 14px; padding: 12px;
  display: grid; place-items: center;
}
.qr-frame img, .qr-frame canvas, .qr-frame svg { width: 100%; height: 100%; display: block; }
.qr-amount { font-size: 40px; font-weight: 700; letter-spacing: -1px; font-variant-numeric: tabular-nums; margin-top: 16px; line-height: 1.1; }
.qr-amount .cur { font-size: 19px; font-weight: 600; color: var(--muted); margin-left: 6px; }
.qr-payee { font-size: 14px; color: var(--muted); margin-top: 6px; }
.qr-payee b { color: var(--text); }
.qr-meta { font-size: 12.5px; color: var(--faint); margin-top: 4px; }
.qr-acts { display: flex; gap: 9px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.qr-acts .confirm-pay { min-width: 240px; min-height: 52px; font-size: 15.5px; font-weight: 700; }
.qr-note {
  margin-top: 14px; font-size: 12.5px; color: var(--muted);
  background: #fbfcf8; border: 1px solid var(--border); border-radius: 10px; padding: 10px 13px;
  display: inline-block;
}

/* โหมดหันจอให้คนไข้ */
.qr-fullscreen {
  position: fixed; inset: 0; z-index: 70; background: #fff;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 24px;
}
.qr-fullscreen.open { display: flex; }
.qr-fullscreen .qr-frame { width: min(calc(58vh / var(--zf, 1)), 430px); height: min(calc(58vh / var(--zf, 1)), 430px); border-width: 2px; }
.qr-fullscreen .qr-amount { font-size: 58px; }
.qr-fullscreen .qr-payee { font-size: 17px; }
.qr-fullscreen .exit { position: fixed; top: 18px; right: 18px; }
.qr-fullscreen .scan-hint { font-size: 17px; color: var(--muted); margin-bottom: 10px; }

@media (max-width: 720px) {
  .qr-frame { width: min(calc(86vw / var(--zf, 1)), 320px); height: min(calc(86vw / var(--zf, 1)), 320px); }
  .qr-amount { font-size: 34px; }
  .qr-acts .confirm-pay { width: 100%; }
}
