/* GoClinic Tablet — ออกแบบสำหรับจอสัมผัส: ปุ่มใหญ่ ตัวหนังสือใหญ่ ระยะกดสบายนิ้ว */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'Sarabun', 'Segoe UI', Tahoma, sans-serif;
  font-size: 17px;
  background: #f1f5f9;
  color: #1e293b;
  overscroll-behavior: none;
}
button { font-family: inherit; font-size: inherit; border: none; cursor: pointer; }
input, textarea { font-family: inherit; font-size: 17px; }

/* ── Login ── */
.view { display: none; height: 100%; }
.view.active { display: block; }
#view-login.active { display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: linear-gradient(160deg, #1e3a5f, #0f2340); }
.login-box { background: #fff; border-radius: 20px; padding: 36px 32px; width: min(92vw, 420px);
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-logo { font-size: 3rem; text-align: center; }
.login-box h1 { text-align: center; font-size: 1.4rem; color: #1e3a5f; margin-bottom: 6px; }
.login-box input { padding: 14px 16px; border: 2px solid #e2e8f0; border-radius: 12px; }
.login-box input:focus { outline: none; border-color: #2563eb; }
.login-error { color: #dc2626; text-align: center; min-height: 1.4em; font-size: .95rem; }

.btn-big { padding: 15px 20px; border-radius: 12px; font-weight: 700; font-size: 1.05rem; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:active { background: #1d4ed8; }
.btn-green { background: #16a34a; color: #fff; }
.btn-outline { background: #fff; color: #334155; border: 2px solid #cbd5e1; }
.btn-mic { background: #dc2626; color: #fff; }
.btn-mic.listening { animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .6 } }

/* ── Shell ── */
#app-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#topbar { background: #1e3a5f; color: #fff; padding: 14px 20px; display: flex;
  justify-content: space-between; align-items: center; font-weight: 700; font-size: 1.1rem;
  padding-top: calc(14px + env(safe-area-inset-top)); flex-shrink: 0; }
#topbar-user { font-weight: 400; font-size: .9rem; opacity: .85; }
#main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; }
.page { display: none; }
.page.active { display: block; }

#bottomnav { display: flex; background: #fff; border-top: 1px solid #e2e8f0; flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom); }
.nav-btn { flex: 1; padding: 10px 0 12px; background: none; display: flex; flex-direction: column;
  align-items: center; gap: 2px; color: #64748b; font-size: .85rem; }
.nav-btn.active { color: #2563eb; font-weight: 700; }
.nav-icon { font-size: 1.5rem; }

/* ── Cards ── */
.qcard { background: #fff; border-radius: 16px; padding: 16px 18px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.07);
  border-left: 6px solid #cbd5e1; }
.qcard:active { background: #f8fafc; }
.qcard.st-waiting { border-left-color: #f59e0b; }
.qcard.st-in_progress { border-left-color: #2563eb; }
.qcard.st-completed { border-left-color: #16a34a; }
.qnum { font-size: 1.7rem; font-weight: 800; color: #1e3a5f; min-width: 56px; text-align: center; }
.qinfo { flex: 1; min-width: 0; }
.qname { font-weight: 700; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qmeta { color: #64748b; font-size: .9rem; margin-top: 2px; }
.qstatus { font-size: .85rem; padding: 6px 12px; border-radius: 999px; background: #f1f5f9;
  white-space: nowrap; font-weight: 600; }

.empty { text-align: center; color: #94a3b8; padding: 60px 20px; font-size: 1.05rem; }
.section-title { font-weight: 800; font-size: 1.05rem; color: #334155; margin: 20px 0 10px; }

/* ── Search ── */
.search-row { display: flex; gap: 10px; margin-bottom: 14px; }
.search-row input { flex: 1; padding: 14px 18px; border: 2px solid #e2e8f0; border-radius: 14px; }
.search-row input:focus { outline: none; border-color: #2563eb; }

/* ── Patient page ── */
.pt-head { background: #fff; border-radius: 16px; padding: 18px; display: flex; gap: 16px;
  align-items: center; margin-bottom: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.pt-avatar { width: 72px; height: 72px; border-radius: 50%; background: #e2e8f0; object-fit: cover;
  display: flex; align-items: center; justify-content: center; font-size: 2rem; flex-shrink: 0; }
.pt-name { font-weight: 800; font-size: 1.25rem; }
.pt-meta { color: #64748b; margin-top: 2px; }
.backbtn { background: none; color: #2563eb; font-weight: 700; padding: 6px 0 14px; font-size: 1rem; }

.actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }

.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.doc-thumb { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; background: #e2e8f0; display: block; }
.doc-date { font-size: .75rem; color: #94a3b8; text-align: center; margin-top: 3px; }

.note-box { background: #fff; border-radius: 16px; padding: 16px; margin-top: 8px; }
.note-box textarea { width: 100%; min-height: 130px; border: 2px solid #e2e8f0; border-radius: 12px;
  padding: 12px; resize: vertical; }
.note-actions { display: flex; gap: 10px; margin-top: 10px; }
.note-actions .btn-big { flex: 1; }

/* ── Toast / Lightbox ── */
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #1e293b;
  color: #fff; padding: 12px 22px; border-radius: 999px; font-size: .95rem; opacity: 0;
  transition: opacity .25s; pointer-events: none; z-index: 999; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }
#lightbox { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 998;
  align-items: center; justify-content: center; touch-action: pan-y; }
#lightbox.show { display: flex; }
#lightbox img { max-width: 96vw; max-height: 92vh; object-fit: contain; }
.lb-counter { position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.6); color: #fff; padding: 6px 16px; border-radius: 999px; font-size: .95rem; }
.lb-arrow { position: fixed; top: 50%; transform: translateY(-50%); width: 56px; height: 88px;
  background: rgba(255,255,255,.12); color: #fff; font-size: 2.2rem; border-radius: 14px;
  display: flex; align-items: center; justify-content: center; }
.lb-arrow:active { background: rgba(255,255,255,.28); }
.lb-prev { left: 8px; }
.lb-next { right: 8px; }
.lb-close { position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 14px; width: 46px; height: 46px;
  border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; font-size: 1.2rem; }

.spinner { border: 4px solid #e2e8f0; border-top-color: #2563eb; border-radius: 50%;
  width: 38px; height: 38px; margin: 40px auto; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }

/* ── ส่วนแก้ไขใน visit detail ── */
.mic-sm { width: 42px; height: 42px; border-radius: 50%; background: #dc2626; color: #fff;
  font-size: 1.05rem; display: inline-flex; align-items: center; justify-content: center; }
.mic-sm.listening { animation: pulse 1.2s infinite; }
.vitals-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 640px) { .vitals-grid { grid-template-columns: repeat(2, 1fr); } }
.eye-table { width: 100%; border-collapse: collapse; }
.eye-table th, .eye-table td { padding: 6px 8px; border-bottom: 1px solid #f1f5f9; text-align: left; font-size: .92rem; }
.eye-table th { color: #64748b; font-size: .8rem; }
.sig-role { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px;
  border: 2px solid #cbd5e1; border-radius: 12px; background: #fff; font-weight: 600; }
.sig-role:has(input:checked) { border-color: #2563eb; background: #eff6ff; color: #2563eb; }

/* ── ตัวเลือกยา ── */
.rx-cats { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
.rx-chip { flex-shrink: 0; padding: 10px 16px; border-radius: 999px; border: 2px solid #cbd5e1;
  background: #fff; font-weight: 600; color: #475569; }
.rx-chip.on { border-color: #2563eb; background: #2563eb; color: #fff; }
.rx-drug { min-height: 64px; display: flex; flex-direction: column; gap: 2px; text-align: left;
  align-items: flex-start; padding: 10px 14px; }
.rx-drug-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; max-width: 100%; white-space: nowrap; }
.rx-pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 8px;
  color: #64748b; font-size: .88rem; }

/* ── เครื่องมือวาดรูป ── */
.draw-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.draw-color { width: 42px; height: 42px; border-radius: 50%; border: 3px solid transparent; }
.draw-color.on { border-color: #1e293b; transform: scale(1.12); }
.draw-tool { padding: 10px 14px; border-radius: 10px; background: #fff; border: 2px solid #cbd5e1;
  font-weight: 600; min-width: 56px; }
.draw-tool.on { border-color: #2563eb; background: #eff6ff; color: #2563eb; }
