/* ============================================================
   clinic-ui-3.css — ชั้นที่ 2 ของดีไซน์ใหม่
   ครอบคลุม: ปฏิทิน พ.ศ. · หน้าเข้าสู่ระบบ · สถานะว่าง/โหลด/ผิดพลาด
             แชทภายใน · สมุดวัคซีน · ใบเสร็จ A5 · ฟอร์มใบรับรองแพทย์
   วิธีใช้ (ต่อจาก clinic-ui-2.css):
     <link rel="stylesheet" href="/css/clinic-ui-3.css">
   ============================================================ */

/* ---------- 1. ปฏิทิน พ.ศ. (แทน input type=date) ---------- */
.be-date { position: relative; }
.be-date > input {
  cursor: pointer; background: #fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236f7566' stroke-width='2'><rect x='3' y='5' width='18' height='16' rx='2'/><path d='M8 3v4M16 3v4M3 11h18'/></svg>") no-repeat right 11px center;
  padding-right: 34px;
}
.be-cal {
  position: absolute; top: calc(100% + 5px); left: 0; z-index: 40; width: 292px;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--sh-lg); padding: 12px; display: none;
}
.be-cal.open { display: block; }
.be-cal-head { display: flex; align-items: center; gap: 6px; margin-bottom: 9px; }
.be-cal-head .nav {
  width: 32px; height: 32px; min-height: 32px; padding: 0; border-radius: 8px;
  background: #fff; color: var(--muted); border: 1px solid var(--border); font-size: 15px;
}
.be-cal-head .nav:hover { background: #f4f6ee; color: var(--text); }
.be-cal-head .title { flex: 1; text-align: center; font-size: 14.5px; font-weight: 600; cursor: pointer; }
.be-cal-dow { display: grid; grid-template-columns: repeat(7,1fr); gap: 2px; margin-bottom: 3px; }
.be-cal-dow span { text-align: center; font-size: 11px; color: var(--muted); padding: 4px 0; }
.be-cal-dow span.sun { color: var(--danger); }
.be-cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 2px; }
.be-cal-grid button {
  min-height: 36px; padding: 0; background: #fff; color: var(--text);
  border: 1px solid transparent; border-radius: 8px; font-size: 13.5px; font-weight: 400;
  font-variant-numeric: tabular-nums;
}
.be-cal-grid button:hover { background: var(--primary-soft); }
.be-cal-grid button.dim { color: #cfd4c4; }
.be-cal-grid button.today { border-color: #c8cfa8; font-weight: 700; }
.be-cal-grid button.on { background: var(--primary); color: #fff; font-weight: 700; }
.be-cal-grid button.holiday { color: var(--danger); }
.be-cal-foot { display: flex; gap: 6px; margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line); }
.be-cal-foot button { flex: 1; min-height: 34px; font-size: 12.5px; }
/* เลือกปี/เดือนแบบเร็ว */
.be-cal-years { display: grid; grid-template-columns: repeat(4,1fr); gap: 4px; max-height: 210px; overflow-y: auto; }
.be-cal-years button { min-height: 36px; font-size: 13px; background: #fff; color: var(--text); border: 1px solid var(--border); }
.be-cal-years button.on { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- 2. หน้าเข้าสู่ระบบ ---------- */
.login-page {
  min-height: calc(100vh / var(--zf, 1)); display: grid; grid-template-columns: 1.1fr .9fr;
  background: var(--bg);
}
.login-side {
  background: var(--primary); color: #fff; padding: 46px 44px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.login-side .brand { font-size: 26px; font-weight: 700; letter-spacing: -.3px; }
.login-side .tag { font-size: 14.5px; color: #dfe3cd; margin-top: 6px; }
.login-side .pts { margin-top: 34px; display: flex; flex-direction: column; gap: 14px; }
.login-side .pt { display: flex; gap: 11px; align-items: flex-start; font-size: 14px; color: #eef0e4; }
.login-side .pt .ic { font-size: 17px; line-height: 1.25; }
.login-side .foot { font-size: 12px; color: #b9bfae; }
.login-form { display: flex; align-items: center; justify-content: center; padding: 34px 28px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { font-size: 22px; font-weight: 700; letter-spacing: -.2px; }
.login-card .sub { font-size: 13.5px; color: var(--muted); margin: 4px 0 22px; }
.login-card label { margin-top: 14px; }
.login-card .go { width: 100%; margin-top: 20px; min-height: 48px; font-size: 15.5px; font-weight: 600; }
.login-card .err {
  background: var(--danger-soft); border: 1px solid #f4cccc; color: var(--danger-ink);
  border-radius: 10px; padding: 10px 13px; font-size: 13.5px; margin-top: 14px;
}
.login-card .hint { font-size: 12px; color: var(--faint); margin-top: 16px; text-align: center; }
@media (max-width: 860px) {
  .login-page { grid-template-columns: 1fr; }
  .login-side { padding: 28px 22px; }
  .login-side .pts { display: none; }
}

/* ---------- 3. สถานะ ว่าง / กำลังโหลด / ผิดพลาด ---------- */
.state {
  text-align: center; padding: 40px 22px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.state .ic { font-size: 30px; line-height: 1; opacity: .8; }
.state .t { font-size: 15px; font-weight: 600; color: var(--text); }
.state .d { font-size: 13.5px; max-width: 380px; }
.state .act { margin-top: 6px; }
.state.error .t { color: var(--danger-ink); }
.state.error .ic { opacity: 1; }

/* โครงร่างระหว่างโหลด (skeleton) */
.sk { background: linear-gradient(90deg,#eef0ea 25%,#f6f7f3 50%,#eef0ea 75%); background-size: 200% 100%; animation: skm 1.2s infinite linear; border-radius: 8px; }
@keyframes skm { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.sk-line { height: 13px; margin-bottom: 8px; }
.sk-line.w40 { width: 40%; } .sk-line.w60 { width: 60%; } .sk-line.w80 { width: 80%; }
.sk-row { height: 44px; margin-bottom: 7px; }
.sk-card { height: 96px; }

/* แถบแจ้งออฟไลน์ / ผิดพลาดทั้งหน้า */
.bar-offline {
  background: var(--amber-soft); border-bottom: 1px solid #f6dfb8; color: var(--amber-ink);
  font-size: 13px; padding: 9px 16px; display: flex; align-items: center; gap: 9px;
}
.bar-offline .retry { margin-left: auto; }

/* ---------- 4. แชทภายในระหว่างเครื่อง ---------- */
.chat-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 45;
  width: 54px; height: 54px; min-height: 54px; border-radius: 50%; padding: 0;
  box-shadow: 0 6px 20px rgba(31,36,25,.25); font-size: 21px;
}
.chat-fab .dot {
  position: absolute; top: 6px; right: 6px; min-width: 19px; height: 19px;
  border-radius: 99px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--primary);
}
.chat-panel {
  position: fixed; right: 20px; bottom: 84px; z-index: 46; width: 340px; max-width: calc(calc(100vw / var(--zf, 1)) - 32px);
  height: 460px; max-height: calc(calc(100vh / var(--zf, 1)) - 120px); background: #fff;
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--sh-modal);
  display: none; flex-direction: column; overflow: hidden;
}
.chat-panel.open { display: flex; }
.chat-head { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 9px; }
.chat-head .h { font-size: 14.5px; font-weight: 700; }
.chat-head .s { font-size: 11.5px; color: var(--muted); }
.chat-body { flex: 1; overflow-y: auto; padding: 12px 14px; background: #fbfcf8; }
.chat-day { text-align: center; font-size: 11px; color: var(--faint); margin: 8px 0; }
.msg { max-width: 82%; margin-bottom: 9px; }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg .bubble {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 11px; font-size: 13.5px; line-height: 1.5;
}
.msg .time { font-size: 10.5px; color: var(--faint); margin-top: 3px; }
.msg.me { margin-left: auto; }
.msg.me .bubble { background: var(--primary-soft); border-color: #c8cfa8; }
.msg.me .who, .msg.me .time { text-align: right; }
.chat-foot { padding: 10px 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.chat-foot input { flex: 1; }
.chat-foot button { min-width: 46px; }
.chat-quick { display: flex; gap: 6px; padding: 0 12px 10px; flex-wrap: wrap; }
@media (max-width: 720px) {
  .chat-panel { right: 10px; left: 10px; width: auto; bottom: 78px; height: calc(60vh / var(--zf, 1)); }
  .chat-fab { right: 14px; bottom: 14px; }
}

/* ---------- 5. สมุดวัคซีน ---------- */
.vx-course { border: 1px solid var(--border); border-radius: 12px; padding: 13px 15px; margin-bottom: 12px; background: #fff; }
.vx-course .hd { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.vx-course .nm { font-size: 15px; font-weight: 600; }
.vx-steps { display: flex; gap: 0; margin-top: 13px; overflow-x: auto; padding-bottom: 4px; }
.vx-step { flex: 1; min-width: 118px; position: relative; padding: 0 6px; text-align: center; }
.vx-step::before {
  content: ""; position: absolute; top: 13px; left: 0; right: 0; height: 2px; background: var(--border);
}
.vx-step:first-child::before { left: 50%; }
.vx-step:last-child::before { right: 50%; }
.vx-step .bead {
  position: relative; width: 28px; height: 28px; margin: 0 auto 7px; border-radius: 50%;
  background: #fff; border: 2px solid var(--border); color: var(--faint);
  display: flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 700;
}
.vx-step.done .bead { background: var(--green); border-color: var(--green); color: #fff; }
.vx-step.due .bead { background: var(--amber-soft); border-color: var(--amber); color: var(--amber-ink); }
.vx-step.late .bead { background: var(--danger-soft); border-color: var(--danger); color: var(--danger-ink); }
.vx-step .lbl { font-size: 12px; font-weight: 600; }
.vx-step .dt { font-size: 11.5px; color: var(--muted); }
.vx-step.late .dt { color: var(--danger); font-weight: 600; }

/* ---------- 6. ใบเสร็จ A5 + งานพิมพ์ ---------- */
.paper {
  background: #fff; margin: 0 auto; box-shadow: var(--sh);
  color: #000; font-size: 12pt; line-height: 1.55;
}
.paper-a5 { width: 148mm; min-height: 210mm; padding: 14mm 13mm; }
.paper-a4 { width: 210mm; min-height: 297mm; padding: 18mm 16mm; }
.paper h1 { font-size: 17pt; text-align: center; font-weight: 700; }
.paper h2 { font-size: 13pt; }
.paper .ph-head { display: flex; gap: 12px; align-items: flex-start; border-bottom: 1.5px solid #000; padding-bottom: 8px; }
.paper .ph-head .logo { width: 54px; height: 54px; border: 1px solid #999; display: grid; place-items: center; font-size: 9pt; color: #777; }
.paper .ph-head .who { flex: 1; }
.paper .ph-head .clinic { font-size: 14pt; font-weight: 700; }
.paper .ph-head .addr { font-size: 9.5pt; }
.paper .ph-meta { display: flex; justify-content: space-between; font-size: 10pt; margin-top: 7px; }
.paper table { width: 100%; border-collapse: collapse; font-size: 11pt; margin-top: 9px; }
.paper th, .paper td { border-bottom: 1px solid #bbb; padding: 5px 4px; }
.paper th { text-align: left; font-size: 10pt; }
.paper td.num, .paper th.num { text-align: right; }
.paper .grand { display: flex; justify-content: space-between; font-size: 13pt; font-weight: 700; border-top: 1.5px solid #000; margin-top: 8px; padding-top: 7px; }
.paper .sign { margin-top: 26px; display: flex; gap: 22px; }
.paper .sign .box { flex: 1; text-align: center; font-size: 10pt; }
.paper .sign .line { border-bottom: 1px dotted #000; height: 30px; margin-bottom: 5px; }
.paper .fill { border-bottom: 1px dotted #000; display: inline-block; min-width: 120px; }
.paper .chk { display: inline-block; width: 12px; height: 12px; border: 1px solid #000; margin-right: 5px; vertical-align: -1px; }
.paper .chk.on::after { content: "✓"; display: block; font-size: 11px; line-height: 11px; text-align: center; }

.print-bar { display: flex; gap: 9px; justify-content: center; padding: 14px; }
@media print {
  body { background: #fff; }
  .no-print, .print-bar, .chat-fab, .chat-panel, nav, .topbar, .tabs, .pipeline { display: none !important; }
  .paper { box-shadow: none; margin: 0; width: auto; min-height: 0; padding: 0; }
  @page { margin: 12mm; }
  .page-break { page-break-before: always; }
}

/* ---------- 7. ตารางที่มีแถวสรุปท้าย ---------- */
tfoot td, tfoot th { border-top: 1.5px solid var(--border); border-bottom: 0; font-weight: 700; }
tr.total-row td { background: #fbfcf8; font-weight: 700; }
