:root {
  --text-body: 16px;
  --text-control: 14px;
  --text-help: 13px;
  --primary: #6d3d8e;
  --teal: #0f766e;
  --primary-dark: #4f2a6b;
  --ink: #182231;
  --muted: #687386;
  --line: #e2e8f0;
  --surface: #ffffff;
  --page: #f6f8fb;
  --coral: #ef6f6c;
  --indigo: #5b5fc7;
  --amber: #e4a11b;
  --shadow: 0 18px 45px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}
html { overflow-x: hidden; }

/* Accessibility: bump everything ~10% larger on screen so older staff/patients read it easily.
   The app uses hardcoded px sizes, so `zoom` is the only uniform lever. Print is @media print
   (separate) so paper output is unaffected; the on-screen OPD print PREVIEWS are reset to 1:1 via a
   nested counter-zoom so the preview still matches the mm-sized A4 sheet. */
@media screen {
  body { zoom: 1.1; }
  #opdVisitLogPage, #opdPrintCard, #opdIntakeCardPage { zoom: 0.909; }
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 18px;
  color: #f8fafc;
  background: #172033;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-weight: 800;
}

.brand-logo {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 8px;
  object-fit: contain;
  background: #ffffff;
}

.brand.has-logo .brand-mark {
  display: none;
}

.brand strong,
.user-card strong {
  display: block;
}

.brand span,
.user-card span {
  display: block;
  color: #b8c1d1;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.nav-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.nav-list::-webkit-scrollbar {
  width: 6px;
}

.nav-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.nav-item {
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: 8px;
  color: #dbe4f0;
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.user-card {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 10px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.role-switcher {
  display: grid;
  gap: 5px;
  margin-top: 8px;
  color: #b8c1d1;
  font-size: 12px;
}

.role-switcher select {
  width: 100%;
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  color: #ffffff;
  background: #243047;
}

.nav-item.hidden-by-role {
  display: none;
}
/* Any element gated by role permission (e.g. revenue cards) */
.hidden-by-role {
  display: none !important;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #2dd4bf;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 14px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 34px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 19px;
}

h3 {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#branchSelector {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
}
.cloud-sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 700;
  background: #f1f5f9;
  color: #475569;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
  position: relative;
  /* FIXED width on every viewport — chip never expands based on content
     length so adjacent topbar items (version chip, switch button, etc.)
     stay rock-stable. Truncated detail is visible via the title tooltip
     (set in setCloudSyncStatus).
     • Desktop: 110px wide → shows icon + first ~12 chars of detail
     • Mobile: 44px wide → icon-only */
  width: 110px;
  flex: 0 0 110px;
  justify-content: flex-start;
  overflow: hidden;
  transition: background 0.15s, color 0.15s;
}
.cloud-sync-badge .cloud-sync-detail {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
/* Mobile: shrink to icon-only — hide detail span entirely. */
@media (max-width: 600px) {
  .cloud-sync-badge {
    width: 44px;
    flex: 0 0 44px;
    padding: 5px 8px;
    gap: 0;
  }
  .cloud-sync-badge .cloud-sync-detail { display: none; }
}
/* Pulse animation when syncing (pushing/pulling) */
.cloud-sync-badge[data-level="pushing"],
.cloud-sync-badge[data-level="pulling"] {
  animation: cloud-pulse 1.4s ease-in-out infinite;
}
@keyframes cloud-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); transform: scale(1); }
  50% { box-shadow: 0 0 0 6px rgba(59, 130, 246, 0); transform: scale(1.03); }
}
/* Error state — gentle shake */
.cloud-sync-badge[data-level="error"] {
  animation: cloud-shake 0.5s ease-in-out;
}
@keyframes cloud-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
/* Success — gentle bounce on every sync */
.cloud-sync-badge[data-level="synced"] {
  animation: cloud-bounce 0.5s ease-out;
}
@keyframes cloud-bounce {
  0% { transform: scale(0.95); opacity: 0.6; }
  50% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); }
}
.cloud-sync-badge:hover { opacity: 0.92; }
.cloud-sync-badge .cloud-sync-detail {
  font-weight: 500;
  opacity: 0.8;
  font-size: 13px;
}
/* (Old `max-width: 720px → hide detail` rule removed — now handled by the
   compact-idle + hover-expand strategy at line ~258. Mobile <600px hides
   detail entirely; tablets keep a 110px chip with truncated detail.) */

.icon-button,
.primary-action,
.ghost-button,
.chip,
.visit-card button,
.settings-menu button {
  min-height: 38px;
  border-radius: 8px;
}

.icon-button {
  width: 40px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
  font-size: 20px;
  transition: border-color 0.14s ease, background 0.14s ease, color 0.14s ease;
}

.icon-button:hover {
  border-color: var(--primary);
  background: var(--tpl-50,#faf5ff);
  color: var(--primary);
}

.notification-button {
  position: relative;
  font-weight: 900;
}

.notification-button::after {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--coral);
  color: #ffffff;
  content: attr(data-count);
  font-size: 13px;
  line-height: 1;
}

.notification-button[data-count="0"]::after {
  display: none;
}

.primary-action {
  border: 0;
  padding: 0 18px;
  color: #ffffff;
  background: var(--primary);
  font-weight: 700;
  transition: background 0.14s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.primary-action:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(109, 61, 142, 0.32);
}

.primary-action:active {
  transform: translateY(0);
  box-shadow: none;
}

.primary-action.full {
  width: 100%;
}

.ghost-button {
  border: 1px solid var(--line);
  padding: 0 14px;
  color: var(--primary-dark);
  background: #ffffff;
  transition: border-color 0.14s ease, color 0.14s ease, background 0.14s ease;
}

.ghost-button:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--tpl-50,#faf5ff);
}

.ghost-button:active {
  background: var(--tpl-100,#f3e8ff);
}

/* Universal focus ring — visible only on keyboard navigation */
.primary-action:focus-visible,
.ghost-button:focus-visible,
.icon-button:focus-visible,
.chip:focus-visible,
button:focus-visible {
  outline: 2.5px solid var(--primary);
  outline-offset: 2px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.metric-card,
.panel,
.lane,
.receipt-preview {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 132px;
  padding: 20px;
  border-top: 4px solid var(--primary);
}

.metric-card.coral {
  border-top-color: var(--coral);
}

.metric-card.indigo {
  border-top-color: var(--indigo);
}

.metric-card.amber {
  border-top-color: var(--amber);
}

.metric-card span,
.muted,
.service-list span,
.invoice-list span {
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 10px 0 4px;
  font-size: 30px;
}

.metric-card small {
  color: var(--primary-dark);
  font-weight: 700;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  gap: 18px;
}

.panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.panel-head.wide {
  align-items: flex-start;
}

.appointment-list,
.service-list,
.invoice-list {
  display: grid;
  gap: 12px;
}

.appointment-row,
.service-list div,
.invoice-list div {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.appointment-row[data-dashboard-appointment] {
  cursor: pointer;
}

.calendar-event[data-appointment-event] {
  cursor: pointer;
}

.appointment-row[data-dashboard-appointment]:hover {
  border-color: var(--primary);
  background: var(--acc-50);
}

.calendar-event[data-appointment-event]:hover {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  filter: saturate(1.05);
}

.appointment-list .visit-card {
  display: none;
}

.appointment-row time {
  color: var(--primary-dark);
  font-weight: 800;
}

.appointment-row span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.badge.arrived,
.calendar-event.arrived {
  color: #0f766e;
  background: #ccfbf1;
}

.badge.treatment,
.calendar-event.treatment {
  color: var(--tpl-deep,#5b21b6);
  background: var(--tpl-100,#ede9fe);
}

.badge.scheduled,
.calendar-event.scheduled {
  color: #9a3412;
  background: #ffedd5;
}

/* เห็นการ์ดในเครื่องยังไม่ใช่หลักฐานว่า cloud รับแล้ว — ป้ายนี้หายได้เฉพาะ
   เมื่อ /state/appointment ตอบ id นัดกลับมาจริง */
.badge.cloud-pending,
.calendar-mini-event.cloud-pending,
.appointment-cloud-pending-badge {
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #f59e0b;
}

.appointment-cloud-pending-badge {
  display: inline-flex;
  align-items: center;
  flex: none;
  white-space: nowrap;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 13px;
  font-weight: 800;
}

.badge.queued,
.badge.reminder,
.calendar-event.queued,
.calendar-event.reminder {
  color: #0f766e;
  background: #dffdf7;
}

.badge.consult,
.calendar-event.consult {
  color: #0369a1;
  background: #e0f2fe;
}

.badge.payment,
.calendar-event.payment {
  color: #92400e;
  background: #fef3c7;
}

.badge.done,
.calendar-event.done {
  color: #475569;
  background: #e2e8f0;
}

.badge.confirmed,
.calendar-event.confirmed {
  color: #1d4ed8;
  background: #dbeafe;
}

.badge.no_show,
.calendar-event.no_show {
  color: #b91c1c;
  background: #fee2e2;
}

.appointment-row.synced {
  border-color: var(--acc-200);
  background: var(--acc-50);
}

.calendar-event.selected {
  outline: 3px solid var(--primary);
  outline-offset: -3px;
}

.queue-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.queue-columns div {
  min-height: 160px;
  padding: 14px;
  background: #f8fafc;
  border-radius: 8px;
}

.queue-columns p {
  margin-bottom: 8px;
  padding: 9px;
  background: #ffffff;
  border-radius: 8px;
}

.queue-columns [data-dashboard-queue-item] {
  cursor: pointer;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.queue-columns [data-dashboard-queue-item]:hover {
  border-color: var(--primary);
  background: var(--acc-50);
}

/* Backup reminder banner — shows when last full backup > 7 days */
/* Force-hide for banners that carry inline `style="display: flex"` — without
   this, `banner.hidden = true` is overridden by the inline style and the
   banner stays visible even after admin clicks "จ่ายแล้ว" or "ภายหลัง". */
.line-quota-banner[hidden],
.backup-reminder-banner[hidden] { display: none !important; }

/* ─── PWA install banner ─────────────────────────────────────────────
   Shown when the browser advertises installability (Android Chrome fires
   beforeinstallprompt) OR when we detect iOS Safari (manual share-sheet
   instructions). Sits above all other content in the workspace. */
.pwa-install-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 12px 0;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--tpl-100,#ede9fe), var(--tpl-200,#ddd6fe));
  border: 1px solid var(--tpl-200,#c4b5fd);
  border-left: 4px solid var(--tpl-main,#7c3aed);
  border-radius: 10px;
  box-shadow: 0 4px 12px color-mix(in srgb,var(--tpl-main,#7c3aed) 12%,transparent);
}
.pwa-install-banner[hidden] { display: none !important; }
.pwa-install-banner .pwa-install-icon { font-size: 32px; flex: 0 0 32px; }
.pwa-install-banner .pwa-install-text { flex: 1; min-width: 0; }
.pwa-install-banner .pwa-install-text strong {
  display: block;
  color: var(--tpl-deep,#4c1d95);
  font-size: 15px;
  margin-bottom: 2px;
}
.pwa-install-banner .pwa-install-text span {
  display: block;
  color: var(--tpl-deep,#5b21b6);
  font-size: 13px;
}
.pwa-install-banner .pwa-install-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.pwa-install-banner .pwa-install-actions .primary-action {
  background: var(--tpl-main,#7c3aed);
  border: none;
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 700;
}
@media (max-width: 600px) {
  .pwa-install-banner {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
  .pwa-install-banner .pwa-install-actions {
    width: 100%;
  }
  .pwa-install-banner .pwa-install-actions button {
    flex: 1;
  }
}

.backup-reminder-banner {
  margin: 0 0 14px 0;
  padding: 14px 18px;
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border: 1px solid #fcd34d;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.15);
  animation: backup-reminder-pulse 3s ease-in-out infinite;
}
@keyframes backup-reminder-pulse {
  0%, 100% { box-shadow: 0 2px 8px rgba(245, 158, 11, 0.15); }
  50%      { box-shadow: 0 4px 16px rgba(245, 158, 11, 0.35); }
}
.backup-reminder-content {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.backup-reminder-icon {
  font-size: 32px;
}
.backup-reminder-text {
  flex: 1;
  min-width: 200px;
}
.backup-reminder-text strong {
  display: block;
  color: #78350f;
  font-size: 15px;
}
.backup-reminder-text span {
  display: block;
  font-size: 12px;
  color: #92400e;
  margin-top: 2px;
}
.backup-reminder-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
@media (max-width: 600px) {
  .backup-reminder-content { flex-direction: column; align-items: stretch; }
  .backup-reminder-actions { width: 100%; }
  .backup-reminder-actions button { flex: 1; }
}

/* LINE Users — NEW badge for follows within last 24h */
.line-new-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
  font-size: 13px;
  font-weight: 700;
  margin-right: 6px;
  border: 1px solid #fcd34d;
  animation: line-new-pulse 2s ease-in-out infinite;
}
@keyframes line-new-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
}
.line-user-row-new {
  background: #fffbeb;
}
.line-users-count-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  background: #16a34a;
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  vertical-align: middle;
}
.welcome-message-config summary:hover {
  color: #15803d;
}

/* Service catalog table — 7 columns (name/category/price/df/recipe/status/actions) */
.service-table .table-row {
  grid-template-columns: minmax(160px, 1.6fr) minmax(90px, 0.8fr) minmax(90px, 0.7fr) minmax(80px, 0.7fr) minmax(150px, 1.3fr) minmax(110px, 0.9fr) minmax(110px, 0.9fr);
  align-items: center;
}
.service-table .table-row.head {
  font-weight: 700;
  color: var(--muted);
  font-size: 13px;
}
.service-table .service-row {
  transition: background 0.15s, transform 0.1s;
}
.service-table .service-row:hover {
  background: #f8fafc;
}
.service-table .service-row.muted strong {
  color: var(--muted);
  text-decoration: line-through;
}
.service-table .row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.service-table .row-actions button {
  padding: 4px 8px;
  min-height: 28px;
  font-size: 13px;
}
.service-table .row-actions .delete-row-button {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}
.service-table .recipe-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--tpl-100,#ede9fe);
  color: var(--tpl-deep,#5b21b6);
  font-size: 12px;
  font-weight: 600;
}
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  font-style: normal;
}
.status-active {
  background: #d1fae5;
  color: #065f46;
}
.status-review {
  background: #fef3c7;
  color: #92400e;
}
.status-inactive {
  background: #e5e7eb;
  color: #4b5563;
}
.service-catalog-summary {
  margin: 6px 0;
}
@media (max-width: 820px) {
  .service-table .table-row {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 8px;
  }
  .service-table .table-row.head { display: none; }
  .service-table .service-row > span {
    display: block;
  }
}

.dashboard-queue-remove {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(220, 38, 38, 0.25);
  background: rgba(254, 226, 226, 0.5);
  color: #b91c1c;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.dashboard-queue-remove:hover {
  background: #fee2e2;
  border-color: #dc2626;
  transform: scale(1.08);
}

.dashboard-queue-remove:active {
  transform: scale(0.95);
}

.chart-panel,
.service-panel {
  min-height: 240px;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  align-items: end;
  gap: 12px;
  height: 170px;
  padding-top: 18px;
}

.bar-chart span {
  display: block;
  height: var(--value);
  min-height: 8px;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, var(--indigo), var(--primary));
  position: relative;
  cursor: pointer;
  transition: filter 0.15s ease;
}
.bar-chart span:hover { filter: brightness(1.1); }

/* 🎯 ไล่สีแท่งตามยอดเทียบ "เป้ารายวัน" (เป้าเดือน ÷ จำนวนวัน)
   เจ้าของ 2026-08-28: "ถ้ายอดรายวันเกินเป้า ให้ใช้สีเข้มขึ้น ตัวไหนยอดน้อยก็ลดหลั่นลงไป"
   ⇒ อ่านกราฟได้จากที่ไกลโดยไม่ต้องอ่านตัวเลขทีละแท่ง
   ⚠️ ไล่ด้วย "ความเข้มของสีเดียวกัน" ไม่ใช่สลับเป็นคนละสี — คนละสีจะอ่านเป็น "คนละประเภท"
      ส่วนแท่งที่ถึงเป้าใช้สีเขียวเพราะมันคือ "ผ่านเกณฑ์" ซึ่งเป็นความหมายคนละแกนกับปริมาณ */
.bar-chart span[data-tier="0"] { background: linear-gradient(180deg, #e9d5ff, #ddd6fe); }
.bar-chart span[data-tier="1"] { background: linear-gradient(180deg, #c4b5fd, #a78bfa); }
.bar-chart span[data-tier="2"] { background: linear-gradient(180deg, #a78bfa, #8b5cf6); }
.bar-chart span[data-tier="3"] { background: linear-gradient(180deg, #8b5cf6, #6d28d9); }
/* ถึงเป้ารายวัน — เขียวเข้ม + ขอบเรืองให้เด่นออกมาจากกลุ่ม */
.bar-chart span[data-tier="4"] {
  background: linear-gradient(180deg, #34d399, #059669);
  box-shadow: 0 0 0 1.5px rgba(5, 150, 105, 0.35), 0 3px 10px rgba(5, 150, 105, 0.28);
}
.bar-chart.with-values span[data-tier="4"]::before { color: #047857; font-weight: 800; }
/* Today's bar — gradient stays the same but adds a glow + thicker label so
   user can spot "วันนี้" at a glance even if revenue is 0. */
.bar-chart span[data-today="1"] {
  background: linear-gradient(180deg, #f59e0b, #d97706);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3), 0 4px 12px rgba(245, 158, 11, 0.35);
}
.bar-chart span[data-today="1"]::after {
  color: #b45309;
  font-weight: 800;
}
/* Day label under each bar (data-day = "อา" / "จ" / "อ" / ...) */
.bar-chart span::after {
  content: attr(data-day);
  position: absolute;
  bottom: -20px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.bar-chart { padding-bottom: 22px; }

/* Selected hour bar (drill-down) — orange highlight + ring */
.bar-chart span.bar-selected {
  background: linear-gradient(180deg, #f59e0b, #d97706);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.45), 0 6px 16px rgba(245, 158, 11, 0.4);
}
/* Selection summary at the TOP of the chart area (hour drill-down) */
.reports-selection-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin: 0 0 12px;
  background: #fff7ed;
  border: 1px solid #fdba74;
  border-left: 4px solid #f97316;
  border-radius: 10px;
  font-size: 15px;
  color: #9a3412;
}
.reports-selection-summary[hidden] { display: none; }
.reports-selection-summary strong { color: #7c2d12; }

/* Amount label ABOVE each bar — only on the Reports chart (.with-values).
   Empty (฿0) bars carry an empty data-amount-label so nothing renders. */
.bar-chart.with-values { padding-top: 26px; }
.bar-chart.with-values span::before {
  content: attr(data-amount-label);
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
  color: var(--indigo, var(--tpl-main,#6366f1));
  pointer-events: none;
}
/* Service-row layout for "บริการขายดี" — matches dashboard look */
.service-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 8px 12px;
  background: #f9fafb;
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 13px;
}
.service-row strong { color: #0f172a; font-weight: 600; }
.service-row span { color: var(--muted); font-size: 12px; align-self: center; }

/* Reports summary KPI cards */
.report-summary-card {
  padding: 14px;
  background: linear-gradient(135deg, #fff, #f9fafb);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.report-summary-card span { color: var(--muted); font-size: 12px; }
.report-summary-card strong { font-size: 22px; color: var(--ink); }
.report-summary-card em { font-size: 13px; color: var(--muted); font-style: normal; }

/* Category eyebrow at the top of each KPI card */
.report-summary-card .card-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: var(--muted);
}
/* Month anchor card — indigo accent */
.report-summary-card.is-month {
  background: linear-gradient(135deg, var(--tpl-50,#f5f3ff), var(--tpl-50,#eef2ff));
  border-color: var(--tpl-200,#c7d2fe);
}
.report-summary-card.is-month .card-eyebrow { color: var(--tpl-main,#6366f1); }
.report-summary-card.is-month strong { color: #4338ca; }
/* Selected-day card — orange accent (matches the highlighted bar) */
.report-summary-card.is-day {
  background: linear-gradient(135deg, #fff7ed, #ffedd5);
  border-color: #fdba74;
  border-left: 4px solid #f97316;
}
.report-summary-card.is-day .card-eyebrow { color: #ea580c; }
.report-summary-card.is-day strong { color: #c2410c; }

/* Cancel ✕ button on dashboard appointment rows — sits at the far right. */
.dashboard-appointment-cancel {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(220, 38, 38, 0.25);
  background: rgba(254, 226, 226, 0.5);
  color: #b91c1c;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: 8px;
  transition: background 0.15s, transform 0.1s;
}
.dashboard-appointment-cancel:hover {
  background: #fee2e2;
  border-color: #dc2626;
  transform: scale(1.08);
}
.dashboard-appointment-cancel:active { transform: scale(0.95); }

.service-list div,
.invoice-list div {
  grid-template-columns: minmax(0, 1fr) auto;
}

.calendar-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.chip,
.calendar-toolbar select {
  border: 1px solid var(--line);
  padding: 0 12px;
  background: #ffffff;
}

.chip.active {
  border-color: var(--primary);
  color: #ffffff;
  background: var(--primary);
}

.upload-chip {
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}

.upload-chip input {
  display: none;
}

.visually-hidden-file {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  opacity: 0;
  overflow: hidden;
}

.print-tool-status {
  flex-basis: 100%;
  margin: 4px 0 0;
  font-weight: 800;
}

.calendar-grid {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.calendar-grid.calendar-mode-week,
.calendar-grid.calendar-mode-month {
  grid-template-columns: repeat(7, minmax(130px, 1fr));
  gap: 0;
  overflow-x: auto;
}

.calendar-grid.calendar-mode-week > div,
.calendar-grid.calendar-mode-month > div {
  min-height: 150px;
  border-right: 1px solid var(--line);
}

.calendar-day-card,
.calendar-month-day {
  display: grid;
  align-content: start;
  gap: 8px;
  background: #ffffff;
}

.calendar-day-card strong,
.calendar-month-day strong {
  color: var(--ink);
}

.calendar-day-card small,
.calendar-month-day small {
  color: var(--muted);
  font-weight: 800;
}

.calendar-month-day.muted-day {
  background: #f8fafc;
  color: var(--muted);
}

.calendar-mini-event {
  display: block;
  padding: 7px 8px;
  border-radius: 7px;
  background: #ecfeff;
  color: #0f766e;
  font-size: 12px;
  font-weight: 900;
}

.appointment-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  align-items: start;
}

.calendar-grid > div {
  min-height: 74px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.time-slot {
  color: var(--muted);
  background: #f8fafc;
  font-weight: 800;
}

.time-slot.locked,
.calendar-event.locked {
  color: #991b1b;
  background: #fef2f2;
}

.calendar-event {
  border-radius: 8px;
  font-weight: 800;
}

.attendance-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.attendance-row {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-radius: 8px;
  background: #ffffff;
}

.attendance-row span {
  color: var(--muted);
  font-size: 13px;
}

.attendance-row.available {
  border-left: 4px solid var(--primary);
}

.attendance-row.unavailable {
  border-left: 4px solid var(--coral);
}

.recurring-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.recurring-panel section {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.recurring-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffffff;
}

.recurring-row span {
  color: var(--muted);
}

.split-view,
.payment-layout,
.settings-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.85fr);
  gap: 18px;
  align-items: start;
}

/* Sticky right detail panel — follows scroll so admin always sees selected customer */
#customers.view .split-view > .customer-profile {
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  scrollbar-width: thin;
}
#customers.view .split-view > .customer-profile::-webkit-scrollbar { width: 6px; }
#customers.view .split-view > .customer-profile::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 999px; }
#customers.view .split-view > .customer-profile::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  #customers.view .split-view > .customer-profile {
    position: static;
    max-height: none;
  }
}

.search-field {
  width: 100%;
  min-height: 42px;
  margin-bottom: 14px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.customer-workflow-guide {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.customer-workflow-guide > div {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.customer-workflow-guide .new {
  border-color: rgba(20, 184, 166, 0.45);
  background: var(--acc-50);
}

.customer-workflow-guide .returning {
  border-color: rgba(245, 158, 11, 0.45);
  background: #fffbeb;
}

.customer-workflow-guide strong {
  font-size: 0.95rem;
}

.customer-workflow-guide span {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 750;
}

.customer-workflow-guide b {
  display: grid;
  flex: 0 0 24px;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--acc-bright);
}

.customer-workflow-guide .returning b {
  background: #f59e0b;
}

.data-table {
  display: grid;
  gap: 8px;
}

.customer-row > span:first-child {
  display: grid;
  gap: 2px;
  cursor: zoom-in;
}

.customer-row > span:first-child strong {
  color: var(--ink);
}

.customer-row > span:first-child em {
  color: var(--muted);
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 850;
}

.save-status {
  display: block;
  margin-top: 3px;
  color: #0f766e;
  font-size: 0.82rem;
  font-weight: 850;
}

.table-row {
  display: grid;
  grid-template-columns: 1fr 1fr 0.8fr 0.7fr;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

#customers .table-row {
  grid-template-columns: 1fr 1fr 0.75fr 0.65fr auto;
  align-items: center;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
}

.delete-row-button {
  min-height: 34px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 0 12px;
  color: #b91c1c;
  background: #fff5f5;
  font-weight: 900;
}

.delete-row-button:hover {
  border-color: #ef4444;
  background: #fee2e2;
}

.table-row.head {
  color: var(--muted);
  background: #f8fafc;
  font-weight: 800;
}

.table-row.selected {
  border-color: var(--primary);
  background: var(--acc-50);
}

.customer-row {
  cursor: pointer;
}

.customer-row > span:not(.row-actions) {
  cursor: zoom-in;
}

.customer-row:hover {
  border-color: rgba(20, 184, 166, 0.7);
  background: #f8fffd;
}

.customer-next-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}

.selected-customer-next-step {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid rgba(20, 184, 166, 0.35);
  border-radius: 8px;
  color: #0f766e;
  background: var(--acc-50);
  font-weight: 800;
}

.products-table .table-row {
  /* 6 columns: สินค้า · หมวด · ราคา · คงเหลือ · สถานะ · จัดการ(✏️🗑). Was 5 → the 6th
     span (actions) wrapped to a new line UNDER the product, making every row tall. With
     a real 6th column the edit/delete buttons sit on the far right, on one line. */
  grid-template-columns: 1.6fr 0.9fr 0.8fr 0.7fr 0.7fr 0.8fr;
  align-items: center;
}

.course-table .table-row {
  grid-template-columns: 1fr 1.3fr 0.7fr 0.9fr 0.7fr;
}

.table-row.warning {
  border-color: #f59e0b;
  background: #fffbeb;
}

/* Out-of-stock (0) = RED, a step more urgent than amber "ต่ำกว่า min". */
.table-row.danger {
  border-color: #dc2626;
  background: #fef2f2;
}
.status-badge.status-danger {
  background: #fee2e2;
  color: #b91c1c;
}

/* Count badge on the สินค้า/สต็อก sidebar tab → standing "N ของเข้ารออนุมัติ" indicator. */
.nav-pending-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-left: auto;
  padding: 0 5px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}
.nav-pending-badge[hidden] { display: none; }

.profile-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--coral);
  font-weight: 900;
  font-size: 22px;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar.has-photo { background: #f1f5f9; padding: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.profile-head p {
  margin-bottom: 0;
  color: var(--muted);
}

.tabs,
.payment-methods {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tabs button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: #eef2f7;
}

.tabs button.active {
  color: #ffffff;
  background: var(--ink);
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.consent-status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.consent-status-strip div,
.consent-rule-list div,
.media-guard-banner {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.consent-status-strip span,
.consent-rule-list span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.consent-status-strip .safe,
.consent-rule-list .safe {
  border-color: var(--acc-200);
  background: #ecfeff;
}

.consent-status-strip .blocked,
.consent-rule-list .blocked,
.media-guard-banner {
  border-color: #fecaca;
  background: #fef2f2;
}

.consent-rule-list .warning {
  border-color: #fde68a;
  background: #fffbeb;
}

.media-guard-banner {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
  color: #991b1b;
}

.media-guard-banner span {
  color: #7f1d1d;
}

.integration-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.wallet-summary {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.wallet-summary span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.followup-panel {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.customer-care-strip {
  display: grid;
  grid-template-columns: 1.35fr 0.65fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.customer-care-strip div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.customer-care-strip span,
.timeline-item time {
  color: var(--muted);
  font-weight: 800;
}

.timeline-panel,
.case-gallery {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.timeline-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: #f8fafc;
}

.timeline-item div {
  display: grid;
  gap: 4px;
}

.timeline-item span,
.timeline-item em {
  color: var(--muted);
  font-style: normal;
}

.case-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.case-grid div {
  position: relative;
  display: grid;
  align-content: end;
  aspect-ratio: 1 / 1;
  min-height: 0;
  overflow: hidden;
  padding: 12px;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  background: linear-gradient(135deg, #f8fafc, var(--tpl-50,#eef2ff));
}

.case-grid img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.case-grid span {
  position: relative;
  color: var(--ink);
  font-weight: 900;
  z-index: 1;
}

.case-grid strong {
  position: relative;
  color: var(--muted);
  font-size: 12px;
  z-index: 1;
}

.case-grid em {
  position: relative;
  color: #64748b;
  font-size: 13px;
  font-style: normal;
  line-height: 1.35;
  z-index: 1;
}

.case-gallery-item:has(img) {
  border: 0;
  background: linear-gradient(180deg, transparent 35%, rgba(15, 23, 42, 0.76));
}

.case-gallery-item:has(img) span,
.case-gallery-item:has(img) strong,
.case-gallery-item:has(img) em {
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(15, 23, 42, 0.55);
}

.timeline-drawer {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  justify-items: end;
  pointer-events: none;
  background: rgba(15, 23, 42, 0);
  transition: background 0.2s ease;
}

.timeline-drawer.show {
  pointer-events: auto;
  background: rgba(15, 23, 42, 0.28);
}

.drawer-panel {
  width: min(680px, 100%);
  height: 100%;
  overflow: auto;
  padding: 22px;
  background: #ffffff;
  box-shadow: -18px 0 40px rgba(15, 23, 42, 0.18);
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.timeline-drawer.show .drawer-panel {
  transform: translateX(0);
}

.timeline-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0;
}

.drawer-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.drawer-summary div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.drawer-summary span {
  color: var(--muted);
  font-weight: 800;
}

.drawer-timeline {
  display: grid;
  gap: 12px;
}

.drawer-event {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: #ffffff;
}

.drawer-event time,
.drawer-event span,
.drawer-event em {
  color: var(--muted);
  font-style: normal;
}

.followup-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffffff;
}

.followup-row span {
  color: var(--muted);
}

.followup-row.warning {
  color: #991b1b;
  background: #fef2f2;
}

.profile-stats div,
.note-box,
.integration-strip div,
.line-preview {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.integration-strip div,
.line-preview {
  background: #f8fafc;
}

.profile-stats span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.integration-strip span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.kanban {
  display: grid;
  grid-template-columns: repeat(6, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.lane {
  min-height: 300px;
  padding: 12px;
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.lane.empty {
  background: linear-gradient(180deg, #ffffff, #f8fafc);
}

.lane.empty::after {
  content: "ไม่มีคิว";
  display: grid;
  min-height: 72px;
  place-items: center;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  color: #94a3b8;
  font-weight: 850;
}

.lane.drag-over {
  border-color: rgba(20, 184, 166, 0.65);
  background: var(--acc-50);
  box-shadow: inset 0 0 0 2px rgba(20, 184, 166, 0.18);
}

.lane h2 {
  font-size: 1.05rem;
}

.visit-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  cursor: grab;
  user-select: none;
  position: relative;
  transition: opacity 0.18s, transform 0.18s;
  /* Allow vertical scroll on iPad but capture drag for our pointer handler.
     We block scroll only AFTER a drag actually starts (via .dragging class). */
  touch-action: pan-y;
}
.visit-card.dragging {
  /* During an active drag, block scroll so finger movement is interpreted as drag */
  touch-action: none;
}
.queue-card-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: #94a3b8;
  font-size: 18px;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  z-index: 2;
}
.queue-card-remove:hover {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
}
.queue-assignment {
  display: block;
  font-size: 12px;
  font-style: normal;
  color: #475569;
  background: #f1f5f9;
  padding: 4px 8px;
  border-radius: 6px;
  font-weight: 600;
}
.queue-card-removing {
  opacity: 0;
  transform: translateX(20px) scale(0.95);
  pointer-events: none;
}

/* Queue assignment modal */
.queue-assign-form { display: grid; gap: 12px; max-height: 70vh; overflow-y: auto; padding-right: 4px; }
.queue-assign-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  padding: 10px 12px;
  background: linear-gradient(135deg, var(--tpl-50,#eef2ff) 0%, #ecfeff 100%);
  border-radius: 8px;
  font-size: 13px;
}
.queue-assign-head strong { font-size: 15px; }

/* ─── iOS Cloud Diagnostic Modal (task #252) ──────────────────────── */
.ios-diagnostic-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  z-index: 10000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px 16px;
  overflow-y: auto;
}
.ios-diagnostic-card {
  background: #fff;
  border-radius: 14px;
  padding: 18px 20px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 24px 48px -8px rgba(15, 23, 42, 0.45);
  display: grid;
  gap: 12px;
}
.ios-diagnostic-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid #e2e8f0;
}
.ios-diagnostic-head strong { font-size: 15px; color: #0f172a; }
.ios-diagnostic-meta {
  font-size: 13px;
  color: #64748b;
  background: #f8fafc;
  padding: 8px 10px;
  border-radius: 6px;
  line-height: 1.6;
}
.ios-diagnostic-meta code {
  background: #fff;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  color: #475569;
  word-break: break-all;
  font-size: 13px;
}
.ios-diagnostic-rows {
  display: grid;
  gap: 8px;
}
.ios-diagnostic-row {
  padding: 8px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
}
.ios-diagnostic-note {
  font-size: 13px;
  color: #64748b;
  margin-top: 4px;
  word-break: break-all;
  font-family: ui-monospace, monospace;
}
.ios-diagnostic-error {
  font-size: 13px;
  color: #b91c1c;
  background: #fef2f2;
  border-radius: 4px;
  padding: 4px 6px;
  margin-top: 4px;
  font-family: ui-monospace, monospace;
  word-break: break-all;
}
.ios-diagnostic-running {
  text-align: center;
  color: #64748b;
  font-size: 12px;
  padding: 8px;
}
.ios-diagnostic-summary {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}
.ios-diagnostic-summary.success {
  background: #d1fae5;
  border: 1px solid #6ee7b7;
  color: #065f46;
}
.ios-diagnostic-summary.warning {
  background: #fef3c7;
  border: 1px solid #fbbf24;
  color: #92400e;
}
.ios-diagnostic-summary.error {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}
.ios-diagnostic-summary code {
  background: #fff;
  padding: 1px 4px;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}
.ios-diagnostic-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.ios-diagnostic-actions button { flex: 1; min-width: 140px; }
@media (max-width: 480px) {
  .ios-diagnostic-actions { flex-direction: column; }
  .ios-diagnostic-actions button { width: 100%; }
}

/* ─── Cloud Pull Recovery Alert (task #251) ──────────────────────── */
#cloudPullRecoveryAlert {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  max-width: 540px;
  width: calc(100vw - 24px);
  box-sizing: border-box;
}
.cloud-recovery-card {
  background: #fff5f5;
  border: 2px solid #f87171;
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 12px 36px -8px rgba(239, 68, 68, 0.35);
  display: grid;
  gap: 10px;
}
.cloud-recovery-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.cloud-recovery-head strong {
  color: #b91c1c;
  font-size: var(--text-body);
}
.cloud-recovery-detail {
  background: #fff;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: var(--text-body);
  display: grid;
  gap: 4px;
  color: #374151;
}
.cloud-recovery-detail code {
  background: #fef2f2;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  color: #b91c1c;
  word-break: break-all;
}
.cloud-recovery-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.cloud-recovery-actions button { flex: 1; min-width: 120px; }

@media (max-width: 480px) {
  .cloud-recovery-actions { flex-direction: column; }
  .cloud-recovery-actions button { width: 100%; }
}

/* ─── Topbar Version Chip — single-line + truncate (task #251) ─────── */
.topbar-version-chip {
  font-size: 13px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  vertical-align: middle;
  line-height: 1.4;
}
.topbar-version-chip:hover { background: #e2e8f0; color: #1e293b; }

@media (max-width: 768px) {
  .topbar-version-chip {
    max-width: 90px;
    font-size: 13px;
    padding: 3px 7px;
  }
}
@media (max-width: 480px) {
  .topbar-version-chip {
    max-width: 70px;
  }
}

/* ─── Mobile overflow guards (topbar + banner buttons) ─────────────── */
@media (max-width: 600px) {
  .topbar-actions {
    flex-wrap: wrap;
    width: 100%;
    justify-content: flex-end;
    gap: 6px;        /* tighter from 10px so small chips fit one row */
    align-items: center;
  }
  .topbar-actions > * {
    max-width: 100%;
  }
  /* Small chips never grow/shrink — stay compact + cluster together */
  #topbarUserChip,
  #appVersionChip,
  .cloud-sync-badge,
  .topbar-actions > .icon-button {
    flex: 0 0 auto;
  }
  /* User chip on mobile: tighter padding so Dr.Golf + role pill fit in less width */
  .topbar-user-chip { padding: 4px 8px; font-size: 12px; gap: 6px; }
  .topbar-user-chip-avatar { width: 22px; height: 22px; font-size: 13px; }
  /* HIDE role label ("Super Admin", "Doctor", etc.) inside the user chip on
     mobile — saves ~70px so the cloud sync chip can join row 1 instead of
     wrapping alone. Role is still discoverable via the chip's title attribute
     and via the "👥 สลับ" button next to it. */
  .topbar-user-chip span:nth-child(3) { display: none !important; }
  /* Cap user name width — if someone's name is very long it would still push
     other chips off the row. Truncate with ellipsis. */
  .topbar-user-chip span:nth-child(2) {
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* Icon buttons (🔒 ⌕ !) → smaller so 3+ can share row */
  .topbar-actions > .icon-button { width: 36px; min-height: 36px; font-size: 16px; }
  /* Branch selector takes its OWN row (full width) — it carries long Thai text
     "พัทยา (สำนักงานใหญ่)" and benefits from not being squished into a chip cluster. */
  #branchSelector {
    flex: 1 1 100%;
    min-height: 36px;
    padding: 0 10px;
    font-size: 13px;
  }
  /* "เปิด Visit" CTA stays compact, never grows */
  .topbar-actions > .primary-action {
    flex: 0 0 auto;
    padding: 0 14px;
    min-height: 36px;
    font-size: 13px;
  }
  /* LINE quota banner + backup banner: stack buttons full-width on mobile */
  .line-quota-banner > div:last-child,
  .backup-reminder-actions {
    width: 100%;
  }
  .line-quota-banner > div:last-child button,
  .backup-reminder-actions button {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
  }
  .workspace {
    padding: 14px;
    max-width: 100%;
    overflow-x: hidden;
  }
  .topbar h1 { font-size: 24px; }
}

/* ─── Pre-Print Vitals Quick-Fill Modal (task #250) ──────────────────── */
.vitals-quickfill-form {
  display: grid;
  gap: 12px;
  max-height: 75vh;
  overflow-y: auto;
  padding-right: 4px;
}
.vitals-quickfill-banner {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 14px;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 1px solid #fbbf24;
  border-radius: 10px;
}
.vitals-quickfill-banner strong { color: #92400e; font-size: 14px; }
.vitals-quickfill-banner p { color: #92400e; }

.vitals-section {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  gap: 10px;
}
.vitals-section-title {
  font-weight: 700;
  font-size: 13px;
  padding-bottom: 6px;
  border-bottom: 1px dashed #e2e8f0;
}
.vitals-section-title.required { color: #b91c1c; }
.vitals-section-title.warning { color: #92400e; }

.vitals-status-bad {
  display: inline-block;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 13px;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 700;
  margin-left: 4px;
  vertical-align: middle;
}
.vitals-status-warn {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  font-size: 13px;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 700;
  margin-left: 4px;
  vertical-align: middle;
}

.vitals-consent-notice {
  padding: 10px 12px;
  background: #eff6ff;
  border: 1px dashed #93c5fd;
  border-radius: 8px;
  color: #1e40af;
  font-size: 12px;
  line-height: 1.5;
}

.vitals-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 4px;
}

.vitals-override-btn {
  background: #fff;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.vitals-override-btn:hover {
  background: #fee2e2;
  border-color: #ef4444;
}
.vitals-override-btn.vitals-override-armed {
  background: #dc2626;
  color: #fff;
  border-color: #b91c1c;
  animation: vitals-override-pulse 0.6s ease-in-out infinite alternate;
}
@keyframes vitals-override-pulse {
  from { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4); }
  to { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}

@media (max-width: 640px) {
  .vitals-actions { flex-direction: column-reverse; }
  .vitals-actions button { width: 100%; }
}

.visit-card:active {
  cursor: grabbing;
}

.visit-card.dragging {
  opacity: 0.55;
  transform: scale(0.99);
}

.visit-card.active {
  border-color: var(--indigo);
  background: var(--tpl-50,#eef2ff);
  box-shadow: 0 0 0 2px rgba(91, 95, 199, 0.08);
}

.visit-card.opd-open {
  border-color: var(--primary);
  background: var(--acc-50);
}

.visit-card.ready-payment {
  border-color: #f59e0b;
  background: #fffbeb;
}

.visit-card.ready-payment::before {
  content: "รอชำระเงิน";
  width: fit-content;
  padding: 2px 8px;
  border-radius: 999px;
  color: #92400e;
  background: #fef3c7;
  font-size: 12px;
  font-weight: 900;
}

.visit-card.opd-open::before {
  content: "OPD active";
  width: fit-content;
  padding: 2px 8px;
  border-radius: 999px;
  color: #0f766e;
  background: #ccfbf1;
  font-size: 12px;
  font-weight: 900;
}

.visit-card span {
  color: var(--muted);
}

.visit-card .queue-hn {
  width: fit-content;
  padding: 1px 7px;
  border-radius: 999px;
  color: #475569;
  background: #f1f5f9;
  font-size: 13px;
  font-weight: 900;
}

.visit-card .queue-meta {
  color: #64748b;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.visit-card .queue-handler {
  display: block;
  width: fit-content;
  margin-top: 2px;
  padding: 2px 8px;
  border-radius: 999px;
  color: #3730a3;
  background: var(--tpl-50,#eef2ff);
  font-size: 13px;
  font-style: normal;
  font-weight: 700;
}

/* ── OPD warning banner — terminal / typewriter look ────────────────── */
.opd-warning-banner {
  /* block (not flex) so the cursor flows inline right after the last character
     even when the text wraps to 2 lines — flex was floating it to the far right
     as a stray "dash". */
  display: block;
  margin-bottom: 14px;
  padding: 16px 20px;
  border-radius: 12px;
  background-color: #0c0f14;
  background-image: radial-gradient(rgba(148, 163, 184, 0.18) 1px, transparent 1px);
  background-size: 22px 22px;
  border: 1px solid #1f2733;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02), 0 6px 20px rgba(0, 0, 0, 0.25);
  /* Single Thai+Latin family so ไทย and อังกฤษ render at the SAME weight. The
     old mono stack made Latin use DejaVu Mono and Thai fall back to a different
     system font → uneven boldness. */
  font-family: "Sarabun", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 800;
  font-size: clamp(18px, 2.6vw, 30px);
  line-height: 1.35;
  letter-spacing: 0.01em;
  color: #e8edf4;
  overflow-wrap: anywhere;
}
.opd-warning-banner .owb-text {
  white-space: pre-wrap;
}
.opd-warning-banner .owb-cursor {
  display: inline;
  margin-left: 3px;
  color: #84cc16;
  font-weight: 800;
  animation: owb-blink 1s steps(1) infinite;
}
@keyframes owb-blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}
.opd-warning-banner.owb-preview {
  margin-bottom: 0;
  font-size: clamp(15px, 2vw, 22px);
  padding: 14px 18px;
}

/* Compact variant — sits inline in the top bar (between page title and the
   action chips) so it doesn't eat a tall full-width row. Wraps if needed so
   bigger sizes still show the full message. Font-size comes from .owb-size-*. */
.opd-warning-banner.owb-compact {
  flex: 1 1 auto;
  min-width: 0;
  margin-bottom: 0;
  padding: 10px 18px;
  border-radius: 12px;
  line-height: 1.25;
  white-space: normal;
  overflow: hidden;
}
.opd-warning-banner.owb-compact .owb-text {
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Staff-adjustable size — applied to header banner AND the settings preview.
   Declared LAST so it wins over .owb-compact / .owb-preview base font-size. */
.opd-warning-banner.owb-size-sm { font-size: 16px; }
.opd-warning-banner.owb-size-md { font-size: 20px; }
.opd-warning-banner.owb-size-lg { font-size: 25px; }
.opd-warning-banner.owb-size-xl { font-size: 31px; }

@media (max-width: 768px) {
  .opd-warning-banner {
    padding: 12px 14px;
  }
  /* On phones the topbar stacks — the warning becomes a clean full-width strip
     directly under the page title (NOT shoved below the action chips). Natural
     DOM order (title → banner → actions) + flex-basis:100% places it there. */
  .opd-warning-banner.owb-compact {
    flex-basis: 100%;
    order: 0;
    text-align: center;
    padding: 12px 16px;
  }
  /* Cap the very largest size a touch on phones so it doesn't dominate */
  .opd-warning-banner.owb-size-lg { font-size: 22px; }
  .opd-warning-banner.owb-size-xl { font-size: 26px; }
}

/* OPD warning settings — toggle row */
.opd-warning-settings .owb-toggle-field {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-direction: row;
}
.opd-warning-settings .owb-toggle-field input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex: none;
}
.opd-warning-settings textarea {
  width: 100%;
  font-family: inherit;
  resize: vertical;
}
.opd-warning-settings .owb-color-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}
.opd-warning-settings .owb-color-field input[type="color"] {
  width: 100%;
  height: 40px;
  padding: 2px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  cursor: pointer;
  background: #fff;
}

.visit-card .queue-zone {
  width: fit-content;
  padding: 2px 8px;
  border-radius: 999px;
  color: #0f766e;
  background: #ccfbf1;
  font-size: 12px;
  font-weight: 900;
}

.visit-card .doctor-line-badge {
  width: fit-content;
  padding: 3px 8px;
  border-radius: 999px;
  color: #166534;
  background: #dcfce7;
  font-size: 12px;
  font-weight: 900;
}

.visit-card button {
  border: 1px solid var(--line);
  background: #f8fafc;
}

.visit-card button + button {
  margin-top: 2px;
}

.visit-card.opd-open button {
  color: #0f766e;
  background: #ecfeff;
}

.visit-card.status-consult {
  border-color: #38bdf8;
  background: #f0f9ff;
}

.visit-card.status-numbing {
  border-color: #f59e0b;
  background: #fffbeb;
}

.visit-card.status-treatment {
  border-color: var(--indigo);
  background: var(--tpl-50,#eef2ff);
}

.visit-card.status-recovery {
  border-color: var(--acc-bright);
  background: var(--acc-50);
}

.visit-card.status-payment {
  border-color: #f59e0b;
  background: #fffbeb;
}

.opd-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.required-star {
  color: #dc2626;
  font-style: normal;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
}

textarea {
  min-height: 120px;
  padding: 12px;
  resize: vertical;
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

.field-invalid {
  border-color: #dc2626 !important;
  background: #fff1f2 !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.photo-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  grid-column: 1 / -1;
}

.photo-strip div {
  display: grid;
  place-items: center;
  min-height: 160px;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  color: var(--muted);
  background: #f8fafc;
  font-weight: 800;
}

.facechart-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.75fr) minmax(260px, 0.45fr);
  gap: 16px;
  margin-top: 16px;
}

.opd-start-guide {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.opd-start-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.opd-start-flow {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
}

.opd-start-flow h3 {
  margin: 0 0 4px;
}

.opd-start-flow div {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 4px 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 8px;
  background: #ffffff;
}

.opd-start-flow span {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #ffffff;
  font-weight: 900;
}

.opd-start-flow strong {
  grid-column: 2;
  grid-row: 1;
  color: #111827;
}

.opd-start-flow em {
  grid-column: 2;
  grid-row: 2;
  color: #64748b;
  font-size: 12px;
  font-style: normal;
}

.opd-start-flow button {
  grid-column: 3;
  grid-row: 1 / span 2;
  min-width: 118px;
}

.opd-start-flow.new-patient {
  border-color: rgba(20, 184, 166, 0.55);
  background: var(--acc-50);
}

.opd-start-flow.new-patient span {
  background: var(--acc-bright);
}

.opd-start-flow.returning-patient {
  border-color: rgba(245, 158, 11, 0.55);
  background: #fffbeb;
}

.opd-start-flow.returning-patient span {
  background: #f59e0b;
}

.opd-print-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.opd-print-tools h3 {
  margin: 0 0 4px;
}

.print-preset-note {
  margin-top: 4px;
  font-size: 12px;
}

.hybrid-opd-flow,
.pdpa-consent-panel,
.opd-card-pack-panel,
.opd-day-workflow,
.opd-complete-panel,
.opd-admin-worklist,
.opd-cloud-panel,
.opd-status-board,
.paper-folder-panel,
.opd-posting-panel,
.opd-evidence-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.opd-day-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.opd-day-grid div {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  min-height: 104px;
  padding: 12px;
  border: 1px solid #d7e1ef;
  border-radius: 8px;
  background: #f8fafc;
}

.opd-day-grid span {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(14, 116, 144, 0.25);
  border-radius: 50%;
  color: #0f766e;
  background: #ecfeff;
  font-weight: 900;
}

.opd-day-grid strong {
  color: #111827;
  font-size: 15px;
}

.opd-day-grid em {
  color: #64748b;
  font-style: normal;
  line-height: 1.45;
}

.opd-day-note {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(20, 184, 166, 0.4);
  border-radius: 8px;
  background: var(--acc-50);
  color: #0f172a;
}

.opd-day-note span {
  color: #475569;
}

.opd-action-center {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  grid-template-rows: auto auto auto;
  gap: 10px 14px;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid rgba(109, 61, 142, 0.22);
  border-radius: 10px;
  background: var(--tpl-50,#faf5ff);
}

.opd-action-summary {
  display: grid;
  gap: 5px;
  grid-row: 1 / span 2;
  align-self: start;
  padding: 10px 12px;
  border-right: 1px solid rgba(109, 61, 142, 0.15);
}

.opd-action-summary span,
.opd-action-summary em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.opd-action-summary > span:first-child {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 13px;
  font-weight: 800;
  color: var(--primary);
  opacity: 0.7;
}

.opd-action-summary strong {
  color: var(--primary-dark);
  font-size: 0.92rem;
  line-height: 1.3;
}

.opd-progress {
  display: grid;
  gap: 5px;
  margin-top: 6px;
}

.opd-progress > span {
  color: var(--primary);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.opd-progress > strong {
  display: block;
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(109, 61, 142, 0.15);
}

.opd-progress i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #cb2bb8);
  transition: width 280ms cubic-bezier(.4,0,.2,1);
}

.opd-steps-hint {
  grid-column: 2;
  margin: 0;
  font-size: 12px;
  color: var(--primary-dark);
  background: rgba(109, 61, 142, 0.06);
  border: 1px dashed rgba(109, 61, 142, 0.3);
  border-radius: 8px;
  padding: 8px 11px;
  line-height: 1.45;
  align-self: start;
}

.opd-action-buttons {
  display: grid;
  grid-column: 2;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.opd-action-buttons button {
  min-height: 44px;
}

.opd-action-buttons button[data-opd-step-button] {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 62px;
  padding: 8px 6px 6px;
  border: 1.5px solid #e2e8f0;
  border-radius: 9px;
  color: var(--ink);
  background: #ffffff;
  box-shadow: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

/* Real navigation affordance */
.opd-action-buttons button[data-opd-step-button]:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 16px rgba(109, 61, 142, 0.18);
  border-color: var(--primary);
  background: var(--tpl-50,#faf5ff);
}
.opd-action-buttons button[data-opd-step-button]:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.1);
}

.opd-action-buttons button[data-opd-step-button]::after {
  content: attr(data-step-status);
  display: block;
  margin-top: 3px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.15;
  opacity: 0.85;
  letter-spacing: 0.01em;
}

/* ── Done: purple filled (on-brand) ─────────────────────── */
.opd-action-buttons button.step-done {
  border-color: var(--primary);
  color: #ffffff;
  background: var(--primary);
}
.opd-action-buttons button.step-done:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: 0 4px 14px rgba(109, 61, 142, 0.3);
}

/* ── Next: pink pulse ──────────────────────────────────── */
.opd-action-buttons button.step-next {
  border-color: #db2777;
  border-width: 2px;
  color: #9d174d;
  background: #fff0f7;
  box-shadow: 0 0 0 3px rgba(219, 39, 119, 0.08);
  animation: opdStepPulse 1.8s ease-in-out infinite;
}
.opd-action-buttons button.step-next:hover {
  animation: none;
  background: #fce7f3;
  box-shadow: 0 4px 14px rgba(219, 39, 119, 0.25);
}
@keyframes opdStepPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(219, 39, 119, 0.10); }
  50%       { box-shadow: 0 0 0 7px rgba(219, 39, 119, 0.18); }
}
@media (prefers-reduced-motion: reduce) {
  .opd-action-buttons button.step-next { animation: none; }
}

/* ── Waiting: muted ──────────────────────────────────────── */
.opd-action-buttons button.step-waiting {
  border-color: #e9edf3;
  color: #94a3b8;
  background: #f8fafc;
  cursor: default;
}
.opd-action-buttons button.step-waiting:hover {
  transform: none;
  box-shadow: none;
  border-color: #e9edf3;
  background: #f8fafc;
}

/* ── Blocked: soft red ──────────────────────────────────── */
.opd-action-buttons button.step-blocked {
  border-color: #fca5a5;
  border-width: 2px;
  color: #b91c1c;
  background: #fff5f5;
}
.opd-action-buttons button.step-blocked:hover {
  background: #fee2e2;
  border-color: #f87171;
  box-shadow: 0 3px 12px rgba(185, 28, 28, 0.18);
}

.opd-status-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  grid-column: 1 / -1;
  padding-top: 6px;
  border-top: 1px solid rgba(109, 61, 142, 0.12);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.opd-status-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.opd-status-legend i {
  width: 12px;
  height: 12px;
  border: 1px solid #dbe3ef;
  border-radius: 999px;
  background: #ffffff;
}

.opd-status-legend .legend-done {
  border-color: var(--primary);
  background: var(--primary);
}

.opd-status-legend .legend-next {
  border-color: #db2777;
  background: #fff0f7;
}

.opd-status-legend .legend-waiting {
  border-color: #e2e8f0;
  background: #f8fafc;
}

.opd-status-legend .legend-blocked {
  border-color: #fca5a5;
  background: #fff5f5;
}

.opd-document-guard,
.opd-readiness-panel,
.opd-cloud-controls-panel,
.opd-integration-panel,
.opd-safety-panel,
.opd-production-panel {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.opd-document-grid,
.opd-readiness-grid,
.opd-nonline-summary,
.opd-control-grid,
.opd-integration-grid,
.opd-safety-grid,
.opd-production-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.opd-document-grid button,
.opd-nonline-summary div,
.opd-control-grid button,
.opd-integration-grid button,
.opd-safety-grid button,
.opd-production-grid button,
.opd-readiness-grid div,
.opd-audit-list div,
.opd-pilot-grid div,
.opd-mini-log div {
  display: grid;
  gap: 4px;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  text-align: left;
}

.opd-document-grid button,
.opd-control-grid button {
  cursor: pointer;
}

.opd-integration-grid button {
  cursor: pointer;
}

.opd-safety-grid button {
  cursor: pointer;
}

.opd-production-grid button {
  cursor: pointer;
}

.opd-document-grid button.done,
.opd-nonline-summary div.done,
.opd-control-grid button.done,
.opd-integration-grid button.done,
.opd-safety-grid button.done,
.opd-production-grid button.done,
.opd-readiness-grid div.done,
.opd-pilot-grid div.done,
.opd-mini-log div.done {
  border-color: rgba(15, 118, 110, 0.45);
  background: var(--acc-50);
}

.opd-document-grid button.missing,
.opd-nonline-summary div.pending,
.opd-control-grid button.missing,
.opd-integration-grid button.missing,
.opd-safety-grid button.missing,
.opd-production-grid button.missing,
.opd-readiness-grid div.pending,
.opd-pilot-grid div.pending,
.opd-mini-log div.pending {
  border-color: #fecaca;
  background: #fff5f5;
}

.opd-control-grid button.missing.soon {
  border-color: #fed7aa;
  background: #fff7ed;
}

.opd-control-grid button.missing.normal {
  border-color: #dbe4ef;
  background: #f8fafc;
}

.opd-document-grid span,
.opd-nonline-summary span,
.opd-control-grid span,
.opd-integration-grid span,
.opd-safety-grid span,
.opd-production-grid span,
.opd-readiness-grid span,
.opd-audit-list span,
.opd-pilot-grid span,
.opd-mini-log span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.opd-document-grid button.done span,
.opd-nonline-summary div.done span,
.opd-control-grid button.done span,
.opd-integration-grid button.done span,
.opd-safety-grid button.done span,
.opd-production-grid button.done span,
.opd-readiness-grid div.done span,
.opd-pilot-grid div.done span,
.opd-mini-log div.done span {
  color: #0f766e;
}

.opd-document-grid button.missing span,
.opd-nonline-summary div.pending span,
.opd-control-grid button.missing span,
.opd-integration-grid button.missing span,
.opd-safety-grid button.missing span,
.opd-production-grid button.missing span,
.opd-readiness-grid div.pending span,
.opd-pilot-grid div.pending span,
.opd-mini-log div.pending span {
  color: #b91c1c;
}

.opd-document-grid strong,
.opd-nonline-summary strong,
.opd-control-grid strong,
.opd-integration-grid strong,
.opd-safety-grid strong,
.opd-production-grid strong,
.opd-readiness-grid strong,
.opd-audit-list strong,
.opd-pilot-grid strong,
.opd-mini-log strong {
  color: var(--ink);
}

.opd-document-grid em,
.opd-nonline-summary em,
.opd-control-grid em,
.opd-integration-grid em,
.opd-safety-grid em,
.opd-production-grid em,
.opd-readiness-grid em,
.opd-audit-list em,
.opd-pilot-grid em,
.opd-mini-log em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.45;
}

.opd-audit-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.opd-audit-list div {
  min-height: auto;
  grid-template-columns: 130px minmax(0, 0.8fr) minmax(0, 1fr);
  align-items: center;
}

.opd-audit-list em {
  text-align: right;
}

.opd-pilot-panel {
  margin-top: 14px;
}

.opd-pilot-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.opd-pilot-grid div {
  min-height: 74px;
}

.opd-cloud-ops-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.opd-cloud-ops-grid section {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.opd-mini-log {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.opd-mini-log div {
  min-height: 68px;
}

.opd-payload-preview {
  min-height: 220px;
  max-height: 360px;
  overflow: auto;
  margin: 10px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #172033;
  background: #f8fafc;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.opd-attention {
  animation: opdAttention 1.8s ease;
}

@keyframes opdAttention {
  0%,
  100% {
    box-shadow: none;
  }
  20%,
  65% {
    box-shadow: 0 0 0 4px rgba(203, 43, 184, 0.18);
  }
}

.opd-visit-meta-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.opd-visit-meta-grid div {
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.opd-visit-meta-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.opd-visit-meta-grid strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 0.95rem;
}

.opd-tabs {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding: 0 2px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.opd-tabs button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  color: #0f766e;
  background: #f8fafc;
  font-weight: 900;
  white-space: nowrap;
  cursor: pointer;
}

.opd-tabs button.active {
  color: var(--ink);
  background: #ffffff;
  border-color: rgba(203, 43, 184, 0.55);
  box-shadow: inset 0 -3px 0 var(--primary);
}

.opd-tab-panel {
  display: none !important;
}

.opd-tab-panel.active {
  display: block !important;
}

.opd-print-tools.opd-tab-panel.active {
  display: flex !important;
}

.opd-evidence-panel.opd-tab-panel.active,
.opd-admin-entry.opd-tab-panel.active,
.opd-grid.opd-tab-panel.active,
.facechart-layout.opd-tab-panel.active,
.photo-gallery.opd-tab-panel.active {
  display: grid !important;
}

.opd-print-preview-panel.opd-tab-panel.active {
  display: grid !important;
  gap: 14px;
}

.opd-completion-grid > div.active-step {
  border-color: rgba(203, 43, 184, 0.7);
  background: #fdf2f8;
  box-shadow: 0 0 0 2px rgba(203, 43, 184, 0.08);
}

.opd-completion-grid > div.active-step span {
  background: var(--primary);
}

.evidence-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.upload-dropzone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 210px;
  padding: 18px;
  border: 2px dashed #94a3b8;
  border-radius: 8px;
  color: #475569;
  background: #ffffff;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.upload-dropzone strong {
  color: #334155;
  font-size: 1.05rem;
}

.upload-dropzone span,
.upload-dropzone em {
  color: #64748b;
  font-style: normal;
  line-height: 1.45;
}

.upload-dropzone img {
  max-width: 100%;
  max-height: 260px;
  border-radius: 8px;
  object-fit: contain;
}

.upload-dropzone.drag-over,
.upload-dropzone.upload-focus {
  border-color: var(--acc-bright);
  background: var(--acc-50);
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.12);
}

.upload-dropzone.unsupported {
  border-color: #ef4444;
  background: #fff5f5;
}

.upload-dropzone.unsupported strong,
.upload-dropzone.unsupported span {
  color: #b91c1c;
}

.remove-upload-button {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  min-height: 32px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 0 10px;
  color: #b91c1c;
  background: #fff5f5;
  font-weight: 900;
  cursor: pointer;
}

.remove-upload-button:hover {
  border-color: #ef4444;
  background: #fee2e2;
}

.photo-dropzone {
  min-height: 160px;
}

.opd-admin-decision {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr 0.8fr;
  gap: 10px;
  margin-top: 12px;
}

.opd-admin-decision div {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.opd-admin-decision span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.opd-admin-decision strong {
  display: block;
  margin-top: 4px;
}

.opd-return-queue {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-left: 4px solid #94a3b8;
  border-radius: 8px;
  background: #f8fafc;
}

.opd-return-queue.pending {
  border-left-color: var(--amber);
  background: #fffbeb;
}

.opd-return-queue.overdue {
  border-left-color: var(--coral);
  background: #fef2f2;
}

.opd-return-queue.ready {
  border-left-color: var(--acc-bright);
  background: var(--acc-50);
}

.opd-return-queue div {
  display: grid;
  gap: 4px;
}

.opd-return-queue span,
.opd-return-queue em,
.opd-return-queue small {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.opd-return-queue small {
  font-weight: 800;
}

.opd-return-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.opd-return-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.opd-return-metrics div {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.opd-return-metrics span,
.opd-return-metrics em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.pdpa-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.pdpa-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.pdpa-grid select,
.pdpa-grid input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #ffffff;
  font: inherit;
}

.pdpa-preview {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  color: var(--ink);
  background: #f8fafc;
  line-height: 1.55;
}

.workflow-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.opd-completion-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.opd-pack-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

/* ── ICD-10-TM Diagnosis picker ───────────────────────────────────────────── */
.opd-diagnosis-block {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border, #e5e7eb);
}
.opd-optional-tag {
  display: inline-block;
  margin-left: 8px;
  vertical-align: middle;
  font-size: 13px;
  font-weight: 700;
  color: #64748b;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 2px 9px;
  letter-spacing: 0.2px;
}
.icd-picker-wrap {
  position: relative;
  margin-top: 10px;
}
.icd-search-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.icd-search-input {
  flex: 1;
  padding: 7px 11px;
  border: 1.5px solid var(--border, #e5e7eb);
  border-radius: 8px;
  font-size: 13px;
  background: var(--surface, #fff);
  color: var(--text, #111);
  outline: none;
  transition: border-color .15s;
}
.icd-search-input:focus {
  border-color: var(--primary, var(--tpl-main,#6d3d8e));
}
.icd-search-hint {
  font-size: 13px;
  color: var(--muted, #6b7280);
  white-space: nowrap;
}
/* dropdown */
.icd-dropdown {
  position: absolute;
  left: 0; right: 0;
  top: calc(100% + 4px);
  z-index: 200;
  background: var(--surface, #fff);
  border: 1.5px solid var(--border, #e5e7eb);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  overflow: hidden;
  max-height: 320px;
  overflow-y: auto;
}
.icd-result-row {
  display: grid;
  grid-template-columns: 58px 1fr auto auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-bottom: 1px solid var(--border, #f3f4f6);
  transition: background .12s;
}
.icd-result-row:hover:not([disabled]) {
  background: var(--acc-50, var(--tpl-100,#f3e8ff));
}
.icd-result-row[disabled], .icd-result-row.icd-added {
  opacity: .55;
  cursor: default;
}
.icd-result-code {
  font-size: 12px;
  font-weight: 700;
  font-family: monospace;
  color: var(--primary, var(--tpl-main,#6d3d8e));
}
.icd-result-th {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #111);
}
.icd-result-en {
  font-size: 13px;
  color: var(--muted, #6b7280);
  grid-column: 2 / span 2;
}
.icd-result-added {
  font-size: 13px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--acc-200, var(--tpl-200,#d8b4fe));
  color: var(--primary, var(--tpl-main,#6d3d8e));
  font-weight: 600;
}
.icd-no-results {
  padding: 14px;
  font-size: 13px;
  color: var(--muted, #6b7280);
  text-align: center;
}
/* selected chips */
.icd-selected-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  min-height: 30px;
}
.icd-empty-hint {
  font-size: 12px;
  color: var(--muted, #9ca3af);
  padding: 4px 0;
}
.icd-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px 3px 9px;
  border-radius: 20px;
  background: var(--acc-50, var(--tpl-100,#f3e8ff));
  border: 1px solid var(--acc-200, var(--tpl-200,#d8b4fe));
  font-size: 12px;
}
.icd-chip-code {
  font-family: monospace;
  font-weight: 700;
  color: var(--primary, var(--tpl-main,#6d3d8e));
  font-size: 13px;
}
.icd-chip-name {
  color: var(--text, #111);
  font-weight: 500;
}
.icd-chip-remove {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted, #9ca3af);
  font-size: 15px;
  line-height: 1;
  padding: 0 0 0 2px;
  margin-left: 2px;
  border-radius: 50%;
  width: 16px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .12s, background .12s;
}
.icd-chip-remove:hover {
  color: #b91c1c;
  background: #fee2e2;
}
/* visit sheet ICD row (small text) */
.visit-sheet-icd {
  font-size: 9pt !important;
  word-break: break-word;
}

.opd-worklist-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 1.3fr;
  gap: 10px;
  margin-top: 12px;
}

.opd-cloud-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.opd-cloud-grid div {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 4px 10px;
  min-height: 104px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.opd-cloud-grid div.done {
  border-color: var(--acc-bright);
  background: var(--acc-50);
}

.opd-cloud-grid span {
  display: grid;
  grid-row: span 2;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--primary);
  font-weight: 900;
}

.opd-cloud-grid div.done span {
  background: var(--acc-bright);
}

.opd-cloud-grid em {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.45;
}

.opd-worklist-grid div {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.opd-worklist-grid span,
.opd-worklist-grid em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.opd-worklist-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.opd-pack-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.workflow-steps div,
.opd-status-steps div,
.opd-completion-grid div,
.opd-pack-grid div {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 4px 10px;
  min-height: 104px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.workflow-steps span,
.opd-status-steps span,
.opd-completion-grid span,
.opd-pack-grid span {
  display: grid;
  grid-row: span 2;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--primary);
  font-weight: 900;
}

.workflow-steps strong,
.opd-status-steps strong,
.opd-completion-grid strong,
.opd-pack-grid strong {
  color: var(--ink);
}

.workflow-steps em,
.opd-status-steps em,
.opd-completion-grid em,
.opd-pack-grid em {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.45;
}

.opd-completion-grid div.done {
  border-color: var(--acc-bright);
  background: var(--acc-50);
}

.opd-completion-grid div.done span {
  background: var(--acc-bright);
}

.opd-completion-grid div.pending {
  border-color: #cbd5e1;
}

.visit-action-strip,
.photo-upload-actions,
.photo-status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.photo-upload-actions {
  margin-top: 0;
}

.photo-status-row div {
  display: grid;
  gap: 3px;
  min-width: 220px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.photo-status-row span {
  color: var(--muted);
  font-size: 12px;
}

.opd-control-grid small {
  color: #64748b;
  font-size: 13px;
  font-weight: 900;
}

.opd-nonline-summary {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 10px;
}

.opd-nonline-summary div {
  min-height: 68px;
}

.opd-nonline-blockers {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 10px;
}

.opd-nonline-blockers .opd-blocker-head,
.opd-nonline-blockers button {
  display: grid;
  gap: 4px;
  min-height: 76px;
  padding: 12px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff5f5;
  text-align: left;
}

.opd-nonline-blockers button {
  cursor: pointer;
}

.opd-nonline-blockers .opd-blocker-head.done {
  border-color: rgba(15, 118, 110, 0.45);
  background: var(--acc-50);
}

.opd-nonline-blockers span,
.opd-nonline-blockers em {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.opd-nonline-blockers strong {
  color: var(--ink);
}

.opd-nonline-search {
  width: 100%;
  min-height: 46px;
  margin: 0 0 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}

.opd-nonline-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.opd-nonline-filters button {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--teal);
  font-weight: 900;
  cursor: pointer;
}

.opd-nonline-filters button.active {
  border-color: rgba(15, 118, 110, 0.45);
  background: #ccfbf1;
  color: #0f766e;
}

.opd-scenario-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.opd-scenario-summary div,
.opd-scenario-grid > div {
  display: grid;
  gap: 4px;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  text-align: left;
}

.opd-scenario-summary div.done,
.opd-scenario-grid > div.pass {
  border-color: rgba(15, 118, 110, 0.45);
  background: var(--acc-50);
}

.opd-scenario-summary div.pending,
.opd-scenario-grid > div.fail {
  border-color: #fecaca;
  background: #fff5f5;
}

.opd-scenario-grid > div.blocked {
  box-shadow: inset 4px 0 0 #ef4444;
}

.opd-scenario-grid > div.untested {
  border-color: #dbe4ef;
  background: #f8fafc;
}

.opd-scenario-search {
  width: 100%;
  min-height: 46px;
  margin: 0 0 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}

.opd-scenario-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.opd-scenario-filters button,
.scenario-actions button {
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--teal);
  font-weight: 900;
  cursor: pointer;
}

.opd-scenario-filters button.active {
  border-color: rgba(15, 118, 110, 0.45);
  background: #ccfbf1;
  color: #0f766e;
}

.opd-scenario-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.opd-scenario-grid span,
.opd-scenario-grid em,
.opd-scenario-grid small,
.opd-scenario-summary span,
.opd-scenario-summary em {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.scenario-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.certificate-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(520px, 1.1fr);
  gap: 16px;
}

/* ============================================================
   OFFICIAL Medical Certificate Template (Medical Council 2/2564)
   Used for driving license, employment, govt health checks.
   Bilingual (TH/EN) controlled via [data-cert-lang] on the page.
   ============================================================ */
.medical-certificate-official-page,
.medical-certificate-official-en-page,
.medical-certificate-gpo-page { display: none; }
body[data-certificate-type="official"] #medicalCertificatePage { display: none; }
/* Default to Thai (2/2564) layout */
body[data-certificate-type="official"] #medicalCertificateOfficialPage { display: block; }
/* When EN selected, swap to EN-only (4/2018) layout — that's the official translation form */
body[data-certificate-type="official"][data-certificate-lang="en"] #medicalCertificateOfficialPage { display: none; }
body[data-certificate-type="official"][data-certificate-lang="en"] #medicalCertificateOfficialEnPage { display: block; }
body[data-certificate-type="gpo"] #medicalCertificatePage { display: none; }
body[data-certificate-type="gpo"] #medicalCertificateGpoPage { display: block; }

/* ============================================================
 * Print mode — the clone in #opdPrintRoot loses its #id (the print helper
 * strips ids to avoid duplicates with the still-present source). That kills
 * the body[data-certificate-type="…"] #medicalCertificate…Page { display: block }
 * rules above, so the class-only ".medical-certificate-official-page { display: none }"
 * default wins and the clone disappears → blank A4. Force the cloned cert
 * pages visible inside #opdPrintRoot regardless of certificate-type body attr.
 * ============================================================ */
body.printing-opd #opdPrintRoot .medical-certificate-official-page,
body.printing-opd #opdPrintRoot .medical-certificate-official-en-page,
body.printing-opd #opdPrintRoot .medical-certificate-gpo-page {
  display: block !important;
}
body[data-certificate-type="official"] #certOfficialFields { display: block !important; }
body[data-certificate-type="official"] #certOfficialFields[hidden] { display: block !important; }

/* Language toggle on Thai page — for "bilingual" mode show both TH+EN, "th" shows only TH */
.medical-certificate-official-page .cert-en { display: none; }
.medical-certificate-official-page[data-cert-lang="bilingual"] .cert-en { display: inline; }
.medical-certificate-official-page[data-cert-lang="bilingual"] .cert-th + .cert-en::before { content: " / "; color: #64748b; }

/* Same TH/EN toggle for the Visit/General cert — supports th (default) / en / bilingual on ONE page */
.medical-certificate-page .cert-en { display: none; }
.medical-certificate-page[data-cert-lang="en"] .cert-th { display: none; }
.medical-certificate-page[data-cert-lang="en"] .cert-en { display: inline; }
.medical-certificate-page[data-cert-lang="bilingual"] .cert-en { display: inline; }
.medical-certificate-page[data-cert-lang="bilingual"] .cert-th + .cert-en::before { content: " / "; color: #64748b; }

/* English-only page styling tweaks */
.cert-official-translation-tag {
  text-align: center;
  font-style: italic;
  font-size: 13px;
  color: #64748b;
  margin: 4px 0;
}
.cert-official-title-en {
  font-family: "Times New Roman", "Sarabun", serif;
  font-size: 22px;
  letter-spacing: 0.5px;
}
.cert-history-other {
  font-style: normal;
  border-bottom: 1px dotted #94a3b8;
  display: inline-block;
  min-width: 200px;
  padding: 0 4px;
}
.cert-official-vitals-inline {
  display: block !important;
  grid-template-columns: none !important;
  background: transparent !important;
  padding: 4px 0 !important;
  margin: 8px 0 !important;
  border: 0;
  font-size: 13px !important;
}
.medical-certificate-official-en-page {
  background: #ffffff;
  color: #0f172a;
  padding: 28px 32px;
  font-size: 13px;
  line-height: 1.7;
  font-family: "Times New Roman", "Sarabun", serif;
}

.medical-certificate-official-page {
  background: #ffffff;
  color: #0f172a;
  padding: 28px 32px;
  font-size: 13px;
  line-height: 1.55;
  font-family: "Sarabun", "Noto Sans Thai", system-ui, -apple-system, sans-serif;
}
.cert-official-header {
  border-bottom: 2px solid #0f172a;
  padding-bottom: 10px;
  margin-bottom: 14px;
  text-align: center;
}
.cert-official-clinic {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-bottom: 8px;
}
.cert-official-clinic strong {
  font-size: 16px;
  font-weight: 800;
}
.cert-official-clinic .muted { font-size: 13px; color: #475569; }
.cert-official-title {
  font-size: 17px;
  font-weight: 800;
  margin: 6px 0;
  line-height: 1.35;
}
.cert-official-title span { display: block; }
.cert-official-meta {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  font-size: 12px;
  margin-top: 6px;
}
.cert-official-section {
  margin: 14px 0;
  padding: 12px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  page-break-inside: avoid;
}
.cert-official-section h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 800;
  color: #0f172a;
}
/* Rectangular black badge for "ส่วนที่ 1" / "ส่วนที่ 2" — matches the
 * official 2/2564 PDF reference (solid dark fill, white bold caps). */
.cert-section-badge {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 5px;
  background: #0f172a;
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin-right: 8px;
}
.cert-official-line { margin: 6px 0; line-height: 1.7; }
.cert-official-line strong { font-weight: 700; border-bottom: 1px dotted #94a3b8; padding: 0 4px; }

/* ============================================================
 * Signature rows — both screen + print use these layout rules.
 * Put them OUTSIDE @media print so the on-screen preview matches
 * what the printer outputs. Sizing-only tweaks (font/padding) stay
 * inside @media print where appropriate.
 * ============================================================ */
.cert-official-sig-row { text-align: right; }
/* Pin the patient signature line to the right edge. Belt + suspenders:
 * flex justify-content + margin-left auto on the child, both with
 * !important so print stylesheets can't accidentally override.
 * Without this the line drifts to the left because of inherited rules. */
.cert-official-sig-patient {
  display: flex !important;
  justify-content: flex-end !important;
  margin-top: 16px;
}
.cert-official-sig-patient .cert-sig-singleline {
  display: inline-block;
  white-space: nowrap;
  margin-left: auto !important;
}
.cert-official-sig-doctor { text-align: right; margin-top: 20px; }
.cert-official-sig-doctor .cert-official-doctor-sig {
  display: inline-block;
  text-align: right;
  vertical-align: top;
}
.cert-sig-stack {
  display: inline-block;
  vertical-align: top;
  text-align: center;
}
.cert-sig-stack .cert-sig-line,
.cert-sig-stack .cert-sig-role,
.cert-sig-stack strong {
  display: block;
  text-align: center;
}
.cert-sig-stack strong {
  font-style: normal;
  font-weight: 700;
  margin-top: 2px;
  /* Shift name slightly right so it centers under the DOTTED part of
   * "ลงชื่อ ............." (the dots take ~70% of the line width). Without
   * this, the name sits under the geometric middle including the "ลงชื่อ"
   * word, which looks shifted left of the actual signature line. */
  padding-left: 36px;
  line-height: 1.4;
}
.cert-official-sig-doctor .cert-sig-role-suffix {
  display: inline-block;
  vertical-align: top;
  margin-left: 8px;
}
.cert-official-statement { margin: 10px 0 6px; font-weight: 600; }
.cert-official-history { margin: 8px 0 12px; padding-left: 0; list-style: none; }
.cert-official-history li {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 6px 0;
  border-bottom: 1px dashed #e2e8f0;
}
.cert-history-check { font-size: 12px; color: #334155; }
.cert-history-check em { font-style: normal; font-weight: 600; color: #0f172a; border-bottom: 1px dotted #94a3b8; min-width: 80px; display: inline-block; padding: 0 4px; }
.cert-official-fine { margin-top: 10px; font-size: 13px; color: #475569; font-style: italic; }
.cert-official-sig-row {
  display: flex;
  justify-content: space-between;
  margin-top: 18px;
  font-size: 12px;
}
.cert-official-sig-row.right { justify-content: flex-end; }
.cert-official-vitals {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 14px;
  background: #f8fafc;
  padding: 8px 12px;
  border-radius: 6px;
  margin: 10px 0;
  font-size: 12.5px;
}
.cert-official-attestation { margin: 12px 0; }
.cert-official-attestation p { font-size: 12px; line-height: 1.7; text-align: justify; }
.cert-official-diseases { padding-left: 22px; margin-top: 8px; }
.cert-official-diseases li { font-size: 12px; line-height: 1.7; }
.cert-official-doctor-sig {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  font-size: 12px;
}
.cert-official-doctor-sig img { max-height: 60px; margin-bottom: 4px; }
.cert-official-doctor-sig strong { font-weight: 700; margin-top: 2px; }
.cert-official-doctor-sig em { font-style: normal; color: #64748b; }
.cert-official-notes { margin-top: 14px; font-size: 13px; color: #475569; }
.cert-official-notes p { line-height: 1.55; }
.cert-official-footnote { font-style: italic; margin-top: 6px; }

/* ============================================================
 * ใบรับรองแพทย์ กพ. (5 โรคต้องห้ามตามกฎ ก.พ. 2553)
 * Reuses .cert-official-* base; only the bits that differ from
 * the 2/2564 form live here.
 * ============================================================ */
.cert-gpo-meta { margin: 8px 0 12px; }
.cert-gpo-meta .cert-official-line { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.cert-gpo-body { font-size: 12.5px; line-height: 1.85; }
.cert-gpo-body .cert-official-line { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.cert-gpo-attestation { margin: 10px 0 4px; font-size: 13px; }
.cert-gpo-diseases { padding-left: 22px; margin: 6px 0 8px; }
.cert-gpo-diseases li { font-size: 12px; line-height: 1.75; margin-bottom: 4px; }
.cert-gpo-extra-note { font-size: 13px; font-style: italic; color: #64748b; margin: 4px 0 14px; }
.cert-gpo-opinion strong { font-weight: 500; }
.cert-gpo-sig-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 28px;
  align-items: end;
}
.cert-gpo-staff-sig { font-size: 12px; }
.cert-gpo-staff-sig em {
  display: block;
  font-style: normal;
  color: #64748b;
  font-size: 13px;
  margin-top: 2px;
  text-align: center;
}
.cert-gpo-notes { margin-top: 18px; font-size: 13px; }
.cert-gpo-notes ol { font-size: 13px; line-height: 1.55; }
.certificate-official-fields {
  margin: 12px 0;
  padding: 12px;
  background: #ecfdf5;
  border: 1px solid #6ee7b7;
  border-radius: 8px;
}
.certificate-official-fields .certificate-form-grid label.wide {
  grid-column: 1 / -1;
  font-weight: 700;
  color: #15803d;
  padding-top: 8px;
}
@media print {
  /* Force A4 with zero margin so Chrome/Safari can't inject the URL footer
   * + date/title header. The clinic doesn't want those on a legal document. */
  @page {
    size: A4 portrait;
    margin: 0;
  }
  /* Print sizing — fill the A4 with generous line spacing matching the
   * official 2/2564 PDF reference, while still capping at ONE page. The
   * trick is bumping line-height (1.75) without bumping font (12.5px) so
   * each row breathes but the cumulative height stays within 297mm. */
  .medical-certificate-official-page,
  .medical-certificate-official-en-page,
  .medical-certificate-gpo-page {
    padding: 12mm 14mm;
    font-size: 12.5px;
    line-height: 1.75;
    color: #000 !important;
  }
  /* Pull text to black under print but KEEP border-color at its default
   * (light gray) so the section item separators look soft/clean — matches
   * the on-screen preview. Forcing all borders to #000 made them too heavy. */
  .medical-certificate-official-page *,
  .medical-certificate-official-en-page *,
  .medical-certificate-gpo-page * {
    color: #000 !important;
  }
  .cert-official-section {
    break-inside: avoid;
    padding: 10px 14px;
    margin: 12px 0;
  }
  .cert-official-header { padding-bottom: 6px; margin-bottom: 8px; }
  .cert-official-clinic { gap: 1px; margin-bottom: 4px; }
  .cert-official-clinic strong { font-size: 16px; }
  .cert-official-clinic .muted { font-size: 13px; }
  .cert-official-title { font-size: 17px; margin: 4px 0; }
  .cert-official-section h2 { font-size: 14px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
  /* Rectangular black "ส่วนที่ N" badge matching the official PDF — solid
   * dark block, white bold text, bigger horizontal padding so it reads as a
   * label not a number. Forced dark even under "all colors black" override. */
  .cert-section-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 4px;
    background: #0f172a !important;
    color: #fff !important;
    font-size: 12.5px;
    font-weight: 800;
    letter-spacing: 0.5px;
    width: auto;
    height: auto;
  }
  /* Generous line height to match the official PDF — readable without
   * cramping, but stops short of overflowing the page. */
  .cert-official-line { font-size: 12.5px; line-height: 1.85; margin: 5px 0; }
  .cert-official-attestation p { line-height: 1.75; margin: 6px 0; }
  .cert-official-diseases,
  .cert-gpo-diseases { margin: 6px 0 8px; padding-left: 24px; }
  .cert-official-diseases li,
  .cert-gpo-diseases li { font-size: 13px; line-height: 1.8; margin-bottom: 2px; }
  .cert-official-notes,
  .cert-gpo-notes { font-size: 13px; line-height: 1.55; margin-top: 12px; }
  .cert-official-notes p,
  .cert-gpo-notes ol { line-height: 1.55; }
  .cert-official-footnote { font-size: 13px; }
  /* Signature rows — print-only sizing tweaks. Layout structure lives
   * outside @media print so the screen preview matches print. */
  .cert-official-sig-patient { font-size: 12.5px; line-height: 1.85; margin-top: 14px; }
  .cert-official-sig-doctor,
  .cert-gpo-sig-row { margin-top: 18px; }
  .cert-sig-stack strong { font-size: 12px; }
  .cert-official-sig-doctor .cert-sig-role-suffix { font-size: 12.5px; }
  .cert-official-doctor-sig img { max-height: 46px; }
}

.certificate-type-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.certificate-type-grid button {
  display: grid;
  gap: 5px;
  min-height: 96px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  text-align: left;
  cursor: pointer;
}

.certificate-type-grid button.active {
  border-color: rgba(15, 118, 110, 0.45);
  background: #ecfeff;
}

.certificate-type-grid span,
.certificate-type-grid em {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.certificate-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.certificate-form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.certificate-form-grid label.wide {
  grid-column: 1 / -1;
}

.certificate-form-grid input,
.certificate-form-grid select,
.certificate-form-grid textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}

.certificate-form-grid textarea {
  min-height: 96px;
  resize: vertical;
}

.certificate-log-panel {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.certificate-log-list {
  display: grid;
  gap: 8px;
}

.certificate-log-list div {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.certificate-log-list div.issued,
.certificate-log-list div.printed {
  border-color: rgba(15, 118, 110, 0.35);
  background: var(--acc-50);
}

.certificate-log-list span,
.certificate-log-list em {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.certificate-preview-panel {
  overflow: auto;
}

.medical-certificate-page {
  width: min(100%, 794px);
  min-height: 1123px;
  margin-inline: auto;
}

.certificate-header,
.certificate-sign-grid {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 3px solid var(--ink);
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.certificate-header strong {
  display: block;
  color: var(--ink);
  font-size: 30px;
}

.certificate-header span,
.certificate-sign-grid span {
  display: block;
  color: var(--ink);
  font-weight: 800;
}

.certificate-section {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
}

.certificate-section h4 {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 18px;
}

.certificate-section p {
  margin: 0 0 10px;
  color: var(--ink);
  font-weight: 800;
  line-height: 1.5;
}

.certificate-row {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed #cbd5e1;
}

.certificate-row span {
  color: var(--muted);
  font-weight: 800;
}

.certificate-checks {
  display: none;
  gap: 8px;
}

.certificate-checks.active {
  display: grid;
}

.certificate-sign-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 3px solid var(--ink);
  border-bottom: 0;
  padding-top: 24px;
  margin-top: 18px;
}

.opd-status-steps {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.opd-status-steps div {
  min-height: 92px;
  background: #ffffff;
}

.opd-status-steps div.done {
  border-color: var(--acc-bright);
  background: var(--acc-50);
}

.opd-status-steps div.done span {
  background: var(--acc-bright);
}

.folder-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.folder-grid div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
}

.folder-grid span,
.folder-grid em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.folder-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.opd-print-card {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid #94a3b8;
  border-radius: 6px;
  background: #ffffff;
  color: #111827;
  font-size: 13.5px;
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
}

.opd-page-label {
  margin-bottom: 7px;
  color: #64748b;
  font-size: 13px;
  font-weight: 900;
  text-align: right;
}

.opd-print-card.paper-a4.portrait {
  width: min(100%, 794px);
  min-height: 1123px;
  margin-inline: auto;
}

.opd-print-card.paper-a4.landscape {
  width: min(100%, 1123px);
  min-height: 794px;
  margin-inline: auto;
}

.opd-print-card.paper-a5.portrait {
  width: min(100%, 560px);
  min-height: 794px;
  margin-inline: auto;
  padding: 14px;
  font-size: 13px;
}

.opd-intake-card {
  line-height: 1.35;
  border: 0;
  box-shadow: none;
}

.intake-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.intake-grid section {
  padding: 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
}

.intake-line-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  align-items: end;
  gap: 8px;
  padding: 4px 0;
}

.intake-line-row span,
.intake-grid em {
  color: #475569;
  font-weight: 800;
}

.intake-line-row b {
  min-height: 18px;
  border-bottom: 1px dotted #64748b;
}

.intake-check-grid,
.intake-photo-grid {
  display: grid;
  gap: 5px 10px;
}

.intake-check-grid.two,
.intake-photo-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.intake-check-grid span,
.intake-photo-grid span {
  font-weight: 800;
}

.intake-note-box {
  min-height: 38px;
  margin-top: 6px;
  padding: 6px;
  border: 1px dotted #94a3b8;
  color: #64748b;
  font-weight: 800;
}

.intake-sign-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
  font-weight: 900;
}

.intake-sign-grid.final {
  padding-top: 8px;
  border-top: 2px solid #111827;
}

.intake-bottom-note {
  margin-top: 6px;
  color: #64748b;
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.opd-print-card.paper-a5.landscape {
  width: min(100%, 794px);
  min-height: 560px;
  margin-inline: auto;
  padding: 12px;
  font-size: 13px;
}

.opd-intake-card.paper-a5.landscape,
.opd-intake-card.paper-a5.portrait,
.opd-intake-card.paper-a4.landscape,
.opd-intake-card.paper-a4.portrait {
  width: min(100%, 794px);
  min-height: 0;
  margin-inline: auto;
  padding: 12px;
  font-size: 13px;
}

.opd-visit-log.portrait {
  padding: 22px;
  font-size: 13px;
}

.opd-print-card.landscape {
  display: block;
}

.opd-print-card.landscape .opd-card-header,
.opd-print-card.landscape .opd-card-sign {
  grid-column: auto;
}

.opd-card-header,
.opd-card-sign {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 2px solid #111827;
  padding-bottom: 8px;
}

.opd-card-header div {
  display: grid;
  gap: 3px;
}

.opd-card-header > div:first-child.has-logo {
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 10px;
}

.opd-card-logo {
  grid-row: 1 / span 2;
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.opd-card-header strong {
  font-size: 18px;
}

.opd-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.opd-print-card.paper-a5.landscape .opd-card-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.opd-print-card.paper-a5.portrait .opd-card-grid {
  grid-template-columns: 1fr;
  gap: 6px;
}

.opd-card-grid section,
.opd-card-chart > div {
  min-height: 112px;
  padding: 10px;
  border: 1px solid #cbd5e1;
}

.opd-print-card.paper-a5 .opd-card-grid section,
.opd-print-card.paper-a5 .opd-card-chart > div {
  min-height: auto;
  padding: 7px;
}

.opd-print-card h4 {
  margin: 0 0 7px;
  padding-bottom: 4px;
  border-bottom: 1px solid #cbd5e1;
}

/* Consent heading row: title left + Checklist inline on the right (fills the
   heading's empty space so it costs 0 extra height — Dr.Golf 2026-07-24). The
   underline moves from the <h4> to this wrapper so it still spans full width. */
.opd-pdpa-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 7px;
  padding-bottom: 4px;
  border-bottom: 1px solid #cbd5e1;
}
.opd-pdpa-head h4 {
  margin: 0;
  padding: 0;
  border-bottom: 0;
  flex: 0 0 auto;
}
.opd-consent-checklist {
  font-weight: 400;
  white-space: nowrap;
  text-align: right;
}
.opd-consent-checklist strong { font-weight: 600; }

.opd-print-card p {
  margin: 0;
  line-height: 1.5;
}

.opd-card-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
  border-bottom: 1px dotted #cbd5e1;
}

.opd-card-row.alert strong {
  color: #b91c1c;
}

.opd-card-row.alert span::before,
.visit-sheet-critical .critical span::before,
.visit-sheet-critical .wide span::before {
  color: #b91c1c;
}

.opd-card-pdpa {
  grid-column: 1 / -1;
}

/* Prominent active-patient banner at top of OPD Record panel */
.opd-active-patient-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--acc-50) 0%, #ecfeff 50%, var(--tpl-50,#eef2ff) 100%);
  border: 1px solid var(--acc-200);
  border-radius: 14px;
  box-shadow: 0 1px 0 rgba(15,23,42,0.04);
  position: sticky;
  top: 0;
  z-index: 5;
}
.opd-active-patient-banner.has-patient {
  border-color: var(--primary);
  box-shadow: 0 4px 14px rgba(38, 182, 178, 0.18);
}
.opd-active-photo,
.opd-active-photo-placeholder {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  border: 3px solid #ffffff;
  box-shadow: 0 2px 8px rgba(15,23,42,0.12);
  background: linear-gradient(135deg, var(--primary), #6c5ce7);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 800;
}
/* Make sure [hidden] beats display:grid */
.opd-active-photo[hidden],
.opd-active-photo-placeholder[hidden] { display: none !important; }

/* Edit Customer Profile modal */
.edit-customer-form {
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 6px;
  display: grid;
  gap: 10px;
}
.edit-customer-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: linear-gradient(135deg, var(--tpl-50,#eef2ff) 0%, #ecfeff 100%);
  border-radius: 8px;
}
.edit-customer-head strong { display: block; font-size: 15px; }
.edit-customer-head .muted { font-size: 12px; font-family: ui-monospace, monospace; }
.edit-customer-photo,
.edit-customer-photo-placeholder {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(15,23,42,0.12);
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), #6c5ce7);
  color: #fff;
  font-size: 28px;
  font-weight: 800;
  flex-shrink: 0;
}
.edit-customer-photo-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.edit-customer-photo-upload {
  cursor: pointer;
  padding: 4px 8px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink);
  font-weight: 700;
  text-align: center;
}
.edit-customer-photo-upload:hover { background: var(--acc-50); border-color: var(--primary); }
.edit-customer-photo-clear {
  padding: 3px 6px;
  background: #fff;
  border: 1px solid #fecaca;
  border-radius: 6px;
  font-size: 13px;
  color: #b91c1c;
  cursor: pointer;
}
.edit-customer-form h4 {
  margin: 8px 0 4px;
  font-size: 13px;
  font-weight: 800;
  color: var(--primary-dark, #1d9692);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.edit-customer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.edit-customer-form .line-test-field input,
.edit-customer-form .line-test-field select,
.edit-customer-form .line-test-field textarea { width: 100%; }
.opd-active-info {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}
.opd-active-name { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.opd-active-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--primary-dark, #1d9692);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  background: #ffffffcc;
  padding: 2px 8px;
  border-radius: 999px;
}
.opd-active-name strong { font-size: 20px; font-weight: 800; color: var(--ink); }
.opd-active-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
  color: #475569;
}
.opd-active-hn {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 700;
  color: #1e40af;
  background: #dbeafe;
  padding: 1px 8px;
  border-radius: 6px;
}
.opd-active-alert {
  display: inline-block;
  margin-top: 2px;
  padding: 4px 10px;
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 700;
  font-size: 12px;
  border-radius: 999px;
  align-self: flex-start;
  width: fit-content;
}
.opd-active-actions {
  /* 2×2 grid instead of a 4-tall vertical stack — keeps the right side the
     same height as the patient info on the left so the banner stays balanced
     (was: tall thin button column + short info = lopsided whitespace). */
  display: grid;
  grid-template-columns: repeat(2, minmax(132px, 1fr));
  gap: 8px;
  align-content: center;
  flex-shrink: 0;
}
.opd-active-actions button { white-space: nowrap; width: 100%; }
.opd-panel-subhead { margin-bottom: 8px; padding-top: 4px; }
.opd-panel-subhead h2 { display: none; }
.opd-meta-toggle { font-size: 13px; padding: 4px 8px; }

@media (max-width: 720px) {
  .opd-active-patient-banner { flex-direction: column; align-items: stretch; text-align: left; }
  .opd-active-actions { width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.opd-card-patient-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
  padding-bottom: 6px;
  border-bottom: 1px dotted #cbd5e1;
}
.opd-card-patient-head-text { flex: 1; min-width: 0; }
.opd-card-patient-head-text .opd-card-row {
  border-bottom: none;
  padding: 1px 0;
}
.opd-card-patient-photo {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
  flex-shrink: 0;
  background: #f8fafc;
}
@media print {
  .opd-card-patient-photo { width: 50px; height: 50px; }
}

.pdpa-sign-line {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  padding-top: 8px;
  margin-bottom: 6px;
  border-top: 1px dotted #cbd5e1;
}

/* pen toolbar inside the Consent section sat flush under the ผู้ป่วย/เจ้าหน้าที่ sign line
   ("มันเบียด" — Dr.Golf 2026-07-14): give it its own breathing room above the PDPA sign box. */
.opd-card-pdpa .hw-palette {
  margin: 10px 0 8px;
}

.pdpa-sign-line span {
  color: var(--muted);
  font-size: 12px;
}

/* Inline pen-sign slot: the patient's pen box lives INSIDE the ผู้ป่วย/เจ้าหน้าที่/วันที่ line
   instead of a separate full-width row below it — saves a whole row so the Master card body map
   fits page 1 ("ปรับช่องลายเซ็นด้วยปากกาไปแทรกที่อื่น จะได้ไม่กินบรรทัด" — Dr.Golf 2026-07-14). */
.pdpa-sign-line-inline { align-items: center; }
.pdpa-sign-slot { display: flex; align-items: center; gap: 6px; flex: 1 1 46%; min-width: 0; }
.pdpa-slot-cap { color: var(--muted); font-size: 12px; white-space: nowrap; }
.pdpa-sign-slot .pdpa-sign-box { flex: 1; min-width: 0; min-height: 52px; margin-top: 0; }

.consent-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 12px;
}

.consent-split-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.consent-statement,
.consent-section,
.media-consent-box {
  margin-top: 8px;
  padding: 8px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  color: #334155;
  background: #f8fafc;
  font-size: 12px;
  line-height: 1.55;
}

.consent-section {
  display: grid;
  gap: 3px;
}

.consent-mini-sign {
  display: grid;
  grid-template-columns: auto minmax(70px, 1fr) auto minmax(58px, 0.75fr);
  align-items: end;
  gap: 5px;
  margin-top: 4px;
}

.consent-mini-sign span {
  color: #64748b;
  font-size: 13px;
  font-weight: 800;
}

.consent-mini-sign b {
  display: block;
  min-height: 13px;
  border-bottom: 1px solid #111827;
  color: transparent;
}

.consent-section strong,
.media-consent-box strong {
  color: var(--ink);
}

.media-consent-box {
  background: #fffafa;
  border-color: #fecaca;
}

.media-choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin-top: 5px;
  color: #172033;
  font-weight: 800;
}

.media-consent-box em {
  display: block;
  margin-top: 5px;
  color: #b91c1c;
  font-style: normal;
  font-weight: 900;
}

.consent-check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px 12px;
  margin-top: 8px;
  color: #172033;
  font-size: 12px;
  font-weight: 800;
}

.opd-card-chart {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(220px, 0.7fr);
  gap: 10px;
  margin-top: 10px;
}

.opd-card-chart.body-map-only {
  /* Body map RESTORED per Dr.Golf 2026-07-14 หลังลองแบบไม่มีแล้ว "ไม่ลงตัว" — the Master card
     keeps its 3-panel composite (front|face|back, now the bald+soles art) at the bottom,
     exactly like the proven old paper layout. */
  grid-template-columns: minmax(0, 1fr);
}

.opd-print-card.paper-a5.landscape .opd-card-chart {
  grid-template-columns: minmax(0, 1.35fr) minmax(190px, 0.65fr);
  gap: 6px;
}

.opd-print-card.paper-a5.landscape .opd-card-chart.body-map-only,
.opd-print-card.paper-a4.portrait .opd-card-chart.body-map-only {
  grid-template-columns: minmax(0, 1fr);
}

.opd-print-card.paper-a4.portrait .opd-card-chart {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
}

.opd-print-card.paper-a4.portrait .opd-map-sheet {
  min-height: 360px;
}

.opd-print-card.paper-a4.portrait .opd-map-sheet .chart-template-image {
  /* width-driven (was max-height:360px → rendered as a small centered thumbnail) */
  max-height: 700px;
}

.opd-print-card.paper-a4.portrait .mini-photo-grid span {
  min-height: 86px;
}

.opd-print-card.paper-a5.portrait .opd-card-chart {
  grid-template-columns: 1fr;
  gap: 6px;
}

.beauty-face-section {
  min-height: 380px;
}

.beauty-face-sheet {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 380px;
  margin: 8px 0;
  border: 1px dashed #94a3b8;
  background: #ffffff;
}

.chart-template-image {
  display: block;
  width: min(100%, 680px);
  max-height: 380px;
  object-fit: contain;
  border-radius: 6px;
  background: #ffffff;
  filter: contrast(1.04);
}

.opd-map-sheet {
  min-height: 380px;
  background: #ffffff;
}

.opd-map-sheet .chart-template-image {
  /* Big like the printed card the doctor approved (24 มิ.ย. paper) — width-driven so the
     3-panel composite fills the card, not a small centered thumbnail (Dr.Golf 2026-07-14). */
  width: min(100%, 980px);
  max-height: 700px;
}

.opd-print-card.paper-a5.landscape .beauty-face-section,
.opd-print-card.paper-a5.landscape .opd-map-sheet {
  min-height: 170px;
}

.opd-print-card.paper-a5.landscape .opd-map-sheet .chart-template-image {
  max-height: 170px;
}

.opd-print-card.paper-a5.portrait .opd-map-sheet .chart-template-image {
  max-height: 220px;
}

.opd-print-card.paper-a5 .marker-legend {
  grid-template-columns: 1fr;
  gap: 4px;
}

.opd-print-card.paper-a5 .marker-legend div {
  min-height: 34px;
  padding: 5px 7px;
}

.opd-map-sheet .face-mark {
  display: none;
}

.opd-visit-log {
  margin-top: 18px;
}

.visit-sheet-layout {
  display: grid;
  grid-template-columns: 1fr 1.28fr 1.18fr;
  gap: 8px;
  margin-top: 10px;
}

.visit-sheet-critical {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

/* 2-row identity grid: [ชื่อ/HN ×2 | แพ้ยา | โรค] / [ยา ×2 | Last visit ×2].
   The name cell is 2 columns wide so a long name + HN never clips. */
.visit-sheet-critical > div:nth-child(1) { grid-column: span 2; }
.visit-sheet-critical > div:nth-child(4) { grid-column: span 2; }

/* Minimal identity cards: white, hairline border, generous padding, BIG readable value.
   White (not gray fill) also prints clean without "Background graphics". */
.visit-sheet-critical div {
  display: grid;
  gap: 3px;
  padding: 8px 11px;
  border: 1px solid #e5e9f0;
  border-radius: 7px;
  background: #fff;
}

.visit-sheet-critical .wide {
  grid-column: span 2;
}

/* Allergy = safety-critical → strong red BORDER (prints without a fill) + red value. */
.visit-sheet-critical .critical {
  border: 1.5px solid #dc2626;
  background: #fff;
}

.visit-sheet-critical span {
  color: #64748b;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .1px;
}

.visit-sheet-critical strong {
  color: #0f172a;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
}

/* Patient name is the anchor — make it the biggest thing on the row. */
.visit-sheet-critical > div:first-child strong {
  font-size: 19px;
  color: #1d4ed8;
}

.visit-sheet-critical .critical strong,
.visit-sheet-critical .wide strong {
  color: #b91c1c;
}

.visit-sheet-layout section {
  min-height: 380px;
  padding: 8px;
  border: 1px solid #cbd5e1;
}

.opd-visit-log.portrait .visit-sheet-layout {
  grid-template-columns: 1fr;
  gap: 12px;
}

.opd-visit-log.portrait .visit-sheet-layout section {
  min-height: auto;
  padding: 12px;
}

.opd-visit-log.portrait .visit-sheet-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 16px;
}

.opd-visit-log.portrait .visit-sheet-summary h4,
.opd-visit-log.portrait .visit-sheet-checks {
  grid-column: 1 / -1;
}

.opd-visit-log.portrait .visit-sheet-checks {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.opd-visit-log.portrait .visit-sheet-map {
  min-height: 380px;
}

.opd-visit-log.portrait .visit-sheet-map img {
  width: min(100%, 760px);
  max-height: 360px;
}

.opd-visit-log.portrait .visit-sheet-note {
  min-height: 520px;
}

.opd-visit-log.portrait .handwriting-lines {
  min-height: 420px;
}
/* No signature (default) → writing box takes the freed height on screen too. */
.opd-visit-log.portrait.no-sign .handwriting-lines {
  min-height: 500px;
}

/* ── Layout B "รูปซ้าย-เขียนขวา" (vs-side): BIG map column LEFT, writing RIGHT ──
   Arrangement copied from the clinic's old paper card the doctor showed:
   face top-center, then front + back bodies side-by-side below — no frames. */
.opd-visit-log.portrait.vs-side .visit-sheet-layout {
  grid-template-columns: minmax(0, 0.54fr) minmax(0, 0.46fr);
}
.opd-visit-log.portrait.vs-side .visit-sheet-summary { grid-column: 1 / -1; }
.opd-visit-log.portrait.vs-side .vs-map-split { flex-direction: column; align-items: center; gap: 6px; }
.opd-visit-log.portrait.vs-side .vs-map-face-cell { flex: none; width: 68%; }
.opd-visit-log.portrait.vs-side .vs-map-body-cell { flex: none; width: 100%; flex-direction: row; gap: 10px; }
.opd-visit-log.portrait.vs-side .visit-sheet-map { min-height: 0; border: none; }
.opd-visit-log.portrait.vs-side .vs-map-face-cell img { max-height: 280px; }
.opd-visit-log.portrait.vs-side .vs-map-body-cell img { max-height: 400px; }
.opd-visit-log.portrait.vs-side .handwriting-lines,
.opd-visit-log.portrait.vs-side.no-sign .handwriting-lines { min-height: 900px; }

.visit-sheet-summary .opd-card-row {
  align-items: baseline;
  padding: 5px 0;
}
.visit-sheet-summary .opd-card-row span { font-size: 14px; color: #64748b; }
.visit-sheet-summary .opd-card-row strong { font-size: 15px; color: #0f172a; }
.visit-sheet-summary h4 { font-size: 15px; }

.visit-sheet-checks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
  color: #0f172a;
  font-weight: 700;
  font-size: 14px;
}

.visit-sheet-checks span {
  padding: 6px 8px;
  border: 1px solid #e5e9f0;
  border-radius: 6px;
}

.visit-sheet-map {
  display: grid;
  align-content: start;
  justify-items: center;
}

.visit-sheet-map img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
}

/* ── Split body map: face on top, front+back bodies below (2 rows) ──
   Used instead of the single wide composite so each figure is bigger and
   the column's vertical space is fully used (no letterbox whitespace). */
.vs-map-composite { display: none; }            /* hidden unless custom upload */
.visit-sheet-map.custom-chart .vs-map-split { display: none; }
.visit-sheet-map.custom-chart .vs-map-composite { display: block; width: 100%; max-height: 320px; object-fit: contain; }

.vs-map-split {
  width: 100%;
  display: flex;
  flex-direction: row;            /* wide/screen default: 3 across (2-up overrides to column) */
  align-items: flex-start;
  justify-content: center;
  gap: 12px;
}

.vs-map-face-cell {
  margin: 0;
  flex: 1.1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.vs-map-body-cell {
  flex: 1.6;
  display: flex;
  gap: 10px;
  justify-content: center;
}

.vs-map-body-cell figure {
  margin: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.vs-map-split img {
  width: auto;
  max-width: 100%;
  max-height: 280px;
  object-fit: contain;
}

.vs-map-split figcaption {
  margin-top: 3px;
  font-size: 13px;
  font-weight: 700;
  color: #64748b;
}

.handwriting-lines {
  min-height: 205px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  position: relative;
}

/* ONE vertical divider down the middle → splits the note box into LEFT / RIGHT halves.
   Drawn as a BORDER on a pseudo-element, NOT a background gradient: Chrome/Safari strip
   background-image/color when the print dialog's "Background graphics" is OFF (default) —
   that is why the line "ไม่ขึ้นตอนปริ้น". Borders always print. */
.handwriting-lines::before {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 50%;
  border-left: 1px solid #94a3b8;
  pointer-events: none;
}

/* Divider toggle (print config): `no-divider` removes the middle line for a clean single box. */
.opd-visit-log.no-divider .handwriting-lines::before { display: none; }

/* Signature toggle: `no-sign` hides the pen boxes (แพทย์/ผู้บันทึก) but KEEPS the date cell. */
/* ซ่อนช่องเซ็นเฉพาะ "ตอนพิมพ์" เท่านั้น — บนจอต้องโชว์เสมอ (หมอเซ็นด้วย Apple Pencil บน iPad;
   v11c เคยซ่อนทั้งจอทั้งกระดาษ → หมอทัก "ช่องลายเซ็นสำหรับ iPad ไม่มีแล้วหรอ") */
body.printing-opd .opd-visit-log.no-sign .sign-row .sign-cell:not(.sign-date-cell) { display: none; }

/* Vitals block (screen + single-A4 base styles; 2-up overrides in @media print) */
.visit-sheet-vitals {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.vs-vital-alerts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 13px;
}

.vs-vital-alerts .vs-allergy strong { color: #b91c1c; font-weight: 900; }
.vs-vital-alerts .vs-disease strong { color: #92400e; font-weight: 700; }

.vs-vital-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 8px 0;
  border-top: 1px dashed #cbd5e1;
  border-bottom: 1px dashed #cbd5e1;
  font-size: 13px;
  color: #475569;
}

.vs-vital-fields b { color: #0f172a; }

.mini-field-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 1fr;
  margin-top: 8px;
  border: 1px solid #cbd5e1;
}

.mini-field-grid span {
  min-height: 42px;
  padding: 6px;
  border-right: 1px solid #cbd5e1;
  color: #64748b;
  font-weight: 800;
}

.mini-field-grid span:last-child {
  border-right: 0;
}

.signature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 2px solid #111827;
  font-weight: 800;
}

.visit-log-summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0;
  padding: 8px 0;
  border-bottom: 1px solid #cbd5e1;
}

.visit-log-table {
  display: grid;
  border: 1px solid #cbd5e1;
}

.visit-log-row {
  display: grid;
  grid-template-columns: 90px 1.15fr 1.45fr 90px 110px;
  min-height: 46px;
  border-bottom: 1px solid #cbd5e1;
}

.visit-log-row:last-child {
  border-bottom: 0;
}

.visit-log-row span {
  padding: 8px;
  border-right: 1px solid #cbd5e1;
}

.visit-log-row span:last-child {
  border-right: 0;
}

.visit-log-row.head {
  min-height: 34px;
  color: #111827;
  background: #f8fafc;
  font-weight: 900;
}

.visit-log-row.empty {
  min-height: 58px;
}

.visit-log-note {
  margin: 12px 0;
}

.visit-log-note div {
  min-height: 170px;
  border: 1px solid #cbd5e1;
  background:
    repeating-linear-gradient(#ffffff 0 31px, #cbd5e1 32px);
}

.opd-visit-log.paper-a5.landscape .visit-log-row {
  grid-template-columns: 68px 1fr 1.45fr 72px 86px;
  min-height: 34px;
}

.opd-visit-log.paper-a5.landscape .visit-log-row.empty {
  min-height: 38px;
}

.opd-visit-log.paper-a5.landscape .visit-log-row span {
  padding: 5px;
}

.opd-visit-log.paper-a5.landscape .visit-log-note div {
  min-height: 104px;
  background: repeating-linear-gradient(#ffffff 0 24px, #cbd5e1 25px);
}

.opd-visit-log.paper-a5.landscape .opd-card-sign {
  margin-top: 10px;
}

.opd-visit-log.paper-a5.landscape {
  min-height: 560px;
}

.opd-visit-log.paper-a5.landscape .visit-sheet-layout section {
  min-height: 390px;
}

.opd-visit-log.paper-a5.landscape .visit-sheet-map img {
  max-height: 325px;
}

.opd-visit-log.portrait {
  font-size: 12.5px;
}

.opd-visit-log.portrait .opd-card-header {
  margin-bottom: 14px;
}

.opd-visit-log.portrait .visit-sheet-layout {
  grid-template-columns: 1fr;
  gap: 12px;
}

.opd-visit-log.portrait .visit-sheet-layout section {
  min-height: auto;
  padding: 12px;
}

.opd-visit-log.portrait .visit-sheet-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 14px;
}

.opd-visit-log.portrait .visit-sheet-summary h4,
.opd-visit-log.portrait .visit-sheet-checks {
  grid-column: 1 / -1;
}

.opd-visit-log.portrait .visit-sheet-checks {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.opd-visit-log.portrait .visit-sheet-map {
  min-height: 420px;
}

.opd-visit-log.portrait .visit-sheet-map img {
  width: min(100%, 700px);
  max-height: 360px;
}

.opd-visit-log.portrait .handwriting-lines {
  min-height: 420px;
}

/* Compact single-visit sheet: drop the blocks that REPEAT the critical bar (ชื่อ/แพ้ยา/โรค show 3×)
   so it fits one A4/A5 page. The critical bar + vitals row keep the safety info once each. */
.opd-visit-log.portrait .opd-dup-hide { display: none; }
.opd-visit-log.portrait .visit-sheet-summary { gap: 3px 16px; }

.opd-visit-log.portrait .mini-field-grid span {
  min-height: 58px;
}
/* Single-visit sheet drops the Treatment/Dose/Follow-up grid on SCREEN too (WYSIWYG with print) —
   the L/R divider in the writing box already serves that purpose. */
.opd-visit-log.portrait .mini-field-grid { display: none; }

.opd-visit-log.portrait .signature-grid {
  margin-top: 16px;
  padding-top: 12px;
}

.opd-evidence-panel {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 14px;
}

.opd-evidence-panel section,
.opd-admin-entry section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.opd-admin-entry {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: 14px;
  margin-top: 14px;
}

.opd-history-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.opd-history-list div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: #ffffff;
}

.opd-history-list span,
.opd-history-list em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.posting-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.posting-grid div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
}

.posting-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.posting-grid em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.posting-grid .done {
  border-color: var(--acc-bright);
  background: var(--acc-50);
}

.posting-grid .done span,
.posting-grid .done strong {
  color: #047857;
}

.upload-evidence-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  overflow: hidden;
}

.upload-evidence-button input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.evidence-card {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.evidence-card div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dotted var(--line);
}

.evidence-card div:last-child {
  border-bottom: 0;
}

.evidence-preview {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 220px;
  margin-top: 12px;
  padding: 16px;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  text-align: center;
}

.evidence-preview img {
  display: block;
  max-width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.evidence-preview.pdf {
  align-content: center;
  background: #f8fafc;
}

.evidence-preview a {
  color: var(--primary-dark);
  font-weight: 800;
  text-decoration: none;
}

.ai-imported-evidence {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  background: #f0f9ff;
}

.ai-imported-evidence div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.ai-imported-evidence span,
.ai-imported-evidence em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.ai-imported-evidence strong {
  overflow-wrap: anywhere;
}

.ocr-quality-panel,
.field-review-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.ocr-quality-panel {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ocr-quality-panel div,
.field-review-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
}

.ocr-quality-panel span,
.field-review-list span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.field-review-list .done {
  border-color: var(--acc-bright);
  background: var(--acc-50);
}

.field-review-list .done strong {
  color: #047857;
}

.field-review-list .review strong {
  color: #92400e;
}

.status-pill.review {
  color: #92400e;
}

.status-pill.success {
  color: #047857;
}

.ai-draft-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.ai-draft-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.ai-draft-grid input,
.ai-draft-grid textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: #ffffff;
  font: inherit;
}

.ai-draft-grid textarea {
  min-height: 76px;
  resize: vertical;
}

.ai-review-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.face-mark {
  position: absolute;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #ef4444;
  color: #ffffff;
  font-size: 13px;
  font-weight: 900;
}

.face-mark.jaw-left {
  left: 35%;
  top: 64%;
}

.face-mark.jaw-right {
  right: 35%;
  top: 64%;
}

.face-mark.cheek-left {
  left: 39%;
  top: 47%;
}

.face-mark.cheek-right {
  right: 39%;
  top: 47%;
}

.template-male .face-mark.jaw-left {
  left: 34%;
  top: 65%;
}

.template-male .face-mark.jaw-right {
  right: 34%;
  top: 65%;
}

.template-male .face-mark.cheek-left {
  left: 36%;
  top: 38%;
}

.template-male .face-mark.cheek-right {
  right: 36%;
  top: 38%;
}

.template-side .face-mark.jaw-left {
  left: 57%;
  top: 69%;
}

.template-side .face-mark.jaw-right {
  right: 26%;
  top: 47%;
}

.template-side .face-mark.cheek-left {
  left: 58%;
  top: 28%;
}

.template-side .face-mark.cheek-right {
  right: 28%;
  top: 58%;
}

.template-body-front .face-mark.jaw-left,
.template-body-back .face-mark.jaw-left,
.template-female-body-front .face-mark.jaw-left,
.template-female-body-back .face-mark.jaw-left,
.template-male-body-front .face-mark.jaw-left,
.template-male-body-back .face-mark.jaw-left {
  left: 35%;
  top: 37%;
}

.template-body-front .face-mark.jaw-right,
.template-body-back .face-mark.jaw-right,
.template-female-body-front .face-mark.jaw-right,
.template-female-body-back .face-mark.jaw-right,
.template-male-body-front .face-mark.jaw-right,
.template-male-body-back .face-mark.jaw-right {
  right: 35%;
  top: 37%;
}

.template-body-front .face-mark.cheek-left,
.template-body-back .face-mark.cheek-left,
.template-female-body-front .face-mark.cheek-left,
.template-female-body-back .face-mark.cheek-left,
.template-male-body-front .face-mark.cheek-left,
.template-male-body-back .face-mark.cheek-left {
  left: 39%;
  top: 61%;
}

.template-body-front .face-mark.cheek-right,
.template-body-back .face-mark.cheek-right,
.template-female-body-front .face-mark.cheek-right,
.template-female-body-back .face-mark.cheek-right,
.template-male-body-front .face-mark.cheek-right,
.template-male-body-back .face-mark.cheek-right {
  right: 39%;
  top: 61%;
}

.mini-photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.master-baseline-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mini-photo-grid span {
  display: grid;
  place-items: center;
  min-height: 104px;
  border: 1px dashed #94a3b8;
  color: #64748b;
  font-weight: 800;
  overflow: hidden;
  text-align: center;
}

.master-baseline-grid span {
  aspect-ratio: 4 / 5;
  min-height: 0;
}

.mini-photo-grid img {
  width: 100%;
  height: 100%;
  min-height: 88px;
  object-fit: cover;
}

.master-baseline-grid img {
  min-height: 0;
}

.mini-photo-grid em {
  padding: 4px;
  color: #111827;
  font-size: 13px;
  line-height: 1.2;
}

.marker-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.marker-legend div {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 4px 7px;
  padding: 7px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
}

.marker-legend span {
  display: grid;
  place-items: center;
  grid-row: span 2;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #ef4444;
  color: #ffffff;
  font-weight: 900;
}

.marker-legend strong,
.marker-legend em {
  min-width: 0;
}

.marker-legend em {
  color: #64748b;
  font-style: normal;
}

.opd-card-sign {
  margin-top: 12px;
  border-top: 1px solid #111827;
  border-bottom: 0;
  padding-top: 12px;
  padding-bottom: 0;
}

.facechart-panel,
.facechart-points,
.photo-gallery {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.facechart-canvas-wrap {
  display: grid;
  place-items: center;
  padding: 12px;
  border-radius: 8px;
  background: #ffffff;
}

#facechartCanvas {
  width: min(100%, 360px);
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff7ed;
  cursor: crosshair;
}

.point-list {
  display: grid;
  gap: 10px;
}

.point-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffffff;
}

.point-list span {
  color: var(--muted);
}

.photo-gallery {
  margin-top: 16px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

/* Backup & Restore list — dated snapshot rows */
.backup-list { padding: 0 12px 12px; }
.backup-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) 1fr 1fr 1.2fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line, #e5e7eb);
  font-size: 14px;
}
.backup-row.head {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted, #64748b);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 2px solid var(--line, #e5e7eb);
}
.backup-row:not(.head):hover { background: #f9fafb; }
.backup-row:last-child { border-bottom: none; }
@media (max-width: 640px) {
  .backup-row { grid-template-columns: minmax(0, 1.6fr) 1fr auto; }
  .backup-row span:nth-child(3), .backup-row span:nth-child(4) { display: none; }
}

.gallery-grid div {
  position: relative;
  display: grid;
  align-items: end;
  aspect-ratio: 1 / 1;
  min-height: 0;
  overflow: hidden;
  padding: 10px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(15, 23, 42, 0.52)),
    linear-gradient(135deg, #dbeafe, #fce7f3);
}

.gallery-grid img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}

.gallery-grid span {
  position: relative;
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  z-index: 1;
}

.gallery-grid em {
  position: relative;
  color: rgba(255, 255, 255, 0.88);
  font-size: 12px;
  font-style: normal;
  z-index: 1;
}

.gallery-grid .baseline-dropzone {
  grid-column: span 2;
  align-content: start;
  gap: 8px;
  overflow: visible;
  aspect-ratio: auto;
  min-height: 250px;
}

.gallery-grid .baseline-tile-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  aspect-ratio: auto;
  min-height: 0;
  overflow: visible;
  padding: 0;
  border-radius: 0;
  background: transparent;
}

.gallery-grid .baseline-photo-tile {
  position: relative;
  display: grid;
  align-items: end;
  aspect-ratio: 1 / 1;
  min-height: 0;
  overflow: hidden;
  padding: 6px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(15, 23, 42, 0.58)),
    linear-gradient(135deg, #dbeafe, #fce7f3);
  color: #ffffff;
}

.gallery-grid .baseline-photo-tile.print-selected {
  outline: 3px solid var(--primary);
  outline-offset: -3px;
}

.gallery-grid .baseline-photo-tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-grid .baseline-photo-tile b {
  place-self: center;
  color: #ffffff;
  font-size: 30px;
}

.gallery-grid .baseline-photo-tile em {
  display: -webkit-box;
  overflow: hidden;
  color: #ffffff;
  font-size: 13px;
  line-height: 1.2;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.gallery-grid .baseline-photo-tile .print-select-button {
  position: absolute;
  left: 6px;
  top: 6px;
  z-index: 2;
  min-height: 26px;
  border: 0;
  border-radius: 999px;
  padding: 3px 8px;
  color: #0f766e;
  background: #ccfbf1;
  font-size: 13px;
  font-weight: 900;
}

.gallery-grid .baseline-photo-tile:not(.print-selected) .print-select-button {
  color: #475569;
  background: rgba(255, 255, 255, 0.86);
}

.gallery-grid .baseline-photo-tile .remove-upload-button {
  top: 6px;
  right: 6px;
  padding: 4px 6px;
  font-size: 12px;
}

.photo-status-row em {
  display: block;
  margin-top: 4px;
  color: #64748b;
  font-size: 12px;
  font-style: normal;
}

.receipt-preview {
  padding: 24px;
  background: #e8edf5;
}

.receipt-paper {
  max-width: 420px;
  margin: 0 auto;
  padding: 28px;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 22px 50px rgba(15, 23, 42, 0.12);
}

.receipt-paper.thermal {
  max-width: 280px;
  padding: 20px 18px;
  font-size: 13px;
}

.receipt-paper.thermal h2 {
  font-size: 17px;
}

.receipt-paper h2,
.receipt-paper p {
  text-align: center;
}

.receipt-paper p {
  color: var(--muted);
}

.receipt-paper > div {
  display: flex;
  justify-content: space-between;
  margin: 12px 0;
}

/* Receipt items list — DON'T inherit the flex-row layout */
.receipt-paper .receipt-items {
  display: block;
  margin: 8px 0;
}
.receipt-paper .receipt-items .receipt-items-header,
.receipt-paper .receipt-items .receipt-item {
  display: flex !important;
  justify-content: space-between !important;
  margin: 3px 0 !important;
  align-items: flex-start;
}
.receipt-paper .receipt-items .receipt-item > div {
  display: block !important;
  margin: 0 !important;
}
.receipt-paper .receipt-items hr.receipt-items-divider {
  display: block !important;
  margin: 8px 0 !important;
}

.invoice-list .total {
  border-color: var(--primary);
  background: var(--acc-50);
}

.medical-alert {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #991b1b;
  background: #fef2f2;
}

.medical-alert strong {
  white-space: nowrap;
}

.treatment-costing,
.course-layout,
.wallet-layout,
.stock-overview,
.document-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.treatment-costing section,
.recipe-panel,
.share-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.recipe-panel {
  margin-top: 18px;
}

.stock-lot-panel,
.stock-detail-panel,
.movement-panel,
.product-category-summary,
.stock-policy-summary,
.stock-policy-settings {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.stock-kpi-grid,
.stock-detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.stock-kpi-grid div,
.stock-detail-grid div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.stock-kpi-grid span,
.stock-kpi-grid em,
.stock-detail-grid span,
.stock-detail-grid em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.category-rule-grid,
.category-settings-grid,
.category-editor-grid,
.policy-summary-grid,
.policy-editor-grid,
.supplier-grid {
  display: grid;
  gap: 10px;
}

.category-rule-grid,
.category-settings-grid,
.policy-summary-grid,
.supplier-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.category-rule-grid div,
.category-setting-card,
.policy-summary-grid div,
.supplier-grid div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.category-rule-grid span,
.category-setting-card span,
.category-rule-grid em,
.category-setting-card em,
.policy-summary-grid span,
.policy-summary-grid em,
.supplier-grid span,
.supplier-grid em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.product-category-settings {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.category-editor-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 12px;
}

.policy-editor-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 12px;
}

.category-editor-grid label,
.policy-editor-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.category-editor-grid input,
.category-editor-grid textarea,
.policy-editor-grid input,
.policy-editor-grid select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
}

.category-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

.lot-table .table-row {
  grid-template-columns: 1.25fr 0.85fr 0.85fr 0.7fr 0.85fr;
}

.products-table .table-row,
.lot-table .table-row {
  cursor: pointer;
}

.movement-list {
  display: grid;
  gap: 10px;
}

.movement-list div {
  display: grid;
  grid-template-columns: 95px minmax(0, 1fr);
  gap: 4px 12px;
  padding: 12px;
  border-left: 4px solid var(--indigo);
  border-radius: 8px;
  background: #f8fafc;
}

.movement-list span {
  grid-row: span 2;
  color: var(--muted);
  font-weight: 800;
}

.movement-list em {
  color: var(--muted);
  font-style: normal;
}

.movement-list .stock-movement-preview.in { border-left-color: #16a34a; }
.movement-list .stock-movement-preview.out { border-left-color: #dc2626; }

.stock-history-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100100;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(3px);
}

.stock-history-modal {
  width: min(1440px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 28px 90px rgba(15, 23, 42, 0.28);
}

.stock-history-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
}

.stock-history-head h2 { margin: 0 0 5px; }
.stock-history-head p { margin: 0; color: var(--muted); }

.stock-history-tools {
  display: grid;
  grid-template-columns: minmax(240px, 2fr) repeat(4, minmax(135px, 1fr));
  gap: 10px;
  padding: 18px 24px 8px;
}

.stock-history-tools label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stock-history-tools input,
.stock-history-tools select {
  width: 100%;
  min-height: 40px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.stock-history-range {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  padding: 6px 24px 14px;
}

.stock-history-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 0 24px 16px;
}

.stock-history-summary > div {
  display: grid;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
}

.stock-history-summary span,
.stock-history-summary em { color: var(--muted); font-size: 12px; font-style: normal; }
.stock-history-summary strong { font-size: 20px; }
.stock-history-summary .in { color: #15803d; }
.stock-history-summary .out { color: #b91c1c; }

.stock-history-table-wrap { margin: 0 24px; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.stock-history-table { width: 100%; min-width: 980px; border-collapse: collapse; }
.stock-history-table th { position: sticky; top: 76px; z-index: 2; padding: 11px 12px; background: var(--tpl-50,#f5f3ff); color: var(--tpl-deep,#4c1d95); text-align: left; font-size: 12px; }
.stock-history-table td { padding: 11px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.stock-history-table td strong,
.stock-history-table td small { display: block; }
.stock-history-table td small { margin-top: 4px; color: var(--muted); line-height: 1.35; }
.stock-history-table .stock-history-delta { font-size: 18px; font-weight: 900; white-space: nowrap; }
.stock-history-table .stock-history-delta.in { color: #15803d; }
.stock-history-table .stock-history-delta.out { color: #b91c1c; }
.stock-history-table .stock-history-delta small { font-size: 13px; font-weight: 600; }

.stock-history-pill {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
}
.stock-history-pill.in { color: #166534; background: #dcfce7; }
.stock-history-pill.out { color: #991b1b; background: #fee2e2; }
.stock-history-empty { padding: 42px 20px; color: var(--muted); text-align: center; }

.stock-history-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 24px 22px;
  color: var(--muted);
}
.stock-history-foot > span:last-child { display: flex; align-items: center; gap: 9px; }

@media (max-width: 900px) {
  .stock-history-backdrop { padding: 0; }
  .stock-history-modal { max-height: 100vh; border-radius: 0; }
  .stock-history-tools { grid-template-columns: 1fr 1fr; padding-inline: 14px; }
  .stock-history-tools label:first-child { grid-column: 1 / -1; }
  .stock-history-range,
  .stock-history-summary { padding-inline: 14px; }
  .stock-history-summary { grid-template-columns: 1fr 1fr; }
  .stock-history-table-wrap { margin-inline: 14px; }
  .stock-history-foot { padding-inline: 14px; flex-direction: column; align-items: stretch; }
  .stock-history-foot > span:last-child { justify-content: space-between; }
}

.stock-transfer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.stock-transfer-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.transfer-row {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.transfer-row.selected {
  border-color: var(--primary);
  background: var(--acc-50);
}

.transfer-row.warning {
  color: #991b1b;
  background: #fef2f2;
}

.transfer-row span,
.transfer-row em {
  color: var(--muted);
  font-style: normal;
}

.costing-row,
.recipe-row,
.share-member {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffffff;
}

.costing-row span,
.recipe-row span,
.share-card > span,
.share-member em {
  color: var(--muted);
}

.share-member em {
  font-style: normal;
  font-weight: 800;
}

.wallet-hero {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
  padding: 22px;
  border-radius: 8px;
  color: #ffffff;
  background: linear-gradient(135deg, #172033, var(--primary));
}

.wallet-hero strong {
  font-size: 38px;
}

.wallet-hero small {
  color: rgba(255, 255, 255, 0.78);
  font-weight: 700;
}

.wallet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tier-progress {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8f0;
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--indigo));
}

.tier-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffffff;
}

.tier-row span {
  color: var(--muted);
}

.tier-settings {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.service-catalog {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.opd-template-settings {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.template-option-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.template-option {
  display: grid;
  gap: 6px;
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.template-option.active {
  border-color: rgba(38, 182, 178, 0.5);
  background: #ecfeff;
}

.template-option span {
  color: var(--muted);
  font-weight: 800;
}

.template-option strong {
  font-size: 20px;
}

.template-option em {
  color: var(--muted);
  font-style: normal;
  line-height: 1.45;
}

.service-table .table-row {
  grid-template-columns: 1.25fr 0.7fr 0.7fr 1.1fr 0.7fr;
}

.recipe-pill {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--tpl-50,#eef2ff);
  color: #3730a3;
  font-weight: 800;
}

.catalog-rules {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.catalog-rules div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-radius: 8px;
  background: #f8fafc;
}

.catalog-rules span {
  color: var(--muted);
  font-weight: 800;
}

.tier-rule-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.tier-rule-card {
  display: grid;
  gap: 6px;
  min-height: 118px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.tier-rule-card.active {
  border-color: rgba(38, 182, 178, 0.5);
  background: #ecfeff;
}

.tier-rule-card span {
  color: var(--muted);
  font-weight: 800;
}

.tier-rule-card strong {
  font-size: 22px;
}

.tier-rule-card em {
  color: var(--muted);
  font-style: normal;
  line-height: 1.45;
}

.rule-list {
  display: grid;
  gap: 10px;
}

.rule-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.rule-list span {
  color: var(--muted);
}

.document-table .table-row {
  grid-template-columns: 1.2fr 0.8fr 0.7fr 0.8fr;
}

.df-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.42fr);
  gap: 18px;
}

.df-table .table-row {
  grid-template-columns: 0.5fr 1.05fr 0.75fr 0.6fr 0.7fr 0.95fr;
}

.df-summary {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.notification-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.45fr);
  gap: 18px;
}

.notification-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.notification-list {
  display: grid;
  gap: 10px;
}

.notification-list div {
  display: grid;
  grid-template-columns: 0.55fr minmax(0, 1fr) minmax(160px, 0.45fr);
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: #ffffff;
}

.notification-list div.warning {
  border-left-color: var(--amber);
  background: #fffbeb;
}

.notification-list div.critical {
  border-left-color: var(--coral);
  background: #fef2f2;
}

.notification-list div.done {
  opacity: 0.62;
  border-left-color: #94a3b8;
  background: #f8fafc;
}

.notification-list span,
.notification-list em {
  color: var(--muted);
  font-style: normal;
}

.data-tools-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.45fr);
  gap: 18px;
}

.import-dropzone {
  display: grid;
  place-items: center;
  min-height: 150px;
  margin-bottom: 16px;
  padding: 18px;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  background: #f8fafc;
  text-align: center;
  cursor: pointer;
}

.import-dropzone.drag-over {
  border-color: var(--teal);
  background: #ecfeff;
}

.import-dropzone span {
  margin-top: 6px;
  color: var(--muted);
}

.import-table .table-row {
  grid-template-columns: 1.3fr 0.8fr 0.6fr 0.6fr;
}

.export-list,
.validation-panel {
  display: grid;
  gap: 10px;
}

.export-list div,
.validation-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.prototype-state-panel {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.state-backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.file-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.file-action input {
  display: none;
}

.validation-panel {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.validation-row span,
.export-list span {
  color: var(--muted);
}

.validation-row.warning {
  color: #991b1b;
  background: #fef2f2;
}

.signature-pad {
  display: grid;
  place-items: center;
  min-height: 180px;
  margin-bottom: 16px;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
}

.signature-pad strong {
  color: var(--ink);
  font-size: 36px;
  font-family: "Brush Script MT", cursive;
  font-weight: 500;
}

.consent-preview,
.audit-panel,
.approval-queue {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.consent-preview p {
  margin-bottom: 0;
  color: var(--muted);
}

.audit-list,
.approval-list {
  display: grid;
  gap: 10px;
}

.audit-list div,
.approval-list div {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) minmax(180px, 0.45fr);
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: #ffffff;
}

.audit-list span,
.audit-list em,
.approval-list span,
.approval-list em {
  color: var(--muted);
  font-style: normal;
}

.split-payment {
  display: grid;
  gap: 8px;
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.coupon-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin: 16px 0;
}

.payment-link-panel {
  display: grid;
  gap: 10px;
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.payment-control-panel,
.payment-evidence-panel {
  display: grid;
  gap: 12px;
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.payment-control-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.payment-control-row label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 800;
}

.payment-control-row input {
  width: 100%;
}

.payment-status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.payment-status-grid div {
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.payment-status-grid span {
  color: var(--muted);
}

.payment-status-grid .warning {
  color: #9a3412;
}

.payment-status-grid .success {
  color: #0f766e;
}

.payment-slip-dropzone {
  display: grid;
  gap: 6px;
  min-height: 112px;
  padding: 18px;
  border: 2px dashed #9db2d3;
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
}

.payment-slip-dropzone strong {
  color: var(--ink);
}

.payment-slip-dropzone.drag-over {
  border-color: var(--primary);
  background: #ecfeff;
}

.qr-preview {
  display: grid;
  place-items: center;
  width: 120px;
  height: 120px;
  border-radius: 8px;
  color: var(--ink);
  background:
    linear-gradient(90deg, #111827 10px, transparent 10px) 0 0 / 24px 24px,
    linear-gradient(#111827 10px, transparent 10px) 0 0 / 24px 24px,
    #ffffff;
  font-weight: 900;
}

.payment-link-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffffff;
}

.payment-link-row span {
  color: var(--muted);
}

.marketing-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.45fr);
  gap: 18px;
}

.campaign-table .table-row {
  grid-template-columns: 1fr 0.8fr 0.6fr 0.8fr 0.7fr;
}

.marketing-consent-panel {
  grid-column: 1 / -1;
}

.consent-rule-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.consent-audit-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.consent-audit-list div {
  display: grid;
  grid-template-columns: 70px minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.consent-audit-list span,
.consent-audit-list em {
  color: var(--muted);
  font-style: normal;
}

.split-payment h3 {
  margin-bottom: 2px;
}

.split-payment div {
  display: flex;
  justify-content: space-between;
}

.split-payment .split-balance {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  font-weight: 800;
}

.split-payment .split-balance.warning {
  border-color: #fed7aa;
  color: #9a3412;
  background: #fff7ed;
}

.button-row,
.receipt-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  row-gap: 12px;   /* breathing room between wrapped rows */
  column-gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid color-mix(in srgb,var(--tpl-main,#7c3aed) 12%,transparent); /* subtle separator from the panel above */
}
.receipt-actions > button { white-space: nowrap; }

.installment-panel,
.outstanding-strip,
.approval-panel {
  display: grid;
  gap: 8px;
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.installment-row,
.approval-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffffff;
}

.installment-row span,
.outstanding-strip span,
.approval-row span {
  color: var(--muted);
}

.installment-row.warning,
.approval-row.warning {
  color: #991b1b;
  background: #fef2f2;
}

.outstanding-strip {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.outstanding-strip div {
  padding: 12px;
  border-radius: 8px;
  background: #ffffff;
}

.outstanding-strip span {
  display: block;
  margin-bottom: 5px;
}

.receipt-size {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.receipt-size h3 {
  width: 100%;
  margin-bottom: 0;
}

/* OPD Print grouped chip layout */
.receipt-size.opd-print-config {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 10px;
}

/* ── Compact print-config bar (single row of pills + popups) ─────────────── */
.opd-print-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.opd-pill-wrap { position: relative; }
/* ── Print bar grouping (Dr.Golf 2026-07-25) ───────────────────────────────────
   9 identical pills in one row meant re-reading the whole bar every print. The two
   that actually change per patient (เอกสาร + เพศ) get a frame; the set-once ones
   collapse into a single ⚙️ dropdown. */
.opd-bar-primary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 7px;
  border: 1.5px solid var(--tpl-200,#ddd6fe);
  border-radius: 14px;
  background: #faf7ff;
}
.opd-bar-primary .opd-pill { border-color: var(--tpl-200,#c4b5fd); background: #fff; font-weight: 700; }
.opd-pill-more { color: #475569; background: #f8fafc; }
.opd-pill-more:hover { border-color: var(--tpl-bright,#a78bfa); background: var(--tpl-50,#faf5ff); }
.opd-pop-more { width: 300px; max-height: 68vh; overflow-y: auto; }
.opd-pop-more .opd-pop-head:not(:first-child) { margin-top: 7px; border-top: 1px solid #eef2f7; padding-top: 8px; }
.opd-pop-fav-inline { display: flex; flex-direction: column; gap: 2px; }
.opd-pop-fav-inline .opd-fav-empty { padding: 5px 9px; color: #94a3b8; font-size: 13px; line-height: 1.35; }

.opd-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #334155;
  border-radius: 9px;
  padding: 8px 13px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.opd-pill:hover { border-color: var(--tpl-bright,#a78bfa); background: var(--tpl-50,#faf5ff); }
.opd-pill-caret { color: #94a3b8; font-size: 12px; }
.opd-pill-upload { font-weight: 500; color: #475569; background: #f8fafc; }
.opd-print-go { font-weight: 800; }
.opd-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 200px;
  max-width: 280px;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
  padding: 6px;
  z-index: 60;
}
.opd-pop-head { font-size: 13px; color: #94a3b8; padding: 5px 9px 3px; }
.opd-pop-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  color: #1f2937;
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13.5px;
  cursor: pointer;
}
.opd-pop-item:hover { background: var(--tpl-100,#f3e8ff); color: var(--tpl-main,#6d28d9); }
.opd-pop-item.active { background: var(--tpl-100,#ede9fe); color: var(--tpl-main,#6d28d9); font-weight: 700; }
.opd-pop-sep { border-top: 1px solid #eef2f7; margin-top: 3px; padding-top: 10px; color: #475569; }
.opd-fav-row { display: flex; align-items: center; gap: 2px; }
.opd-fav-row .opd-pop-item { flex: 1; }
.opd-fav-del {
  border: none;
  background: none;
  color: #cbd5e1;
  cursor: pointer;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 8px;
}
.opd-fav-del:hover { color: #dc2626; background: #fef2f2; }
.opd-fav-empty { font-size: 13px; color: #94a3b8; padding: 8px 10px; line-height: 1.5; }
.opd-fav-save { color: #0f766e; font-weight: 700; border-top: 1px solid #eef2f7; margin-top: 4px; padding-top: 10px; }
.opd-fav-save:hover { background: #f0fdfa; color: #0f766e; }

.opd-print-group {
  display: grid;
  gap: 5px;
}

.opd-print-group-label {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.opd-print-group-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* Visual separator between chip sub-groups (e.g. A4/A5 | แนวตั้ง/แนวนอน) */
.opd-print-separator {
  width: 1px;
  height: 22px;
  background: var(--line);
  margin: 0 2px;
}

.opd-print-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.opd-print-action-row .primary-action {
  min-height: 36px;
  padding: 0 20px;
}

.daily-close-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.45fr);
  gap: 18px;
}

.cash-count {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.line-preview {
  margin-top: 16px;
}

.line-preview p {
  margin-bottom: 0;
  color: var(--muted);
}

.doctor-line-panel {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.doctor-line-list {
  display: grid;
  gap: 8px;
}

.doctor-line-list div {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: #ffffff;
}

.doctor-line-list span,
.doctor-line-list em {
  color: var(--muted);
  font-style: normal;
  font-weight: 800;
}

.security-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.branch-readiness {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.branch-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffffff;
}

.branch-row.active {
  border-left: 4px solid var(--primary);
}

.branch-row span {
  color: var(--muted);
}

.readiness-score {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.readiness-score div {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.readiness-score span,
.readiness-score em,
.readiness-list span,
.readiness-list em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.readiness-score strong {
  color: var(--ink);
  font-size: 28px;
}

.readiness-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.readiness-board section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.readiness-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.readiness-list div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: #ffffff;
}

.readiness-list.good div {
  border-left-color: var(--acc-bright);
}

.readiness-list.warning div {
  border-left-color: #f59e0b;
}

.readiness-list.action div {
  border-left-color: var(--tpl-main,#6366f1);
}

.security-grid section {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.security-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffffff;
}

.security-row span {
  color: var(--muted);
}

.reports-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.report-card {
  min-height: 180px;
  cursor: pointer;
}

.report-card.selected {
  border-color: var(--primary);
  box-shadow: inset 4px 0 0 var(--primary);
}

.report-card strong {
  display: block;
  margin: 28px 0 8px;
  font-size: 30px;
}

.report-detail-panel {
  margin-top: 18px;
}

.report-detail-list {
  display: grid;
  gap: 8px;
}

.report-detail-list div {
  display: grid;
  grid-template-columns: 0.7fr minmax(0, 1fr) minmax(160px, 0.5fr);
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.report-detail-list span,
.report-detail-list em {
  color: var(--muted);
  font-style: normal;
}

.settings-layout {
  position: relative;
  grid-template-columns: 220px minmax(0, 1fr);
}

.settings-menu {
  position: sticky;
  top: 18px;
  display: grid;
  align-content: start;
  gap: 8px;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 6px 12px;
  scroll-behavior: smooth;
  /* subtle scrollbar */
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.settings-menu::-webkit-scrollbar { width: 6px; }
.settings-menu::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.settings-menu::-webkit-scrollbar-track { background: transparent; }

.settings-menu button {
  transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.15s;
}
.settings-menu button.active {
  transform: translateX(2px);
  font-weight: 700;
}

.settings-menu button {
  border: 1px solid var(--line);
  padding: 0 12px;
  background: #ffffff;
  text-align: left;
}

.settings-menu button.active {
  color: #ffffff;
  background: var(--ink);
}

.settings-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.settings-section-card {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

/* ============================================================
 * TAB MODE — click left nav swaps to ONE section in right pane.
 * No scrolling, no fatigue. activateSettingsSection() in app.js
 * applies .is-active-section to the target. Body gets
 * .settings-tab-mode the moment the Settings view opens.
 * ============================================================ */
body.settings-tab-mode .settings-section-card { display: none; }
body.settings-tab-mode .settings-section-card.is-active-section { display: block; }
/* security-grid contains 3 sub-sections. In tab mode hide all three by
 * default; the parent grid is hidden too. The active sub gets shown +
 * the parent gets .has-active-tab so it stays visible. */
body.settings-tab-mode .security-grid { display: none; }
body.settings-tab-mode .security-grid.has-active-tab { display: grid; }
body.settings-tab-mode .security-grid > section { display: none; }
body.settings-tab-mode .security-grid > section.is-active-section { display: block; }
/* Section-flash + opd-attention pulses are designed for scroll mode; mute
 * them in tab mode since the user already sees the section instantly. */
body.settings-tab-mode .opd-attention,
body.settings-tab-mode .section-flash { animation: none !important; }
/* Active nav button — bolder accent so the current tab is unmistakable. */
body.settings-tab-mode .settings-menu button.active {
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.18);
}

.settings-mini-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.settings-mini-grid div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.settings-mini-grid span,
.settings-mini-grid em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

/* LINE OA test panel */
.line-test-panel {
  margin-top: 16px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #fdfdff;
  display: grid;
  gap: 10px;
}
.line-test-panel h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}
.line-test-panel p.muted {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
}
.line-test-field {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}
.line-test-field input,
.line-test-field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 500;
  resize: vertical;
}
.line-test-field input:focus,
.line-test-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(38, 182, 178, 0.16);
}
.line-test-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.line-test-result {
  margin: 0;
  padding: 10px 12px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #1e293b;
  background: #0f172a08;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* LINE Routing card grid */
.line-routing-toggles {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.line-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}
.line-toggle input { width: 18px; height: 18px; cursor: pointer; }

.line-routing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

/* LINE troubleshooting block (collapsible) */
.line-troubleshoot {
  margin: 14px 0;
  padding: 12px 16px;
  background: #fff8e6;
  border: 1px solid #f5d77a;
  border-radius: 10px;
  font-size: 13px;
  color: #6a4c10;
}
.line-troubleshoot summary {
  cursor: pointer;
  font-weight: 700;
  color: #7d5400;
  user-select: none;
}
.line-troubleshoot ol { margin: 10px 0 6px 22px; padding: 0; line-height: 1.7; }
.line-troubleshoot ol li { margin-bottom: 6px; }
.line-troubleshoot code {
  padding: 1px 6px;
  background: #fff;
  border: 1px solid #e0c060;
  border-radius: 4px;
  font-size: 12px;
  color: #553700;
}
.line-troubleshoot p { margin: 8px 0 0; }

/* LINE Users captured-from-webhook panel */
.settings-line-users { display: grid; gap: 12px; }
.line-users-hint {
  padding: 12px 14px;
  background: #f4f7ff;
  border: 1px solid #d3deff;
  border-radius: 10px;
  font-size: 13px;
  color: #3c4f7a;
  line-height: 1.55;
}
.line-users-hint code {
  padding: 2px 6px;
  background: #ffffff;
  border: 1px solid #c8d3f0;
  border-radius: 4px;
  font-size: 12px;
  color: #1a2a55;
}
.line-users-search { margin: 10px 0 12px; }
.line-users-search input { width: 100%; max-width: 520px; min-height: 44px; padding: 10px 14px; border: 1px solid var(--line, #d6d9e6); border-radius: 10px; font-size: 16px; }

.line-users-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.line-users-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #475569;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.line-users-tab:hover { border-color: #94a3b8; }
.line-users-tab.active {
  background: var(--tpl-deep,#6b21a8);
  border-color: var(--tpl-deep,#6b21a8);
  color: #fff;
}
.line-users-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(100, 116, 139, .18);
  color: inherit;
  font-size: 12px;
  font-weight: 700;
}
.line-users-tab.active .line-users-tab-count { background: rgba(255, 255, 255, .28); }
.line-users-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
}
.line-users-pagination button[disabled] { opacity: .45; cursor: default; }
.line-users-page-label { font-size: 13px; color: #475569; font-weight: 600; }
.line-users-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.line-users-table {
  width: 100%;
  min-width: 600px; /* avatar+name+id+pill+actions — scroll on mobile, not squish */
  border-collapse: collapse;
  font-size: 13px;
}
.line-users-table thead th {
  position: sticky;
  top: 0;
  background: #f8f9fb;
  text-align: left;
  padding: 10px 12px;
  font-weight: 700;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.line-users-table tbody td {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}
.line-users-table tbody tr:hover { background: #fafbff; }
.line-users-table .line-user-avatar {
  display: flex;
  align-items: center;
  gap: 10px;
}
.line-users-table .line-user-avatar img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--line);
}
.line-users-table .line-user-avatar .placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #6c5ce7);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.line-users-table .line-user-name { font-weight: 700; }
.line-users-table .line-user-id-cell {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: #555;
}
.line-users-table .line-user-bound-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}
.line-users-table .line-user-bound-pill.bound { background: #e0f7e9; color: #176b3a; }
.line-users-table .line-user-bound-pill.unbound { background: #fdecec; color: #a02020; }
.line-users-table .line-user-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.line-users-table .line-user-actions button {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}
.line-users-table .line-user-actions button:hover { background: #f0f3ff; border-color: #b9c5e8; }
.line-users-table .line-user-actions button.danger { color: #a02020; border-color: #f0b3b3; }
.line-users-table .line-users-empty td {
  padding: 30px 20px;
  text-align: center;
  color: #888;
}
.line-users-table .line-users-empty code {
  padding: 2px 6px;
  background: #f0f3ff;
  border-radius: 4px;
  font-size: 12px;
}
.line-routing-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.line-routing-card h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}
.line-routing-card > span.muted {
  font-size: 13px;
  line-height: 1.4;
}

.line-recipient-list, .line-doctor-list, .line-audit-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}
.line-recipient-list li,
.line-doctor-list li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid #f1f5f9;
  border-radius: 6px;
  background: #fafbfc;
  font-size: 12px;
}
.line-recipient-list li.line-empty,
.line-doctor-list li.line-empty {
  background: transparent;
  border: 1px dashed #cbd5e1;
  font-style: italic;
  color: var(--muted);
  justify-content: center;
}
.line-recipient-list strong, .line-doctor-list strong {
  flex: 1;
  font-weight: 700;
  color: var(--ink);
  font-size: 12.5px;
}
.line-recipient-list code, .line-doctor-list code {
  font-size: 13px;
  color: #475569;
  padding: 1px 5px;
  background: #e2e8f0;
  border-radius: 4px;
  font-family: ui-monospace, Menlo, monospace;
}

.line-badge {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.line-badge.success { background: #d1fae5; color: #047857; }
.line-badge.warning { background: #fef3c7; color: #b45309; }

.line-add-recipient {
  display: grid;
  grid-template-columns: 1.4fr 1fr auto;
  gap: 6px;
  margin-top: 4px;
}
.line-add-recipient input {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
}
.line-add-recipient input:focus {
  outline: none;
  border-color: var(--primary);
}

.line-doctor-roster {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  display: grid;
  gap: 8px;
}
.line-doctor-roster h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
}
.line-doctor-roster > span.muted {
  font-size: 13px;
}

.line-audit-trail {
  margin-top: 12px;
}
.line-audit-trail summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 12px;
  background: #f1f5f9;
  border-radius: 6px;
  user-select: none;
}
.line-audit-list {
  margin-top: 8px;
}
.line-audit-list li {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  font-size: 13px;
  background: #fafbfc;
  border: 1px solid #f1f5f9;
  border-radius: 6px;
}
.line-audit-time {
  font-family: ui-monospace, monospace;
  font-size: 13px;
  color: var(--muted);
}

/* Broadcast section */
.line-broadcast-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}
.line-broadcast-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}
.line-broadcast-actions .muted { flex: 1; font-size: 12px; }

/* Doctor admin editor */
.doctor-roster-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.doctor-roster-empty {
  text-align: center;
  padding: 14px;
  font-style: italic;
}
.team-member-list,
.team-room-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}
.team-member-row,
.team-room-row {
  display: grid;
  grid-template-columns: minmax(120px, 1.2fr) minmax(180px, 1.5fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.team-room-row { grid-template-columns: minmax(180px, 1fr) auto auto; }
.team-member-row.inactive,
.team-room-row.inactive { opacity: 0.55; background: #f8fafc; }
.team-member-row input[type="text"],
.team-room-row input[type="text"] {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  width: 100%;
}
.team-member-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}
.team-member-toggle input { width: 16px; height: 16px; cursor: pointer; }
.doctor-roster-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
}
.doctor-roster-card[open] {
  border-color: var(--primary, var(--primary));
  box-shadow: 0 4px 14px rgba(38, 182, 178, 0.10);
}
.doctor-roster-card summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  flex-wrap: wrap;
}
.doctor-roster-card summary::-webkit-details-marker { display: none; }
.doctor-roster-card summary::before {
  content: "▶";
  color: var(--primary);
  font-size: 13px;
  transition: transform 0.2s;
}
.doctor-roster-card[open] summary::before { transform: rotate(90deg); }
.doctor-roster-card summary strong {
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}
.doctor-roster-card summary .muted {
  font-size: 12.5px;
}
.doctor-card-badges {
  margin-left: auto;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.doctor-badge {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.3px;
}
.doctor-badge.owner { background: #fef3c7; color: #92400e; }
.doctor-badge.active { background: #d1fae5; color: #047857; }
.doctor-badge.inactive { background: #f3f4f6; color: #6b7280; }
.doctor-badge.line-linked { background: #ecfdf5; color: #047857; }
.doctor-badge.line-missing { background: #fef2f2; color: #b91c1c; }

.doctor-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
}
.doctor-form-grid label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}
.doctor-form-grid label.wide-field { grid-column: 1 / -1; }
.doctor-form-grid input,
.doctor-form-grid textarea {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 500;
  font-family: inherit;
  resize: vertical;
}
.doctor-form-grid input:focus,
.doctor-form-grid textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(38, 182, 178, 0.14);
}
.doctor-flag-row {
  display: flex;
  gap: 16px;
  padding: 4px 0;
}
.doctor-flag {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}
.doctor-flag input { width: 18px; height: 18px; }

.doctor-signature-row {
  display: grid;
  gap: 6px;
}
.doctor-signature-control {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}
.doctor-signature-preview {
  height: 64px;
  max-width: 200px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  padding: 4px;
}
.doctor-signature-empty {
  height: 64px;
  width: 200px;
  display: grid;
  place-items: center;
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
  border: 1px dashed #cbd5e1;
  border-radius: 6px;
  background: #f8fafc;
}
.doctor-signature-actions {
  display: flex;
  gap: 6px;
}
.doctor-signature-actions .ghost-button {
  cursor: pointer;
  font-size: 12.5px;
}
.doctor-card-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 4px;
}

/* QR Intake panel */
.qr-intake-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 1.4fr;
  gap: 18px;
  margin: 14px 0;
}
.qr-intake-display {
  text-align: center;
  padding: 18px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.qr-code-box img {
  width: 240px;
  height: 240px;
  border-radius: 12px;
  background: #fff;
  padding: 8px;
  box-shadow: 0 4px 12px rgba(15,23,42,0.06);
}
.qr-placeholder {
  width: 240px;
  height: 240px;
  display: grid;
  place-items: center;
  background: #fff;
  border-radius: 12px;
  color: var(--muted);
  margin: 0 auto;
}
.qr-intake-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.btn-link {
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  font-weight: 700;
}
.btn-link:hover { background: rgba(38, 182, 178, 0.08); }

.qr-intake-info { font-size: 13px; line-height: 1.6; }
.qr-intake-info h3 { font-size: 14px; font-weight: 800; margin: 0 0 8px; }
.qr-intake-info ol { padding-left: 18px; margin: 0; color: var(--ink); }
.qr-intake-info ol li { margin: 4px 0; }
.qr-intake-langs {
  margin-top: 12px;
  padding: 8px 12px;
  background: linear-gradient(135deg, var(--tpl-50,#eef2ff) 0%, var(--tpl-50,#fdf4ff) 100%);
  border-radius: 8px;
  font-size: 12px;
  color: var(--tpl-deep,#4c1d95);
  font-weight: 600;
}

.intake-pending-list { display: grid; gap: 8px; margin-top: 8px; }
.intake-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.intake-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.intake-card-head strong { font-size: 14px; color: var(--ink); }
.intake-lang-pill {
  background: var(--tpl-100,#ede9fe);
  color: var(--tpl-main,#6d28d9);
  font-size: 13px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.3px;
}
.intake-card {
  flex-direction: column;
  align-items: stretch;
}
.intake-card-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
  font-size: 12px;
}
.intake-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.intake-card.status-approved { background: #f0fdf4; border-color: #bbf7d0; }
.intake-card.status-rejected { background: #fef2f2; border-color: #fecaca; opacity: 0.85; }
.intake-status-pill {
  font-size: 13px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.3px;
}
.intake-status-pill.pending { background: #fef3c7; color: #92400e; }
.intake-status-pill.approved { background: #d1fae5; color: #047857; }
.intake-status-pill.rejected { background: #fee2e2; color: #b91c1c; }
.intake-hn-pill {
  background: #dbeafe;
  color: #1e40af;
  font-size: 13px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.intake-list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 18px;
  flex-wrap: wrap;
  gap: 6px;
}
.intake-list-head h3 { margin: 0; }
.intake-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  margin-left: 4px;
}
.intake-processed-wrap {
  margin-top: 16px;
  padding: 8px 0;
  border-top: 1px dashed var(--line);
}
.intake-processed-wrap summary {
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
  font-weight: 700;
}
.intake-processed-wrap summary h3 { margin: 0; }
.intake-processed-list {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

/* Intake review modal */
.intake-review {
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 6px;
}
.intake-review h3 {
  margin: 18px 0 8px;
  font-size: 13px;
  color: var(--primary);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}
.intake-summary-bar {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: linear-gradient(135deg, var(--tpl-50,#eef2ff) 0%, #ecfeff 100%);
  border-radius: 8px;
  font-size: 12.5px;
  margin-bottom: 10px;
}
.intake-summary-bar strong { font-size: 15px; }
.intake-field-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 12px;
  align-items: start;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid #f1f5f9;
}
.intake-field-label { color: var(--muted); font-weight: 700; }
.intake-orig { color: var(--ink); font-weight: 500; }
.intake-trans { color: var(--primary); font-size: 12.5px; margin-top: 2px; font-style: italic; }
.intake-consents-row { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 0; }
.consent-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
}
.consent-badge.ok { background: #d1fae5; color: #047857; }
.consent-badge.bad { background: #fee2e2; color: #b91c1c; }
.intake-signature {
  max-width: 240px;
  max-height: 100px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 4px;
}
.intake-summary-bar { align-items: center; }
.intake-selfie-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 8px rgba(15,23,42,0.15);
  cursor: zoom-in;
}
.intake-selfie-wrap {
  display: flex;
  justify-content: center;
  padding: 10px 0;
}
.intake-selfie-full {
  max-width: 240px;
  max-height: 320px;
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: 0 4px 12px rgba(15,23,42,0.1);
  object-fit: cover;
}

@media (max-width: 720px) {
  .qr-intake-grid { grid-template-columns: 1fr; }
}

/* Vision intake modal */
.vision-intake {
  display: grid;
  gap: 14px;
  padding: 0 0 8px;
}
.vision-uploader {
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 28px 16px;
  border: 2px dashed #94a3b8;
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}
.vision-uploader:hover, .vision-uploader.drag-over {
  border-color: var(--primary, var(--primary));
  background: #ecfeff;
}
.vision-uploader strong { font-size: 14px; color: var(--ink); }
.vision-uploader .muted { font-size: 12px; }

.vision-preview {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.vision-preview img {
  max-width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid var(--line);
}
.vision-preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
}
.vision-preview-meta strong { color: var(--ink); font-weight: 700; }

.vision-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.vision-loading {
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.vision-error {
  padding: 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #b91c1c;
  font-size: 13px;
}

.vision-result-header {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 8px;
  margin-bottom: 12px;
}
.vision-result-header strong { font-size: 13px; color: #047857; }
.vision-notes {
  font-size: 12px;
  color: #075985;
  background: #f0f9ff;
  padding: 6px 8px;
  border-radius: 6px;
}

.vision-draft-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.vision-draft-grid label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}
.vision-draft-grid label.wide-field { grid-column: 1 / -1; }
.vision-draft-grid input,
.vision-draft-grid select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 500;
  font-family: inherit;
}
.vision-draft-grid input:focus,
.vision-draft-grid select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(38, 182, 178, 0.14);
}

.conf-pill {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 6px;
  font-style: normal;
  letter-spacing: 0.3px;
}
.conf-pill.conf-high { background: #d1fae5; color: #047857; }
.conf-pill.conf-mid { background: #fef3c7; color: #b45309; }
.conf-pill.conf-low { background: #fee2e2; color: #b91c1c; }

/* Customer import */
.customer-import { display: grid; gap: 12px; }
.modal-form .customer-import { grid-column: 1 / -1; min-width: 0; }
.customer-import > .import-step { min-width: 0; } /* the preview table scrolls instead of widening the modal on phones */
.import-template-help {
  margin-top: 10px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  font-size: 13px;
}
.import-template-help strong { display: block; margin-bottom: 4px; font-size: 13px; }
.import-template-help p { margin: 4px 0; color: var(--muted); }
.import-template-help code { background: #fff; padding: 2px 6px; border-radius: 4px; font-size: 13px; color: #475569; }
.import-map-table { width: 100%; border-collapse: collapse; }
.import-map-table th, .import-map-table td { padding: 6px 8px; text-align: left; font-size: 14px; border-bottom: 1px solid #f1f5f9; }
.import-map-table th { background: #f8fafc; font-weight: 700; color: var(--muted); }
.import-map-table select { width: 100%; padding: 5px 8px; border: 1px solid var(--line); border-radius: 5px; font-size: 14px; font-family: inherit; }
.import-preview-stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.import-stat { padding: 6px 12px; background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 6px; font-size: 14px; color: #047857; }
.import-stat.warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.import-stat strong { font-weight: 800; }
.import-preview-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.import-preview-tbl th, .import-preview-tbl td { padding: 4px 8px; border: 1px solid var(--line); text-align: left; }
.import-preview-tbl th { background: #f8fafc; font-weight: 700; }
.import-preview-table { overflow-x: auto; }
.import-rejected { margin-bottom: 10px; padding: 10px 12px; background: #fff7ed; border: 1px solid #fed7aa; border-radius: 8px; font-size: 14px; color: #9a3412; }
.import-rejected ul { margin: 6px 0 8px; padding-left: 18px; }
.import-result-stop { padding: 10px 12px; background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; font-size: 14px; color: #92400e; }
.settings-import-help { margin: 20px 0 12px; font-size: 14px; line-height: 1.6; } /* clears the category chip */

.vision-thumbs {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.vision-thumbs-summary {
  font-size: 12.5px;
  color: var(--muted);
}
.vision-thumbs-summary strong { color: var(--ink); font-weight: 700; }
.vision-thumbs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 6px;
}
.vision-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
}
.vision-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vision-thumb .thumb-label {
  position: absolute; top: 4px; left: 4px;
  background: rgba(0,0,0,0.65); color: #fff;
  font-size: 13px; font-weight: 800;
  padding: 1px 6px; border-radius: 4px;
}
.vision-thumb .thumb-remove {
  position: absolute; top: 4px; right: 4px;
  background: rgba(239, 68, 68, 0.9); color: #fff;
  border: none; cursor: pointer;
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 12px; font-weight: 800;
  display: grid; place-items: center;
  padding: 0;
}

.vision-item-card {
  margin: 12px 0;
  padding: 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 1px 0 rgba(15,23,42,0.02);
}
/* Select-all bar above the review item list */
.vision-select-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  margin: 10px 0;
  background: var(--tpl-50,#f5f3ff);
  border: 1px solid var(--tpl-200,#ddd6fe);
  border-radius: 8px;
  font-size: 14px;
}
/* Dim unchecked review cards so it's obvious they won't be imported */
.vision-item-card:has(.vision-item-select:not(:checked)) {
  opacity: 0.5;
  background: #f9fafb;
}
.vision-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--line);
}
.vision-item-header strong { font-size: 14px; color: var(--primary, var(--primary)); }

.vision-trackby-toggle {
  display: grid;
  gap: 6px;
  padding: 8px;
  background: #f8fafc;
  border-radius: 6px;
}
.vision-tb-opt {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background 0.15s;
}
.vision-tb-opt:hover { background: #ffffff; }
.vision-tb-opt input { margin-top: 2px; cursor: pointer; }
.vision-tb-opt span { font-size: 12.5px; line-height: 1.5; }
.vision-tb-opt span strong { font-weight: 700; color: var(--ink); }
.vision-tb-opt span em { font-style: normal; color: var(--muted); font-size: 13px; }

.vision-ambig {
  margin-top: 8px;
  padding: 8px 12px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  color: #92400e;
  font-size: 12.5px;
}
.vision-ambig ul { margin: 4px 0 0 18px; padding: 0; }

@media (max-width: 600px) {
  .vision-draft-grid { grid-template-columns: 1fr; }
}

/* Editable vital signs on OPD card */
.editable-vital {
  cursor: text;
  border-bottom: 1px dashed #cbd5e1;
  padding: 0 4px 1px;
  border-radius: 3px;
  outline: none;
  transition: background 0.15s, border-color 0.15s;
}
.editable-vital:hover { background: #f0f9ff; border-bottom-color: var(--primary, var(--primary)); }
.editable-vital:focus { background: #ecfeff; border-bottom-style: solid; border-bottom-color: var(--primary, var(--primary)); }

/* Print: remove dashed underline */
@media print {
  .editable-vital { border-bottom: none; padding: 0; }
}

/* Product row highlight after add */
.table-row.highlight-new {
  animation: highlightNew 2.2s ease;
  background: linear-gradient(90deg, #fef9c3 0%, #ecfdf5 100%);
}
@keyframes highlightNew {
  0% { background: #fef9c3; transform: scale(1.01); }
  60% { background: #ecfdf5; transform: scale(1); }
  100% { background: transparent; }
}
.row-meta {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: #64748b;
  font-style: normal;
  font-weight: 500;
}

/* Branch admin editor */
.branch-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.branch-empty {
  text-align: center;
  padding: 14px;
  font-style: italic;
}
.branch-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.branch-card[open] {
  border-color: var(--primary, var(--primary));
  box-shadow: 0 4px 14px rgba(38, 182, 178, 0.10);
}
.branch-card summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  flex-wrap: wrap;
}
.branch-card summary::-webkit-details-marker { display: none; }
.branch-card summary::before {
  content: "▶";
  color: var(--primary);
  font-size: 13px;
  transition: transform 0.2s;
}
.branch-card[open] summary::before { transform: rotate(90deg); }
.branch-card summary strong {
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}
.branch-card summary .muted { font-size: 12.5px; }
.branch-summary-badges {
  margin-left: auto;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.branch-badge {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.3px;
}
.branch-badge.main { background: #fef3c7; color: #92400e; }
.branch-badge.warehouse { background: var(--tpl-100,#e0e7ff); color: #4338ca; }
.branch-badge.success { background: #d1fae5; color: #047857; }
.branch-badge.warning { background: #fef3c7; color: #92400e; }
.branch-badge.muted { background: #f3f4f6; color: #6b7280; }
.branch-badge.info { background: var(--tpl-100,#e0e7ff); color: #4338ca; }

.branch-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
}
.branch-form-grid label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}
.branch-form-grid label.wide-field { grid-column: 1 / -1; }
.branch-form-grid input,
.branch-form-grid textarea,
.branch-form-grid select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 500;
  font-family: inherit;
  resize: vertical;
}
.branch-form-grid input:focus,
.branch-form-grid textarea:focus,
.branch-form-grid select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(38, 182, 178, 0.14);
}
.branch-flag-row {
  display: flex;
  gap: 16px;
  padding: 4px 0;
}

@media (max-width: 600px) {
  .branch-form-grid { grid-template-columns: 1fr; }
}

/* Medical certificate doctor signature block */
.cert-signature-block {
  display: grid;
  gap: 4px;
}
.cert-signature-line {
  font-size: 12px;
  color: #475569;
}
.cert-signature-image-slot {
  display: grid;
  gap: 6px;
  min-height: 60px;
}
#certPreviewSignature {
  max-height: 70px;
  max-width: 200px;
  object-fit: contain;
}
.cert-doctor-fullname {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}
.cert-doctor-specialty {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}
#certPreviewLicense {
  font-size: 12px;
  color: #1e293b;
}

@media (max-width: 600px) {
  .doctor-form-grid {
    grid-template-columns: 1fr;
  }
}

/* AI card buttons (clickable) */
.ai-card-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary, var(--primary)) 0%, #1d9692 100%);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.ai-card-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(38, 182, 178, 0.25);
}
.ai-card-button:active {
  transform: translateY(0);
}

.wide-field {
  grid-column: 1 / -1;
}

.clinic-logo-field,
.clinic-color-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.clinic-logo-control,
.clinic-color-control {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.clinic-logo-preview {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 96px;
  height: 96px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: #ffffff;
  background: var(--primary);
  font-weight: 900;
  font-size: 22px;
  overflow: hidden;
}

.clinic-logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #ffffff;
}

.clinic-logo-actions {
  display: grid;
  gap: 6px;
}

/* Logo display options — apply to ANY logo image with these classes */
img.logo-circular {
  border-radius: 50% !important;
  object-fit: cover !important;
  background: transparent !important;
}
/* White-blend: multiply with background → white pixels become transparent
   on top of darker backgrounds (purple, accent colors).
   Works best on logos with pure-white backgrounds.
   Note: looks slightly off on pure-white container, but designed for colored bg. */
img.logo-blend-white {
  mix-blend-mode: multiply;
  background: transparent !important;
}
/* When BOTH circular + blend are on, multiply still works inside the circle */
img.logo-circular.logo-blend-white {
  mix-blend-mode: multiply;
}

.clinic-logo-options {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.logo-process-actions {
  padding: 10px 12px;
  background: #ecfeff;
  border: 1px solid var(--acc-200);
  border-radius: 6px;
}
.logo-process-actions .ghost-button { font-size: 12px; padding: 6px 10px; }

/* Users & Roles management */
.users-role-legend {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 10px 0 14px;
}
.role-badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}
.role-badge.role-super-admin { background: #dc2626; }
.role-badge.role-admin { background: var(--tpl-main,#9333ea); }
.role-badge.role-doctor { background: var(--primary); }
.role-badge.role-sales { background: #16a34a; }
.role-badge.role-bt { background: #ea580c; }
.role-badge.role-marketing { background: #db2777; }
.role-badge.role-accounting { background: #475569; }

.users-table-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  /* Horizontal scroll instead of clipping — on mobile the action column
     (2FA/ลิงก์/devices/reset/delete) sits off-screen; this lets the user swipe
     left/right to reach it. -webkit-overflow-scrolling gives momentum on iOS. */
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 14px;
}
.users-table {
  width: 100%;
  /* Keep columns readable; on narrow screens this forces the wrap to scroll
     horizontally rather than squishing the action buttons into nothing. */
  min-width: 820px;
  border-collapse: collapse;
  font-size: 13px;
}
/* Scroll hint only matters where the table can't fit (mobile/tablet) */
@media (max-width: 860px) {
  .users-table-scroll-hint { display: block !important; }
}
.users-table thead {
  background: #f8fafc;
}
/* Clickable profile-photo avatar in the name cell */
.user-avatar-edit {
  position: relative;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: #0ea5e9;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  border: 1px solid #e2e8f0;
}
.user-avatar-edit .user-avatar-cam {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #0f172a;
  color: #fff;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #fff;
}
.users-table th {
  padding: 8px 12px;
  text-align: left;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink);
}
.users-table tbody tr {
  border-top: 1px solid var(--line);
}
.users-table tbody tr.user-inactive { opacity: 0.5; }
.users-table tbody tr:hover { background: #fafbff; }
.users-table td { padding: 6px 8px; vertical-align: middle; }
.users-table input[type="text"],
.users-table input[type="email"],
.users-table select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: transparent;
}
.users-table input[type="text"]:hover,
.users-table input[type="email"]:hover,
.users-table select:hover,
.users-table input[type="text"]:focus,
.users-table input[type="email"]:focus,
.users-table select:focus {
  background: #fff;
  border-color: var(--primary);
  outline: none;
}
.users-table small { display: block; font-size: 13px; padding-left: 8px; }
.users-active-toggle {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  cursor: pointer;
  font-size: 12px;
}
.users-active-toggle input { width: 14px; height: 14px; cursor: pointer; }

.users-perm-matrix {
  margin: 14px 0;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.users-perm-matrix summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  user-select: none;
}
/* Generic horizontal-scroll wrapper for any wide table on narrow screens. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 10px;
}
.perm-table {
  width: 100%;
  min-width: 640px; /* 8 columns — overflow + scroll on mobile, not squish */
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 10px;
}
.perm-table th, .perm-table td {
  padding: 5px 8px;
  border: 1px solid var(--line);
  text-align: center;
}
.perm-table th { background: var(--tpl-100,#ede9fe); font-weight: 700; }
.perm-table td:first-child { text-align: left; font-weight: 600; }

.auth-roadmap-note {
  margin-top: 14px;
  padding: 12px 14px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  font-size: 12px;
  color: #92400e;
}
.auth-roadmap-note strong { display: block; margin-bottom: 4px; font-size: 13px; }
.auth-roadmap-note p { margin: 0; line-height: 1.55; }

/* Customer list filters: tag chips + HN-range tabs */
.customer-filter-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 8px 0;
}
.customer-filter-chips .chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #ffffff;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.customer-filter-chips .chip:hover { background: #f1f5f9; }
.customer-filter-chips .chip.active {
  background: var(--primary, var(--primary));
  color: #ffffff;
  border-color: var(--primary, var(--primary));
}
.chip-count {
  font-size: 13px;
  font-weight: 600;
  opacity: 0.7;
  margin-left: 4px;
}
.customer-range-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.range-tab {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fafbfc;
  font-size: 13px;
  font-weight: 700;
  color: #475569;
  cursor: pointer;
  font-family: inherit;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  transition: all 0.15s;
}
.range-tab:hover { background: var(--tpl-100,#e0e7ff); }
.range-tab.active {
  background: var(--tpl-deep,#4c1d95);
  color: #fff;
  border-color: var(--tpl-deep,#4c1d95);
}
.range-count {
  font-size: 12px;
  opacity: 0.7;
  margin-left: 4px;
  background: rgba(255,255,255,0.2);
  padding: 1px 6px;
  border-radius: 999px;
}
.range-tab:not(.active) .range-count {
  background: #e2e8f0;
}
.customer-list-info {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
  padding: 4px 8px;
}

.customer-dedupe-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 4px 8px 8px;
  padding: 8px 12px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  font-size: 13px;
  color: #92400e;
}
.customer-dedupe-bar button {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
}

.dedupe-group {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  background: #f9fafb;
}
.dedupe-group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 700;
}
.dedupe-group-head .reason {
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
}
.dedupe-entry {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 12px;
}
.dedupe-entry.primary {
  background: #ecfdf5;
  border-color: #6ee7b7;
}
.dedupe-entry input[type="radio"] {
  margin: 0;
}
.dedupe-entry .meta {
  font-size: 13px;
  color: var(--muted);
}
.dedupe-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

/* Medicine label form */
.med-label-form {
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 6px;
  display: grid;
  gap: 10px;
}
.med-label-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  padding: 10px 12px;
  background: var(--acc-50);
  border: 1px solid var(--acc-200);
  border-radius: 8px;
}
.med-label-head strong { font-size: 15px; }
.med-label-form h4 {
  margin: 8px 0 4px;
  font-size: 13px;
  font-weight: 800;
  color: var(--primary-dark, #1d9692);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.med-label-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.med-timing-checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px;
  padding: 8px 10px;
  background: #f8fafc;
  border-radius: 6px;
}
.med-timing-checkboxes label {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  cursor: pointer;
}
.med-timing-checkboxes input { width: 16px; height: 16px; cursor: pointer; }

/* Medicine templates + sets panel */
.med-tmpl-panel {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}
.med-tmpl-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.med-tmpl-label {
  font-size: 12px;
  font-weight: 800;
  color: #475569;
  margin-right: 4px;
  white-space: nowrap;
}
.med-tmpl-chip {
  border: 1px solid var(--tpl-200,#c7d2fe);
  background: var(--tpl-50,#eef2ff);
  color: #4338ca;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .12s;
}
.med-tmpl-chip:hover { background: #4338ca; color: #fff; border-color: #4338ca; }
.med-set-chip {
  border: 1px solid #fbcfe8;
  background: #fdf2f8;
  color: #be185d;
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all .12s;
}
.med-set-chip em { font-style: normal; opacity: .7; font-size: 13px; }
.med-set-chip:hover { background: #be185d; color: #fff; border-color: #be185d; }
/* ปุ่มลบชุดยาที่คุณหมอสร้างเอง — ติดหลังชิป ชุด built-in ไม่มีปุ่มนี้ (ลบไม่ได้) */
.med-set-del {
  border: 1px solid #fecaca; background: #fff1f2; color: #b91c1c;
  border-radius: 999px; width: 22px; height: 22px; line-height: 1;
  font-size: 13px; font-weight: 800; cursor: pointer; margin: 0 6px 0 -4px; padding: 0;
}
.med-set-del:hover { background: #b91c1c; color: #fff; border-color: #b91c1c; }

/* 🧺 ตะกร้ายา — รายการที่จะพิมพ์รวดเดียว */
.med-basket {
  border: 1.5px solid #6ee7b7; background: #ecfdf5; border-radius: 12px;
  padding: 10px 12px; margin: 10px 0 4px;
}
.med-basket-head { font-size: 13px; font-weight: 800; color: #065f46; margin-bottom: 8px; }
/* 🔴 9 ส.ค. 69 — เดิมเป็นชิปเรียงต่อกันแนวนอน พอเพิ่มปุ่มเลือกโดส + ช่องจำนวนเม็ดเข้าไป
   แถวยาวเกินจอมือถือ ⇒ ปุ่ม × กับปุ่ม "ล้างรายการ" หลุดออกนอกขอบขวา กดไม่ได้เลย
   (คุณหมอเจอจริงบนมือถือ: "หน้าไม่เต็ม") · เปลี่ยนเป็น **แถวละรายการเต็มความกว้าง**
   ชื่อยายืดได้/ตัดบรรทัดได้ ส่วนตัวควบคุมชิดขวาเสมอ ⇒ ไม่มีวันล้นอีกไม่ว่าชื่อยาจะยาวแค่ไหน */
.med-basket-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.med-basket-item {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #fff; border: 1px solid #a7f3d0; border-radius: 8px;
  padding: 6px 8px 6px 10px; font-size: 12.5px; color: #064e3b;
  max-width: 100%; box-sizing: border-box;
}
.med-basket-name { flex: 1 1 130px; min-width: 0; overflow-wrap: anywhere; font-weight: 700; }
.med-basket-ctl { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.med-basket-qty {
  width: 52px; padding: 3px 6px; border: 1px solid #a7f3d0; border-radius: 6px;
  font-size: 12.5px; font-weight: 700; color: #064e3b; text-align: center; background: #f0fdfa;
}
.med-basket-qty:focus { outline: 2px solid #34d399; outline-offset: 1px; }
.med-basket-item em { font-style: normal; color: #64748b; font-size: 13px; }
.med-basket-x {
  border: none; background: #d1fae5; color: #065f46; border-radius: 6px;
  width: 20px; height: 20px; line-height: 1; font-size: 13px; font-weight: 800; cursor: pointer; padding: 0;
}
.med-basket-x:hover { background: #b91c1c; color: #fff; }
.med-basket-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Drug-name autocomplete dropdown */
.med-dd {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  margin-top: 2px;
  max-height: 240px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .18);
}
.med-dd-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: none;
  background: none;
  text-align: left;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
}
.med-dd-item:hover { background: var(--tpl-50,#eef2ff); }
.med-dd-item:last-child { border-bottom: 0; }
.med-dd-tag {
  font-style: normal;
  font-size: 13px;
  font-weight: 700;
  color: #4338ca;
  background: var(--tpl-50,#eef2ff);
  border-radius: 4px;
  padding: 1px 6px;
  flex-shrink: 0;
}
.med-dd-tag.stock { color: #047857; background: #ecfdf5; }

/* Rich Menu uploader */
.richmenu-config-block {
  padding: 14px;
  background: var(--tpl-50,#faf5ff);
  border: 1px solid var(--tpl-200,#e9d5ff);
  border-radius: 10px;
  margin-top: 14px;
}
.richmenu-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-top: 12px;
  flex-wrap: wrap;
}
.richmenu-side {
  flex: 1 1 240px;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.richmenu-reqs {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  color: #6b7280;
  line-height: 1.7;
}
.richmenu-reqs .warn { color: #b91c1c; list-style: none; margin-left: -18px; }
.richmenu-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: auto;
}
.richmenu-upload-area {
  position: relative;
  padding: 16px 14px;
  border: 2px dashed var(--tpl-bright,#c084fc);
  border-radius: 12px;
  text-align: center;
  background: #ffffff;
  cursor: pointer;
  transition: all 0.15s;
  aspect-ratio: 2500 / 1686;
  flex: 0 0 clamp(260px, 40%, 440px);
  max-width: 440px;
  overflow: hidden;
}
.richmenu-upload-area.dragging { background: var(--tpl-100,#f3e8ff); border-color: var(--tpl-main,#9333ea); }
.richmenu-upload-area #richmenuPlaceholder {
  display: grid;
  gap: 6px;
  place-items: center;
  height: 100%;
}
.richmenu-upload-area #richmenuPlaceholder strong { font-size: 15px; color: var(--tpl-main,#6d28d9); }
.richmenu-upload-area #richmenuPlaceholder small { font-size: 13px; color: #6b7280; }
.richmenu-upload-area img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.richmenu-upload-area #richmenuCellOverlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.richmenu-cell-marker {
  position: absolute;
  background: rgba(167, 139, 250, 0.2);
  border: 1px solid color-mix(in srgb,var(--tpl-main,#7c3aed) 50%,transparent);
  color: var(--tpl-deep,#4c1d95);
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
  padding: 4px;
  text-shadow: 0 1px 2px rgba(255,255,255,0.8);
}
.richmenu-cell-list {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}
.richmenu-cell-config {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.richmenu-cell-num {
  width: 28px; height: 28px;
  background: var(--tpl-bright,#a855f7);
  color: #fff;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800; font-size: 13px;
  flex-shrink: 0;
}
.richmenu-cell-fields {
  display: grid;
  grid-template-columns: 1fr 100px 2fr;
  gap: 6px;
  flex: 1;
}
.richmenu-cell-fields input,
.richmenu-cell-fields select {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  width: 100%;
}

.qr-intake-liff-warn {
  padding: 10px 14px;
  margin: 0 0 12px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  font-size: 13px;
  color: #92400e;
  line-height: 1.55;
}
.qr-intake-liff-warn code {
  padding: 1px 6px;
  background: rgba(255,255,255,0.5);
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}

/* LINE OA config — editable form */
.line-oa-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin: 10px 0;
}

/* Payment Methods settings */
.payment-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin: 6px 0 10px;
}
.payment-toggle-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 6px;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 8px;
}
.payment-preview-card {
  margin-top: 14px;
  padding: 12px;
  background: var(--acc-50);
  border: 1px solid var(--acc-200);
  border-radius: 10px;
}
.payment-preview-card h4 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--primary-dark, #1d9692);
}
.qr-test-result { margin-top: 10px; }
.qr-test-card {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 10px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.qr-test-card img {
  width: 160px;
  height: 160px;
  border-radius: 8px;
}
.qr-test-info {
  display: grid;
  gap: 4px;
}
.qr-test-info strong { font-size: 14px; }
.qr-test-info .muted { font-size: 12px; }
.qr-amount {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary-dark, #1d9692);
}

/* Payment modal QR preview (real PromptPay) */
.qr-preview img { max-width: 100%; }
.qr-amount-label {
  margin-top: 6px;
  text-align: center;
  font-weight: 800;
  font-size: 16px;
  color: var(--primary-dark, #1d9692);
}
.qr-payee-label {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.qr-placeholder, .qr-placeholder-warn {
  padding: 24px 12px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.qr-placeholder-warn {
  color: #b91c1c;
  background: #fee2e2;
  border-radius: 8px;
}
.logo-option-toggle {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  line-height: 1.5;
}
.logo-option-toggle input { margin-top: 3px; width: 16px; height: 16px; cursor: pointer; }
.logo-option-toggle span strong { font-weight: 700; }

.clinic-logo-dropzone {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 72px;
  min-width: 240px;
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 12px 20px;
  color: var(--primary);
  background: #ffffff;
  font-weight: 900;
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.clinic-logo-dropzone:hover,
.clinic-logo-dropzone:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(38, 182, 178, 0.14);
  outline: none;
}

.clinic-logo-dropzone.drag-over {
  border-style: solid;
  border-color: var(--primary);
  background: rgba(38, 182, 178, 0.08);
}

.clinic-logo-dropzone small {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.clinic-logo-actions span,
.clinic-logo-actions em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.logo-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  opacity: 0;
  overflow: hidden;
}

.danger-text {
  color: #b91c1c;
}

.clinic-color-trigger {
  display: grid;
  grid-template-columns: 96px auto;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  border: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

.clinic-color-trigger span {
  display: block;
  width: 96px;
  height: 58px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--primary);
  box-shadow: inset 0 0 0 4px #ffffff;
}

.clinic-color-popover {
  display: grid;
  gap: 10px;
  max-width: 430px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #ffffff;
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.12);
}

.clinic-shade-picker {
  position: relative;
  height: 180px;
  border-radius: 10px;
  background:
    linear-gradient(0deg, #000000, transparent),
    linear-gradient(90deg, #ffffff, hsl(var(--clinic-hue, 178), 100%, 50%));
  cursor: crosshair;
}

.clinic-shade-picker span {
  position: absolute;
  left: calc(var(--clinic-saturation, 67) * 1%);
  top: calc((100 - var(--clinic-value, 71)) * 1%);
  width: 18px;
  height: 18px;
  border: 3px solid #ffffff;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.35);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.clinic-color-popover label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 900;
}

.clinic-color-popover input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

#clinicColorHexInput {
  max-width: 150px;
  text-transform: uppercase;
}

.toast {
  display: none;
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #065f46;
  background: #d1fae5;
  font-weight: 800;
}

.toast.show {
  display: block;
}

.global-toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 40;
  box-shadow: var(--shadow);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.46);
}

.modal-backdrop.show,
.modal-backdrop.active {
  /* `.active` is an alias for `.show`: 5 modals (openStockInDetail "ดูรูป" ของเข้า, openItemPickerModal,
     _showImportDupSummaryModal, openBulkReorderPicker, openPoQuoteModal) create the backdrop with
     className "modal-backdrop active" — without this rule they stayed display:none → appended but
     INVISIBLE ("กดแล้วเงียบ ไม่เด้ง"). Aliasing fixes all five without touching JS. */
  display: flex;
}

.modal {
  width: min(620px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  padding: 20px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.24);
}

.modal-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.modal-form .wide-field,
.modal-form .line-confirm-preview,
.modal-form .modal-actions {
  grid-column: 1 / -1;
}

.line-confirm-preview {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--acc-200);
  border-radius: 8px;
  color: #0f766e;
  background: var(--acc-50);
  white-space: pre-line;
  font-weight: 800;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 6px;
}

.modal-actions .ghost-button:first-child {
  margin-right: auto;
}

.ai-connector-settings {
  display: grid;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.ai-connector-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.ai-connector-grid section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.ai-header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.ai-connector-grid label,
.ai-chat-input {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 800;
}

.ai-line-btn {
  margin-top: 10px;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid #86efac;
  border-radius: 8px;
  background: #f0fdf4;
  color: #047857;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.ai-line-btn:disabled { opacity: .7; cursor: default; }

.ai-line-send { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.ai-line-choices { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
.ai-line-choices .ai-line-btn { margin-top: 0; }

.ai-chat-input-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ai-chat-input-head label { color: var(--muted); font-weight: 800; }

.ai-mic-button {
  min-height: 40px;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.ai-mic-button[data-state="listening"],
.ai-mic-button[data-state="talking"] {
  color: #fff;
  background: #dc2626;
  border-color: #dc2626;
}

.ai-mic-button[data-state="hearing"],
.ai-mic-button[data-state="opening"] { opacity: .75; }

.ai-scope-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ai-scope-grid button.active {
  color: #0f766e;
  border-color: var(--acc-bright);
  background: #ccfbf1;
}

.ai-endpoint-display,
.ai-health-panel {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
}

/* Mobile-first: stack label + value vertically so URLs get full row width.
   Previously used display:grid with fixed 150px label column, which left URL
   only ~50px on narrow phones → broke into 1 char per line. The override that
   tried to fix this with `flex-direction: column` did NOTHING because grid
   ignores flex props. Now: explicit single-column grid on mobile. */
.ai-endpoint-display div,
.ai-health-panel div {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  align-items: start;
  min-width: 0;
}

.ai-endpoint-display span,
.ai-health-panel span,
.ai-health-panel em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.ai-endpoint-display strong,
.ai-health-panel strong {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-all;
  white-space: normal;
  display: block;
  text-align: left;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.45;
}

/* Tablet+ (≥700px): switch to 2-column grid with fixed label column */
@media (min-width: 700px) {
  .ai-endpoint-display div,
  .ai-health-panel div {
    grid-template-columns: 150px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
  }
}

.ai-health-panel.ok {
  color: #0f766e;
  border-color: var(--acc-bright);
  background: var(--acc-50);
}

.ai-health-panel.error {
  color: #991b1b;
  border-color: #fecaca;
  background: #fff1f2;
}

.ai-connector-status {
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  color: #475569;
  background: #ffffff;
  font-weight: 900;
}

.ai-connector-status.on {
  color: #0f766e;
  border-color: var(--acc-bright);
  background: var(--acc-50);
}

.ai-security-note,
.ai-policy-banner,
.ai-save-warning {
  padding: 12px;
  border: 1px solid #fbbf24;
  border-radius: 8px;
  color: #78350f;
  background: #fffbeb;
  font-size: 13px;
  font-weight: 800;
}

.ai-save-warning {
  margin-top: 2px;
}

.ai-security-grid,
.ai-spec-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ai-security-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.ai-security-grid div,
.ai-spec-grid section,
.ai-test-result-panel,
.ai-log-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.ai-security-grid span,
.ai-security-grid em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.ai-code-block {
  min-height: 260px;
  max-height: 420px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  color: #0f172a;
  background: #ffffff;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.ai-log-list {
  display: grid;
  gap: 8px;
}

.ai-log-list div,
.ai-log-list button {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 4px 12px;
  padding: 10px;
  border-left: 4px solid #94a3b8;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  border-radius: 8px;
  background: #ffffff;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.ai-log-list div.success,
.ai-log-list button.success {
  border-left-color: var(--acc-bright);
}

.ai-log-list div.error,
.ai-log-list button.error,
.ai-log-list button.invalid-secret {
  border-left-color: #ef4444;
}

.ai-log-list button.timeout,
.ai-log-list button.missing-field,
.ai-log-list button.credit-low {
  border-left-color: #f59e0b;
}

.ai-log-list button.selected {
  outline: 2px solid rgba(20, 184, 166, 0.35);
  background: #ecfeff;
}

.ai-log-list span {
  grid-row: span 2;
  color: var(--muted);
  font-weight: 800;
}

.ai-log-list em {
  color: var(--muted);
  font-style: normal;
}

.ai-log-detail-panel,
.ai-result-detail {
  display: grid;
  gap: 10px;
}

.ai-result-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.ai-result-summary div,
.ai-result-section {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.ai-result-section.error {
  border-color: #fecaca;
  background: #fff7ed;
}

.ai-result-summary span,
.ai-result-section span,
.ai-log-detail-panel > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ai-result-section p,
.ai-result-section ul {
  margin: 0;
  white-space: pre-wrap;
}

.ai-result-section ul {
  padding-left: 18px;
}

.ai-result-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ai-result-card,
.ai-result-empty {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.ai-result-card.suggested,
.ai-result-empty {
  grid-column: 1 / -1;
}

.ai-result-card span {
  color: #0f766e;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.ai-result-card p,
.ai-result-card ul {
  margin: 0;
  white-space: pre-wrap;
}

.ai-result-card ul {
  padding-left: 18px;
}

.ai-result-empty {
  color: var(--muted);
  font-weight: 800;
}

.ai-log-detail-panel {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.ai-ops-readiness {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.ai-ops-readiness .panel-head strong {
  color: #0f766e;
  font-size: 1.45rem;
}

.ai-ops-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-ops-actions .active {
  color: #0f766e;
  border-color: var(--acc-bright);
  background: #ccfbf1;
}

.ai-ops-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-height: 520px;
  overflow: auto;
}

.ai-ops-item {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff7f7;
}

.ai-ops-item.ready {
  border-color: var(--acc-200);
  background: var(--acc-50);
}

.ai-ops-item span {
  color: #b91c1c;
  font-size: 0.82rem;
  font-weight: 900;
}

.ai-ops-item.ready span {
  color: #0f766e;
}

.ai-ops-item strong {
  color: var(--ink);
}

.ai-ops-item em {
  color: var(--muted);
  font-style: normal;
}

/* ============================================================
   AI Assistant launcher — premium gradient pill with subtle shimmer
   ============================================================ */
/* Back-to-top FAB — appears when scrolled down. Tap → smooth scroll to top
   so user can quickly switch to other views via the sidebar nav without
   manually scrolling all the way up. Sits below the AI launcher. */
.back-to-top-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 24;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  color: #ffffff;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.15) inset,
    0 6px 18px -4px rgba(15, 23, 42, 0.5),
    0 10px 30px -8px rgba(15, 23, 42, 0.35);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.85);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.back-to-top-fab.visible {
  opacity: 0.92;
  visibility: visible;
  transform: translateY(0) scale(1);
}
.back-to-top-fab:hover,
.back-to-top-fab:focus {
  opacity: 1;
  transform: translateY(-2px) scale(1.03);
  outline: none;
}
.back-to-top-fab:active {
  transform: translateY(0) scale(0.96);
}
/* On mobile, position higher so it doesn't sit on top of system gesture bar */
@media (max-width: 640px) {
  .back-to-top-fab {
    right: 16px;
    bottom: 16px;
    width: 44px;
    height: 44px;
    font-size: 20px;
  }
}

.ai-assistant-launcher {
  position: fixed;
  right: 24px;
  bottom: 86px;
  z-index: 25;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  /* Collapsed by default → a compact circular orb. Expands to a pill on hover
     (see :hover rule). width/padding/gap are all transitioned so the reveal is
     smooth. Anchored right:24px → it grows leftward, never off-screen. */
  width: 52px;
  height: 52px;
  min-height: 52px;
  padding: 0;
  border: none;
  border-radius: 999px;
  color: #ffffff;
  background: linear-gradient(
    115deg,
    var(--tpl-main,#6366f1) 0%,    /* indigo */
    #8b5cf6 25%,   /* violet */
    #d946ef 50%,   /* fuchsia */
    #f97316 80%,   /* orange */
    #fbbf24 100%   /* amber */
  );
  background-size: 220% 220%;
  background-position: 0% 50%;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  overflow: hidden;
  white-space: nowrap;
  /* Layered glow — colored halo, never harsh */
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.22) inset,
    0 8px 24px -6px rgba(139, 92, 246, 0.55),
    0 12px 36px -10px rgba(217, 70, 239, 0.45),
    0 2px 8px rgba(15, 23, 42, 0.18);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.25s ease,
              width 0.3s cubic-bezier(0.34, 1.4, 0.64, 1),
              padding 0.3s cubic-bezier(0.34, 1.4, 0.64, 1),
              gap 0.3s ease,
              background-position 0.4s ease;
  animation: ai-launcher-gradient-drift 8s ease-in-out infinite;
}

.ai-assistant-launcher:hover {
  /* Expand to full pill + reveal the label */
  width: 178px;
  gap: 10px;
  padding: 0 22px 0 18px;
  justify-content: flex-start;
  transform: translateY(-2px);
  background-position: 100% 50%;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.32) inset,
    0 12px 32px -4px color-mix(in srgb,var(--tpl-bright,#8b5cf6) 70%,transparent),
    0 16px 48px -8px rgba(217, 70, 239, 0.6),
    0 4px 12px rgba(15, 23, 42, 0.22);
  animation-play-state: paused;
}

/* While being dragged it stays collapsed (the JS adds .dragging). */
.ai-assistant-launcher.dragging:hover {
  width: 52px;
  gap: 0;
  padding: 0;
  justify-content: center;
}

.ai-assistant-launcher:active {
  transform: translateY(0) scale(0.98);
}

.ai-assistant-launcher.dragging {
  cursor: grabbing;
  animation-play-state: paused;
}

/* Sparkle icon — has its own gentle pulse */
.ai-launcher-orb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(4px);
  color: #ffffff;
  flex-shrink: 0;
  animation: ai-launcher-orb-pulse 3.5s ease-in-out infinite;
}

.ai-launcher-orb svg {
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.85));
}

.ai-launcher-label {
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
  /* Hidden when collapsed — clips to 0 width and fades. Revealed on hover. */
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-width 0.3s ease, opacity 0.2s ease 0.05s;
}

.ai-assistant-launcher:hover .ai-launcher-label {
  max-width: 140px;
  opacity: 1;
}

/* Keep the label hidden while dragging */
.ai-assistant-launcher.dragging:hover .ai-launcher-label {
  max-width: 0;
  opacity: 0;
}

/* Slow diagonal shine sweep — fires every 6s, never spammy */
.ai-launcher-shine {
  position: absolute;
  top: 0;
  left: -60%;
  width: 50%;
  height: 100%;
  background: linear-gradient(
    100deg,
    transparent 0%,
    rgba(255, 255, 255, 0) 30%,
    rgba(255, 255, 255, 0.42) 50%,
    rgba(255, 255, 255, 0) 70%,
    transparent 100%
  );
  transform: skewX(-18deg);
  animation: ai-launcher-shine-sweep 6s ease-in-out infinite;
  pointer-events: none;
}

@keyframes ai-launcher-gradient-drift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes ai-launcher-orb-pulse {
  0%, 100% {
    transform: scale(1);
    background: rgba(255, 255, 255, 0.18);
  }
  50% {
    transform: scale(1.08);
    background: rgba(255, 255, 255, 0.28);
  }
}

@keyframes ai-launcher-shine-sweep {
  0%   { left: -60%; opacity: 0; }
  10%  { opacity: 1; }
  45%  { left: 130%; opacity: 0.9; }
  46%, 100% { left: 130%; opacity: 0; }
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .ai-assistant-launcher,
  .ai-launcher-orb,
  .ai-launcher-shine {
    animation: none;
  }
}

.ai-assistant-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 35;
  display: none;
  width: min(520px, 100vw);
  padding: 18px;
  background: rgba(15, 23, 42, 0.28);
}

.ai-assistant-drawer.show {
  display: block;
}

.ai-assistant-panel {
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 14px;
  height: 100%;
  padding: 18px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.24);
}

.ai-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-chat-log {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.ai-message {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  background: #ffffff;
}

.ai-message.user {
  border-color: var(--acc-200);
  background: var(--acc-50);
}

.ai-message strong {
  color: var(--ink);
  font-size: 0.9rem;
}

.ai-message span {
  color: #475569;
  white-space: pre-line;
}

/* ============================================================
   AI Assistant — Structured response cards
   ============================================================ */
.ai-message.assistant {
  padding: 10px 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border-color: var(--tpl-100,#e0e7ff);
}

.ai-card {
  display: grid;
  gap: 10px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px 14px 12px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02), 0 4px 14px rgba(15, 23, 42, 0.04);
}

.ai-card.plain {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  gap: 6px;
}

.ai-card.plain p {
  margin: 0;
  color: #475569;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-line;
}

/* 18a — agent answers: Markdown text, exact result cards, a quiet "what was searched" chip */
.ai-rich { display: grid; gap: 8px; color: #334155; font-size: 15px; line-height: 1.6; }
.ai-rich p, .ai-rich h4, .ai-rich ol, .ai-rich ul { margin: 0; }
.ai-rich h4 { font-size: 16px; color: var(--ink, #0f172a); }
.ai-rich b { color: var(--ink, #0f172a); font-weight: 700; }
.ai-rich ol, .ai-rich ul { padding-left: 22px; display: grid; gap: 4px; }
.ai-rich code { font-size: 14px; background: #f1f5f9; border-radius: 6px; padding: 0 5px; }
.ai-rcard {
  margin-top: 10px; background: #fff; border: 1px solid var(--acc-200, #e0e7ff); border-radius: 16px;
  overflow: hidden; box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}
.ai-rcard-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: linear-gradient(180deg, var(--acc-50, #eef2ff), #fff);
  border-bottom: 1px solid var(--acc-100, #e0e7ff);
}
.ai-rcard-icon { flex: none; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: #fff; font-size: 22px; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08); }
.ai-rcard-titles { flex: 1; min-width: 0; }
.ai-rcard-title { font-size: 16px; font-weight: 700; color: var(--ink, #0f172a); }
.ai-rcard-sub { font-size: 13px; color: #64748b; margin-top: 2px; }
.ai-rcard-count { flex: none; text-align: center; color: var(--primary, #4f46e5); line-height: 1.05; }
.ai-rcard-count b { display: block; font-size: 30px; font-weight: 800; }
.ai-rcard-count span { font-size: 13px; color: #64748b; }
.ai-rows { list-style: none; margin: 0; padding: 4px 0; }
.ai-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.ai-row + .ai-row { border-top: 1px solid #f1f5f9; }
.ai-avatar { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--acc-100, #e0e7ff); color: var(--primary, #4f46e5); font-weight: 700; font-size: 16px; }
.ai-time { flex: none; min-width: 58px; text-align: center; padding: 6px 8px; border-radius: 10px; background: var(--acc-50, #eef2ff); color: var(--primary, #4f46e5); font-weight: 700; font-size: 15px; }
.ai-row-main { flex: 1; min-width: 0; }
.ai-row-name { font-size: 15px; font-weight: 700; color: var(--ink, #0f172a); }
.ai-row-name small { font-size: 13px; font-weight: 500; color: #64748b; }
.ai-row-meta { font-size: 13px; color: #64748b; margin-top: 1px; }
.ai-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.ai-chip { font-size: 12px; line-height: 1.5; padding: 1px 8px; border-radius: 999px; background: #f1f5f9; color: #475569; white-space: nowrap; }
.ai-chip.warn { background: #fef3c7; color: #92400e; }
/* 18d: tap a customer → OPD / call / LINE / Facebook, from this device's own file */
.ai-row[data-ai-cust-hn] { flex-wrap: wrap; cursor: pointer; border-radius: 12px; }
.ai-row[data-ai-cust-hn]:hover, .ai-row[aria-expanded="true"] { background: var(--acc-50, #eef2ff); }
.ai-row[data-ai-cust-hn]:focus-visible { outline: 2px solid var(--primary, #4f46e5); outline-offset: -2px; }
.ai-row-name-btn { all: unset; cursor: pointer; text-decoration: underline; text-decoration-color: rgba(79, 70, 229, 0.35); text-underline-offset: 3px; }
.ai-row-name-btn:focus-visible { outline: 2px solid var(--primary, #4f46e5); border-radius: 4px; }
.ai-row-actions { flex: 1 0 100%; display: grid; gap: 8px; padding: 4px 0 2px 50px; cursor: default; }
.ai-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-act { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 999px; border: 1px solid rgba(99, 102, 241, 0.25); background: #fff; color: #312e81; font: inherit; font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer; }
.ai-act:hover { background: var(--acc-50, #eef2ff); }
.ai-act.line { background: #06c755; border-color: #06c755; color: #fff; }
.ai-act.fb { background: #1877f2; border-color: #1877f2; color: #fff; }
.ai-act:disabled { opacity: 0.6; cursor: wait; }
.ai-act-note { font-size: 13px; color: #64748b; }
.ai-act-note.warn { color: #92400e; }
.ai-line-compose { display: grid; gap: 8px; }
.ai-line-compose textarea { width: 100%; box-sizing: border-box; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 12px; border: 1px solid #cbd5e1; resize: vertical; }
@media (max-width: 640px) { .ai-row-actions { padding-left: 0; } }
.ai-days { flex: none; font-size: 14px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.ai-days.hot { background: #fee2e2; color: #b91c1c; }
.ai-days.warm { background: #fef3c7; color: #b45309; }
.ai-days.cool { background: #ecfdf5; color: #047857; }
.ai-more { border-top: 1px solid #f1f5f9; }
.ai-more > summary { cursor: pointer; padding: 10px 16px; font-size: 14px; font-weight: 600; color: var(--primary, #4f46e5); list-style: none; }
.ai-more > summary::-webkit-details-marker { display: none; }
.ai-more > summary::after { content: " ▾"; }
.ai-more[open] > summary::after { content: " ▴"; }
.ai-rcard-foot, .ai-rcard-empty { padding: 10px 16px; font-size: 13px; color: #64748b; border-top: 1px solid #f1f5f9; }
.ai-tools { margin-top: 8px; font-size: 13px; color: #64748b; }
.ai-key-scope-note { margin: 0 0 10px; padding: 8px 10px; border-radius: 8px; background: #ecfdf5; color: #065f46; font-size: 13px; line-height: 1.5; }

/* ── 🧸 มาสคอตผู้ช่วย (18b) ── */
.mascot-dock { position: fixed; right: 12px; bottom: calc(76px + var(--push-bar-h, 0px)); z-index: 26; /* 18f: 🏠 moved into the mascot bar, the dock takes its place above ⬆ */ display: flex; flex-direction: column; align-items: flex-end; gap: 4px; pointer-events: none; }
.mascot-dock[hidden] { display: none !important; }
.mascot-dock > * { pointer-events: auto; }
.mascot-figure { position: relative; width: 104px; height: 104px; margin-right: 4px; padding: 0; border: 0; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.mascot-figure::after { content: ""; position: absolute; left: 28%; right: 28%; bottom: 5px; height: 9px; border-radius: 50%; background: rgba(30, 27, 75, 0.2); filter: blur(3px); z-index: -1; animation: mascot-shadow 3.2s ease-in-out infinite; }
.mascot-figure::before { content: ""; position: absolute; inset: 10%; border-radius: 50%; opacity: 0; z-index: -1; }
.mascot-body { position: absolute; inset: 0; display: block; transform-origin: 50% 88%; filter: drop-shadow(0 6px 10px rgba(30, 27, 75, 0.16)); animation: mascot-float 3.2s ease-in-out infinite; }
.mascot-img, .mascot-arm, .mascot-blink { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; pointer-events: none; }
/* 18d น้องพัลส์ layers: the arm swings at the shoulder (pack: 1.7 Hz, ±0.075 rad); the eyes close for 0.18 s every 4.8 s */
.mascot-arm { transform-origin: 65.22% 63.8%; animation: mascot-arm 0.59s ease-in-out infinite; }
.mascot-blink { opacity: 0; } /* 18g: shown while the dock blinks (random, JS), each frame has its own */
.mascot-dock.blinking .mascot-blink { opacity: 1; }
@keyframes mascot-arm { 0%, 100% { transform: rotate(-4.3deg); } 50% { transform: rotate(4.3deg); } }
.mascot-dock.open .mascot-body { animation: mascot-hop 0.7s ease-out, mascot-float 3.2s ease-in-out 0.7s infinite; }
.mascot-dock[data-state="listening"] .mascot-figure::before { background: radial-gradient(circle, rgba(34, 211, 238, 0.55), rgba(99, 102, 241, 0) 70%); animation: mascot-ring 1.2s ease-out infinite; }
.mascot-dock[data-state="thinking"] .mascot-body { animation: mascot-sway 1.4s ease-in-out infinite; }
.mascot-dock[data-state="speaking"] .mascot-body { animation: mascot-talk 0.36s ease-in-out infinite; }
.mascot-body.pose-in { animation: mascot-pose-in 0.32s ease-out, mascot-float 3.2s ease-in-out 0.32s infinite; }
.mascot-dock[data-pose="sleep"] .mascot-body, .mascot-dock[data-pose="sit"] .mascot-body { animation: mascot-breathe 4.2s ease-in-out infinite; }
.mascot-zzz { position: absolute; right: 4px; top: -24px; width: 40px; height: 56px; pointer-events: none; display: none; }
.mascot-dock[data-pose="sleep"] .mascot-zzz { display: block; }
.mascot-zzz i { position: absolute; left: 0; bottom: 0; font-style: normal; font-weight: 800; color: #6366f1; opacity: 0; text-shadow: 0 1px 0 #fff, 0 0 6px rgba(255, 255, 255, 0.9); animation: mascot-zzz 3s ease-in-out infinite; }
.mascot-zzz i:nth-child(1) { font-size: 14px; }
.mascot-zzz i:nth-child(2) { font-size: 18px; animation-delay: 1s; }
.mascot-zzz i:nth-child(3) { font-size: 22px; animation-delay: 2s; }
@keyframes mascot-pose-in { 0% { transform: translateY(3px) scale(0.96); } 60% { transform: translateY(-3px) scale(1.02); } 100% { transform: none; } }
@keyframes mascot-breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.012, 0.985); } }
@keyframes mascot-zzz { 0% { transform: translate(0, 0) rotate(-8deg); opacity: 0; } 15% { opacity: 1; } 100% { transform: translate(18px, -40px) rotate(12deg); opacity: 0; } }
.mascot-pill { display: flex; gap: 2px; padding: 4px; margin-right: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.97); border: 1px solid rgba(99, 102, 241, 0.16); box-shadow: 0 8px 24px rgba(30, 27, 75, 0.16); opacity: 0; visibility: hidden; transform: translateY(6px) scale(0.96); transition: opacity 0.18s, transform 0.18s, visibility 0.18s; }
.mascot-dock:hover .mascot-pill, .mascot-dock.open .mascot-pill, .mascot-dock:focus-within .mascot-pill, .mascot-dock[data-state="listening"] .mascot-pill { opacity: 1; visibility: visible; transform: none; }
.mascot-pill-btn { width: 46px; height: 42px; border: 0; border-radius: 999px; background: transparent; color: #312e81; display: grid; place-items: center; cursor: pointer; }
.mascot-pill-btn[hidden] { display: none; }
.mascot-pill-btn:hover, .mascot-pill-btn:focus-visible { background: var(--acc-50, #eef2ff); outline: none; }
.mascot-pill-btn svg { width: 22px; height: 22px; }
/* 19c: the 🎙 stays lit while a conversation keeps the microphone open */
.mascot-dock.is-talking .mascot-pill-btn[data-mascot="voice"] { background: #4f46e5; color: #fff; animation: mascot-live 1.6s ease-out infinite; }
@keyframes mascot-live { 0% { box-shadow: 0 0 0 0 rgba(79, 70, 229, .45); } 100% { box-shadow: 0 0 0 10px rgba(79, 70, 229, 0); } }
.mascot-dock[data-state="listening"] [data-mascot="voice"] { background: #ef4444; color: #fff; animation: mascot-mic 1.2s ease-in-out infinite; }
.mascot-bubble { position: relative; max-width: 240px; margin-right: 8px; padding: 9px 13px; border-radius: 16px; background: #fff; color: #1e1b4b; font-size: 14px; line-height: 1.45; border: 1px solid rgba(99, 102, 241, 0.18); box-shadow: 0 8px 24px rgba(30, 27, 75, 0.16); }
.mascot-bubble[hidden] { display: none; }
/* 18f: dragged anywhere; walk frames; the answer over the head */
.has-mascot .home-fab { display: none !important; }
/* 18g: hop when pointed at (crouch, up, land). 18j (owner, comparing with Codex's pet: "ไม่แน่ใจว่าดูใน ipad หรือมือถือ
   ขนาดจะไม่ใหญ่ไปใช่ไหม"): the 16-bit sprite is Codex-pet sized, 96 px (1.5 px per sprite px, 3 device px on retina)
   on computers and iPads, 72 px on phones */
.mascot-dock.hopping .mascot-body { animation: mascot-jump 0.53s ease-out; }
@keyframes mascot-jump { 0% { transform: translateY(0) scale(1.04, 0.95); } 20% { transform: translateY(1px) scale(1.07, 0.92); } 50% { transform: translateY(-20px) scale(0.97, 1.04); } 80% { transform: translateY(-3px); } 90% { transform: translateY(0) scale(1.05, 0.95); } 100% { transform: none; } }
.mascot-dock.is-pixel .mascot-figure { width: 96px; height: 96px; }
.mascot-dock.is-pixel .mascot-img, .mascot-dock.is-pixel .mascot-blink { image-rendering: pixelated; }
.mascot-dock.is-pixel .mascot-body { filter: drop-shadow(0 3px 0 rgba(30, 27, 75, 0.12)); animation-name: mascot-bob8; animation-duration: 1.1s; animation-timing-function: steps(2, jump-none); }
@keyframes mascot-bob8 { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }
.mascot-sprite { position: absolute; inset: 0; display: block; background-repeat: no-repeat; background-size: 800% 900%; pointer-events: none; }
.mascot-sprite[hidden], .mascot-img[hidden] { display: none; }
.mascot-dock.is-atlas .mascot-figure { width: 80px; height: 104px; } /* 18k/18q: a Codex pet's cell (160 x 208) at half, 1:1 on retina */
.mascot-dock.is-atlas .mascot-body, .mascot-dock.is-atlas[data-state] .mascot-body { animation: none; filter: drop-shadow(0 3px 0 rgba(30, 27, 75, 0.12)); } /* its own frames carry the motion */
.mascot-dock.is-atlas[data-pose="sleep"] .mascot-body { animation: mascot-breathe 4.2s ease-in-out infinite; }
.mascot-dock.is-atlas.landing .mascot-body { animation: mascot-land 0.42s ease-out; }
.mascot-dock.is-atlas.dragging .mascot-body { transform: none; }
.mascot-dock.is-atlas.walking .mascot-body { animation: mascot-run-l 1.92s linear; }
.mascot-dock.is-atlas.on-left.walking .mascot-body { animation-name: mascot-run-r; }
@keyframes mascot-run-l { 50% { transform: translateX(-40px); } }
@keyframes mascot-run-r { 50% { transform: translateX(40px); } }
.ui-mascot-sprite { display: block; width: 92px; height: 120px; background-repeat: no-repeat; background-size: 800% 900%; }
.mascot-picker-backdrop { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, 0.45); }
.mascot-picker-sheet { width: 100%; max-width: 640px; max-height: 88vh; overflow: auto; padding: 18px; border-radius: 16px; background: #fff; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
.mascot-picker-top { display: flex; align-items: center; justify-content: space-between; }
.mascot-picker-top h2 { margin: 0; font-size: 18px; }
.mascot-picker-close { border: 0; background: none; font-size: 22px; line-height: 1; color: #64748b; cursor: pointer; }
.ui-mascot-stage { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border-radius: 16px; background: linear-gradient(135deg, #eef2ff, #f5f3ff); }
.ui-mascot-stage-fig { flex: none; width: 120px; height: 120px; display: grid; place-items: center; }
.ui-mascot-stage-fig img { width: 120px; height: 120px; object-fit: contain; }
.ui-mascot-stage.is-pixel .ui-mascot-stage-fig img, .ui-mascot-btn.is-pixel img { image-rendering: pixelated; }
.ui-mascot-stage-text { display: grid; gap: 4px; }
.ui-mascot-stage-text strong { font-size: 16px; }
.ui-mascot-stage-text small, .ui-mascot-btn small { font-size: 13px; color: #64748b; line-height: 1.4; }
.ui-mascot-btn .ui-mascot-name { font-size: 14px; }
.ui-mascot-btn.is-pixel img { width: 80px; height: 80px; }
.mascot-figure { touch-action: none; cursor: grab; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.mascot-menu { position: fixed; z-index: 10000; width: max-content; min-width: 240px; max-width: min(320px, calc(100vw - 16px)); padding: 6px; border-radius: 14px; background: #fff; border: 1px solid rgba(99, 102, 241, 0.18); box-shadow: 0 16px 40px rgba(30, 27, 75, 0.22); display: grid; gap: 2px; }
.mascot-menu-item { display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 10px; background: transparent; font: inherit; font-size: 14px; color: #1e1b4b; text-align: left; cursor: pointer; }
.mascot-menu-item:hover, .mascot-menu-item:focus-visible { background: var(--acc-50, #eef2ff); outline: none; }
.mascot-menu-item:disabled { opacity: 0.55; cursor: not-allowed; }
.mascot-menu-icon { flex: none; width: 22px; text-align: center; font-size: 16px; line-height: 1.4; }
.mascot-menu-label { display: grid; gap: 1px; line-height: 1.4; font-weight: 600; }
.mascot-menu-label small { font-size: 13px; font-weight: 400; color: #64748b; }
.mascot-dock.dragging .mascot-figure { cursor: grabbing; }
.mascot-dock.dragging .mascot-pill, .mascot-dock.dragging .mascot-bubble { opacity: 0 !important; visibility: hidden !important; } /* only the mascot travels with the finger */
.mascot-dock.dragging .mascot-body { animation: none !important; transform: rotate(var(--mascot-swing, 0deg)); transform-origin: 50% 10%; transition: transform 0.12s ease-out; }
.mascot-dock.dragging .mascot-figure::after { opacity: 0.35; transform: translateY(14px) scaleX(0.7); }
.mascot-dock.landing .mascot-body { animation: mascot-land 0.42s ease-out; }
.mascot-dock.walking .mascot-body { animation: mascot-step 0.34s ease-in-out infinite; }
.mascot-dock.on-left { align-items: flex-start; }
.mascot-dock.on-left .mascot-figure { margin: 0 0 0 4px; }
.mascot-dock.on-left .mascot-pill, .mascot-dock.on-left .mascot-bubble { margin: 0 0 0 8px; }
.mascot-dock.on-left .mascot-bubble::after { left: 42px; right: auto; }
.mascot-dock.on-top { flex-direction: column-reverse; }
.mascot-dock.on-top .mascot-bubble::after { top: -7px; bottom: auto; transform: rotate(225deg); }
.mascot-bubble.answer { max-width: 280px; }
.mascot-bubble-text { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.mascot-help-text { display: block; }
.mascot-bubble.help { padding-right: 40px; }
.mascot-help-close { position: absolute; top: 4px; right: 4px; width: 34px; height: 34px; border: 0; border-radius: 999px; background: transparent; color: #64748b; font: inherit; font-size: 16px; line-height: 1; cursor: pointer; }
.mascot-help-close:hover, .mascot-help-close:focus-visible { background: #f1f5f9; color: #1e1b4b; outline: none; }
.mascot-help-btn { display: block; width: 100%; margin-top: 8px; padding: 8px 12px; border: 0; border-radius: 10px; background: var(--primary, #4f46e5); color: #fff; font: inherit; font-size: 14px; font-weight: 700; text-align: center; text-decoration: none; cursor: pointer; box-sizing: border-box; }
.mascot-help-steps { display: block; margin-top: 6px; font-size: 13px; color: #475569; line-height: 1.45; }
.mascot-bubble-more { display: block; margin-top: 6px; padding: 2px 0; border: 0; background: none; color: var(--primary, #4f46e5); font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; }
.ui-mascot-voice { display: grid; gap: 8px; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line, #e2e8f0); background: #fff; }
.ui-mascot-voice > strong { font-size: 15px; }
.ui-mascot-voice-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; }
.ui-mascot-voice-opt { display: grid; gap: 2px; text-align: left; padding: 10px 12px; border-radius: 12px; border: 1.5px solid var(--line, #e2e8f0); background: #fff; font: inherit; font-size: 14px; font-weight: 700; color: var(--ink, #0f172a); cursor: pointer; }
.ui-mascot-voice-opt small { font-size: 13px; font-weight: 400; color: #64748b; line-height: 1.4; }
.ui-mascot-voice-opt.is-active { border-color: var(--primary, #4f46e5); box-shadow: 0 0 0 3px var(--acc-100, #e0e7ff); }
.ui-mascot-voice-opt:disabled { opacity: 0.55; cursor: not-allowed; }
.ui-mascot-pace { display: grid; gap: 6px; }
.ui-mascot-pace > strong { font-size: 14px; }
.ui-mascot-pace-opts { display: flex; flex-wrap: wrap; gap: 6px; }
.ui-mascot-pace-opt { min-height: 40px; padding: 8px 12px; border-radius: 999px; border: 1.5px solid var(--line, #e2e8f0); background: #fff; font: inherit; font-size: 14px; font-weight: 700; color: var(--ink, #0f172a); cursor: pointer; }
.ui-mascot-pace-opt.is-active { border-color: var(--primary, #4f46e5); background: var(--acc-100, #e0e7ff); color: var(--primary, #4f46e5); }
.ui-mascot-voice-try { justify-self: start; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--primary, #4f46e5); background: #fff; color: var(--primary, #4f46e5); font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; }
.ui-mascot-voice-note { font-size: 13px; color: #64748b; }
.ui-mascot-mic { display: grid; gap: 6px; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line, #e2e8f0); background: #fff; }
.ui-mascot-mic > strong { font-size: 15px; }
.ui-mascot-mic-select { width: 100%; min-height: 42px; padding: 8px 10px; border-radius: 10px; border: 1.5px solid var(--line, #e2e8f0); background: #fff; font: inherit; font-size: 14px; color: var(--ink, #0f172a); }
.ui-mascot-reset { justify-self: start; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line, #e2e8f0); background: #fff; font-size: 14px; color: var(--ink, #0f172a); cursor: pointer; }
@keyframes mascot-land { 0% { transform: translateY(-6px) scale(1, 1); } 45% { transform: translateY(0) scale(1.08, 0.9); } 100% { transform: none; } }
@keyframes mascot-step { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.mascot-bubble::after { content: ""; position: absolute; right: 42px; bottom: -7px; width: 12px; height: 12px; background: #fff; border-right: 1px solid rgba(99, 102, 241, 0.18); border-bottom: 1px solid rgba(99, 102, 241, 0.18); transform: rotate(45deg); }
@keyframes mascot-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes mascot-shadow { 0%, 100% { transform: scaleX(1); opacity: 1; } 50% { transform: scaleX(0.82); opacity: 0.7; } }
@keyframes mascot-hop { 0% { transform: translateY(0) rotate(0); } 35% { transform: translateY(-12px) rotate(-6deg); } 65% { transform: translateY(-4px) rotate(5deg); } 100% { transform: translateY(0) rotate(0); } }
@keyframes mascot-sway { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
@keyframes mascot-talk { 0%, 100% { transform: translateY(0) scale(1, 1); } 50% { transform: translateY(-2px) scale(1.02, 0.98); } }
@keyframes mascot-ring { 0% { transform: scale(0.8); opacity: 0.9; } 100% { transform: scale(1.35); opacity: 0; } }
@keyframes mascot-mic { 0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); } 50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); } }
@media (max-width: 640px) { .mascot-dock { right: 8px; } .mascot-figure { width: 80px; height: 80px; } .mascot-dock.is-pixel .mascot-figure { width: 72px; height: 72px; } .mascot-dock.is-atlas .mascot-figure { width: 60px; height: 78px; } .mascot-bubble { max-width: 210px; } .ui-mascot-stage-fig, .ui-mascot-stage-fig img { width: 80px; height: 80px; } .ui-mascot-sprite { width: 62px; height: 80px; } }
@media (prefers-reduced-motion: reduce) { .mascot-body, .mascot-arm, .mascot-blink, .mascot-dock.walking .mascot-body, .mascot-dock.landing .mascot-body, .mascot-dock.hopping .mascot-body, .mascot-figure::after, .mascot-figure::before, .mascot-dock:hover .mascot-body, .mascot-dock .mascot-pill-btn, .mascot-body.pose-in, .mascot-dock.is-atlas.walking .mascot-body { animation: none !important; } .mascot-zzz i { animation: none !important; opacity: 1; position: static; } }
@media print { .mascot-dock { display: none !important; } }
.ui-mascot-row { margin-top: 18px; display: grid; gap: 10px; }
.ui-mascot-head strong { display: block; font-size: 16px; }
.ui-mascot-head small { font-size: 13px; color: #64748b; }
.ui-mascot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.ui-mascot-btn { display: grid; justify-items: center; gap: 4px; padding: 8px 6px 10px; border-radius: 14px; border: 1.5px solid var(--line, #e2e8f0); background: #fff; cursor: pointer; font-size: 14px; color: var(--ink, #0f172a); }
.ui-mascot-btn img { width: 72px; height: 72px; object-fit: contain; }
.ui-mascot-btn.is-active { border-color: var(--primary, #4f46e5); box-shadow: 0 0 0 3px var(--acc-100, #e0e7ff); font-weight: 700; }
.ui-mascot-off { width: 72px; height: 72px; display: grid; place-items: center; border-radius: 50%; background: #f1f5f9; color: #64748b; font-size: 13px; }

.ai-card-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--ink, #0f172a);
  line-height: 1.35;
  letter-spacing: 0.1px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f1f5f9;
}

.ai-card-subtitle {
  margin-top: -4px;
  font-size: 12.5px;
  color: #64748b;
  font-weight: 500;
  line-height: 1.45;
}

.ai-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-badge {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--tpl-50,#eef2ff);
  color: #4338ca;
  border: 1px solid var(--tpl-200,#c7d2fe);
  letter-spacing: 0.2px;
}
.ai-badge.success { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.ai-badge.warning { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.ai-badge.danger  { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.ai-badge.info    { background: var(--tpl-50,#eef2ff); color: #4338ca; border-color: var(--tpl-200,#c7d2fe); }

.ai-kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.ai-kpi {
  display: grid;
  gap: 1px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  min-width: 0;
}

.ai-kpi span {
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: normal;
}

.ai-kpi strong {
  font-size: 14px;
  font-weight: 800;
  color: #0f172a;
  word-break: break-word;
  font-feature-settings: "tnum" 1;
}

.ai-card-section {
  display: grid;
  gap: 6px;
}

.ai-card-section h4 {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  color: #334155;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.ai-card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.ai-card-list li {
  position: relative;
  padding: 6px 10px 6px 22px;
  background: #f8fafc;
  border: 1px solid #f1f5f9;
  border-radius: 6px;
  font-size: 13px;
  color: #334155;
  line-height: 1.5;
}

.ai-card-list li::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 14px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary, var(--primary));
}

.ai-action-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
  color: #0f766e;
  background: linear-gradient(135deg, #ecfeff 0%, var(--acc-50) 100%);
  border: 1px solid var(--acc-200);
  border-radius: 999px;
  width: fit-content;
}

.ai-quote {
  margin: 0;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.6;
  color: #334155;
  font-style: italic;
  background: #fefce8;
  border-left: 3px solid #facc15;
  border-radius: 4px;
}

.ai-card-note {
  font-size: 13px;
  color: #64748b;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  padding: 6px 10px;
  border-radius: 6px;
  line-height: 1.5;
}

.ai-card-text {
  margin: 0;
  font-size: 14px;
  color: #475569;
  line-height: 1.55;
  white-space: pre-line;
}

.ai-card-divider {
  border: none;
  border-top: 1px dashed #e2e8f0;
  margin: 2px 0;
}

@media (max-width: 480px) {
  .ai-kpi-grid {
    grid-template-columns: 1fr;
  }
}

.danger-ghost {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fff7f7;
}

.danger-ghost:hover {
  color: #991b1b;
  border-color: #fca5a5;
  background: #fee2e2;
}

.secondary-action {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 700;
}

@media (max-width: 1180px) {
  .metrics-grid,
  .reports-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid,
  .split-view,
  .payment-layout,
  .daily-close-grid,
  .appointment-workbench,
  .workflow-steps,
  .opd-status-steps,
  .pdpa-grid,
  .folder-grid,
  .opd-worklist-grid,
  .opd-cloud-grid,
  .opd-evidence-panel,
  .opd-admin-entry,
  .posting-grid,
  .readiness-score,
  .readiness-board,
  .opd-pack-grid,
  .opd-completion-grid,
  .opd-action-center,
  .opd-visit-meta-grid,
  .opd-admin-decision,
  .category-rule-grid,
  .category-settings-grid,
  .category-editor-grid,
  .policy-summary-grid,
  .policy-editor-grid,
  .supplier-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    padding: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .metrics-grid,
  .queue-columns,
  .kanban,
  .opd-grid,
  .opd-start-columns,
  .facechart-layout,
  .opd-card-grid,
  .opd-card-chart,
  .gallery-grid,
  .recurring-panel,
  .treatment-costing,
  .course-layout,
  .wallet-layout,
  .wallet-summary,
  .stock-overview,
  .stock-kpi-grid,
  .stock-detail-grid,
  .stock-transfer-grid,
  .document-layout,
  .df-layout,
  .data-tools-grid,
  .notification-layout,
  .marketing-layout,
  .security-grid,
  .outstanding-strip,
  .integration-strip,
  .customer-care-strip,
  .profile-stats,
  .consent-status-strip,
  .consent-rule-list,
  .consent-audit-list div,
  .case-grid,
  .drawer-summary,
  .marker-legend,
  .workflow-steps,
  .opd-day-grid,
  .opd-action-buttons,
  .customer-workflow-guide,
  .pdpa-grid,
  .opd-evidence-panel,
  .ai-draft-grid,
  .ai-security-grid,
  .ai-spec-grid,
  .template-option-grid,
  .catalog-rules,
  .tier-rule-grid,
  .settings-layout,
  .settings-form,
  .modal-form {
    grid-template-columns: 1fr;
  }

  .opd-start-flow div {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .opd-start-flow button {
    grid-row: auto;
    grid-column: 1 / -1;
  }

  .table-row,
  .products-table .table-row,
  .course-table .table-row,
  .document-table .table-row,
  .df-table .table-row,
  .campaign-table .table-row,
  .lot-table .table-row,
  .import-table .table-row,
  .notification-list div,
  .audit-list div,
  .approval-list div {
    grid-template-columns: 1fr;
  }

  .appointment-row {
    grid-template-columns: 1fr;
  }

  .opd-return-queue {
    align-items: stretch;
    flex-direction: column;
  }

  .opd-return-actions {
    justify-content: stretch;
  }

  .opd-return-actions .ghost-button {
    flex: 1 1 140px;
  }

  .opd-return-metrics {
    grid-template-columns: 1fr;
  }
}

@media print {
  html,
  body {
    margin: 0;
    background: #ffffff;
  }

  body.printing-opd > :not(#opdPrintRoot) {
    display: none !important;
  }

  body.printing-opd #opdPrintRoot {
    display: block;
    margin: 0;
    padding: 0;
    background: #ffffff;
  }

  body.printing-opd #opdPrintRoot .opd-print-card {
    box-sizing: border-box;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #ffffff;
  }

  body.printing-opd #opdPrintRoot .opd-print-card + .opd-print-card {
    break-before: page;
  }

  body.printing-opd #opdPrintRoot.two-up {
    display: grid;
    grid-template-columns: 1fr;
    /* Explicit px rows: Chrome print does NOT reliably resolve 1fr in a fixed-height
       container — each visit gets an explicit 128mm row. 128+128+2(gap)+~15(header) = 273mm
       which fits the 277mm usable A4 area (@page margin:10mm each side). */
    grid-template-rows: auto 128mm 128mm;
    row-gap: 2mm;
    width: 190mm;
    height: 277mm;
    overflow: hidden;
  }

  /* ── 4-up: same single-column stack as 2-up but 4 half-height slots per A4 sheet.
     Reuses every .two-up inner rule; only the grid + slot height shrink.
     auto(~13mm header) + 4×62mm(248) + 4×1.5mm gaps(6) = ~267mm ≤ 277mm usable. ── */
  body.printing-opd #opdPrintRoot.two-up.four-up {
    grid-template-rows: auto 62mm 62mm 62mm 62mm;
    row-gap: 1.5mm;
  }
  body.printing-opd #opdPrintRoot.two-up.four-up .opd-visit-log {
    height: 62mm;
    font-size: 13px;
  }

  /* ── 2-up header: compact single-row + conditional alert strip ── */
  body.printing-opd #opdPrintRoot.two-up .opd-two-up-header {
    display: flex;
    flex-direction: column;
    gap: 1.5mm;
    padding-bottom: 2mm;
    border-bottom: 1.4mm solid #111827;
    color: #111827;
  }

  body.printing-opd #opdPrintRoot.two-up .two-up-h-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 4mm;
  }

  body.printing-opd #opdPrintRoot.two-up .two-up-clinic strong {
    font-size: 11pt;
    font-weight: 900;
    line-height: 1;
  }

  body.printing-opd #opdPrintRoot.two-up .two-up-clinic em {
    font-size: 6.5pt;
    font-style: normal;
    color: #64748b;
    margin-left: 2mm;
    font-weight: 400;
  }

  body.printing-opd #opdPrintRoot.two-up .two-up-patient-info {
    font-size: 7.5pt;
    font-weight: 600;
    color: #0f172a;
    text-align: right;
    flex-shrink: 0;
  }

  /* Alert strip — only rendered when allergy/disease present */
  body.printing-opd #opdPrintRoot.two-up .two-up-alert-strip {
    display: flex;
    gap: 4mm;
    flex-wrap: wrap;
    padding: 1mm 2mm;
    background: #fff7ed;
    border: 0.3mm solid #fed7aa;
    border-radius: 1mm;
    font-size: 7pt;
    line-height: 1.35;
  }

  body.printing-opd #opdPrintRoot.two-up .two-up-alert-allergy {
    color: #b91c1c;
    font-weight: 900;
  }

  body.printing-opd #opdPrintRoot.two-up .two-up-alert-disease,
  body.printing-opd #opdPrintRoot.two-up .two-up-alert-meds {
    color: #92400e;
    font-weight: 700;
  }

  body.printing-opd #opdPrintRoot.two-up .opd-print-card + .opd-print-card {
    break-before: auto;
  }

  body.printing-opd #opdPrintRoot.two-up.intake-print {
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 2mm;
    width: 190mm;
    min-height: 277mm;
  }

  body.printing-opd #opdPrintRoot.two-up.intake-print .opd-print-card + .opd-print-card {
    border-top: 0.4mm dashed #94a3b8;
    padding-top: 2mm;
  }

  body.printing-opd #opdPrintRoot.two-up.intake-print .opd-intake-card.paper-a4.portrait {
    width: auto;
    min-height: 136.5mm;
    height: 136.5mm;
    padding: 0;
    border: 0;
    font-size: 9.2pt;
  }

  /* ── Visit slot: flex column so map fills full 128mm ── */
  body.printing-opd #opdPrintRoot.two-up .opd-visit-log {
    position: relative;
    width: auto;
    height: 128mm;
    min-height: 0;
    padding: 0;
    border: 1px solid #cbd5e1;
    font-size: 13px;
    overflow: hidden;
    break-inside: auto;
    display: flex;
    flex-direction: column;
  }

  body.printing-opd #opdPrintRoot.two-up .opd-visit-log::before {
    content: attr(data-visit-copy);
    position: absolute;
    top: 2mm;
    right: 3mm;
    color: #94a3b8;
    font-weight: 900;
    font-size: 8pt;
    z-index: 1;
  }

  body.printing-opd #opdPrintRoot.two-up .opd-card-header {
    display: none;
  }

  body.printing-opd #opdPrintRoot.two-up .visit-sheet-critical {
    display: none;
  }

  body.printing-opd #opdPrintRoot.two-up .visit-sheet-summary {
    display: none;
  }

  /* ── Visit layout: SIDE-BY-SIDE — body map LEFT (big), doctor writes RIGHT ──
     Left column = full body map filling the slot height.
     Right column = vitals + allergy/disease + doctor handwriting + treatment table. */
  body.printing-opd #opdPrintRoot.two-up .visit-sheet-layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 1.3fr;   /* writing column bigger (owner: maximize note box, OK to encroach map); map still wide enough that figures don't shrink — verified in preview */
    grid-template-rows: 1fr;                  /* single row fills the slot height */
    gap: 2mm;
    margin-top: 1.5mm;
    padding: 0 2mm 2mm;
  }

  body.printing-opd #opdPrintRoot.two-up .visit-sheet-layout section {
    min-height: 0;
    min-width: 0;
    padding: 1.5mm;
    border: 1px solid #cbd5e1;
    box-sizing: border-box;
  }

  /* LEFT — body map fills its column edge-to-edge */
  body.printing-opd #opdPrintRoot.two-up .visit-sheet-map {
    min-height: 0;
    max-height: none;
    display: flex;
    flex-direction: column;
    align-content: unset;
    justify-items: unset;
  }

  body.printing-opd #opdPrintRoot.two-up .visit-sheet-map h4 {
    flex-shrink: 0;
    margin: 0 0 0.5mm 0;
    font-size: 6pt;
    font-weight: 800;
    color: #334155;
  }

  /* Split map: face = LEFT column (slightly smaller), front+back STACKED on the
     RIGHT (top/bottom) — the arrangement the owner approved. Spacing around the
     figures is squeezed (tiny h4 + captions) so the stacked bodies get max height. */
  body.printing-opd #opdPrintRoot.two-up .vs-map-split {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: flex-start;   /* pack face+bodies to the left, free space goes to the writing column */
    gap: 0.5mm;
  }

  body.printing-opd #opdPrintRoot.two-up .vs-map-face-cell {
    flex: 1.35;
    min-height: 0;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  /* close the middle gap: face picture hugs the RIGHT (toward the bodies) */
  body.printing-opd #opdPrintRoot.two-up .vs-map-face-cell img { object-position: right center; }

  body.printing-opd #opdPrintRoot.two-up .vs-map-body-cell {
    flex: 1;
    min-height: 0;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    display: flex;
    flex-direction: column;
    gap: 0.5mm;
    justify-content: center;
  }
  /* close the middle gap: body pictures hug the LEFT (toward the face) */
  body.printing-opd #opdPrintRoot.two-up .vs-map-body-cell img { object-position: left center; }

  body.printing-opd #opdPrintRoot.two-up .vs-map-body-cell figure {
    flex: 1;
    min-height: 0;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  body.printing-opd #opdPrintRoot.two-up .vs-map-split img {
    flex: 1;
    min-height: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    max-width: 100%;
    object-fit: contain;
    object-position: center;
  }

  body.printing-opd #opdPrintRoot.two-up .vs-map-split figcaption {
    flex-shrink: 0;
    margin-top: 0.2mm;
    font-size: 5pt;
    font-weight: 700;
    color: #94a3b8;
    line-height: 1;
  }

  /* RIGHT — vitals + doctor writing, stacked in a flex column */
  body.printing-opd #opdPrintRoot.two-up .visit-sheet-note {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 1mm;
  }

  /* Vitals block (allergy/disease + blank BP/PR/Temp/Wt/Ht) */
  body.printing-opd #opdPrintRoot.two-up .visit-sheet-vitals {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1mm;
  }

  body.printing-opd #opdPrintRoot.two-up .vs-vital-alerts {
    display: flex;
    flex-direction: column;
    gap: 0.5mm;
    font-size: 7pt;
    line-height: 1.3;
  }

  body.printing-opd #opdPrintRoot.two-up .vs-vital-alerts .vs-allergy strong {
    color: #b91c1c;
    font-weight: 900;
  }

  body.printing-opd #opdPrintRoot.two-up .vs-vital-alerts .vs-disease strong {
    color: #92400e;
    font-weight: 700;
  }

  body.printing-opd #opdPrintRoot.two-up .vs-vital-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5mm 3mm;
    padding: 1mm 0;
    border-top: 0.3mm dashed #cbd5e1;
    border-bottom: 0.3mm dashed #cbd5e1;
    font-size: 7pt;
    color: #475569;
  }

  body.printing-opd #opdPrintRoot.two-up .vs-vital-fields b {
    color: #0f172a;
    letter-spacing: 0.2mm;
  }

  body.printing-opd #opdPrintRoot.two-up .visit-sheet-note h4 {
    flex-shrink: 0;
    font-size: 7pt;
    font-weight: 800;
    color: #334155;
    margin: 0.5mm 0 0.5mm 0;
  }

  /* Handwriting area grows to fill remaining right-column height */
  body.printing-opd #opdPrintRoot.two-up .handwriting-lines {
    flex: 1;
    min-height: 30mm;
  }

  body.printing-opd #opdPrintRoot.two-up .mini-field-grid {
    flex-shrink: 0;
  }

  body.printing-opd #opdPrintRoot.two-up .mini-field-grid span {
    min-height: 6mm;
    font-size: 6.8pt;
  }

  /* 📅 แถบวันที่ต่อช่อง (2-up) — ฉีดเข้าหัว .visit-sheet-summary; ครั้งที่ 1 มีวันที่ ครั้งที่ 2 เว้นว่าง */
  body.printing-opd #opdPrintRoot.two-up .two-up-slot-date {
    font-size: 7.5pt;
    font-weight: 700;
    color: #0f172a;
    background: #f1f5f9;
    border-radius: 3px;
    padding: 0.6mm 1.5mm;
    margin-bottom: 1mm;
  }
  body.printing-opd #opdPrintRoot.two-up .two-up-slot-date b { color: #1d4ed8; }
  /* หน้าจอปกติ (1-up) ไม่ต้องโชว์แถบนี้ */
  .two-up-slot-date { display: none; }
  body.printing-opd #opdPrintRoot.two-up .two-up-slot-date { display: block; }

  body.printing-opd #opdPrintRoot.two-up .signature-grid {
    flex-shrink: 0;
    margin-top: 1.5mm;
    padding-top: 1.5mm;
    font-size: 7pt;
  }

  body.printing-opd .opd-card-grid,
  body.printing-opd .opd-card-chart,
  body.printing-opd .visit-log-table {
    break-inside: avoid;
  }

  /* Single-visit A4 portrait — clamp to exactly one page (same strategy as master-print).
     min-height:1123px from the screen rule causes overflow without this. */
  body.printing-opd #opdPrintRoot:not(.two-up) .opd-visit-log.portrait {
    width: 190mm;
    min-height: 0;
    height: 277mm;
    overflow: hidden;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .opd-card-chart {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(43mm, 0.55fr);
    gap: 2.5mm;
    min-height: 0;
    margin-top: 3mm;
    padding-top: 0;
    break-inside: avoid;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .opd-card-chart.body-map-only {
    grid-template-columns: minmax(0, 1fr);
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .beauty-face-section {
    min-height: auto;
    padding: 2mm;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .opd-map-sheet {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 92mm;
    margin: 1.5mm 0;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .chart-template-image {
    display: block !important;
    width: 100%;
    max-width: 176mm;
    max-height: 92mm;
    object-fit: contain;
    visibility: visible !important;
    opacity: 1 !important;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .marker-legend {
    display: none;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .opd-card-chart h4 {
    margin-bottom: 2mm;
    padding-bottom: 1.5mm;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .opd-card-chart small {
    display: none;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .mini-photo-grid span {
    min-height: 32mm;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .opd-card-sign {
    margin-top: 3mm;
    padding-top: 3mm;
    break-inside: avoid;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .opd-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2.5mm;
    margin-top: 3mm;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .opd-card-grid section,
  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .opd-card-chart > div {
    min-height: auto;
    padding: 2mm;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .opd-card-pdpa {
    grid-column: 1 / -1;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .opd-page-label {
    margin-bottom: 2mm;
    font-size: 8pt;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait h4 {
    margin-bottom: 1.5mm;
    padding-bottom: 1mm;
  }

  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait p,
  body.printing-opd #opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait .opd-card-row {
    line-height: 1.25;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-print-card.paper-a4.portrait {
    width: 190mm;
    /* เดิม height:277mm + overflow:hidden = "ตัดช่วงท้าย" (body map/ลายเซ็น) ทิ้งเมื่อข้อมูลผู้ป่วยยาวเกิน 1 หน้า
       เวชระเบียนห้ามตกหล่น → ใช้ min-height ปล่อยให้ไหลไปหน้า 2 เต็มๆ (body map/sign มี break-inside:avoid ไม่ขาดครึ่ง) */
    min-height: 277mm;
    overflow: visible;
    font-size: 9.9pt;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-page-label {
    display: none;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-card-header {
    padding-bottom: 2.2mm;
  }

  /* :not(.opd-visit-log) so these master-card font sizes DON'T leak onto the Visit page
     when it rides along in cardVisit (Master+Visit duplex) / "all" mode — the Visit sheet
     must print identically whether alone or as page 2. Master card = .opd-print-card
     WITHOUT .opd-visit-log, so it still matches. (verified 2026-07-14) */
  body.printing-opd #opdPrintRoot.master-print .opd-print-card:not(.opd-visit-log) .opd-card-header strong {
    font-size: 17.2pt;
    line-height: 1;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-print-card:not(.opd-visit-log) .opd-card-header span {
    font-size: 10pt;
    line-height: 1.15;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-card-logo {
    width: 12mm;
    height: 12mm;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-card-grid {
    gap: 1.3mm;
    margin-top: 1.3mm;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-card-grid section,
  body.printing-opd #opdPrintRoot.master-print .opd-card-chart > div {
    padding: 1.3mm;
  }

  /* Print cleanup + slack (Dr.Golf 2026-07-24 "เอา 84 เหมือนเดิม ลองลดบรรทัดก่อน"):
     hide on-screen edit hints in print · Checklist sits INLINE next to the Consent heading
     (fills the heading's empty right side → 0 extra vertical) so the 84mm body map stays page 1. */
  body.printing-opd .opd-edit-hint { display: none; }
  body.printing-opd #opdPrintRoot.master-print .opd-pdpa-head {
    margin-bottom: 0.8mm;
    padding-bottom: 0.7mm;
    gap: 3mm;
  }
  body.printing-opd #opdPrintRoot.master-print .opd-consent-checklist { font-size: 9.2pt; }

  body.printing-opd #opdPrintRoot.master-print .opd-print-card:not(.opd-visit-log) h4 {
    margin-bottom: 0.8mm;
    padding-bottom: 0.7mm;
    font-size: 10.6pt;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-card-row {
    padding: 0.42mm 0;
    gap: 2mm;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-print-card:not(.opd-visit-log) .opd-card-row span,
  body.printing-opd #opdPrintRoot.master-print .opd-print-card:not(.opd-visit-log) .opd-card-row strong {
    font-size: 9.9pt;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-print-card p {
    font-size: 9.8pt;
    line-height: 1.2;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-card-row strong {
    text-align: right;
  }

  body.printing-opd #opdPrintRoot.master-print .pdpa-sign-line {
    margin-top: 1.2mm;
    padding-top: 1.2mm;
  }

  body.printing-opd #opdPrintRoot.master-print .pdpa-sign-line span {
    font-size: 9.2pt;
  }

  body.printing-opd #opdPrintRoot.master-print .consent-summary-grid {
    gap: 0 2mm;
  }

  body.printing-opd #opdPrintRoot.master-print .consent-check-grid {
    gap: 0.6mm 3mm;
    margin-top: 1mm;
    font-size: 9.2pt;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-card-chart {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.8mm;
    margin-top: 1.2mm;
  }

  /* ⚠️ SELECTOR ARMS RACE: the generic `#opdPrintRoot:not(.two-up) .opd-print-card.paper-a4.portrait
     .opd-map-sheet` rule below pins the map at 92mm and OUTRANKS a plain `.master-print` rule
     (6 classes vs 3) — that 92mm is what always shoved the chart+sign to page 2 and made the
     "A4 หน้าเดียว" master card print with its tail missing. These selectors copy the full long
     form + .master-print so they finally win, and the sheet truly fits ONE page. */
  body.printing-opd #opdPrintRoot.master-print:not(.two-up) .opd-print-card.paper-a4.portrait .opd-map-sheet {
    /* 84mm = map ใหญ่แบบใบ 24 มิ.ย. ที่หมอชอบ (คง 84mm ตามหมอสั่ง 2026-07-24 "เอา 84 เหมือนเดิม
       ลองลดบรรทัดก่อน"). fit แบบ borderline: เนื้อหา master-print (ข้อมูลจริง) ~264-277mm + ฟอนต์
       เครื่องจริง +~12mm (บทเรียน v14d) → tip 2 หน้า. แก้ด้วย "คืนพื้นที่จากบรรทัด" แทนหด map:
       ย้าย Checklist ไปท้าย Consent + ตัด "(คลิกเพื่อแก้)"/"Snapshot" ออกจากพิมพ์ + บีบ spacing เล็กน้อย
       (ลด ~14mm → slack จริง ~15mm). harness-verified: ใบคุณหมอ (Janjira/Kay) 1 หน้าพร้อม slack. */
    min-height: 84mm;
    margin: 0.5mm 0;
  }

  body.printing-opd #opdPrintRoot.master-print:not(.two-up) .opd-print-card.paper-a4.portrait .chart-template-image {
    max-width: 176mm;
    max-height: 84mm;
  }

  /* PAPER only — on screen the row stays for Apple-Pencil signing. Scoped :not(.opd-visit-log)
     so the Visit page's แพทย์/ผู้บันทึก sign row still prints in the Master+Visit duplex mode. */
  body.printing-opd #opdPrintRoot.master-print .opd-print-card:not(.opd-visit-log) .opd-card-sign {
    display: none;
  }

  body.printing-opd #opdPrintRoot.master-print:not(.two-up) .opd-print-card.paper-a4.portrait .pdpa-sign-box.pen-sign-box {
    /* inline in the ผู้ป่วย line — tall enough for a signature, no separate row */
    min-height: 10mm;
  }

  body.printing-opd #opdPrintRoot.master-print:not(.two-up) .opd-print-card.paper-a4.portrait .opd-card-sign .pen-sign-box {
    min-height: 10mm;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-card-chart small {
    display: none;
  }

  body.printing-opd #opdPrintRoot.master-print .mini-photo-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.2mm;
  }

  body.printing-opd #opdPrintRoot.master-print .mini-photo-grid span {
    min-height: 0;
    aspect-ratio: 4 / 5;
    font-size: 6.8pt;
  }

  body.printing-opd #opdPrintRoot.master-print .mini-photo-grid img {
    min-height: 0;
  }

  body.printing-opd #opdPrintRoot.master-print .mini-photo-grid em {
    font-size: 5.8pt;
  }

  body.printing-opd #opdPrintRoot.master-print .opd-card-sign {
    margin-top: 2mm;
    padding-top: 2mm;
  }

  body.printing-opd #opdPrintRoot.intake-print .opd-intake-card.paper-a5.landscape {
    /* เดิม height:136.5mm ตายตัว — พื้นที่จริง A5 แนวนอน (margin 6mm) = 136mm → ล้นหน้า 2 เสมอ
       (แถบลายเซ็นท้ายใบตกไปอีกหน้า). ปล่อย auto ให้เนื้อหากำหนด แล้วคุมความสูงที่ section แทน */
    width: 186mm;
    min-height: 0;
    height: auto;
    padding: 0;
    border: 0;
    font-size: 8.6pt;
  }
  body.printing-opd #opdPrintRoot.intake-print .opd-intake-card.paper-a5.landscape .intake-grid {
    margin-top: 2mm;
    gap: 2mm;
  }
  body.printing-opd #opdPrintRoot.intake-print .opd-intake-card.paper-a5.landscape .intake-grid section {
    min-height: 30mm;
    padding: 2mm;
  }
  body.printing-opd #opdPrintRoot.intake-print .opd-intake-card.paper-a5.landscape .opd-card-header {
    padding-bottom: 1.5mm;
  }
  body.printing-opd #opdPrintRoot.intake-print .opd-intake-card.paper-a5.landscape .intake-bottom-note {
    margin-top: 0.5mm;
    font-size: 6.5pt;
  }
  body.printing-opd #opdPrintRoot.intake-print .opd-intake-card.paper-a5.landscape .intake-line-row {
    padding: 0.8mm 0;
  }
  body.printing-opd #opdPrintRoot.intake-print .opd-intake-card.paper-a5.landscape .intake-check-grid {
    gap: 0.8mm 2mm;
  }
  body.printing-opd #opdPrintRoot.intake-print .opd-intake-card.paper-a5.landscape .intake-note-box {
    min-height: 9mm;
    padding: 1mm;
  }
  body.printing-opd #opdPrintRoot.intake-print .opd-intake-card.paper-a5.landscape .intake-sign-grid.final {
    margin-top: 1mm;
    padding-top: 1mm;
  }

  body.printing-opd #opdPrintRoot.intake-print .opd-intake-card.paper-a4.portrait {
    width: 190mm;
    min-height: 136.5mm;
    height: 136.5mm;
    padding: 0;
    border: 0;
    font-size: 9.2pt;
  }

  body.printing-opd #opdPrintRoot.intake-print .opd-card-header {
    padding-bottom: 3mm;
  }

  body.printing-opd #opdPrintRoot.intake-print .opd-card-header strong {
    font-size: 18pt;
  }

  body.printing-opd #opdPrintRoot.intake-print .opd-card-header span {
    font-size: 10.5pt;
  }

  body.printing-opd #opdPrintRoot.intake-print .intake-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 2.7mm;
    margin-top: 3mm;
  }

  body.printing-opd #opdPrintRoot.intake-print .intake-grid section {
    min-height: 36mm;
    padding: 2.4mm;
    border-radius: 0;
  }

  body.printing-opd #opdPrintRoot.intake-print .intake-line-row {
    grid-template-columns: 33mm 1fr;
    padding: 1.25mm 0;
  }

  body.printing-opd #opdPrintRoot.intake-print .intake-line-row b {
    min-height: 6.2mm;
  }

  body.printing-opd #opdPrintRoot.intake-print .intake-check-grid,
  body.printing-opd #opdPrintRoot.intake-print .intake-photo-grid {
    gap: 1.8mm 3mm;
  }

  body.printing-opd #opdPrintRoot.intake-print .intake-check-grid span,
  body.printing-opd #opdPrintRoot.intake-print .intake-photo-grid span {
    min-height: 6.2mm;
  }

  body.printing-opd #opdPrintRoot.intake-print .intake-note-box {
    min-height: 16.5mm;
    padding: 2mm;
  }

  body.printing-opd #opdPrintRoot.intake-print .intake-sign-grid.final {
    margin-top: 3mm;
    padding-top: 2.8mm;
    font-size: 10.5pt;
  }

  body.printing-opd #opdPrintRoot.intake-print .intake-bottom-note {
    margin-top: 1.8mm;
    font-size: 8pt;
  }

  body.printing-opd .opd-print-card.paper-a5.landscape {
    width: 198mm;
    min-height: 136mm;
    padding: 0;
    font-size: 13px;
  }

  body.printing-opd .opd-print-card.paper-a4.portrait {
    width: 190mm;
    min-height: 277mm;
    padding: 0;
    font-size: 12px;
  }

  body.printing-opd .opd-print-card.paper-a4.landscape {
    width: 277mm;
    min-height: 190mm;
    padding: 0;
    font-size: 13px;
  }

  body.printing-opd .opd-print-card.paper-a5.portrait {
    width: 136mm;
    min-height: 198mm;
    padding: 0;
    font-size: 13px;
  }

  body.printing-opd .opd-visit-log.portrait .visit-sheet-layout {
    grid-template-columns: 1fr;
    gap: 3mm;
    margin-top: 3mm;
    break-inside: auto;
  }

  body.printing-opd .opd-visit-log.portrait .opd-card-header {
    padding-bottom: 1.5mm;
  }

  /* ── TOP IDENTITY = as SLIM as possible → maximise the doctor's writing area ── */
  body.printing-opd .opd-visit-log.portrait .visit-sheet-critical {
    gap: 1mm;
    margin-top: 1mm;
  }

  body.printing-opd .opd-visit-log.portrait .visit-sheet-critical div {
    padding: 0.8mm 1.5mm;
    line-height: 1.12;
  }
  /* Name is prominent; the 2-col-wide cell lets it fit on one line (wraps, never clips). */
  body.printing-opd .opd-visit-log.portrait .visit-sheet-critical > div:first-child strong {
    font-size: 12.5pt;
  }
  body.printing-opd .opd-visit-log.portrait .visit-sheet-critical strong { font-size: 10.5pt; }
  body.printing-opd .opd-visit-log.portrait .visit-sheet-critical span { font-size: 8pt; }

  body.printing-opd .opd-visit-log.portrait .visit-sheet-layout {
    gap: 2mm;
    margin-top: 2mm;
  }
  body.printing-opd .opd-visit-log.portrait .visit-sheet-layout section {
    min-height: auto;
    padding: 1.5mm 2mm;
  }

  /* Patient/Visit strip: tight, no wasted height */
  body.printing-opd .opd-visit-log.portrait .visit-sheet-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 6mm;
  }
  body.printing-opd .opd-visit-log.portrait .visit-sheet-summary h4 {
    margin-bottom: 0.5mm;
    font-size: 9pt;
  }
  body.printing-opd .opd-visit-log.portrait .visit-sheet-summary .opd-card-row { padding: 1mm 0; }

  body.printing-opd .opd-visit-log.portrait .visit-sheet-checks {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 1.5mm;
    gap: 2mm;
  }
  body.printing-opd .opd-visit-log.portrait .visit-sheet-checks span { padding: 0.8mm 1.5mm; }

  /* Redundant on the single-visit sheet — the L/R divider already splits the note box and the
     doctor writes freeform. Dropping it hands ~15mm back to the writing area + keeps it minimal. */
  body.printing-opd .opd-visit-log.portrait .mini-field-grid { display: none; }
  /* Vitals strip: keep it to one tight line. */
  body.printing-opd .opd-visit-log.portrait .visit-sheet-vitals { margin-bottom: 1.5mm; }
  body.printing-opd .opd-visit-log.portrait .vs-vital-fields { padding: 1mm 0; }

  /* ── BODY MAP = big (the doctor marks points on it) ── */
  body.printing-opd .opd-visit-log.portrait .visit-sheet-map {
    min-height: 56mm;
  }

  body.printing-opd .opd-visit-log.portrait .visit-sheet-map img {
    width: 100%;
    max-height: 54mm;
  }

  /* Single-A4 (full-width column): split shows 3 across like the composite */
  body.printing-opd .opd-visit-log.portrait .vs-map-split {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 4mm;
  }

  body.printing-opd .opd-visit-log.portrait .vs-map-face-cell { flex: 1.1; }
  body.printing-opd .opd-visit-log.portrait .vs-map-body-cell { flex: 1.6; gap: 4mm; }

  body.printing-opd .opd-visit-log.portrait .vs-map-split img {
    width: 100%;
    max-height: 54mm;
  }

  body.printing-opd .opd-visit-log.portrait .vs-map-split figcaption {
    font-size: 7pt;
    color: #94a3b8;
  }

  /* ── HANDWRITING = the star of the sheet: give it as much height as fits ── */
  body.printing-opd .opd-visit-log.portrait .handwriting-lines {
    min-height: 68mm;
  }
  /* No signature (default) → hand the sign-row's height straight to the writing box. */
  body.printing-opd .opd-visit-log.portrait.no-sign .handwriting-lines {
    min-height: 80mm;
  }

  body.printing-opd .opd-visit-log.portrait .mini-field-grid span {
    min-height: 8mm;
  }

  body.printing-opd .opd-visit-log.portrait .signature-grid {
    margin-top: 3mm;
    padding-top: 2mm;
  }

  /* Signature boxes are sized tall for iPad pen input on screen; on PAPER they only need a
     short line to sign on — this is the #1 reason the printed single-visit sheet ran long. */
  body.printing-opd .opd-visit-log.portrait .pen-sign-box {
    min-height: 10mm;
    background: transparent;
  }
  body.printing-opd .opd-visit-log.portrait .sign-row {
    gap: 4mm;
    margin-top: 2mm;
    flex-wrap: nowrap;   /* จอใช้ flex-basis 160px → บนกระดาษคอลัมน์แคบจะ wrap ซ้อน 3 ชั้นจนหน้าเกิน */
  }
  body.printing-opd .opd-visit-log.portrait .sign-cell { flex: 1 1 0; min-width: 0; }
  body.printing-opd .opd-visit-log.portrait .sign-cell.sign-date-cell { flex: 0 0 auto; }
  body.printing-opd .opd-visit-log.portrait .sign-date { min-width: 0; }

  /* ── Layout B "รูปซ้าย-เขียนขวา" (vs-side) on PAPER: BIG 100mm map column left, writing right.
     Map arranged like the clinic's old paper card: face top-center, front + back side-by-side
     below — no frames around the figures (frames were also cut out of the PNGs themselves). ── */
  body.printing-opd .opd-visit-log.portrait.vs-side .visit-sheet-layout {
    /* map col 100mm→88mm: ช่องเขียน (Doctor Handwriting) กว้างขึ้น ~+14% (หมอขอ 2026-07-24)
       โดย body map ไม่เล็กลง — รูปคุมด้วย max-height (หน้า 64mm/ตัว 98mm สูงคงที่) + เพิ่ม
       face-cell 66%→75% ให้ช่องหน้ายังกว้าง ~66mm เท่าเดิม; ที่หายคือ ‘ที่ว่างรอบรูป’ ไม่ใช่ตัวรูป. */
    grid-template-columns: 88mm minmax(0, 1fr);
    align-items: stretch;
  }
  body.printing-opd .opd-visit-log.portrait.vs-side .visit-sheet-summary { grid-column: 1 / -1; }
  body.printing-opd .opd-visit-log.portrait.vs-side .visit-sheet-map {
    min-height: 0;
    border: none;              /* no frame around the whole map area */
  }
  body.printing-opd .opd-visit-log.portrait.vs-side .vs-map-split {
    flex-direction: column;
    align-items: center;
    gap: 1mm;
  }
  body.printing-opd .opd-visit-log.portrait.vs-side .vs-map-face-cell { flex: none; width: 75%; }
  body.printing-opd .opd-visit-log.portrait.vs-side .vs-map-body-cell {
    flex: none;
    width: 100%;
    flex-direction: row;
    gap: 3mm;
  }
  body.printing-opd .opd-visit-log.portrait.vs-side .vs-map-face-cell img {
    width: 100%;
    max-height: 64mm;   /* หน้าใหญ่ขึ้นตามสั่ง — bodies เลื่อนลงล่าง */
  }
  body.printing-opd .opd-visit-log.portrait.vs-side .vs-map-body-cell img {
    width: 100%;
    max-height: 98mm;
  }
  body.printing-opd .opd-visit-log.portrait.vs-side .handwriting-lines {
    /* ขยายช่องเขียนลงมาให้เต็มช่องว่าง (หมอขอ 2026-07-14). 132mm ยืนยันด้วย headless-Chrome
       PDF harness (_hw_harness.html): แม้ใส่ข้อมูลยาว (แพ้ยา 5 ตัว/โรค 3/ยา 3) แถวลายเซ็นยังอยู่
       ครบหน้าเดียว. เหลือ slack ~6mm ใต้ 138mm ที่เคยตกหน้า 2 กับข้อมูลจริง. */
    min-height: 132mm;
  }
  body.printing-opd .opd-visit-log.portrait.vs-side.no-sign .handwriting-lines {
    min-height: 146mm;
  }

  /* A5 portrait = same vertical layout as A4, shrunk to fit the smaller sheet (~198mm usable).
     Higher specificity (.paper-a5) so these override the shared .portrait sizes above. */
  body.printing-opd .opd-visit-log.paper-a5.portrait {
    font-size: 8.5pt;
  }
  body.printing-opd .opd-visit-log.paper-a5.portrait .visit-sheet-map {
    min-height: 38mm;
  }
  body.printing-opd .opd-visit-log.paper-a5.portrait .visit-sheet-map img {
    max-height: 34mm;
  }
  body.printing-opd .opd-visit-log.paper-a5.portrait .vs-map-split img {
    max-height: 36mm;
  }
  body.printing-opd .opd-visit-log.paper-a5.portrait .handwriting-lines {
    min-height: 38mm;
  }
  body.printing-opd .opd-visit-log.paper-a5.portrait .mini-field-grid span {
    min-height: 7mm;
  }
  body.printing-opd .opd-visit-log.paper-a5.portrait .pen-sign-box {
    min-height: 9mm;
  }

  /* ── A5 LANDSCAPE (แบบประหยัด — A5 มีแต่แนวนอน แนวตั้งหมอตัดทิ้ง 2026-07-11) ──
     3 คอลัมน์เดิม (ข้อมูล | map | ช่องเขียน) ในพื้นที่ 198×136mm: ตัดแถบ identity บน
     (ชื่อ/แพ้ยา/โรค อยู่คอลัมน์ซ้ายอยู่แล้ว — ใน landscape ไม่มี opd-dup-hide) ไม่งั้นล้นหน้า */
  /* จอ preview ตั้ง .paper-a5.landscape min-height 794px (≈210mm) — ถ้าไม่ override ตอนพิมพ์
     ใบจะสูงเกิน A5 (136mm) เสมอไม่ว่าเนื้อหาสั้นแค่ไหน = สาเหตุหลักที่ล้น 2 หน้า */
  body.printing-opd .opd-visit-log.paper-a5.landscape {
    width: 198mm;
    min-height: 0;
    height: auto;
    padding: 0;
    font-size: 9pt;
  }
  body.printing-opd .opd-visit-log.paper-a5.landscape .visit-sheet-critical { display: none; }
  body.printing-opd .opd-visit-log.paper-a5.landscape .opd-card-header { padding-bottom: 2mm; }
  body.printing-opd .opd-visit-log.paper-a5.landscape .visit-sheet-layout {
    gap: 2mm;
    margin-top: 2mm;
  }

  body.printing-opd .opd-visit-log.paper-a5.landscape .visit-sheet-layout section {
    min-height: 104mm;
    padding: 2mm;
  }

  /* map คอลัมน์กลาง: หน้าอยู่บน + ตัวหน้า/หลังคู่กันล่าง (เหมือน A4 ย่อส่วน) */
  body.printing-opd .opd-visit-log.paper-a5.landscape .vs-map-split {
    flex-direction: column;
    align-items: center;
    gap: 1mm;
  }
  body.printing-opd .opd-visit-log.paper-a5.landscape .vs-map-face-cell { flex: none; width: 54%; }
  body.printing-opd .opd-visit-log.paper-a5.landscape .vs-map-body-cell {
    flex: none;
    width: 100%;
    flex-direction: row;
    gap: 2mm;
  }
  /* !important จำเป็น: ทดสอบ file://-PDF แล้วมี rule อื่น (ยังชี้ตัวไม่ได้) ชนะ max-height
     ปกติของรูปในโหมด A5 landscape — ถ้าถอด !important รูปจะบานจน 2 หน้า (เทสก่อนถอดเสมอ) */
  body.printing-opd .opd-visit-log.paper-a5.landscape .vs-map-face-cell img {
    width: 100% !important;
    max-height: 32mm !important;
  }
  body.printing-opd .opd-visit-log.paper-a5.landscape .vs-map-body-cell img {
    width: 100% !important;
    max-height: 60mm !important;
  }
  body.printing-opd .opd-visit-log.paper-a5.landscape .vs-map-split figcaption {
    font-size: 6.5pt;
    color: #94a3b8;
  }

  body.printing-opd .opd-visit-log.paper-a5.landscape .visit-sheet-map img {
    max-height: 100mm;
  }

  body.printing-opd .opd-visit-log.paper-a5.landscape .mini-field-grid { display: none; }
  body.printing-opd .opd-visit-log.paper-a5.landscape .handwriting-lines {
    min-height: 56mm;
  }
  /* ช่องเซ็น 3 ช่องต้องอยู่แถวเดียว — คอลัมน์แคบกว่า flex-basis 160px ของจอ เลย wrap ซ้อน 3 ชั้นจนล้นหน้า */
  body.printing-opd .opd-visit-log.paper-a5.landscape .sign-row {
    flex-wrap: nowrap;
    gap: 2mm;
    margin-top: 1mm;
  }
  body.printing-opd .opd-visit-log.paper-a5.landscape .sign-cell { flex: 1 1 0; min-width: 0; }
  body.printing-opd .opd-visit-log.paper-a5.landscape .sign-cell.sign-date-cell { flex: 0 0 auto; }
  body.printing-opd .opd-visit-log.paper-a5.landscape .sign-cap { font-size: 6.5pt; }
  body.printing-opd .opd-visit-log.paper-a5.landscape .sign-date { min-width: 0; font-size: 8pt; }
  body.printing-opd .opd-visit-log.paper-a5.landscape .vs-vital-fields {
    padding: 1mm 0;
    gap: 1mm 4mm;
    font-size: 8pt;
  }
  body.printing-opd .opd-visit-log.paper-a5.landscape .sign-row {
    margin-top: 1mm;
  }
  body.printing-opd .opd-visit-log.paper-a5.landscape .pen-sign-box {
    min-height: 9mm;
    background: transparent;
  }
}

/* Empty state placeholders — production-ready (no demo data) */
/* Gallery (photo grid) — cross-device synced via R2 */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  padding: 12px;
  max-height: 70vh;
  overflow-y: auto;
}
.gallery-item {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.gallery-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
}
.gallery-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #f1f5f9;
  display: block;
}
.gallery-item .gallery-meta {
  padding: 8px 10px;
  font-size: 13px;
  color: #475569;
}
.gallery-item .gallery-meta strong {
  display: block;
  color: #0f172a;
  font-size: 12px;
  margin-bottom: 2px;
}
.gallery-item .gallery-meta .kind-tag {
  display: inline-block;
  padding: 2px 6px;
  background: var(--tpl-100,#ede9fe);
  color: var(--tpl-deep,#5b21b6);
  border-radius: 4px;
  font-weight: 600;
  margin-top: 4px;
}
/* Grouped-by-patient gallery — each patient is its own card */
.gallery-grouped {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px;
  max-height: 70vh;
  overflow-y: auto;
}
.gallery-group {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}
.gallery-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: #f8fafc;
  border-bottom: 1px solid #eef2f7;
  position: sticky;
  top: 0;
  z-index: 1;
  cursor: pointer;
  user-select: none;
}
.gallery-group-header:hover { background: #f1f5f9; }
.gallery-group-header .gg-chevron {
  display: inline-block;
  margin-left: 4px;
  transition: transform 0.2s ease;
  font-size: 13px;
}
.gallery-group.expanded .gg-chevron { transform: rotate(180deg); }
/* Collapsed (default): one neat horizontal preview row (swipe to peek). Click
   the header/count badge to expand into a full wrapping grid that shows every
   photo. Expanded uses the base .gallery-group-grid rule (auto-fill wrap). */
.gallery-group:not(.expanded) .gallery-group-grid {
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: 140px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.gallery-group-header .gg-id strong {
  display: block;
  font-size: 14px;
  color: #0f172a;
}
.gallery-group-header .gg-id .gg-hn {
  font-size: 13px;
  color: #64748b;
}
.gallery-group-header .gg-count {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--tpl-deep,#5b21b6);
  background: var(--tpl-100,#ede9fe);
  padding: 3px 10px;
  border-radius: 999px;
}
.gallery-group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  padding: 12px;
}
/* Force a visible thumbnail height inside groups — the aspect-ratio square was
   collapsing to a thin sliver in the column-flow preview strip. */
.gallery-group-grid .gallery-item img {
  height: 130px;
  aspect-ratio: auto;
}
@media (max-width: 600px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
    padding: 8px;
  }
  .gallery-group-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 8px;
    padding: 8px;
  }
}

/* ════════════════════════════════════════════════════════════════════
   Gallery (R2 photos) — pro redesign. Everything is scoped under .rg-*
   so the legacy .gallery-grid / .gallery-item rules above never bleed in
   (the new selectors win on specificity). Left filter rail + clean,
   fixed-size thumbnails (no aspect-ratio collapse, no sliver-clipping).
   ════════════════════════════════════════════════════════════════════ */
.rg-layout { display: flex; gap: 16px; align-items: flex-start; padding: 4px 2px 2px; }
.rg-rail {
  flex: 0 0 198px; width: 198px; position: sticky; top: 8px;
  display: flex; flex-direction: column; gap: 10px;
  background: #faf9fe; border: 1px solid #eceaf6; border-radius: 14px; padding: 12px;
}
.rg-search {
  width: 100%; box-sizing: border-box; padding: 9px 12px;
  border: 1px solid #e2e0ee; border-radius: 10px; font-size: 13px; background: #fff;
}
.rg-search:focus { outline: none; border-color: var(--tpl-bright,#a78bfa); box-shadow: 0 0 0 3px color-mix(in srgb,var(--tpl-main,#7c3aed) 12%,transparent); }
.rg-rail-label { font-size: 13px; font-weight: 800; letter-spacing: 0.4px; color: #9a93b3; text-transform: uppercase; margin-top: 2px; }
.rg-tabs { display: flex; flex-direction: column; gap: 4px; }
.rg-tab {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border: none; background: transparent; border-radius: 9px;
  font-size: 13px; font-weight: 600; color: #475569; cursor: pointer; text-align: left;
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
}
.rg-tab .rg-ic { font-size: 15px; line-height: 1; width: 18px; text-align: center; }
.rg-tab .rg-tx { flex: 1 1 auto; white-space: nowrap; }
.rg-tab .rg-ct {
  flex: none; min-width: 20px; text-align: center; font-size: 13px; font-weight: 700;
  color: #8b87a3; background: #efedf7; border-radius: 999px; padding: 1px 7px;
}
.rg-tab:hover { background: #f1edfd; color: var(--tpl-deep,#5b21b6); }
.rg-tab.active { background: var(--tpl-main,#7c3aed); color: #fff; box-shadow: 0 4px 12px color-mix(in srgb,var(--tpl-main,#7c3aed) 28%,transparent); }
.rg-tab.active .rg-ct { background: rgba(255, 255, 255, 0.26); color: #fff; }
.rg-rail-divider { height: 1px; background: #eceaf6; margin: 4px 0; }
.rg-field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 700; color: #9a93b3; text-transform: uppercase; letter-spacing: 0.3px; }
.rg-select { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid #e2e0ee; border-radius: 9px; font-size: 13px; font-weight: 600; color: #475569; background: #fff; cursor: pointer; }
.rg-switch { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 600; color: #475569; cursor: pointer; user-select: none; }
.rg-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.rg-switch-track { flex: none; width: 38px; height: 22px; background: #d6d3e6; border-radius: 999px; position: relative; transition: background 0.18s; }
.rg-switch-thumb { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.18s; }
.rg-switch input:checked + .rg-switch-track { background: var(--tpl-main,#7c3aed); }
.rg-switch input:checked + .rg-switch-track .rg-switch-thumb { transform: translateX(16px); }
.rg-status { font-size: 13px; color: #9a93b3; }
.rg-main { flex: 1 1 auto; min-width: 0; }

/* Flat grid (เรียงรวม) */
.rg-flat {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 13px; max-height: 74vh; overflow-y: auto; padding: 2px;
}
.rg-flat .gallery-item, .rg-grouped .gallery-item {
  position: relative; background: #fff; border: 1px solid #e8e6f0; border-radius: 13px;
  overflow: hidden; cursor: pointer; transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.rg-flat .gallery-item:hover, .rg-grouped .gallery-item:hover {
  transform: translateY(-3px); box-shadow: 0 10px 24px rgba(91, 33, 182, 0.16);
}
.rg-flat .gallery-item img { width: 100%; height: 150px; object-fit: cover; display: block; background: #eef1f7; }
.rg-flat .gallery-item .gallery-meta, .rg-grouped .gallery-item .gallery-meta { padding: 7px 9px; font-size: 13px; color: #64748b; line-height: 1.45; }
.rg-flat .gallery-item .gallery-meta strong { display: block; color: #0f172a; font-size: 12px; margin-bottom: 2px; }
.rg-flat .gallery-meta .kind-tag, .rg-grouped .gallery-meta .kind-tag {
  display: inline-block; padding: 1px 8px; background: #f3f0ff; color: var(--tpl-main,#6d28d9);
  border-radius: 999px; font-weight: 700; font-size: 13px; margin-top: 3px;
}

/* Grouped-by-patient (จัดกลุ่มตามคนไข้) */
.rg-grouped { display: flex; flex-direction: column; gap: 14px; max-height: 74vh; overflow-y: auto; padding: 2px; }
.rg-grouped .gallery-group { border: 1px solid #e8e6f0; border-radius: 15px; background: #fff; overflow: hidden; }
.rg-grouped .gallery-group-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; background: linear-gradient(180deg, #faf9ff, #f5f3fb);
  border-bottom: 1px solid #efedf6; cursor: pointer; user-select: none; transition: background 0.12s;
}
.rg-grouped .gallery-group-header:hover { background: #f0ebff; }
.rg-grouped .gg-id { min-width: 0; }
.rg-grouped .gg-id strong { display: block; font-size: 14px; font-weight: 700; color: #0f172a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rg-grouped .gg-id .gg-hn { font-size: 13px; color: #8b8698; }
.rg-grouped .gg-count {
  flex: none; display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700;
  color: #fff; background: var(--tpl-main,#7c3aed); padding: 4px 12px; border-radius: 999px;
}
.rg-grouped .gg-chevron { font-size: 12px; }
/* Filmstrip — one neat horizontal row (swipe to peek); click header → full album */
.rg-grouped .gallery-group-grid {
  display: flex; gap: 10px; padding: 13px 16px; overflow-x: auto;
  scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
}
.rg-grouped .gallery-group-grid::-webkit-scrollbar { height: 8px; }
.rg-grouped .gallery-group-grid::-webkit-scrollbar-track { background: transparent; }
.rg-grouped .gallery-group-grid::-webkit-scrollbar-thumb { background: #dcd8ec; border-radius: 999px; }
.rg-grouped .gallery-group-grid .gallery-item { flex: 0 0 auto; width: 124px; scroll-snap-align: start; }
.rg-grouped .gallery-group-grid .gallery-item img { width: 124px; height: 124px; object-fit: cover; display: block; background: #eef1f7; }
.rg-grouped .gallery-group-grid .gallery-meta { padding: 5px 8px; font-size: 13px; }
.rg-grouped .gallery-group-grid .gallery-meta .kind-tag { font-size: 13px; padding: 1px 6px; }
/* Expanded (if a group ever toggles open) → wrapping grid */
.rg-grouped .gallery-group.expanded .gallery-group-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); overflow-x: visible;
}
.rg-grouped .gallery-group.expanded .gallery-group-grid .gallery-item { width: auto; }
.rg-grouped .gallery-group.expanded .gallery-group-grid .gallery-item img { width: 100%; height: 140px; }

/* Responsive — rail collapses to a horizontal strip on top */
@media (max-width: 820px) {
  .rg-layout { flex-direction: column; }
  .rg-rail { position: static; width: 100%; flex: none; }
  .rg-tabs { flex-direction: row; flex-wrap: wrap; }
  .rg-tab { width: auto; }
  .rg-tab .rg-tx { flex: 0 0 auto; }
}

/* ════ App theme: Luxe (gold floral) — opt-in via <html data-theme="luxe"> ════ */
/* Motif defined once on :root so the picker swatch can preview it regardless of
 * the active theme. Luxe rules apply it only in safe, low-distraction zones. */
:root {
  --luxe-motif: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200'%3E%3Cg fill='none' stroke='%23BFA24A' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M30 196 C 60 150 76 120 88 86'/%3E%3Cpath d='M88 120 C 116 104 138 92 152 64'/%3E%3Cpath d='M70 150 C 88 150 108 144 120 130 C 104 150 86 158 70 150 Z'/%3E%3Cpath d='M96 112 C 116 108 134 100 146 84 C 132 106 114 116 96 112 Z'/%3E%3Cg transform='translate(150 56)'%3E%3Cellipse cx='0' cy='-13' rx='6' ry='12'/%3E%3Cellipse cx='0' cy='-13' rx='6' ry='12' transform='rotate(60)'/%3E%3Cellipse cx='0' cy='-13' rx='6' ry='12' transform='rotate(120)'/%3E%3Cellipse cx='0' cy='-13' rx='6' ry='12' transform='rotate(180)'/%3E%3Cellipse cx='0' cy='-13' rx='6' ry='12' transform='rotate(240)'/%3E%3Cellipse cx='0' cy='-13' rx='6' ry='12' transform='rotate(300)'/%3E%3Ccircle cx='0' cy='0' r='4'/%3E%3C/g%3E%3Cg transform='translate(88 78)'%3E%3Cellipse cx='0' cy='-16' rx='7' ry='14'/%3E%3Cellipse cx='0' cy='-16' rx='7' ry='14' transform='rotate(72)'/%3E%3Cellipse cx='0' cy='-16' rx='7' ry='14' transform='rotate(144)'/%3E%3Cellipse cx='0' cy='-16' rx='7' ry='14' transform='rotate(216)'/%3E%3Cellipse cx='0' cy='-16' rx='7' ry='14' transform='rotate(288)'/%3E%3Ccircle cx='0' cy='0' r='5'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
:root[data-theme="luxe"] .empty-state {
  background-image: var(--luxe-motif);
  background-repeat: no-repeat;
  background-position: right 14px bottom 10px;
  background-size: 88px;
}
:root[data-theme="luxe"] #loginOverlay {
  background-image: var(--luxe-motif);
  background-repeat: no-repeat;
  background-position: right -24px top -14px;
  background-size: 300px;
}
:root[data-theme="luxe"] .workspace::before {
  content: "";
  position: fixed;
  right: -36px;
  bottom: -36px;
  width: 240px;
  height: 240px;
  background: var(--luxe-motif) no-repeat center / contain;
  opacity: 0.05;
  pointer-events: none;
  z-index: 0;
}

/* ════ App theme: Oriental Gold (ทองมงคล) — full-frame line-art motif ════ */
/* PNG has a WHITE background (no alpha) → mix-blend-mode:multiply makes the white
 * vanish and only the gold lines blend onto the page. Faint + corners only so the
 * center (tables/numbers) stays clean. */
:root { --oriental-motif: url("assets/theme-oriental-gold.png"); }
:root[data-theme="oriental-gold"] .workspace::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--oriental-motif) no-repeat center / 100% 100%;
  opacity: 0.13;
  mix-blend-mode: multiply;
  pointer-events: none;
  z-index: 0;
}
:root[data-theme="oriental-gold"] #loginOverlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--oriental-motif) no-repeat center / cover;
  opacity: 0.16;
  mix-blend-mode: multiply;
  pointer-events: none;
  z-index: 0;
  border-radius: inherit;
}
:root[data-theme="oriental-gold"] .empty-state {
  background-image: var(--oriental-motif);
  background-repeat: no-repeat;
  background-position: right -30px bottom -30px;
  background-size: 200px;
  background-blend-mode: multiply;
}

/* ════ App theme: Custom — user-uploaded background (--custom-bg set by JS) ════ */
/* Faint full-frame so transparent-PNG frames or photos both stay readable behind
 * tables/numbers. No blend (uploads may be opaque photos). */
:root[data-theme="custom"] .workspace::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--custom-bg) no-repeat center / cover;
  opacity: 0.14;
  pointer-events: none;
  z-index: 0;
}
:root[data-theme="custom"] #loginOverlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--custom-bg) no-repeat center / cover;
  opacity: 0.16;
  pointer-events: none;
  z-index: 0;
  border-radius: inherit;
}
/* Mobile (portrait) → use the 9:16 image if the user uploaded one (falls back to desktop). */
@media (max-width: 768px) {
  :root[data-theme="custom"] .workspace::before { background-image: var(--custom-bg-mobile, var(--custom-bg)); }
  :root[data-theme="custom"] #loginOverlay::before { background-image: var(--custom-bg-mobile, var(--custom-bg)); }
}
/* App theme picker (Settings → ธีมแอป) */
.app-theme-picker { display: flex; flex-direction: column; gap: 10px; padding: 6px 0 2px; }
.app-theme-card { display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff; cursor: pointer; text-align: left; transition: border-color .12s, box-shadow .12s; }
.app-theme-card:hover { border-color: #cbd5e1; }
.app-theme-card.is-active { border-color: var(--tpl-main,#7c3aed); box-shadow: 0 0 0 2px color-mix(in srgb,var(--tpl-main,#7c3aed) 18%,transparent); }
.app-theme-swatch { width: 46px; height: 46px; border-radius: 10px; flex: 0 0 auto; border: 1px solid rgba(15, 23, 42, .08); }
.app-theme-swatch--std { background: #f8fafc; }
.app-theme-swatch--luxe { background: #fbf5e6 var(--luxe-motif) no-repeat center / 74%; }
.app-theme-swatch--oriental-gold { background: #fbf7ec url("assets/theme-oriental-gold.png") no-repeat center / cover; background-blend-mode: multiply; }
.app-theme-swatch--custom { background: var(--custom-bg, none) center / cover, var(--tpl-50,#eef2ff); }
.app-theme-meta { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.app-theme-meta strong { font-size: 14px; color: #0f172a; font-weight: 700; }
.app-theme-meta small { font-size: 12px; color: #64748b; line-height: 1.4; }
.app-theme-check { color: var(--tpl-main,#7c3aed); font-weight: 800; font-size: 18px; flex: 0 0 auto; }

.empty-state {
  padding: 28px 16px;
  text-align: center;
  color: #94a3b8;
  font-size: 14px;
  font-weight: 500;
  background: rgba(148, 163, 184, 0.06);
  border: 1px dashed rgba(148, 163, 184, 0.35);
  border-radius: 10px;
  margin: 6px 0;
}
.appointment-list .empty-state,
.queue-columns .empty-state,
.case-grid .empty-state,
.timeline-list .empty-state,
.followup-panel .empty-state,
.notification-list .empty-state,
.audit-list .empty-state,
.approval-list .empty-state,
.consent-rule-list .empty-state,
.consent-audit-list .empty-state,
.drawer-timeline .empty-state,
.invoice-list .empty-state,
.import-table .empty-state,
.campaign-table .empty-state,
.df-table .empty-state,
.wallet-history .empty-state {
  font-size: 13px;
  padding: 18px 12px;
}
.empty-state[data-empty-state="services"],
.empty-state[data-empty-state="invoice"],
.empty-state[data-empty-state="split"],
.empty-state[data-empty-state="df-summary"] {
  padding: 16px;
  font-size: 13px;
}

/* ============================================================
   LINE Groups & Incoming Slips (Payment slip 2-way sync)
   ============================================================ */
.line-groups-help {
  margin-top: 8px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 8px 12px;
}
.line-groups-help summary {
  cursor: pointer;
  font-weight: 600;
  color: #166534;
  font-size: 14px;
}
.line-groups-help ol {
  margin: 8px 0 0;
  padding-left: 18px;
  line-height: 1.7;
  color: #15803d;
  font-size: 13px;
}
.line-groups-help strong { color: #064e3b; }

.incoming-slips-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
  margin-top: 12px;
}
.incoming-slips-list {
  display: grid;
  gap: 10px;
  max-height: 480px;
  overflow-y: auto;
}
.incoming-slip-card {
  display: grid;
  grid-template-columns: 84px 1fr auto;
  gap: 12px;
  align-items: center;
  background: #fff;
  border: 1px solid var(--tpl-100,#e0e7ff);
  border-radius: 10px;
  padding: 10px;
}
/* Flash the newest slip card when staff taps the Payments nav badge → jumps here */
@keyframes slipFlashPulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb,var(--tpl-main,#7c3aed) 55%,transparent); }
  60% { box-shadow: 0 0 0 9px color-mix(in srgb,var(--tpl-main,#7c3aed) 0%,transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb,var(--tpl-main,#7c3aed) 0%,transparent); }
}
.incoming-slip-card.slip-flash {
  animation: slipFlashPulse 1.3s ease-out 2;
  outline: 2px solid var(--primary, var(--tpl-main,#7c3aed));
  outline-offset: 2px;
}

/* ── OPD card: patient name must POP — owner feedback "กลืนกันไปหมด" ──
   Strong blue + bigger so the name is findable at arm's length on paper.
   Prints dark on B/W printers (size carries the emphasis there). */
#opdCardPatientName,
#visitSheetPatientNameTop,
#visitSheetPatientName {
  color: #1d4ed8 !important;
  font-size: 1.32em !important;
  font-weight: 800 !important;
  letter-spacing: 0.01em;
}
#visitSheetHnTop,
#opdCardHn {
  color: #1d4ed8 !important;
  font-weight: 800 !important;
}

/* ── OPD stepper ยุบได้ — เช็คลิสต์ 9 ขั้นเกะกะ แทบไม่มีใครกาง ──
   หุบ = แถวเดียวแบนจริงๆ (ฆ่า grid 220px เดิม คืนพื้นที่ให้จอ)
   กาง = ปุ่ม 9 ขั้นเต็มความกว้าง. */
details.opd-action-center {
  display: block; /* override grid-template-columns 220px */
}
details.opd-action-center:not([open]) {
  padding: 8px 14px;
}
details.opd-action-center > summary.opd-action-summary {
  display: flex;
  align-items: center;
  gap: 8px 14px;
  flex-wrap: wrap;
  padding: 0;
  border-right: none;
  cursor: pointer;
  list-style: none;
}
details.opd-action-center > summary::-webkit-details-marker { display: none; }
details.opd-action-center > summary::marker { content: ""; }
details.opd-action-center > summary .opd-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  flex: 1;
  min-width: 150px;
}
details.opd-action-center > summary strong { font-size: 0.88rem; }
/* คำใบ้ขั้นถัดไปโชว์เฉพาะตอนกาง — ตอนหุบเอาพื้นที่คืน */
details.opd-action-center:not([open]) > summary em { display: none; }
details.opd-action-center[open] > summary { margin-bottom: 8px; }
.opd-stepper-toggle-hint {
  margin-left: auto;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary, var(--tpl-main,#7c3aed));
  background: var(--tpl-50,#f5f3ff);
  border: 1px solid var(--tpl-200,#ddd6fe);
  border-radius: 999px;
  padding: 3px 12px;
  white-space: nowrap;
}
details.opd-action-center[open] .opd-stepper-toggle-hint { background: var(--tpl-100,#ede9fe); }

/* ── OPD 360 — มุมมองคนไข้ 360° ── */
.opd360-hero {
  background: linear-gradient(135deg, var(--tpl-50,#f5f3ff), #fff);
  border: 1px solid var(--tpl-200,#ddd6fe);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 14px;
}
.opd360-name {
  color: #1d4ed8;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.opd360-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.opd360-kpi {
  background: #fff;
  border: 1px solid #e8e6f0;
  border-radius: 10px;
  padding: 8px 12px;
}
.opd360-kpi span { display: block; font-size: 13px; color: #8b8698; }
.opd360-kpi strong { font-size: 15.5px; color: #0f172a; }
.opd360-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 12px;
}
.opd360-col {
  background: #fff;
  border: 1px solid #e8e6f0;
  border-radius: 12px;
  padding: 12px 14px;
}
.opd360-col h4 { margin: 0 0 8px; font-size: 13.5px; }
.opd360-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid #f4f2fa;
  font-size: 12.5px;
}
.opd360-row:last-child { border-bottom: none; }
.opd360-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
}
.opd360-thumbs img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  background: #eef1f7;
  cursor: pointer;
}

/* ── Reports view tabs — แยกหน้า รายงานยอดขาย / ส่งบัญชี / คีย์ยอดย้อนหลัง / Barter ── */
.reports-tab-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 6px;
  background: var(--surface, #fff);
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 12px;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}
.reports-tab {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 9px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.18s cubic-bezier(0.4, 0, 0.2, 1), color 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}
.reports-tab:hover { background: #f1f5f9; color: #334155; }
.reports-tab.active {
  background: var(--primary, var(--tpl-main,#7c3aed));
  color: #fff;
  box-shadow: 0 2px 8px color-mix(in srgb,var(--tpl-main,#7c3aed) 28%,transparent);
}
.rtab-badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 999px;
  background: #f59e0b;
  color: #fff;
  font-size: 13px;
  line-height: 18px;
  text-align: center;
}
.reports-tab.active .rtab-badge { background: rgba(255, 255, 255, 0.25); }
.incoming-slip-preview {
  width: 84px;
  height: 84px;
  background: linear-gradient(135deg, var(--tpl-50,#eef2ff), var(--tpl-200,#ddd6fe));
  border: 1px dashed var(--tpl-bright,#a78bfa);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  color: var(--tpl-main,#6d28d9);
  font-weight: 700;
  text-align: center;
  padding: 4px;
  transition: transform 0.15s;
}
.incoming-slip-preview:hover { transform: scale(1.03); }
.incoming-slip-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}
.incoming-slip-info strong { font-size: 14px; color: #0f172a; }
.incoming-slip-info span { color: #64748b; font-size: 12px; }
.incoming-slip-info em { color: #94a3b8; font-size: 13px; font-style: normal; }
.incoming-slip-info code {
  font-family: ui-monospace, monospace;
  background: #f1f5f9;
  padding: 1px 4px;
  border-radius: 4px;
}
.slip-verify-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin: 2px 0;
  width: fit-content;
}
.slip-verify-badge.ok { background: #dcfce7; color: #15803d; }
.slip-verify-badge.dup { background: #fef3c7; color: #b45309; }
.slip-verify-badge.fail { background: #fee2e2; color: #b91c1c; }
.incoming-slip-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: stretch;
  min-width: 130px;
}
.incoming-slip-actions button {
  font-size: 12px;
  padding: 4px 8px;
  white-space: nowrap;
}

/* ============================================================
   ONLINE BOOKING — deposit credit row + booking queue + dashboard card
   ============================================================ */
.bill-deposit-credit {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: #065f46;
}
.bill-deposit-credit strong { color: #047857; }
.bill-deposit-credit button { padding: 5px 12px; font-size: 12px; }

/* Dashboard alert card — only shown when pending bookings exist */
.booking-dashboard-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: linear-gradient(135deg, var(--tpl-50,#eef2ff), var(--tpl-50,#faf5ff));
  border: 1px solid var(--tpl-200,#c7d2fe);
  border-radius: 14px;
  padding: 14px 18px;
  margin-bottom: 18px;
}
.booking-dashboard-main { display: flex; flex-direction: column; gap: 2px; }
.booking-dashboard-main strong { font-size: 16px; color: #3730a3; }
.booking-dashboard-badge,
.booking-panel-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--tpl-main,#4f46e5);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  margin-left: 4px;
}

/* Booking queue panel (Appointments view) */
.booking-panel-list { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.booking-section-title { margin: 8px 0 2px; font-size: 13px; color: #475569; }
.booking-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border: 1px solid #e2e8f0;
  border-left: 4px solid var(--tpl-main,#6366f1);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
}
.booking-card-done { border-left-color: #10b981; opacity: 0.85; }
.booking-card-main { display: flex; flex-direction: column; gap: 3px; min-width: 200px; flex: 1; }
.booking-card-main strong { font-size: 15px; }
/* ช่องทางการจอง — แยกให้ชัดว่าลูกค้าจองออนไลน์เอง vs คลินิก/MR ลงให้ */
.booking-src { display: inline-block; font-size: 13px; font-weight: 700; border-radius: 999px; padding: 1px 8px; vertical-align: middle; white-space: nowrap; border: 1px solid transparent; }
.booking-src.src-online { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.booking-src.src-line   { background: #ecfccb; color: #3f6212; border-color: #d9f99d; }
.booking-src.src-phone  { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.booking-src.src-walkin { background: #fef9c3; color: #854d0e; border-color: #fde68a; }
.booking-src.src-staff  { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }
.booking-slot { font-size: 13px; color: #4338ca; font-weight: 600; }
.booking-service { font-size: 13px; color: #0f172a; }
.booking-dep { font-size: 12px; color: #047857; }
.booking-card-main .muted { font-size: 12px; }
.booking-slip-link { font-size: 12px; color: #2563eb; text-decoration: none; }
.booking-card-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; min-width: 120px; }
.booking-card-actions button { font-size: 12px; padding: 6px 10px; white-space: nowrap; }
.booking-confirmed-tag { font-size: 12px; color: #047857; font-weight: 600; }
@media (max-width: 640px) {
  .booking-card-actions { flex-direction: row; flex-wrap: wrap; }
}

/* ============================================================
   BARTER CARD (Mediqueen-only) — recorded off real revenue
   ============================================================ */
.barter-card-panel {
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px dashed #f59e0b;
  border-radius: 12px;
  background: #fffbeb;
}
.barter-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.barter-card-head strong { font-size: 14px; color: #92400e; }
.barter-card-flag {
  font-size: 13px;
  font-weight: 700;
  color: #b45309;
  background: #fef3c7;
  border-radius: 999px;
  padding: 3px 8px;
}
.barter-card-desc { margin: 6px 0 10px; font-size: 12px; color: #78716c; line-height: 1.4; }
.barter-card-row { display: flex; gap: 8px; flex-wrap: wrap; }
.barter-card-row input[type="number"] { width: 150px; }
.barter-card-row input[type="text"] { flex: 1; min-width: 140px; }
.barter-card-row input {
  padding: 8px 10px;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  font-size: 14px;
}
.barter-card-row button { white-space: nowrap; }
.barter-card-today { margin-top: 8px; font-size: 13px; color: #92400e; }
.barter-slip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: #92400e;
  cursor: pointer;
  white-space: nowrap;
}
.barter-slip-btn:hover { background: #fffbeb; }
.barter-slip-preview { margin-top: 8px; display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.barter-slip-preview img {
  max-height: 130px;
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}
.barter-slip-preview button { font-size: 12px; padding: 5px 10px; }

.barter-enable-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  white-space: nowrap;
}
.barter-ledger-table { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 13px; }
.barter-ledger-table th, .barter-ledger-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  text-align: left;
}
.barter-ledger-table thead th { font-size: 12px; color: #64748b; background: #fffbeb; }
.barter-disabled-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
}

/* ============================================================
   Notification Matrix + Routing recipient enrichment
   ============================================================ */
.notification-matrix-wrap {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px 16px;
  margin: 12px 0;
}
.notification-matrix-wrap summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  color: #0f172a;
  padding: 4px 0;
}
.notification-matrix-wrap[open] summary { margin-bottom: 10px; }
/* Inner div that holds the matrix table — scroll it horizontally on mobile. */
.notification-matrix {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.matrix-table {
  width: 100%;
  min-width: 560px; /* event × recipient grid — scroll on mobile, not squish */
  border-collapse: collapse;
  font-size: 13px;
}
.matrix-table th {
  background: #f8fafc;
  color: #475569;
  padding: 10px 8px;
  text-align: center;
  border-bottom: 2px solid #e2e8f0;
  font-weight: 600;
  font-size: 12px;
}
.matrix-table th:first-child { text-align: left; }
.matrix-table td {
  padding: 10px 8px;
  text-align: center;
  border-bottom: 1px solid #f1f5f9;
}
.matrix-table td:first-child { text-align: left; font-weight: 500; color: #0f172a; }
.matrix-table tbody tr:hover { background: #fafbfc; }
.matrix-legend {
  margin-top: 12px;
  padding: 10px;
  background: #fef3c7;
  border-left: 3px solid #f59e0b;
  border-radius: 6px;
  font-size: 13px;
}
.matrix-legend ul { margin: 6px 0 0; padding-left: 18px; line-height: 1.7; }

.line-recipient-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  margin-bottom: 6px;
}
.recipient-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: linear-gradient(135deg, var(--tpl-200,#c4b5fd), var(--tpl-bright,#a78bfa));
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.recipient-avatar.placeholder { font-size: 14px; }
.line-recipient-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.line-recipient-top { display: flex; align-items: center; gap: 6px; }
.line-recipient-info code { font-size: 13px; color: #64748b; }
.line-recipient-line-name { color: #16a34a; font-weight: 600; }
.line-recipient-warn { color: #d97706; font-style: italic; }

/* ============================================================
   Slip verification modal — admin reviews AI findings + decides
   ============================================================ */
.slip-verify-backdrop {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.78);
  z-index: 2000;
}
.slip-verify-modal {
  max-width: 720px;
  width: 92%;
  max-height: 92vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}
.slip-verify-header {
  padding: 22px 28px;
  color: #fff;
  border-radius: 16px 16px 0 0;
}
.slip-verify-header h2 {
  font-size: 22px;
  margin: 0 0 8px;
  color: #fff;
}
.slip-verify-header span { font-size: 13px; opacity: 0.95; }
.slip-source-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.25);
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 600;
}
.slip-verify-body { padding: 24px 28px; }
.slip-comparison {
  display: grid;
  grid-template-columns: 1fr 40px 1fr;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.slip-comparison-side { text-align: center; }
.slip-comparison-side h4 {
  font-size: 12px;
  color: #64748b;
  margin: 0 0 8px;
  font-weight: 600;
  text-transform: uppercase;
}
.slip-comparison-side .big-amount {
  font-size: 28px;
  font-weight: 800;
  color: #0f172a;
  display: block;
}
.slip-comparison-divider {
  font-size: 32px;
  font-weight: 800;
  color: #94a3b8;
  text-align: center;
}
.slip-flags-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.slip-flag {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
}
.slip-flag span { font-size: 22px; text-align: center; }
.slip-flag-success { background: #f0fdf4; color: #166534; border-left: 4px solid #16a34a; }
.slip-flag-warning { background: #fffbeb; color: #92400e; border-left: 4px solid #f59e0b; }
.slip-flag-error { background: #fef2f2; color: #991b1b; border-left: 4px solid #dc2626; }
.slip-details-expand {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
}
.slip-details-expand summary { cursor: pointer; font-weight: 600; color: #475569; }
.slip-details-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 16px;
  margin-top: 10px;
  font-size: 13px;
}
.slip-details-grid div { display: flex; flex-direction: column; gap: 2px; }
.slip-details-grid span { color: #94a3b8; font-size: 13px; text-transform: uppercase; }
.slip-details-grid strong { color: #0f172a; font-size: 13px; }
.slip-decision-help {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  color: #1e40af;
}
.slip-decision-help ul { margin: 6px 0 0; padding-left: 18px; line-height: 1.7; }
.slip-verify-actions {
  display: flex;
  gap: 10px;
  padding: 16px 28px 24px;
  justify-content: flex-end;
  border-top: 1px solid #f1f5f9;
}
.danger-action {
  background: #dc2626;
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}
.danger-action:hover { background: #b91c1c; }

/* ============================================================
   Settings section visual categorization
   Color-code each card by category to reduce monotony when scrolling
   ============================================================ */

/* Base improvements: bigger spacing + lift + section badge */
.settings-section-card {
  position: relative;
  padding: 24px 24px 20px;
  margin-bottom: 28px;
  background: #fff;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
  border-left-width: 6px;
  border-left-style: solid;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  transition: box-shadow 0.2s, transform 0.2s;
}
.settings-section-card:hover {
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
}

/* Category badge — floats in top-right corner */
.settings-section-card[data-category-label]::before {
  content: attr(data-category-label);
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.3px;
  background: var(--cat-tint, #f1f5f9);
  color: var(--cat-text, #475569);
  border: 1px solid var(--cat-border, #cbd5e1);
  pointer-events: none;
  z-index: 1;
}
/* FIX (overlap bug): the chip floats top-right; section headers that carry action
   buttons in the SAME corner (e.g. AI Connector's เปิด/ปิด toggle) sat UNDER it.
   On desktop, reserve a top strip on those .wide headers so the buttons drop below
   the chip. (Mobile already clears it via the card's 60px top padding.) */
@media (min-width: 721px) {
  .settings-section-card[data-category-label] .panel-head.wide {
    padding-top: 16px;
  }
}

/* Subtle background tint matching category */
.settings-section-card[data-category] {
  background: linear-gradient(180deg, var(--cat-tint, #fff) 0%, #fff 60px);
}

/* Category palettes */
.settings-section-card[data-category="line"] {
  --cat-color: #16a34a;
  --cat-tint: #f0fdf4;
  --cat-border: #86efac;
  --cat-text: #166534;
  border-left-color: #16a34a;
}
.settings-section-card[data-category="broadcast"] {
  --cat-color: #9333ea;
  --cat-tint: #faf5ff;
  --cat-border: #d8b4fe;
  --cat-text: #6b21a8;
  border-left-color: var(--tpl-main,#9333ea);
}
.settings-section-card[data-category="intake"] {
  --cat-color: #0284c7;
  --cat-tint: #f0f9ff;
  --cat-border: #7dd3fc;
  --cat-text: #075985;
  border-left-color: #0284c7;
}
.settings-section-card[data-category="payment"] {
  --cat-color: #d97706;
  --cat-tint: #fffbeb;
  --cat-border: #fcd34d;
  --cat-text: #92400e;
  border-left-color: #d97706;
}
.settings-section-card[data-category="people"] {
  --cat-color: #db2777;
  --cat-tint: #fdf2f8;
  --cat-border: #f9a8d4;
  --cat-text: #9d174d;
  border-left-color: #db2777;
}
.settings-section-card[data-category="clinic"] {
  --cat-color: var(--acc-deep);
  --cat-tint: var(--acc-50);
  --cat-border: var(--acc-bright);
  --cat-text: var(--acc-deep);
  border-left-color: var(--acc-deep);
}

/* Make panel-head inside section more prominent */
.settings-section-card .panel-head {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px dashed rgba(0, 0, 0, 0.08);
}
.settings-section-card .panel-head h2 {
  font-size: 19px;
  font-weight: 800;
  color: var(--cat-color, #0f172a);
  margin: 0;
}
.settings-section-card .panel-head .muted {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  color: #64748b;
}

/* When a card is hovered, intensify its left border */
.settings-section-card[data-category]:hover {
  border-left-width: 8px;
}

/* For non-section cards that still need category color (e.g. broadcast inside Settings) */
.settings-section-card .panel-head .primary-action {
  background: var(--cat-color);
}

/* Anchor target highlight when navigating via menu */
.settings-section-card.section-flash {
  animation: section-flash-anim 1.4s ease-out;
}
@keyframes section-flash-anim {
  0% { box-shadow: 0 0 0 4px var(--cat-color, #94a3b8); }
  100% { box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04); }
}

/* Mobile: badge moves below header to avoid overlap */
@media (max-width: 720px) {
  .settings-section-card {
    padding: 60px 16px 16px;
  }
  .settings-section-card[data-category-label]::before {
    top: 16px;
    right: 16px;
    font-size: 13px;
  }
}

/* Settings menu — color-coded by category */
.settings-menu button[data-menu-cat] {
  position: relative;
  padding-left: 14px;
  font-weight: 500;
}
.settings-menu button[data-menu-cat]::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 60%;
  border-radius: 2px;
  background: var(--menu-dot, #cbd5e1);
}
.settings-menu button[data-menu-cat="line"]::before     { background: #16a34a; }
.settings-menu button[data-menu-cat="broadcast"]::before { background: var(--tpl-main,#9333ea); }
.settings-menu button[data-menu-cat="intake"]::before    { background: #0284c7; }
.settings-menu button[data-menu-cat="payment"]::before   { background: #d97706; }
.settings-menu button[data-menu-cat="people"]::before    { background: #db2777; }
.settings-menu button[data-menu-cat="clinic"]::before    { background: var(--acc-deep); }

.settings-menu button.active[data-menu-cat="line"]     { background: #f0fdf4; color: #166534; }
.settings-menu button.active[data-menu-cat="broadcast"] { background: var(--tpl-50,#faf5ff); color: var(--tpl-deep,#6b21a8); }
.settings-menu button.active[data-menu-cat="intake"]    { background: #f0f9ff; color: #075985; }
.settings-menu button.active[data-menu-cat="payment"]   { background: #fffbeb; color: #92400e; }
.settings-menu button.active[data-menu-cat="people"]    { background: #fdf2f8; color: #9d174d; }
.settings-menu button.active[data-menu-cat="clinic"]    { background: var(--acc-50); color: var(--acc-deep); }

/* ============================================================
   Receipt Template editor form
   ============================================================ */
.receipt-template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.receipt-template-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.receipt-template-field.wide { grid-column: 1 / -1; }
.receipt-template-field span {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
}
.receipt-template-field input,
.receipt-template-field textarea,
.receipt-template-field select {
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.receipt-template-field input:focus,
.receipt-template-field textarea:focus,
.receipt-template-field select:focus {
  outline: none;
  border-color: #d97706;
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15);
}
.receipt-template-help {
  margin-top: 14px;
  padding: 10px 14px;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 8px;
}
.receipt-template-help summary {
  cursor: pointer;
  font-weight: 600;
  color: #92400e;
  font-size: 13px;
}
.receipt-template-help ul {
  margin: 8px 0 0;
  padding-left: 18px;
  line-height: 1.8;
  font-size: 13px;
  color: #78350f;
}
.receipt-template-help strong {
  background: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid #fcd34d;
  font-family: ui-monospace, monospace;
}

@media (max-width: 720px) {
  .receipt-template-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   Receipt preview modal
   ============================================================ */
.receipt-preview-backdrop {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: rgba(15, 23, 42, 0.78);
  z-index: 2000;
  overflow-y: auto;
  padding: 24px 12px;
}
.receipt-preview-modal {
  width: 92%;
  max-width: 920px;
  background: #f1f5f9;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}
.receipt-preview-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 22px;
  background: linear-gradient(135deg, #d97706, #92400e);
  color: #fff;
  flex-wrap: wrap;
}
.receipt-preview-modal-head h2 { margin: 0; color: #fff; font-size: 20px; }
.receipt-preview-size-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.receipt-preview-size-tabs .chip {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 6px 12px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.receipt-preview-size-tabs .chip.active { background: #fff; color: #92400e; }
.receipt-preview-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.receipt-preview-actions .ghost-button {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
}
.receipt-preview-stage {
  padding: 24px;
  background: #cbd5e1;
  max-height: 75vh;
  overflow-y: auto;
  display: flex;
  justify-content: center;
}

/* The receipt paper itself — clean white background, official look */
.receipt-preview-paper {
  background: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  padding: 28px 32px;
  color: #0f172a;
  font-family: 'Sarabun', sans-serif;
  line-height: 1.5;
}
.receipt-paper-thermal { width: 280px; padding: 16px 12px; font-size: 13px; }
.receipt-paper-a5 { width: 540px; }
.receipt-paper-a4 { width: 720px; }

.receipt-preview-header {
  text-align: center;
  padding-bottom: 16px;
  border-bottom: 2px solid #0f172a;
}
.receipt-preview-logo {
  max-width: 80px;
  max-height: 80px;
  display: block;
  margin: 0 auto 8px;
}
.receipt-preview-logo-placeholder {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 24px;
  margin: 0 auto 8px;
  color: #0f766e;
}
.receipt-preview-header h1 {
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 4px;
}
.receipt-paper-thermal .receipt-preview-header h1 { font-size: 14px; }
.receipt-preview-en-name {
  font-size: 13px;
  color: #475569;
  margin: 0 0 6px;
  font-weight: 600;
}
.receipt-preview-header p {
  margin: 2px 0;
  font-size: 12px;
  color: #475569;
}

.receipt-preview-title {
  text-align: center;
  margin: 16px 0 12px;
}
.receipt-preview-title h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 1px;
}
.receipt-preview-title p {
  margin: 2px 0 0;
  font-size: 13px;
  color: #94a3b8;
  font-style: italic;
}

.receipt-preview-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
  padding: 10px;
  background: #f8fafc;
  border-radius: 6px;
  font-size: 13px;
}
.receipt-paper-thermal .receipt-preview-meta { grid-template-columns: 1fr; gap: 4px; font-size: 13px; }
.receipt-preview-meta span { display: block; color: #94a3b8; font-size: 13px; }
.receipt-preview-meta strong { color: #0f172a; }

.receipt-preview-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 14px;
  font-size: 13px;
}
.receipt-paper-thermal .receipt-preview-table { font-size: 13px; }
.receipt-preview-table th {
  background: #0f172a;
  color: #fff;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
}
.receipt-preview-table td {
  padding: 8px 6px;
  border-bottom: 1px dashed #e2e8f0;
  vertical-align: top;
}

.receipt-preview-totals {
  border-top: 2px solid #0f172a;
  padding-top: 10px;
  margin-bottom: 14px;
}
.receipt-preview-totals > div {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 14px;
}
.receipt-preview-net {
  font-size: 18px !important;
  font-weight: 800;
  border-top: 1px solid #cbd5e1;
  margin-top: 6px;
  padding-top: 8px !important;
}
.receipt-preview-vat-note small {
  color: #94a3b8;
  font-size: 13px;
  font-style: italic;
}

.receipt-preview-payment {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
  padding: 10px 0;
  border-top: 1px dashed #e2e8f0;
  border-bottom: 1px dashed #e2e8f0;
}
.receipt-paper-thermal .receipt-preview-payment { grid-template-columns: 1fr; gap: 4px; }
.receipt-preview-payment > div { font-size: 12px; }
.receipt-preview-payment span { display: block; color: #94a3b8; }

.receipt-preview-terms {
  margin: 14px 0;
  padding: 8px 12px;
  background: #fafbfc;
  border-left: 3px solid #cbd5e1;
  font-size: 13px;
  color: #475569;
  line-height: 1.6;
}

.receipt-preview-footer {
  text-align: center;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #e2e8f0;
}
.receipt-preview-footer p { margin: 4px 0; font-size: 12px; color: #475569; }
.receipt-preview-sample-watermark {
  color: #fbbf24 !important;
  font-weight: 800;
  letter-spacing: 2px;
  font-size: 13px !important;
}

@media (max-width: 720px) {
  .receipt-preview-paper { padding: 16px; }
  .receipt-paper-a5, .receipt-paper-a4 { width: 100%; }
}

/* ============================================================
   LINE OA usage quota card (Broadcast section)
   ============================================================ */
.line-quota-card {
  background: #fff;
  border: 1px solid var(--tpl-200,#e9d5ff);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, var(--tpl-50,#faf5ff) 0%, #ffffff 100%);
}
.line-quota-loading,
.line-quota-error {
  text-align: center;
  padding: 18px;
  color: #94a3b8;
  font-size: 13px;
}
.line-quota-error { color: #dc2626; }

.line-quota-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.line-quota-cell {
  background: #fff;
  border: 1px solid var(--tpl-200,#e9d5ff);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.line-quota-cell strong {
  font-size: 22px;
  font-weight: 800;
  color: #0f172a;
}
.line-quota-cell small {
  font-size: 13px;
  color: #94a3b8;
}
.line-quota-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--tpl-deep,#6b21a8);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.line-quota-plan-badge {
  display: inline-block;
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  align-self: flex-start;
}
.line-quota-remaining.ok      { color: #16a34a; }
.line-quota-remaining.warn    { color: #d97706; }
.line-quota-remaining.danger  { color: #dc2626; }

.line-quota-progress-wrap {
  margin-bottom: 10px;
}
.line-quota-progress {
  height: 12px;
  background: #f1f5f9;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
}
.line-quota-progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--tpl-bright,#a78bfa), #d946ef);
  transition: width 0.6s ease-out;
}
.line-quota-progress.warn > span   { background: linear-gradient(90deg, #f59e0b, #ea580c); }
.line-quota-progress.danger > span { background: linear-gradient(90deg, #dc2626, #991b1b); }
.line-quota-progress-label {
  display: block;
  text-align: center;
  font-size: 13px;
  color: #64748b;
  margin-top: 4px;
}

.line-quota-warn {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  margin: 8px 0 12px;
}
.line-quota-warn-warn   { background: #fffbeb; border-left: 4px solid #f59e0b; color: #92400e; }
.line-quota-warn-danger { background: #fef2f2; border-left: 4px solid #dc2626; color: #991b1b; }

.line-quota-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px dashed var(--tpl-200,#e9d5ff);
  font-size: 13px;
  color: #64748b;
}
.line-quota-meta small { font-size: 13px; }

@media (max-width: 720px) {
  .line-quota-grid { grid-template-columns: repeat(2, 1fr); }
  .line-quota-meta { flex-direction: column; gap: 4px; }
}

/* ============================================================
   State size diagnostic modal
   ============================================================ */
.state-diag-backdrop {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.78);
  z-index: 2000;
}
.state-diag-modal {
  max-width: 760px;
  width: 92%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,0.4);
}
.state-diag-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #fff;
}
.state-diag-head h2 { color: #fff; margin: 0; font-size: 19px; }
.state-diag-head .icon-button { color: #fff; background: rgba(255,255,255,0.18); border: none; padding: 4px 12px; border-radius: 6px; font-size: 20px; cursor: pointer; }
.state-diag-body { padding: 20px 24px; overflow-y: auto; flex: 1; }

.state-diag-warn {
  padding: 12px 16px;
  border-radius: 8px;
  font-weight: 600;
  margin-bottom: 14px;
}
.state-diag-warn.ok      { background: #f0fdf4; border-left: 4px solid #16a34a; color: #166534; }
.state-diag-warn.warn    { background: #fffbeb; border-left: 4px solid #f59e0b; color: #92400e; }
.state-diag-warn.danger  { background: #fef2f2; border-left: 4px solid #dc2626; color: #991b1b; }

.state-diag-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.state-diag-summary > div {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
}
.state-diag-summary span { display: block; font-size: 13px; color: #94a3b8; }
.state-diag-summary strong { font-size: 18px; color: #0f172a; }

.state-diag-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.state-diag-table th {
  background: #f1f5f9;
  padding: 8px;
  text-align: left;
  border-bottom: 2px solid #e2e8f0;
  font-weight: 600;
  color: #475569;
}
.state-diag-table td {
  padding: 8px;
  border-bottom: 1px solid #f1f5f9;
}
.state-diag-table code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.state-diag-table tr.heavy { background: #fef2f2; }
.state-diag-table tr.heavy code { background: #fecaca; color: #991b1b; }

.state-diag-help {
  margin-top: 16px;
  padding: 10px 14px;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 8px;
}
.state-diag-help summary { cursor: pointer; font-weight: 600; color: #92400e; }
.state-diag-help ul { margin: 8px 0 8px; padding-left: 18px; font-size: 13px; line-height: 1.7; }
.state-diag-help code { background: #fff; padding: 1px 5px; border-radius: 3px; }

.state-diag-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid #f1f5f9;
}

/* ============================================================
   LINE Users — 3-status pills (HN bind / Routing / Doctor roster)
   ============================================================ */
.line-user-status-cell { min-width: 180px; }
.line-status-stack {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.line-status-pill {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
  cursor: help;
}

/* HN bind status */
.line-status-pill.hn-bound {
  background: #f0fdf4;
  color: #166534;
  border-color: #86efac;
}
.line-status-pill.hn-unbound {
  background: #f8fafc;
  color: #94a3b8;
  border-color: #e2e8f0;
}

/* Routing membership */
.line-status-pill.routing-active {
  background: var(--tpl-50,#faf5ff);
  color: var(--tpl-deep,#6b21a8);
  border-color: var(--tpl-200,#d8b4fe);
}
.line-status-pill.routing-empty {
  background: #f8fafc;
  color: #94a3b8;
  border-color: #e2e8f0;
}

/* Doctor roster */
.line-status-pill.doctor-active {
  background: #f0f9ff;
  color: #075985;
  border-color: #7dd3fc;
}
.line-status-pill.doctor-empty {
  background: #f8fafc;
  color: #94a3b8;
  border-color: #e2e8f0;
}

/* Doctor card variant — same shape as routing cards but tinted differently */
.line-routing-card-doctor {
  border-left: 4px solid #0284c7;
  background: linear-gradient(180deg, #f0f9ff 0%, #ffffff 80%);
}
.line-routing-card-doctor h3 { color: #075985; }

.line-users-table th small {
  display: block;
  font-weight: 400;
  font-size: 13px;
  color: #94a3b8;
  margin-top: 2px;
}

/* Field auto-save indicator — subtle green checkmark next to inputs */
.field-saved-mark {
  display: inline-block;
  margin-left: 6px;
  color: #16a34a;
  font-weight: 700;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.field-saved-mark.show {
  opacity: 1;
}

/* ============================================================
   Dashboard Intake Strip — pending intake widget at top of dashboard
   ============================================================ */
.dashboard-intake-strip {
  background: linear-gradient(135deg, var(--tpl-50,#faf5ff) 0%, var(--tpl-50,#fdf4ff) 100%);
  border: 2px solid var(--tpl-200,#d8b4fe);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 18px;
  box-shadow: 0 4px 12px color-mix(in srgb,var(--tpl-bright,#a855f7) 12%,transparent);
  transition: background 0.4s, border-color 0.4s, box-shadow 0.4s;
}
.dashboard-intake-strip[data-state="has-pending"] {
  border-color: var(--tpl-bright,#a855f7);
  background: linear-gradient(135deg, var(--tpl-100,#f3e8ff) 0%, #fae8ff 100%);
  box-shadow: 0 6px 18px color-mix(in srgb,var(--tpl-bright,#a855f7) 22%,transparent);
  animation: intake-strip-attention 1.2s ease-out;
}
.dashboard-intake-strip[data-state="empty"] { opacity: 0.85; }
.dashboard-intake-strip[data-state="error"],
.dashboard-intake-strip[data-state="no-secret"] {
  border-color: #fcd34d;
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
}
@keyframes intake-strip-attention {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb,var(--tpl-bright,#a855f7) 70%,transparent); transform: translateY(-4px); opacity: 0; }
  100% { box-shadow: 0 6px 18px color-mix(in srgb,var(--tpl-bright,#a855f7) 22%,transparent); transform: translateY(0); opacity: 1; }
}
.dashboard-intake-badge {
  background: var(--tpl-bright,#a855f7);
  color: #fff;
  padding: 2px 12px;
  border-radius: 999px;
  font-size: 15px;
  margin: 0 4px;
  font-weight: 800;
  display: inline-block;
  min-width: 28px;
  text-align: center;
}
.dashboard-intake-strip[data-state="has-pending"] .dashboard-intake-badge {
  animation: intake-badge-pulse 1.5s ease-in-out infinite;
}
@keyframes intake-badge-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); box-shadow: 0 0 0 4px color-mix(in srgb,var(--tpl-bright,#a855f7) 25%,transparent); }
}
.dashboard-intake-empty {
  text-align: center;
  padding: 22px 14px;
  color: #94a3b8;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px dashed color-mix(in srgb,var(--tpl-bright,#a855f7) 30%,transparent);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dashboard-intake-empty small { font-size: 13px; color: #cbd5e1; }
.dashboard-intake-more {
  text-align: center;
  font-size: 12px;
  color: var(--tpl-deep,#6b21a8);
  font-style: italic;
  margin-top: 6px;
  padding: 6px;
  background: color-mix(in srgb,var(--tpl-bright,#a855f7) 8%,transparent);
  border-radius: 6px;
}
.dashboard-intake-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.dashboard-intake-head strong {
  font-size: 16px;
  color: var(--tpl-deep,#6b21a8);
}
.dashboard-intake-head strong span {
  background: var(--tpl-bright,#a855f7);
  color: #fff;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 14px;
  margin: 0 4px;
}
.dashboard-intake-head .muted {
  display: block;
  font-size: 12px;
  color: #94a3b8;
  margin-top: 2px;
}
.dashboard-intake-list {
  display: grid;
  gap: 8px;
}
.dashboard-intake-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--tpl-200,#e9d5ff);
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.dashboard-intake-row:hover {
  transform: translateX(4px);
  border-color: var(--tpl-bright,#a855f7);
  box-shadow: 0 4px 10px color-mix(in srgb,var(--tpl-bright,#a855f7) 18%,transparent);
}
.dashboard-intake-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--tpl-bright,#a855f7), var(--tpl-main,#9333ea));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 18px;
}
.dashboard-intake-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dashboard-intake-info strong {
  color: #0f172a;
  font-size: 14px;
}
.dashboard-intake-info span {
  color: #64748b;
  font-size: 12px;
}
.dashboard-intake-row button {
  padding: 6px 14px;
  font-size: 13px;
}
.dashboard-intake-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.dashboard-intake-actions .primary-action {
  background: var(--tpl-bright,#a855f7);
}
.dashboard-intake-actions .primary-action:hover {
  background: var(--tpl-main,#9333ea);
}
.dashboard-intake-actions .ghost-button {
  padding: 6px 10px;
}

/* ============================================================
   Slip Match Banner — auto-suggestion when bill amount matches a pending slip
   ============================================================ */
.slip-match-banner {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 2px solid #f59e0b;
  border-radius: 12px;
  padding: 14px 18px;
  margin: 14px 0;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.25);
  animation: slip-match-pulse 1.2s ease-out;
}
@keyframes slip-match-pulse {
  0%   { transform: scale(0.96); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.6); }
  60%  { transform: scale(1.02); box-shadow: 0 0 0 12px rgba(245, 158, 11, 0); }
  100% { transform: scale(1); }
}
.slip-match-banner-content {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 14px;
  align-items: center;
}
.slip-match-icon {
  font-size: 32px;
  text-align: center;
}
.slip-match-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.slip-match-info strong {
  font-size: 16px;
  color: #78350f;
}
.slip-match-info span {
  font-size: 12px;
  color: #92400e;
}
.slip-match-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.slip-match-actions .primary-action {
  background: #f59e0b;
  color: #fff;
  padding: 8px 14px;
  font-weight: 700;
}
.slip-match-actions .primary-action:hover { background: #d97706; }
.slip-match-more {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #f59e0b;
  font-size: 12px;
  color: #92400e;
  font-style: italic;
  text-align: center;
}

@media (max-width: 720px) {
  .slip-match-banner-content { grid-template-columns: 1fr; text-align: center; }
}

/* ============================================================
 * Mobile-narrow (<600px) — LINE in-app browser / phone portrait
 * Without this, Settings sections overlap with the main sidebar
 * brand-mark and content stacks chaotically. Forces a clean
 * single-column layout with extra padding-bottom so floating AI
 * Assistant button doesn't cover the last section.
 * ============================================================ */
@media (max-width: 600px) {
  /* Main shell already collapses to 1 col at 820px, but the sidebar
     "sticky" behavior on iOS Safari + LINE in-app browser can still
     overlap. Force it to release sticky and shrink padding. */
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    padding: 12px 14px;
    gap: 12px;
    overflow: visible;
  }
  .brand {
    gap: 8px;
  }
  .brand-mark,
  .brand-logo {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
  }
  /* Settings — settings menu becomes a horizontal scroll strip so it
     doesn't take 60% of the screen vertically. */
  #settings .settings-layout {
    /* minmax(0,1fr) — NOT plain 1fr. Plain "1fr" = minmax(auto,1fr) whose auto
       minimum refuses to shrink below content min-width, so a wide table (e.g.
       Users & Roles, min-width 820px) stretches the whole column to 820px and
       the in-table horizontal scroll never engages (body overflow-x:hidden then
       just clips the right side). minmax(0,…) lets the column shrink to the
       viewport so .users-table-wrap can scroll internally. */
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
  #settings .panel { min-width: 0; }
  #settings .settings-menu {
    /* Sticky at top of viewport on mobile — user can switch tabs without
       scrolling back up. z-index above section content but below modals
       (.modal-backdrop is 30 — at 50 the bar covered every modal opened from Settings). */
    position: sticky;
    top: 0;
    z-index: 25;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    padding: 8px 4px;
    gap: 6px;
    border-bottom: 1px solid var(--line);
    -webkit-overflow-scrolling: touch;
  }
  /* Long URL/code fields — never break character-by-character */
  .settings-section-card input[type="text"],
  .settings-section-card input[type="url"],
  .settings-section-card textarea,
  .settings-section-card pre,
  .settings-section-card code {
    word-break: break-all;
    overflow-wrap: anywhere;
    white-space: normal;
    font-size: 13px;
  }
  /* Force any field showing a URL to use normal layout (not one-char-per-line) */
  .settings-section-card .field-url-display,
  .settings-section-card [data-base-worker-url],
  .settings-section-card [data-endpoint-url] {
    display: block;
    width: 100%;
    word-break: break-all;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    font-family: ui-monospace, monospace;
    font-size: 12px;
  }
  #settings .settings-menu button {
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 13px;
    padding: 0 10px;
    min-height: 36px;
  }
  .settings-section-card {
    padding: 18px 14px 14px;
    margin-bottom: 16px;
    border-left-width: 4px;
    background: #ffffff; /* hard solid so nothing bleeds through */
    overflow: hidden; /* clip floating badges */
  }
  .settings-section-card[data-category-label]::before {
    /* Hide the floating category chip — saves space and removes overlap risk */
    display: none;
  }
  .settings-form,
  .settings-mini-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  /* Workspace padding tighter so content uses every pixel */
  .workspace {
    padding: 12px;
  }
  .topbar {
    padding: 10px 0;
    gap: 8px;
  }
  /* AI Assistant floating button — leave room at bottom so it doesn't
     cover the last settings section */
  body {
    padding-bottom: 80px;
  }
  /* Modals fill the screen on tiny viewports */
  .modal-content {
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    margin: 0;
  }
}

/* ============================================================ */
/* LOGIN OVERLAY (Phase 2) — sits above app-shell until login    */
/* ============================================================ */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  /* flex-start (NOT center) so a card TALLER than the viewport keeps its TOP reachable — with
     align-items:center the overflow above the centre is clipped + unscrollable (mobile: top staff
     cards couldn't be scrolled up to). margin:auto on the card re-centres it when it DOES fit. */
  align-items: flex-start;
  justify-content: center;
  background: radial-gradient(ellipse at top, #1f3f4f 0%, #0c1f2a 60%, #060f15 100%);
  padding: 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  -webkit-font-smoothing: antialiased;
}
.login-overlay[hidden] { display: none !important; }

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 36px 32px 28px;
  max-width: 480px;
  width: 100%;
  margin: auto; /* centres vertically when it fits; collapses to top-reachable when taller than viewport */
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04);
  position: relative;
}

.login-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.login-brand {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #1a8e8a);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 22px;
  overflow: hidden;
  flex-shrink: 0;
}
.login-brand-logo {
  width: 100%; height: 100%;
  object-fit: cover;
}
.login-title {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  color: #1a2d3a;
}
.login-subtitle {
  margin: 0;
  font-size: 14px;
  color: #5b6b77;
}

.login-tabs {
  display: flex;
  gap: 4px;
  background: #f0f4f6;
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 20px;
}
.login-tab {
  flex: 1;
  padding: 10px 14px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #4b5b67; /* 2026.11.11a: was #6a7a86 = 4.0:1 on the tab bar; now ≥ 6:1 */
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
/* phones: "👑 เจ้าของ / Admin" broke onto two lines at 390 px — keep each tab on one line (narrower padding,
   same type size; the icon steps aside only on the very narrowest screens) */
@media (max-width: 480px) {
  .login-tab { white-space: nowrap; padding: 10px 6px; }
}
@media (max-width: 360px) {
  .login-tab-icon { display: none; }
}
.login-tab:hover { color: #1a2d3a; }
.login-tab.active {
  background: #fff;
  color: #1a2d3a;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.login-tab-icon { margin-right: 4px; }

.login-pane[hidden] { display: none; }
.login-pane-hint {
  font-size: 13px;
  color: #5b6b77;
  margin: 0 0 16px;
  text-align: center;
}

/* Staff grid */
.login-staff-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.login-staff-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 8px;
  background: #f7f9fa;
  border: 2px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
  min-width: 0;
  box-sizing: border-box;
  overflow: hidden;
}
.login-staff-card:hover {
  border-color: var(--primary);
  background: #fff;
  transform: translateY(-2px);
}
.login-staff-card.no-credentials {
  border-style: dashed;
  border-color: #f0b400;
  background: #fffaea;
}
.login-staff-avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5db8b5, #2c8b88);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 20px;
  overflow: hidden;
}
.login-staff-avatar img {
  width: 100%; height: 100%; object-fit: cover;
}
.login-staff-name {
  font-size: var(--text-control);
  font-weight: 600;
  color: #1a2d3a;
  text-align: center;
  line-height: 1.25;
  width: 100%;
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
}
.login-staff-role {
  font-size: 13px;
  color: #5b6b77; /* 2026.11.11a: was 4.19:1 on the staff card */
  text-align: center;
  width: 100%;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.login-staff-setup-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  color: #b07900;
  background: #fff1c4;
  border-radius: 8px;
  padding: 2px 6px;
  margin-top: 2px;
}

.login-empty {
  text-align: center;
  padding: 32px 16px;
  color: #6a7a86;
}
.login-empty-hint { font-size: 12px; }

/* Owner form */
.login-owner-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.login-field span {
  font-size: 13px;
  font-weight: 600;
  color: #1a2d3a;
}
.login-field input,
.login-field select {
  padding: 10px 12px;
  border: 1.5px solid #e0e6ea;
  border-radius: 10px;
  font-size: 15px;
  background: #fff;
  transition: border-color 0.12s;
}
.login-field input:focus,
.login-field select:focus {
  outline: none;
  border-color: var(--primary);
}
.login-submit {
  padding: 12px 20px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s;
}
.login-submit:hover { background: #1f9d99; }
.login-submit:disabled { background: #b0c6c5; cursor: not-allowed; }

.login-error {
  padding: 10px 12px;
  background: #fde8e6;
  color: #c0392b;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
}

.login-footer-note {
  margin: 22px 0 0;
  text-align: center;
  font-size: 13px;
  color: #64748b; /* 2026.11.11a: was #97a4ab = 2.56:1 */
}

/* ============================================================ */
/* PIN KEYPAD                                                    */
/* ============================================================ */
.pin-keypad-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 22, 30, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  border-radius: 20px;
}
.pin-keypad-backdrop[hidden] { display: none; }

.pin-keypad-card {
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px;
  max-width: 320px;
  width: 100%;
  position: relative;
  text-align: center;
}
.pin-keypad-back {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 36px;
  height: 36px;
  border: none;
  background: #f0f4f6;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  color: #1a2d3a;
}
.pin-keypad-back:hover { background: #e0e6ea; }

.pin-keypad-user {
  margin-bottom: 18px;
}
.pin-keypad-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5db8b5, #2c8b88);
  margin: 0 auto 10px;
  color: #fff;
  font-weight: 700;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.pin-keypad-avatar img { width: 100%; height: 100%; object-fit: cover; }
.pin-keypad-name {
  font-size: 17px;
  font-weight: 700;
  color: #1a2d3a;
}
.pin-keypad-role {
  font-size: var(--mc-type-support);
  color: #6a7a86;
  margin-top: 2px;
}
.pin-keypad-prompt {
  font-size: var(--mc-type-support);
  color: #6a7a86;
  margin-bottom: 12px;
}
.pin-key:disabled:not(.pin-key-blank) { opacity: 0.55; cursor: wait; }
.login-version { font-size: var(--mc-type-meta); color:#5b6b77; text-align:center; margin:8px 0 0; }

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 16px;
}
.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e0e6ea;
  transition: background 0.1s, transform 0.1s;
}
.pin-dot.filled {
  background: var(--primary);
  transform: scale(1.1);
}
.pin-dot.error {
  background: #e74c3c;
  animation: pin-shake 0.4s;
}
@keyframes pin-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.pin-error {
  padding: 8px 12px;
  background: #fde8e6;
  color: #c0392b;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
}

.pin-keys {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.pin-key {
  padding: 16px;
  background: #f0f4f6;
  border: none;
  border-radius: 12px;
  font-size: 20px;
  font-weight: 600;
  color: #1a2d3a;
  cursor: pointer;
  transition: background 0.1s, transform 0.05s;
}
.pin-key:hover { background: #e0e6ea; }
.pin-key:active { transform: scale(0.95); }
.pin-key-blank {
  background: transparent !important;
  pointer-events: none;
}
.pin-key-back {
  font-size: 22px;
  color: #6a7a86;
}

/* ============================================================ */
/* SETUP WIZARD (first-time)                                     */
/* ============================================================ */
.login-setup-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 22, 30, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  border-radius: 20px;
}
.login-setup-backdrop[hidden] { display: none; }

.login-setup-card {
  background: #fff;
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
}
.login-setup-card h2 {
  margin: 0 0 12px;
  font-size: 22px;
}
.login-setup-intro {
  font-size: 14px;
  color: #6a7a86;
  margin: 0 0 20px;
  line-height: 1.5;
}
.login-setup-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ============================================================ */
/* TOPBAR USER CHIP (Phase 5 prep)                               */
/* ============================================================ */
.topbar-user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #f0f4f6;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  border: none;
  transition: background 0.12s;
}
.topbar-user-chip:hover { background: #e0e6ea; }
.topbar-user-chip-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5db8b5, #2c8b88);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.topbar-user-chip-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Mobile login adjustments */
@media (max-width: 520px) {
  .login-card { padding: 28px 20px 20px; border-radius: 16px; }
  .login-staff-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .login-staff-card { padding: 12px 6px; gap: 6px; }
  .login-staff-name { font-size: var(--text-control); }
  .login-staff-role { font-size: 13px; }
  .login-staff-avatar { width: 46px; height: 46px; font-size: 17px; }
  .login-staff-setup-badge { font-size: 13px; padding: 1px 6px; }
  .pin-keypad-card { padding: 22px 18px; }
  .pin-key { padding: 14px; font-size: 18px; }
}

/* ============================================================ */
/* SETTINGS — System Tools / Backup buttons grid                 */
/* ============================================================ */
.settings-action-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.settings-action-grid > button,
.settings-action-grid > label {
  flex: 0 0 auto;
}
.security-grid section h3 {
  display: flex;
  align-items: center;
  gap: 6px;
}
.security-grid details {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 12px;
}
.security-grid details summary::-webkit-details-marker {
  display: none;
}
.security-grid details summary::before {
  content: "▸ ";
  display: inline-block;
  margin-right: 4px;
  transition: transform 0.15s;
}
.security-grid details[open] summary::before {
  transform: rotate(90deg);
}
.security-grid details code {
  background: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: #b91c1c;
  border: 1px solid #fca5a5;
}

/* ============================================================ */
/* Import duplicate summary modal                                */
/* Shows totals + per-type counts + radio for action strategy    */
/* ============================================================ */
.import-dup-modal {
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.import-dup-modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #eef2f4;
}
.import-dup-modal header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}
.import-dup-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
}
.import-dup-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 8px;
}
.import-dup-stat {
  background: #f7f9fa;
  border: 1.5px solid #e2e8ec;
  border-radius: 10px;
  padding: 12px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.import-dup-stat.clean {
  background: #ecfdf5;
  border-color: #6ee7b7;
}
.import-dup-stat.warn {
  background: #fef3c7;
  border-color: #fbbf24;
}
.import-dup-stat .num {
  font-size: 24px;
  font-weight: 800;
  color: #1a2d3a;
}
.import-dup-stat.clean .num { color: #065f46; }
.import-dup-stat.warn .num { color: #92400e; }
.import-dup-stat .lbl {
  font-size: 12px;
  color: #6a7a86;
}
.import-dup-total {
  text-align: center;
  margin: 12px 0 18px;
  color: #6a7a86;
  font-size: 13px;
}
.import-dup-section-title {
  margin: 8px 0 10px;
  font-size: 15px;
  font-weight: 700;
}
.import-dup-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.import-dup-choice {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border: 1.5px solid #e2e8ec;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  align-items: flex-start;
}
.import-dup-choice:hover { border-color: var(--primary); background: #fafdfd; }
.import-dup-choice input[type="radio"] {
  margin-top: 3px;
  cursor: pointer;
  flex-shrink: 0;
}
.import-dup-choice input[type="radio"]:checked + div {
  color: #1a2d3a;
}
.import-dup-choice:has(input:checked) {
  border-color: var(--primary);
  background: #ecfeff;
}
.import-dup-choice strong {
  display: block;
  margin-bottom: 3px;
  font-size: 14px;
  font-weight: 700;
}
.import-dup-choice small {
  display: block;
  font-size: 12px;
  color: #6a7a86;
  line-height: 1.4;
}
.import-dup-choice .recommended {
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
}
.import-dup-details {
  margin: 6px 0;
  background: #fafbfc;
  border: 1px solid #eef2f4;
  border-radius: 8px;
  padding: 8px 12px;
}
.import-dup-details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: #1a2d3a;
  padding: 4px 0;
  user-select: none;
}
.import-dup-details ul {
  margin: 8px 0 0;
  padding-left: 20px;
  font-size: 12.5px;
  color: #4a5764;
}
.import-dup-details li { margin: 4px 0; line-height: 1.4; }
.import-dup-details li.more {
  list-style: none;
  margin-left: -20px;
  color: #97a4ab;
  font-style: italic;
  font-size: 13px;
}
.import-dup-details li small {
  color: #97a4ab;
  font-weight: normal;
  font-size: 13px;
}
.import-dup-clean-msg {
  text-align: center;
  padding: 24px 12px;
  background: #ecfdf5;
  border: 1.5px solid #6ee7b7;
  border-radius: 10px;
  color: #065f46;
  font-weight: 600;
  font-size: 15px;
}
.import-dup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid #eef2f4;
}
@media (max-width: 600px) {
  .import-dup-summary { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================ */
/* Bill items + Item picker modal                                */
/* ============================================================ */
.invoice-item-row {
  display: grid;
  grid-template-columns: 1fr 110px 100px 90px 32px;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid #f0f4f6;
  background: #fff;
}
.invoice-item-row:hover { background: #fafdfd; }
.invoice-item-row.invoice-below-floor {
  background: #fef3c7;
}
.invoice-item-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  line-height: 1.3;
}
.invoice-item-name strong { font-weight: 600; color: #1a2d3a; }
.invoice-kind-icon { font-size: 16px; flex-shrink: 0; }
.invoice-floor-warn {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  color: #b45309;
  background: #fef3c7;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 4px;
  font-style: normal;
}
.invoice-item-qty {
  display: flex;
  align-items: center;
  gap: 2px;
}
.invoice-item-qty button {
  width: 26px; height: 26px;
  background: #f0f4f6;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  color: #1a2d3a;
}
.invoice-item-qty button:hover { background: #e0e6ea; }
.invoice-item-qty input {
  width: 44px;
  text-align: center;
  border: 1px solid #e0e6ea;
  border-radius: 4px;
  padding: 3px 0;
  font-size: 13px;
  -moz-appearance: textfield;
}
.invoice-item-qty input::-webkit-outer-spin-button,
.invoice-item-qty input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.invoice-item-price input {
  width: 100%;
  border: 1px solid #e0e6ea;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 13px;
  text-align: right;
}
.invoice-item-total {
  font-weight: 700;
  text-align: right;
  color: #1a2d3a;
  font-size: 14px;
}
.invoice-item-remove {
  width: 28px; height: 28px;
  background: #fee2e2;
  border: none;
  border-radius: 50%;
  color: #b91c1c;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.invoice-item-remove:hover { background: #fecaca; }

/* Item picker modal */
.item-picker-backdrop .item-picker-modal {
  max-width: 720px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.item-picker-modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #eef2f4;
}
.item-picker-modal header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}
.item-picker-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 18px 0;
  border-bottom: 1px solid #eef2f4;
}
.item-picker-tabs button {
  padding: 9px 14px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 14px;
  font-weight: 600;
  color: #6a7a86;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.item-picker-tabs button:hover { color: #1a2d3a; }
.item-picker-tabs button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.item-picker-tabs .count {
  display: inline-block;
  background: #f0f4f6;
  color: #6a7a86;
  font-size: 13px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  margin-left: 4px;
}
.item-picker-tabs button.active .count {
  background: var(--primary);
  color: #fff;
}
.item-picker-search {
  padding: 12px 18px 8px;
}
.item-picker-search input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #e0e6ea;
  border-radius: 8px;
  font-size: 14px;
}
.item-picker-search input:focus { outline: none; border-color: var(--primary); }

.item-picker-body {
  overflow-y: auto;
  flex: 1;
  padding: 4px 18px 18px;
}
.item-picker-row {
  display: grid;
  grid-template-columns: 1fr auto auto 32px;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid #f0f4f6;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s, transform 0.08s;
  font: inherit;
}
.item-picker-row:hover {
  border-color: var(--primary);
  background: #fafdfd;
  transform: translateX(2px);
}
.item-picker-row.low-stock {
  background: #fef3c7;
  border-color: #fbbf24;
}
.item-picker-name {
  font-size: 14px;
  font-weight: 600;
  color: #1a2d3a;
  line-height: 1.3;
}
.item-picker-name small {
  display: block;
  font-size: 13px;
  font-weight: 400;
  color: #97a4ab;
  margin-top: 2px;
}
.item-picker-cat {
  font-size: 13px;
  color: #6a7a86;
}
.item-picker-price {
  font-size: 14px;
  font-weight: 700;
  color: #1a2d3a;
  text-align: right;
}
.item-picker-add {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.item-picker-more {
  text-align: center;
  padding: 12px;
  color: #97a4ab;
  font-size: 12px;
  font-style: italic;
}
.item-picker-empty {
  text-align: center;
  padding: 40px 20px;
  color: #97a4ab;
  font-size: 14px;
}
.item-picker-custom {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 8px 4px;
}
.item-picker-custom .muted {
  margin: 0;
  font-size: 12.5px;
  color: #6a7a86;
}
.item-picker-custom label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #1a2d3a;
}
.item-picker-custom input {
  padding: 9px 12px;
  border: 1.5px solid #e0e6ea;
  border-radius: 8px;
  font-size: 14px;
}
.item-picker-custom input:focus { outline: none; border-color: var(--primary); }

@media (max-width: 600px) {
  .invoice-item-row {
    grid-template-columns: 1fr 88px 80px 70px 28px;
    gap: 4px;
    font-size: 12px;
  }
  .invoice-item-qty input { width: 32px; }
  .item-picker-row {
    grid-template-columns: 1fr auto 28px;
  }
  .item-picker-row .item-picker-cat { display: none; }
}

/* ============================================================ */
/* Collapsed customer-workflow-guide — saves vertical space      */
/* ============================================================ */
.customer-workflow-guide-collapsed {
  margin: 6px 0 12px;
  border: 1px solid #e2e8ec;
  border-radius: 8px;
  background: #fafbfc;
}
.customer-workflow-guide-collapsed summary {
  cursor: pointer;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: #6a7a86;
  user-select: none;
  list-style: none;
}
.customer-workflow-guide-collapsed summary::-webkit-details-marker {
  display: none;
}
.customer-workflow-guide-collapsed summary::before {
  content: "▸ ";
  display: inline-block;
  margin-right: 4px;
  transition: transform 0.15s;
}
.customer-workflow-guide-collapsed[open] summary::before {
  transform: rotate(90deg);
}
.customer-workflow-guide-collapsed summary:hover { color: #1a2d3a; }
.customer-workflow-guide-collapsed .customer-workflow-guide {
  padding: 4px 14px 12px;
}

/* Ensure import-dup modal stacks ABOVE the import modal that opened it. */
.import-dup-modal-backdrop {
  z-index: 10000 !important;
}
.import-dup-modal {
  z-index: 10001 !important;
}

/* ============================================================ */
/* Bill row v2 — full / discount / sale columns                   */
/* ============================================================ */
.invoice-item-row {
  grid-template-columns: 1.6fr 100px 90px 90px 90px 30px !important;
}
.invoice-item-header {
  background: #f7f9fa;
  font-size: 13px;
  font-weight: 600;
  color: #6a7a86;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.invoice-item-header > div { padding: 4px 2px; }
.invoice-item-header .invoice-item-name { padding-left: 8px; }
.invoice-item-header .total-label { color: #16a34a; }
.invoice-item-qty-label,
.invoice-item-cell-label { text-align: center; }
.invoice-item-fullprice {
  text-align: right;
  font-size: 12.5px;
  color: #4a5764;
  align-self: center;
}
.invoice-item-fullprice input {
  width: 100%;
  text-align: right;
  padding: 4px 6px;
  border: 1px solid #e0e6ea;
  border-radius: 4px;
  font-size: 13px;
  color: #475569;
  background: #f8fafc;
  text-decoration: none;
}
.invoice-item-fullprice input:focus {
  outline: none;
  border-color: var(--tpl-bright,#818cf8);
  background: #fff;
}
.invoice-item-discount input {
  width: 100%;
  text-align: right;
  padding: 4px 6px;
  border: 1px solid #e0e6ea;
  border-radius: 4px;
  font-size: 13px;
  color: #c2410c;
  background: #fff7ed;
}
.invoice-item-discount input:focus {
  outline: none;
  border-color: #f97316;
  background: #fff;
}

/* ============================================================ */
/* Split payment grid                                            */
/* ============================================================ */
.payment-split-host {
  margin-top: 12px;
  padding: 14px;
  background: #fafbfc;
  border: 1.5px solid #e2e8ec;
  border-radius: 10px;
}
.payment-split-host:empty { display: none; }
.pay-split-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.pay-split-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 600;
  color: #1a2d3a;
}
.pay-split-row label span { color: #4a5764; }
.pay-split-row input {
  padding: 7px 10px;
  border: 1.5px solid #e0e6ea;
  border-radius: 8px;
  font-size: 14px;
  text-align: right;
  background: #fff;
}
.pay-split-row input:focus {
  outline: none;
  border-color: var(--primary);
}
.pay-split-row input:not([value=""]):not([value="0"]) {
  background: #ecfeff;
  border-color: #67e8f9;
}
.pay-split-summary {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  padding: 10px 12px;
  background: #fff;
  border-radius: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.pay-split-summary > div {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pay-split-summary span { font-size: 12px; color: #6a7a86; }
.pay-split-summary strong { font-size: 16px; font-weight: 700; color: #1a2d3a; }
.pay-status {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}
.pay-status.ok           { background: #ecfdf5; color: #065f46; }
.pay-status.outstanding  { background: #fee2e2; color: #991b1b; }
.pay-status.change       { background: #fef3c7; color: #92400e; }
.pay-status.empty        { background: #f1f5f9; color: #6a7a86; }
.pay-split-quickfill {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pay-split-quickfill button {
  font-size: 12px;
  padding: 5px 10px;
}

@media (max-width: 700px) {
  .pay-split-row { grid-template-columns: repeat(2, 1fr); }
  .invoice-item-row {
    grid-template-columns: 1.4fr 70px 70px 70px 70px 24px !important;
    font-size: 13px;
  }
}

/* =====================================================================
   REDESIGN 2026.06 — Maprang light shell (override layer, appended last)
   Derives every shade from --primary (= state.clinicColor) via color-mix,
   so each clinic's brand colour re-themes the whole UI. Delete this block
   to fully revert to the previous look.
   ===================================================================== */
:root{
  --acc: var(--primary);
  --acc-deep: color-mix(in srgb, var(--primary), #190f26 36%);
  --acc-bright: color-mix(in srgb, var(--primary), #ffffff 22%);
  --acc-50: color-mix(in srgb, var(--primary), #ffffff 94%);
  --acc-100: color-mix(in srgb, var(--primary), #ffffff 88%);
  --acc-200: color-mix(in srgb, var(--primary), #ffffff 78%);
  --gold:#c2a05b; --gold-100:#f4ecd9; --gold-deep:#9a7c3c; --gold-line:#e2cb93;
  --ink:#2b2230; --muted:#6b5e69;
  --line: color-mix(in srgb, var(--primary), #ffffff 90%);
  --line-2: color-mix(in srgb, var(--primary), #ffffff 84%);
  --surface:#ffffff;
  --surface-2: color-mix(in srgb, var(--primary), #f8f6fa 96%);
  --page: color-mix(in srgb, var(--primary), #fbf9fb 95%);
  --shadow: 0 2px 6px rgba(43,34,48,.05), 0 12px 28px -14px color-mix(in srgb, var(--primary), transparent 84%);
}
body{ font-family:"IBM Plex Sans Thai","Inter",ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif; background:var(--page); }

/* ---- light sidebar ---- */
.sidebar{ background:var(--surface); color:var(--ink); border-right:1px solid var(--line); padding:16px 14px; gap:14px; }
.brand strong{ color:var(--ink); }
.brand span, .user-card span{ color:var(--muted); }
.brand-mark{ border-radius:11px; background:linear-gradient(140deg,var(--acc-bright),var(--primary) 55%,var(--acc-deep)); box-shadow:0 0 0 1.5px var(--gold-line),0 4px 10px -3px color-mix(in srgb,var(--primary),transparent 55%); }
.nav-list{ gap:3px; }
.nav-item{ color:var(--muted); border-radius:11px; padding:9px 12px; font-weight:500; font-size:14px; }
.nav-item:hover{ background:var(--acc-50); color:var(--ink); }
.nav-item.active{ background:var(--acc-100); color:var(--primary); font-weight:600; }
.user-card{ border:1px solid var(--line); background:var(--acc-50); }
.user-card strong{ color:var(--ink); }
.role-switcher{ color:var(--muted); }
.role-switcher select{ background:#fff; color:var(--ink); border:1px solid var(--line); }
.status-dot{ background:#3f9a72; }
/* fix language toggle (was white-on-dark inline styles) */
.lang-toggle-wrap{ border-bottom:1px solid var(--line) !important; }
.lang-toggle-wrap > span{ color:var(--muted) !important; }
.lang-btn{ color:var(--muted) !important; border-color:var(--line) !important; background:#fff !important; }
.lang-btn:hover,.lang-btn.active{ background:var(--acc-100) !important; color:var(--primary) !important; border-color:var(--acc-200) !important; }

/* ---- modern cards + topbar ---- */
.metric-card,.panel,.lane,.receipt-preview{ border-radius:16px; box-shadow:var(--shadow); border-color:var(--line); }
.metric-card{ border-top:0; padding:18px; }
.metric-card strong{ color:var(--ink); }
.metric-card small{ color:var(--primary); }
.topbar h1{ font-weight:600; letter-spacing:.2px; }
.eyebrow{ color:var(--muted); }

/* ---- sidebar nav groups (added in index.html) ---- */
.nav-group{ display:grid; gap:3px; }
.nav-group + .nav-group{ margin-top:12px; }
.nav-group-label{ font-size:13px; font-weight:600; color:var(--muted); letter-spacing:.5px; padding:2px 10px 4px; opacity:.85; }
/* ---- sidebar bottom: system status + version ---- */
.sidebar-status{ background:var(--acc-50); border:1px solid var(--line); border-radius:11px; padding:11px 12px; font-size:12.5px; }
.sidebar-status .ss-title{ font-size:13px; font-weight:600; color:var(--muted); letter-spacing:.5px; margin-bottom:7px; }
.sidebar-status .ss-row{ display:flex; align-items:center; gap:8px; padding:2px 0; color:var(--ink); }
.sidebar-status .ss-row .d{ width:7px; height:7px; border-radius:50%; background:#3f9a72; flex:0 0 auto; }
.sidebar-status .ss-row .v{ margin-left:auto; color:var(--muted); font-size:13px; }
.sidebar-version{ display:flex; align-items:center; gap:6px; font-size:13px; color:color-mix(in srgb,var(--muted),#fff 30%); padding:8px 6px 0; letter-spacing:.3px; }
.sidebar-version .vd{ width:5px; height:5px; border-radius:50%; background:#3f9a72; flex:0 0 auto; }

/* ---- Phase 2 — Dashboard interior (clean cards, maprang/gold) ---- */
.metrics-grid{ gap:16px; margin-bottom:18px; }
.dashboard-grid{ gap:16px; }
.panel-head{ margin-bottom:14px; }
.panel-head h2{ font-size:16px; font-weight:700; color:var(--ink); margin:0; }
.panel-head .ghost-button{ color:var(--primary); font-weight:600; }
.appointment-row,.service-list div,.invoice-list div{ border-radius:12px; border-color:var(--line); padding:11px 13px; }
.appointment-row time{ color:var(--primary); }
.appointment-row[data-dashboard-appointment]:hover,.appointment-row.synced{ border-color:var(--acc-200); background:var(--acc-50); }
.queue-columns{ gap:12px; }
.queue-columns div{ background:var(--surface-2); border:1px solid var(--line); border-radius:12px; }
.queue-columns h3{ color:var(--muted); font-weight:700; font-size:12px; letter-spacing:.3px; margin-bottom:8px; }
.queue-columns p{ background:#fff; border:1px solid var(--line); border-radius:9px; }
.queue-columns [data-dashboard-queue-item]:hover{ border-color:var(--acc-200); background:var(--acc-50); }
.bar-chart span{ background:linear-gradient(180deg,var(--acc-bright),var(--primary)); border-radius:7px 7px 4px 4px; }
.bar-chart span:last-child{ background:linear-gradient(180deg,var(--gold),var(--gold-deep)); }
.dashboard-intake-strip{ border-radius:14px; border-color:var(--line); }
.dashboard-intake-badge,.booking-dashboard-badge{ background:var(--acc-100); color:var(--primary); }
.metric-card strong{ letter-spacing:-.3px; }
/* KPI icon chips (mockup-fidelity) */
.metric-card .mc-top{ display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:6px; }
.metric-card .mc-top span:first-child{ color:var(--muted); font-weight:500; }
.mc-ic{ width:34px; height:34px; border-radius:10px; display:grid; place-items:center; background:var(--acc-100); color:var(--primary); flex:0 0 auto; }
.mc-ic svg{ width:18px; height:18px; stroke-width:1.9; }
.mc-ic-gold{ background:var(--gold-100); color:var(--gold-deep); }

/* ============ Commercial simplification (declutter / progressive disclosure) ============ */
/* version now lives bottom-left of the sidebar → drop the redundant top-bar chip */
#appVersionChip{ display:none !important; }
/* hide internal-only dev tool from the commercial nav (view still reachable for admins) */
.nav-item[data-view="readiness"]{ display:none !important; }
/* ============ OPD warning banner — clean, modern, readable ============
   Colours (bg/text/cursor) + size class + FONT all come INLINE from each clinic's
   Settings (_applyOwbColors) — never override colour/background/font-size/font-
   family here (the 05d bug forced amber+14px and hid the staff's red/green +
   "ใหญ่มาก"). Every selectable font (OWB_FONTS) ships matched Thai+Latin glyphs so
   ไทย and อังกฤษ render at the SAME size = balanced. No pixel font, no hard retro
   shadow. Size stays from owb-size-* (xl = ใหญ่มาก = 31px). */
.opd-warning-banner{
  /* font-family is set INLINE per clinic (OWB_FONTS) — don't force it here */
  font-weight: 700 !important;
  background-image: none !important;              /* drop the gray dotted mesh → clean flat colour */
  border: 1px solid rgba(0,0,0,0.10) !important;
  border-radius: 12px !important;
  box-shadow: 0 4px 14px rgba(0,0,0,0.10) !important;   /* soft modern lift, no hard offset */
  text-shadow: none !important;
  letter-spacing: 0.005em !important;
  line-height: 1.4 !important;
}
/* 2026.11.17d: the compact rule below sets display with !important, which beat [hidden] → an empty dark box
   sat in the header of every clinic with the banner switched off. */
.opd-warning-banner[hidden], .opd-warning-banner.owb-compact[hidden]{ display:none !important; }
.opd-warning-banner .owb-text{ white-space: normal; overflow-wrap: anywhere; }
.opd-warning-banner .owb-cursor{ display:inline !important; }
/* Owner request: keep the header banner a STABLE 2-line box — never grow/shrink (ขยายหุบ) as the
   typewriter types or messages of different length cycle. Reserve exactly 2 lines AND clamp to 2.
   em-based so it scales with the chosen owb-size-* font. */
.opd-warning-banner.owb-compact{
  display:-webkit-box !important;
  -webkit-box-orient:vertical;
  -webkit-line-clamp:2;
  line-clamp:2;
  min-height:calc(2 * 1.4em + 20px);   /* 2 lines × line-height 1.4 + 10px top/bottom padding */
  overflow:hidden;
}
/* No size overrides → the clinic's choice maps to the original scale
   (sm16 / md20 / lg25 / xl31) so both scripts stay big + balanced. */

/* ============ Commercial polish — global components ============ */
:root{ --warn-100:#f8eede; --ok:#3f9a72; --ok-100:#e6f3ec; }
/* ── Buttons ──────────────────────────────────────────────── */
.icon-button,.primary-action,.ghost-button,.chip,.visit-card button,.settings-menu button{ border-radius:10px; }

/* primary-action: gradient base + lift on hover */
.primary-action{
  background:linear-gradient(135deg,var(--acc-bright),var(--primary));
  box-shadow:0 6px 16px -8px color-mix(in srgb,var(--primary),transparent 45%);
  font-weight:600;
  transition:transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
}
.primary-action:hover{
  transform:translateY(-1px);
  box-shadow:0 8px 22px -6px color-mix(in srgb,var(--primary),transparent 35%);
  filter:brightness(1.06);
}
.primary-action:active{ transform:translateY(0); box-shadow:none; filter:brightness(0.97); }

/* ghost-button: subtle accent on hover */
.ghost-button{ color:var(--primary); border-color:var(--line-2); font-weight:600; transition:background 0.13s ease, border-color 0.13s ease; }
.ghost-button:hover{ background:var(--acc-50); border-color:var(--acc-200); }
.ghost-button:active{ background:var(--acc-100); }

/* icon-button */
.icon-button{ border-color:var(--line-2); color:var(--muted); transition:border-color 0.13s ease, color 0.13s ease, background 0.13s ease; }
.icon-button:hover{ border-color:var(--acc-200); color:var(--primary); background:var(--acc-50); }

/* tabs */
.tabs button{ font-weight:500; transition:background 0.13s ease, color 0.13s ease; }
.tabs button:hover:not(.active){ background:var(--acc-100); color:var(--primary); }
.tabs button.active{ background:var(--primary); color:#fff; }

/* delete/danger ghost */
.delete-row-button{ transition:background 0.13s ease, border-color 0.13s ease; }
.delete-row-button:active{ background:#fecaca !important; }

/* ── Table rows ──────────────────────────────────────────── */
.customer-row:hover{ border-color:var(--acc-200) !important; background:var(--acc-50) !important; }
.table-row:not(.head):hover{ border-color:var(--acc-200); background:var(--acc-50); }

/* ── Status indicators ──────────────────────────────────── */
.save-status{ color:var(--primary); }
.selected-customer-next-step{ border-color:var(--acc-200); color:var(--primary); background:var(--acc-50); font-weight:700; }

/* ── Timeline / cards ──────────────────────────────────── */
.timeline-item{ transition:box-shadow 0.14s ease; }
.timeline-item:hover{ box-shadow:0 4px 14px -4px color-mix(in srgb,var(--primary),transparent 72%); }
.drawer-event{ transition:box-shadow 0.14s ease; }
.drawer-event:hover{ box-shadow:0 3px 10px -3px color-mix(in srgb,var(--primary),transparent 75%); }

/* ── visit-card (kanban) ───────────────────────────────── */
.visit-card:hover{ border-color:var(--acc-200); box-shadow:0 4px 16px -6px color-mix(in srgb,var(--primary),transparent 68%); }

/* ── Utility: consistent border-radius for pills ─────── */
.badge,.status-badge{ border-radius:999px; }
.status-active{ color:var(--ok) !important; background:var(--ok-100) !important; }
.status-review{ background:#fef3c7; color:#92400e; }
.status-inactive{ background:var(--line); color:var(--muted); }
/* chips / tabs as soft pills */
.chip,.calendar-toolbar select{ border-radius:999px; border-color:var(--line-2); }
.chip.active{ background:var(--acc-100) !important; color:var(--primary) !important; border-color:var(--acc-200) !important; }
/* form controls — consistent rounded + maprang focus ring */
input,select,textarea{ border-radius:10px; }
input:focus,select:focus,textarea:focus{ outline:none; border-color:var(--acc-200); box-shadow:0 0 0 3px var(--acc-100); }
#branchSelector{ border-color:var(--line-2); border-radius:10px; }
.cloud-sync-badge{ border-radius:999px; }
/* modal */
.modal{ border-radius:18px; box-shadow:0 30px 70px -24px color-mix(in srgb,var(--primary),transparent 55%); }
.modal-backdrop{ backdrop-filter:blur(3px); }
/* tables */
.data-table{ border-radius:12px; overflow:hidden; border:1px solid var(--line); }
.data-table th{ background:var(--surface-2); color:var(--muted); font-weight:600; }
/* settings menu active */
.settings-menu button.active{ background:var(--acc-100); color:var(--primary); }
/* PWA install banner -> maprang (was hardcoded purple) */
.pwa-install-banner{ background:linear-gradient(135deg,var(--acc-100),var(--acc-50)) !important; border-color:var(--acc-200) !important; border-left-color:var(--primary) !important; box-shadow:none !important; }
.pwa-install-banner .pwa-install-text strong{ color:var(--acc-deep) !important; }
.pwa-install-banner .pwa-install-text span{ color:var(--primary) !important; }
.pwa-install-banner .pwa-install-actions .primary-action{ background:var(--primary) !important; }
/* backup reminder -> calm amber, no pulse (commercial) */
.backup-reminder-banner{ animation:none !important; background:var(--warn-100) !important; border:1px solid #f0d9a8 !important; box-shadow:none !important; border-radius:12px !important; }
/* declutter: hide dev/QA-only tools from the commercial UI (reachable in code if needed) */
[data-action="run-app-smoke-test"],
[data-action="run-quality-hardening-200"],
[data-action="audit-ui-buttons"],
[data-action="export-ui-button-audit"],
[data-action="reset-prototype-state"],
[data-action="export-prototype-state"],
[data-action="export-queue-movement-log"]{ display:none !important; }
/* OPD tabs as soft maprang pills */
.opd-tabs button{ border-radius:999px !important; font-weight:600; }
.opd-tabs button.active{ background:var(--acc-100) !important; color:var(--primary) !important; border-color:var(--acc-200) !important; }
/* hide dev-only fake-data generators (commercial) */
[data-action^="simulate-"]{ display:none !important; }
/* sidebar nav — Lucide line icons (replaced emoji); label moved to .lbl span so the bilingual swap doesn't wipe the icon */
.nav-item{ display:flex; align-items:center; gap:11px; }
.nav-item .ico{ width:20px; height:20px; display:inline-flex; align-items:center; justify-content:center; flex:0 0 auto; color:var(--muted); }
.nav-item .ico svg{ width:18px; height:18px; stroke-width:1.75; }
.nav-item .lbl{ flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.nav-item:hover .ico{ color:var(--ink); }
.nav-item.active .ico{ color:var(--primary); }
/* settings submenu — Lucide icons, NO colored left stripes (anti-pattern), clean maprang active (was dark) */
.settings-menu button{ display:flex; align-items:center; gap:10px; border:1px solid var(--line) !important; border-radius:10px !important; }
.settings-menu button .ico{ width:18px; height:18px; display:inline-flex; align-items:center; justify-content:center; flex:0 0 auto; color:var(--muted); }
.settings-menu button .ico svg{ width:17px; height:17px; stroke-width:1.75; }
.settings-menu button.active{ background:var(--acc-100) !important; color:var(--primary) !important; border-color:var(--acc-200) !important; transform:none !important; }
.settings-menu button.active .ico{ color:var(--primary); }
/* safeguard: clicks on icon/label pass through to the button (direct-target handlers) */
.nav-item .ico,.nav-item .lbl,.settings-menu button .ico,.settings-menu button .lbl{ pointer-events:none; }
/* kill the per-category coloured left stripe (::before anti-pattern) + neutralise per-category active tints (higher specificity) */
.settings-menu button[data-menu-cat]::before{ display:none !important; }
.settings-menu button[data-menu-cat]{ padding-left:12px !important; }
.settings-menu button.active[data-menu-cat]{ background:var(--acc-100) !important; color:var(--primary) !important; }

/* ============ OPD screen — bigger fonts (readability for counter/tablet) + maprang ============ */
.opd-action-center{
  background:var(--acc-50) !important;
  border-color:var(--acc-200) !important;
  padding:16px !important;
  gap:14px !important;
  border-radius:14px !important;
  /* layout: summary pinned left, hint+buttons in right column */
  grid-template-columns:220px minmax(0,1fr) !important;
}
.opd-action-summary{
  grid-row:1 / span 2 !important;
  align-self:start !important;
  padding:10px 14px 10px 0 !important;
  border-right:1px solid var(--acc-200) !important;
}
.opd-action-summary strong{ color:var(--primary) !important; font-size:1.1rem !important; line-height:1.3 !important; }
.opd-action-summary span,.opd-action-summary em{ font-size:13px !important; }
.opd-action-summary > span:first-child{ font-size:13px !important; font-weight:800 !important; text-transform:uppercase !important; letter-spacing:0.06em !important; opacity:0.65 !important; }
.opd-progress > span{ color:var(--primary) !important; font-size:12px !important; font-weight:900 !important; }
.opd-progress > strong{ height:8px !important; background:var(--acc-200) !important; }
.opd-progress i{ background:linear-gradient(90deg,var(--primary),var(--gold)) !important; }
.opd-steps-hint{
  grid-column:2 !important;
  font-size:13px !important;
  color:var(--primary) !important;
  background:var(--acc-100) !important;
  border-color:var(--acc-200) !important;
  padding:9px 13px !important;
  margin:0 !important;
}
.opd-action-buttons{
  grid-column:2 !important;
  grid-template-columns:repeat(3,minmax(0,1fr)) !important;
  gap:8px !important;
}
.opd-action-buttons button{ min-height:46px !important; }
.opd-action-buttons button[data-opd-step-button]{
  min-height:68px !important;
  font-size:13.5px !important;
  font-weight:700 !important;
  border-color:var(--acc-200) !important;
  border-radius:12px !important;
  border-width:1.5px !important;
  padding:8px 6px 7px !important;
}
.opd-action-buttons button[data-opd-step-button]::after{ font-size:13px !important; margin-top:4px !important; font-weight:800 !important; }
/* Step states */
.opd-action-buttons button.step-done{
  background:var(--primary) !important;
  border-color:var(--primary) !important;
  border-width:2px !important;
  color:#fff !important;
  box-shadow:0 3px 10px -2px color-mix(in srgb,var(--primary),transparent 48%) !important;
}
.opd-action-buttons button.step-done:hover{
  background:var(--acc-deep) !important;
  border-color:var(--acc-deep) !important;
  transform:translateY(-2px) !important;
  box-shadow:0 6px 16px -4px color-mix(in srgb,var(--primary),transparent 38%) !important;
}
.opd-action-buttons button.step-next{
  border-width:2px !important;
  border-color:#db2777 !important;
  color:#9d174d !important;
  background:#fff0f7 !important;
}
.opd-action-buttons button.step-next:hover{
  background:#fce7f3 !important;
  border-color:#be185d !important;
  transform:translateY(-2px) !important;
  box-shadow:0 5px 14px rgba(219,39,119,0.24) !important;
}
.opd-action-buttons button.step-waiting{
  border-color:var(--line) !important;
  color:var(--muted) !important;
  background:var(--surface) !important;
  opacity:0.7 !important;
}
.opd-action-buttons button.step-waiting:hover{
  transform:none !important;
  box-shadow:none !important;
  opacity:0.85 !important;
}
.opd-action-buttons button.step-blocked{
  border-width:2px !important;
  border-color:#fca5a5 !important;
  color:#b91c1c !important;
  background:#fff5f5 !important;
}
.opd-action-buttons button.step-blocked:hover{
  background:#fee2e2 !important;
  border-color:#f87171 !important;
  transform:translateY(-2px) !important;
  box-shadow:0 4px 12px rgba(185,28,28,0.2) !important;
}
/* OPD metadata + completion cards — bigger */
.opd-visit-meta-grid{ font-size:13.5px !important; }
.opd-visit-meta-grid strong,.opd-visit-meta-grid b{ font-size:15px !important; }
.opd-completion-grid{ gap:14px !important; }
.opd-completion-grid strong,.opd-completion-grid h4{ font-size:15.5px !important; }
.opd-completion-grid em,.opd-completion-grid p,.opd-completion-grid span{ font-size:13px !important; }

/* ---- Gallery: kind filter as chips (was dropdown) + show full slip (was cropped) ---- */
.gallery-kind-chips{ flex-basis:100%; display:flex; gap:8px; flex-wrap:wrap; }
.gallery-kind-chips .chip{ font-size:13px; min-height:34px; padding:0 14px; }
.gallery-grid img{ object-fit:contain !important; background:var(--surface-2); }

/* ============ Chat launcher menu (AI / ลูกค้า) + OmniDesk drawer ============
   Reuses the .ai-assistant-launcher orb (gradient/shine/drift). Clicking it now
   opens this choice menu; the orb morphs to ✕ via .menu-open. Menu is position:
   fixed and JS-anchored above the (draggable) launcher. */
.chat-menu{ position:fixed; z-index:26; display:flex; flex-direction:column; align-items:flex-end; gap:11px; pointer-events:none; }
.chat-opt{ pointer-events:none; opacity:0; transform:translateY(14px) scale(.85); transform-origin:bottom right;
  display:inline-flex; align-items:center; gap:11px; border:none; cursor:pointer; color:#fff; height:50px; padding:0 18px 0 8px;
  border-radius:999px; white-space:nowrap; position:relative; overflow:hidden; background-size:220% 220%; background-position:0% 50%;
  box-shadow:0 0 0 1px rgba(255,255,255,.22) inset, 0 10px 28px -6px color-mix(in srgb,var(--tpl-bright,#8b5cf6) 50%,transparent), 0 3px 10px rgba(15,23,42,.16);
  transition:opacity .35s cubic-bezier(.34,1.56,.64,1), transform .45s cubic-bezier(.34,1.56,.64,1), background-position .4s; }
.chat-menu.show .chat-opt{ pointer-events:auto; opacity:1; transform:none; }
.chat-menu.show .chat-opt:nth-child(1){ transition-delay:.13s; }
.chat-menu.show .chat-opt:nth-child(2){ transition-delay:.05s; }
.chat-opt:hover{ transform:translateY(-2px); background-position:100% 50%; }
.chat-opt .copt-orb{ width:34px; height:34px; border-radius:50%; flex:none; display:grid; place-items:center; font-size:17px; background:rgba(255,255,255,.2); backdrop-filter:blur(4px); }
.chat-opt .copt-txt{ text-align:left; text-shadow:0 1px 2px rgba(0,0,0,.22); }
.chat-opt .copt-txt b{ display:block; font-size:14.5px; font-weight:600; line-height:1.15; }
.chat-opt .copt-txt small{ display:block; font-size:13px; opacity:.9; }
.chat-opt .copt-shine{ position:absolute; top:0; left:-60%; width:50%; height:100%; transform:skewX(-18deg); pointer-events:none;
  background:linear-gradient(100deg,transparent,rgba(255,255,255,0) 30%,rgba(255,255,255,.42) 50%,rgba(255,255,255,0) 70%,transparent);
  animation:ai-launcher-shine-sweep 5s ease-in-out infinite; }
.chat-opt-ai{ background-image:linear-gradient(115deg,var(--tpl-main,#6366f1) 0%,var(--tpl-bright,#8b5cf6) 25%,#d946ef 50%,#f97316 80%,#fbbf24 100%); }
.chat-opt-cust{ background-image:linear-gradient(115deg,#0ea5e9 0%,#06b6d4 30%,#10b981 70%,#34d399 100%);
  box-shadow:0 0 0 1px rgba(255,255,255,.22) inset, 0 10px 28px -6px rgba(6,182,212,.5), 0 3px 10px rgba(15,23,42,.16); }
.chat-opt .copt-badge{ position:absolute; top:5px; right:8px; background:#c9a86a; color:#3a2c12; font-weight:700; font-size:13px;
  min-width:18px; height:18px; border-radius:999px; display:grid; place-items:center; padding:0 5px; border:2px solid #fff; }
/* launcher ↔ ✕ morph when the menu is open */
.ai-assistant-launcher .lx-x{ position:absolute; inset:0; display:grid; place-items:center; opacity:0; transform:rotate(-90deg) scale(.5);
  transition:opacity .25s, transform .4s cubic-bezier(.34,1.56,.64,1); pointer-events:none; }
.ai-assistant-launcher.menu-open .ai-launcher-orb{ opacity:0; transform:scale(.4); }
.ai-assistant-launcher.menu-open .lx-x{ opacity:1; transform:none; }
.ai-assistant-launcher.menu-open{ background-position:100% 50%; }
/* OmniDesk slide-in drawer */
.omnidesk-drawer{ position:fixed; inset:0; z-index:40; pointer-events:none; }
.omnidesk-drawer::before{ content:""; position:absolute; inset:0; background:rgba(44,34,51,.42); backdrop-filter:blur(3px); opacity:0; transition:opacity .4s; }
.omnidesk-drawer.show{ pointer-events:auto; }
.omnidesk-drawer.show::before{ opacity:1; }
.omnidesk-panel{ position:absolute; top:0; right:0; bottom:0; width:440px; max-width:100vw; background:#fff;
  box-shadow:-24px 0 60px rgba(44,34,51,.25); transform:translateX(105%); transition:transform .5s cubic-bezier(.34,1.56,.64,1);
  display:flex; flex-direction:column; }
.omnidesk-drawer.show .omnidesk-panel{ transform:none; }
.omnidesk-head{ padding:15px 18px; color:#fff; background:linear-gradient(120deg,#54306e,var(--tpl-main,#6d3d8e) 60%,#9159b4);
  display:flex; align-items:center; justify-content:space-between; gap:12px; }
.omnidesk-head b{ font-size:16px; font-weight:600; }
.omnidesk-head small{ display:block; font-size:13px; opacity:.85; }
.omnidesk-head .icon-button{ background:rgba(255,255,255,.18); color:#fff; border:none; }
.omnidesk-body{ flex:1; position:relative; background:#faf7fc; }
.omnidesk-body iframe{ width:100%; height:100%; border:0; display:block; }
.omnidesk-empty{ height:100%; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:8px;
  text-align:center; color:#8b7e96; padding:30px; font-size:34px; }
.omnidesk-empty b{ font-size:15px; color:#54306e; }
.omnidesk-empty span{ font-size:12.5px; line-height:1.6; }
/* expand / collapse — gives the embedded OmniDesk room (the narrow 440px squeezes
   its list+detail layout). Toggled by #omnideskExpand, remembered in localStorage. */
.omnidesk-head-actions{ display:flex; align-items:center; gap:8px; }
.omnidesk-head-actions .icon-button{ font-size:18px; line-height:1; }
.omnidesk-drawer.expanded .omnidesk-panel{ width:min(1040px, 94vw); }
@media (max-width:520px){ .omnidesk-panel, .omnidesk-drawer.expanded .omnidesk-panel{ width:100vw; } }

/* ══════════════════════════════════════════════════════════════════════════════
   200-POINT UI POLISH — v2026.06.08m
   Comprehensive pass: hover states, focus rings, transitions, spacing,
   typography, accessibility, empty states, animations.
   Uses !important where commercial block overrides are needed.
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── 1. SIDEBAR ──────────────────────────────────────────────────────────────── */

/* Left-bar indicator on active nav item */
.nav-item.active {
  position: relative;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 60%;
  border-radius: 0 3px 3px 0;
  background: var(--primary, var(--tpl-main,#6d3d8e));
}

/* Smooth nav transitions */
.nav-item {
  transition: background 0.14s ease, color 0.14s ease !important;
}

/* Nav keyboard focus */
.nav-item:focus-visible {
  outline: 2px solid rgba(255,255,255,0.4) !important;
  outline-offset: -2px !important;
}

/* Status dot — subtle ambient pulse */
@keyframes status-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.55); }
  50%       { box-shadow: 0 0 0 5px rgba(45, 212, 191, 0); }
}
.status-dot {
  animation: status-pulse 2.4s ease-in-out infinite;
}

/* Sidebar scrollbar hover */
.nav-list::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.5) !important;
}

/* ── 2. GLOBAL BUTTONS ────────────────────────────────────────────────────────── */

/* Disabled state */
.primary-action:disabled,
.ghost-button:disabled,
button:disabled {
  opacity: 0.45 !important;
  cursor: not-allowed !important;
  transform: none !important;
  box-shadow: none !important;
  filter: saturate(0.5);
}

/* primary-action active — keep subtle inset shadow */
.primary-action:active {
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.15) !important;
}

/* ghost-button active — tint */
.ghost-button:active {
  background: var(--acc-50, var(--tpl-100,#f3e8ff)) !important;
  transform: scale(0.98);
}

/* Chip transition */
.chip {
  transition: border-color 0.14s ease, color 0.14s ease, background 0.14s ease, transform 0.12s ease !important;
}
.chip:hover:not(.active):not(:disabled) {
  border-color: var(--primary, var(--tpl-main,#6d3d8e)) !important;
  color: var(--primary, var(--tpl-main,#6d3d8e)) !important;
  transform: translateY(-1px);
}

/* Icon button lift */
.icon-button:hover {
  transform: translateY(-1px) !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08) !important;
}

/* ── 3. GLOBAL INPUTS / FORMS ─────────────────────────────────────────────────── */

/* Focus ring on all form inputs */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):focus,
select:focus,
textarea:focus {
  border-color: var(--primary, var(--tpl-main,#6d3d8e)) !important;
  outline: none !important;
  box-shadow: 0 0 0 3px rgba(109,61,142,0.1) !important;
}

/* Placeholder color */
input::placeholder,
textarea::placeholder,
select:invalid {
  color: #c4c9d4 !important;
}

/* Disabled inputs */
input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.5 !important;
  cursor: not-allowed !important;
  background: #f8fafc !important;
}

/* Resize textarea vertically only */
textarea {
  resize: vertical;
}

/* Search field focus */
.search-field:focus {
  border-color: var(--primary, var(--tpl-main,#6d3d8e)) !important;
  background: var(--tpl-50,#faf5ff) !important;
  box-shadow: 0 0 0 3px rgba(109,61,142,0.08) !important;
  outline: none !important;
}

/* ── 4. CUSTOMER LIST / TABLE ─────────────────────────────────────────────────── */

/* Table head — stronger visual separation */
.table-row.head {
  background: var(--surface-2, #f8f7fb) !important;
  font-weight: 700 !important;
  border-bottom: 2px solid var(--line, #e5e7eb) !important;
}

/* Customer row — selection feel */
.customer-row.selected,
.customer-row[aria-selected="true"] {
  background: var(--acc-50, var(--tpl-100,#f3e8ff)) !important;
  border-color: var(--primary, var(--tpl-main,#6d3d8e)) !important;
}

/* ── 5. METRIC CARDS ──────────────────────────────────────────────────────────── */
.metric-card {
  transition: transform 0.14s ease, box-shadow 0.14s ease !important;
  cursor: pointer;
}
.metric-card:hover {
  transform: translateY(-2px) !important;
  box-shadow: var(--shadow), 0 0 0 2px rgba(109,61,142,0.12) !important;
}

/* ── 6. VISIT / QUEUE CARDS ───────────────────────────────────────────────────── */
.visit-card {
  transition: opacity 0.18s, transform 0.18s, box-shadow 0.18s, border-color 0.14s !important;
}
.visit-card:hover:not(.dragging) {
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 14px rgba(0,0,0,0.09) !important;
  border-color: var(--acc-200, var(--tpl-200,#d8b4fe)) !important;
}
.visit-card.active {
  border-color: var(--primary, var(--tpl-main,#6d3d8e)) !important;
  box-shadow: 0 0 0 3px rgba(109,61,142,0.15) !important;
  background: var(--acc-50, var(--tpl-100,#f3e8ff)) !important;
}
.queue-card-remove {
  transition: background 0.12s, color 0.12s, border-color 0.12s !important;
}
.queue-assignment {
  transition: background 0.14s, color 0.14s !important;
}

/* Dashboard queue item hover (columns variant) */
.queue-columns [data-dashboard-queue-item]:hover {
  border-color: var(--acc-200, var(--tpl-200,#d8b4fe)) !important;
  background: var(--acc-50, var(--tpl-100,#f3e8ff)) !important;
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(109,61,142,0.07) !important;
}

/* ── 7. APPOINTMENT / SERVICE / INVOICE ROWS ─────────────────────────────────── */
.appointment-row,
.service-list div,
.invoice-list div {
  transition: background 0.13s ease, border-color 0.13s ease, box-shadow 0.13s ease !important;
  cursor: pointer;
}
.appointment-row:hover:not(.head),
.service-list div:hover:not(.head),
.invoice-list div:hover:not(.head) {
  border-color: var(--acc-200, var(--tpl-200,#d8b4fe)) !important;
  background: var(--acc-50, var(--tpl-100,#f3e8ff)) !important;
}

/* Invoice total row — stronger visual */
.invoice-list .total {
  font-weight: 800 !important;
  border-top: 2px solid var(--line, #e5e7eb) !important;
  background: var(--surface-2, #f8f7fb) !important;
}

/* ── 8. OPD TABS ──────────────────────────────────────────────────────────────── */
.opd-tabs button {
  transition: background 0.13s, color 0.13s, border-color 0.13s !important;
}
.opd-tabs button:hover:not(.active) {
  background: var(--tpl-100,#f3e8ff) !important;
  color: var(--primary, var(--tpl-main,#6d3d8e)) !important;
  border-color: var(--acc-200, var(--tpl-200,#d8b4fe)) !important;
}

/* ── 9. CUSTOMER PROFILE TABS ─────────────────────────────────────────────────── */
.tabs button {
  transition: background 0.13s, color 0.13s !important;
  cursor: pointer;
}
.tabs button:hover:not(.active) {
  background: #e2e8f0 !important;
  color: var(--ink, #1e293b) !important;
}

/* Profile stats card hover */
.profile-stats > div {
  transition: box-shadow 0.14s, transform 0.14s !important;
  cursor: default;
}
.profile-stats > div:hover {
  box-shadow: 0 2px 10px rgba(0,0,0,0.07) !important;
  transform: translateY(-1px);
}

/* Consent status strip transitions */
.consent-status-strip div,
.consent-rule-list div {
  transition: border-color 0.15s, background 0.15s !important;
}

/* ── 10. OPD STEP BUTTONS ─────────────────────────────────────────────────────── */
/* Stronger pulse for step-next */
@keyframes step-next-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(236,72,153,0.0); }
  50%       { box-shadow: 0 0 0 5px rgba(236,72,153,0.22); }
}
[data-opd-step-button].step-next {
  animation: step-next-pulse 1.4s ease-in-out infinite !important;
}

/* Progress bar fill — more visible */
.opd-progress strong {
  background: var(--acc-50, var(--tpl-100,#f3e8ff)) !important;
}
.opd-progress i {
  background: linear-gradient(90deg, var(--primary, var(--tpl-main,#6d3d8e)), var(--acc-bright, var(--tpl-bright,#a855f7))) !important;
  min-width: 4px;
  transition: width 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

/* Progress text — more visible */
#opdProgressText {
  color: var(--primary, var(--tpl-main,#6d3d8e)) !important;
  font-weight: 700 !important;
  font-size: 13px !important;
}

/* ── 11. PANEL HEADS ──────────────────────────────────────────────────────────── */
.panel-head {
  flex-wrap: wrap !important;
  gap: 10px !important;
}
.panel-head.wide {
  flex-wrap: wrap !important;
  gap: 10px !important;
}

/* ── 12. BAR CHART ─────────────────────────────────────────────────────────────── */
.bar-chart span {
  transition: transform 0.15s ease, box-shadow 0.15s !important;
  cursor: pointer;
}
.bar-chart span:hover {
  transform: scaleY(1.04) !important;
  filter: brightness(1.1);
}
/* Today's bar — stronger glow */
.bar-chart span[data-today="1"],
.bar-chart span:last-child {
  box-shadow: 0 0 0 3px rgba(245,158,11,0.3), 0 6px 18px rgba(245,158,11,0.3) !important;
}

/* ── 13. EMPTY STATES ─────────────────────────────────────────────────────────── */
.lane.empty::before {
  content: "📭";
  display: block;
  font-size: 28px;
  margin-bottom: 6px;
  opacity: 0.5;
}
.lane:empty,
.empty-placeholder {
  min-height: 80px;
}

/* ── 14. TIMELINE DRAWER ──────────────────────────────────────────────────────── */
.drawer-panel {
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* ── 15. MODAL BACKDROPS ──────────────────────────────────────────────────────── */
.modal-overlay,
.ios-diagnostic-overlay,
.share-vial-modal,
.treatment-plan-modal {
  backdrop-filter: blur(3px) !important;
}

/* ── 16. STATUS PILLS ─────────────────────────────────────────────────────────── */
.status-pill {
  transition: background 0.16s, color 0.16s, border-color 0.16s !important;
}

/* ── 17. NOTIFICATION BADGE ──────────────────────────────────────────────────── */
.notification-button::after {
  box-shadow: 0 1px 4px rgba(0,0,0,0.18) !important;
}

/* ── 18. SCROLLBARS ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar-thumb:hover {
  background: rgba(109,61,142,0.3) !important;
}

/* ── 19. TYPOGRAPHY CONSISTENCY ───────────────────────────────────────────────── */
h1, h2, h3 {
  line-height: 1.25;
}
h3 {
  margin-bottom: 4px;
}
.panel-head h2,
.panel-head h3 {
  margin-bottom: 2px;
}

/* Muted text — ensure readability */
.muted,
.opd-card-row span {
  color: #546070 !important;
}

/* ── 20. RECEIPT PREVIEW ──────────────────────────────────────────────────────── */
.receipt-preview-outer {
  background: #dde3ee !important;
}

/* ── 21. PRINT — SIGNATURE LINE CLARITY ──────────────────────────────────────── */
@media print {
  .signature-grid span {
    display: inline-block;
    border-bottom: 1px solid #333;
    min-width: 120px;
  }
  .handwriting-lines > * {
    border-bottom: 1px solid #ccc;
  }
}

/* ── 22. OPAQUE FOCUS RING FOR INPUT WRAPPERS ─────────────────────────────────── */
input[type="search"]:focus-visible,
input[type="text"]:focus-visible,
input[type="number"]:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2.5px solid var(--primary, var(--tpl-main,#6d3d8e)) !important;
  outline-offset: 1px !important;
}

/* ── 23. AUDIT TRAIL / HISTORY LIST ROWS ─────────────────────────────────────── */
#opdAuditTrailList > div,
#opdHistoryList > div {
  transition: background 0.12s !important;
  border-radius: 6px;
  padding: 4px 8px;
}
#opdAuditTrailList > div:hover,
#opdHistoryList > div:hover {
  background: var(--surface-2, #f8f7fb) !important;
}

/* ── 24. VISIT SHEET IMPROVEMENTS ────────────────────────────────────────────── */
.visit-sheet-checks span {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  letter-spacing: 0.2px;
}
.mini-field-grid span {
  font-size: 9.5pt;
  font-weight: 700;
  color: #374151;
  border-top: 1.5px solid #9ca3af;
  padding-top: 3px;
}
.visit-sheet-critical .critical strong {
  color: #b91c1c !important;
  font-weight: 900 !important;
}

/* ── 25. OPD WORKLIST GRID ROWS ───────────────────────────────────────────────── */
.opd-worklist-grid div,
.opd-admin-decision div {
  transition: background 0.12s !important;
  border-radius: 8px;
  padding: 6px 8px;
}
.opd-worklist-grid div:hover,
.opd-admin-decision div:hover {
  background: var(--surface-2, #f8f7fb) !important;
}

/* ── 26. COMPLETION GRID STEP ITEMS ───────────────────────────────────────────── */
#opdCompletionGrid > div {
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s !important;
}
#opdCompletionGrid > div.done {
  box-shadow: 0 0 0 2px rgba(16,185,129,0.2) !important;
}
#opdCompletionGrid > div.active-step {
  box-shadow: 0 0 0 2px rgba(236,72,153,0.2) !important;
}

/* ── 27. PANEL PADDING CONSISTENCY ────────────────────────────────────────────── */
.opd-diagnosis-block,
.opd-admin-worklist,
.opd-complete-panel,
.opd-admin-decision {
  padding-bottom: 14px;
}

/* ── 28. DOCUMENT GUARD LIST BUTTONS ─────────────────────────────────────────── */
#opdDocumentGuardList button {
  transition: background 0.13s, border-color 0.13s, transform 0.12s !important;
}
#opdDocumentGuardList button:hover {
  transform: translateX(2px) !important;
}

/* ── 29. SAVE STATUS BADGE ────────────────────────────────────────────────────── */
.save-status {
  transition: color 0.2s, background 0.2s !important;
}

/* ── 30. GLOBAL TRANSITION ON STATUS-ACTIVE ────────────────────────────────────── */
.status-active {
  transition: background 0.2s, color 0.2s !important;
}

/* ── 31. QUEUE LANE DROP TARGET GLOW ─────────────────────────────────────────── */
.lane.drag-over {
  border-color: var(--primary, var(--tpl-main,#6d3d8e)) !important;
  background: var(--acc-50, var(--tpl-100,#f3e8ff)) !important;
  box-shadow: inset 0 0 0 2px var(--primary, var(--tpl-main,#6d3d8e)) !important;
}

/* ── 32. CUSTOMER ROW AVATAR INITIALS ─────────────────────────────────────────── */
.customer-avatar-initial,
.opd-active-photo-placeholder {
  font-weight: 700;
  letter-spacing: -0.5px;
  background: var(--acc-100, var(--tpl-200,#e9d5ff)) !important;
  color: var(--primary, var(--tpl-main,#6d3d8e)) !important;
}

/* End of 200-point polish block */

/* ── OPD progress bar ต้องอ่าน % ได้ด้วยตา ──────────────────────────
   ของเดิมรางถูก theme ทับเป็นม่วง (--acc-200) จนกลืนกับตัว fill —
   38% ก็ดูเหมือนเต็มหลอด. ราง = ม่วงจางเกือบขาว, ส่วนที่ทำแล้ว =
   ม่วงเข้ม gradient → เห็นทันทีว่า OPD คืบไปแค่ไหน ขาดอีกเท่าไหร่ */
.opd-progress > strong {
  background: #efeaf8 !important;
  border: 1px solid color-mix(in srgb,var(--tpl-main,#7c3aed) 18%,transparent);
  height: 10px !important;
}
.opd-progress i {
  background: linear-gradient(90deg, var(--primary, var(--tpl-main,#7c3aed)), #cb2bb8) !important;
}
details.opd-action-center > summary .opd-progress > span { white-space: nowrap; }

/* ── opd-collapsible — panel ที่หุบได้ทั่วหน้า OPD (ไกด์/PDPA) ── */
details.opd-collapsible > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
details.opd-collapsible > summary::-webkit-details-marker { display: none; }
details.opd-collapsible > summary::marker { content: ""; }
details.opd-collapsible[open] > summary { margin-bottom: 6px; }

/* ============================================================================
   iPad OPD touch pass v1 (2026-06-30) — make #visits usable on iPad WITHOUT
   touching desktop. Source-ordered AFTER the OPD !important override block
   (~15982) so these win only where their media query matches; desktop
   (>1180px + fine pointer) is byte-identical. Plan phases 1-3; phase 5 (kanban
   drag→tap) deferred. (kpop ref: iPad-OPD audit 2026-06-30)
   ============================================================================ */

/* --- Layout: an UNCONDITIONAL !important block (~15990/16015) pinned
   .opd-action-center to a fixed 220px sidebar + .opd-action-buttons to 3-col,
   defeating the responsive 1fr reflow at :1180/:820. On iPad that 220px sidebar
   eats ~28% of a 768px screen. Re-assert the stack at <=1180 with equal
   specificity + later source order so it wins only on tablet/narrow. --- */
@media (max-width: 1180px) {
  .opd-action-center { grid-template-columns: 1fr !important; }
  /* children were placed into the desktop 2-col grid (column 2 / row-span 2);
     neutralize so they flow cleanly in one column. */
  .opd-action-summary {
    grid-row: auto !important;
    grid-column: auto !important;
    border-right: none !important;
    border-bottom: 1px solid var(--acc-200) !important;
    padding: 0 0 10px 0 !important;
  }
  .opd-steps-hint { grid-column: auto !important; }
  .opd-action-buttons {
    grid-column: auto !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}
/* Very narrow (phone) — one action button per row. */
@media (max-width: 560px) {
  .opd-action-buttons { grid-template-columns: 1fr !important; }
}

/* --- Active-patient banner: the existing stack rule only fired <=720px, so the
   768-834 iPad-portrait band kept the cramped desktop row. Extend to <=900. --- */
@media (max-width: 900px) {
  .opd-active-patient-banner { flex-direction: column; align-items: stretch; text-align: left; }
  .opd-active-actions { width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* --- Touch tap-targets: pointer:coarse = real touch (iPad Safari), desktop
   mouse untouched. WCAG 44x44 minimum on the small controls. --- */
@media (pointer: coarse) {
  /* Kanban card delete X was 22x22 — expand hit-box to 44x44; glyph stays the
     same visual size (centered) and deletion is already confirm()-guarded. */
  .queue-card-remove {
    width: 44px !important;
    height: 44px !important;
    top: 2px !important;
    right: 2px !important;
  }
  .opd-tabs button { min-height: 44px !important; }
  .opd-meta-toggle { min-height: 40px !important; font-size: 13px !important; padding: 6px 12px !important; }
  .opd-start-flow button { min-height: 44px !important; font-size: 13px !important; }
  /* 16px input font stops iOS Safari auto-zooming the page on focus. */
  .icd-search-input { min-height: 44px !important; font-size: 16px !important; padding: 10px 12px !important; }
}

/* ============================================================================
   iPad OPD card touch pass (2026-07-01) — the OPD/Master card is a print-style
   layout with contenteditable ".editable-vital" fields. On touch it was print-sized
   (3px rows + unstyled single-line fields = tiny/near-invisible tap targets). Make
   each field a clear, big "tap to fill" box + comfortable rows, WITHOUT touching
   print (@media print) or desktop (fine pointer). Owner: finish iPad OPD.
   ============================================================================ */
@media (pointer: coarse) {
  .opd-print-card { font-size: 15px; }
  .opd-print-card h4 { font-size: 15.5px; }
  .opd-print-card .opd-card-row { padding: 8px 0; align-items: center; gap: 12px; }
  .opd-print-card .opd-card-row > span { font-size: 14px; color: #475569; }
  /* Editable vitals → a clear, tappable "fill me" box (single-line). */
  .opd-print-card .editable-vital {
    display: inline-block;
    min-height: 42px;
    line-height: 40px;
    min-width: 96px;
    max-width: 100%;
    padding: 0 12px;
    border-radius: 9px;
    background: #f1f5f9;
    border: 1px dashed #b8c2d0;
    color: #0f172a;
    font-weight: 600;
    cursor: text;
    -webkit-user-select: text;
    box-sizing: border-box;
  }
  .opd-print-card .editable-vital:focus {
    background: #fff;
    border: 1.6px solid var(--tpl-main,#7c3aed);
    outline: none;
    box-shadow: 0 0 0 3px color-mix(in srgb,var(--tpl-main,#7c3aed) 12%,transparent);
  }
  /* Multi-line concern paragraph — full-width block. */
  .opd-print-card p.editable-vital { display: block; line-height: 1.55; min-height: 58px; padding: 10px 12px; }
  /* Tappable gender toggle. */
  .opd-print-card [data-action="cycle-gender"] {
    display: inline-block; min-height: 42px; line-height: 40px; padding: 0 16px;
    background: #f1f5f9; border-radius: 9px; border: 1px solid #e2e8f0;
  }
}

/* ============================================================================
   OPD handwriting note (Apple Pencil → R2, roadmap #2) — pen button on the OPD
   card + a fullscreen canvas overlay for writing with pen/finger.
   ============================================================================ */
.opd-page-label { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.opd-write-note-btn {
  font-size: 13px; font-weight: 700; padding: 8px 14px; min-height: 40px;
  background: linear-gradient(135deg, var(--tpl-main,#7c3aed), var(--tpl-bright,#a855f7)); color: #fff; border: none;
  border-radius: 10px; cursor: pointer; box-shadow: 0 3px 8px color-mix(in srgb,var(--tpl-main,#7c3aed) 30%,transparent);
}
@media print { .opd-write-note-btn { display: none !important; } }
.opd-note-overlay { position: fixed; inset: 0; z-index: 100000; background: #e2e8f0; display: flex; flex-direction: column; }
.opd-note-bar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 12px; background: #fff; border-bottom: 1px solid #cbd5e1; box-shadow: 0 2px 6px rgba(0, 0, 0, .08);
}
.opd-note-tool, .opd-note-sz {
  min-height: 44px; padding: 0 14px; font-size: 14px; font-weight: 600;
  border: 1px solid #cbd5e1; background: #f8fafc; color: #334155; border-radius: 9px; cursor: pointer;
}
.opd-note-tool.active, .opd-note-sz.active { background: var(--tpl-100,#ede9fe); border-color: var(--tpl-bright,#a855f7); color: var(--tpl-main,#6d28d9); }
.opd-note-save { background: var(--tpl-main,#7c3aed) !important; color: #fff !important; border-color: var(--tpl-main,#7c3aed) !important; }
.opd-note-stage { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 6px; -webkit-overflow-scrolling: touch; }
#opdNoteCanvas { background: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); border-radius: 4px; width: min(99vw, 1720px); height: auto; touch-action: none; cursor: crosshair; }

/* ── INLINE handwriting on the "Doctor Handwriting" ruled box (Visit Log page) ──
   Transparent canvas sits ON TOP of the CSS ruled lines so the doctor writes in place.
   touch-action: pan-y lets a finger scroll the page while the Pencil draws (pen-only capture). */
.handwriting-lines { position: relative; }
.vs-map-split { position: relative; } /* host for the body-map drawing canvas overlay */
.visit-sheet-map { overflow: hidden; } /* clip the body-map when pinch-zoomed so it stays in its column */
#opdIntakeCardPage { position: relative; } /* host for the full-card intake handwriting overlay */
#beautyFaceSheet { position: relative; } /* host for the master-card body-map drawing canvas */
#opdPrintCard .beauty-face-section { overflow: hidden; } /* clip the master body-map when pinch-zoomed */
/* OPD document "แฟ้ม" sub-tabs — pick ONE print page instead of scrolling all 3 stacked */
.opd-doc-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 14px; position: sticky; top: 0; z-index: 15; background: #fff; padding: 6px 0; }
.opd-doc-tabs button { padding: 8px 16px; border-radius: 10px; border: 1px solid #cbd5e1; background: #f8fafc; color: #334155; font-weight: 600; font-size: 14px; cursor: pointer; }
.opd-doc-tabs button.active { background: var(--tpl-main,#7c3aed); color: #fff; border-color: var(--tpl-main,#7c3aed); }
.opd-doc-hidden { display: none !important; }
@media (pointer: coarse) { .opd-doc-tabs button { padding: 10px 18px; font-size: 15px; } }
/* PDPA signature box on the Master Card — host for the patient's signature canvas overlay */
.pdpa-sign-box { position: relative; min-height: 68px; margin-top: 8px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; }
/* signature boxes on the visit log (แพทย์ / ผู้บันทึก + วันที่) — each hosts a minimal signature canvas */
.sign-row { display: flex; gap: 14px; margin-top: 12px; align-items: flex-end; flex-wrap: wrap; }
.sign-cell { flex: 1 1 160px; min-width: 0; }
.sign-cell.sign-date-cell { flex: 0 0 150px; }
.sign-cap { display: block; font-size: 13px; color: #64748b; margin-bottom: 3px; }
.pen-sign-box { position: relative; min-height: 56px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; }
.sign-date { display: inline-block; padding: 8px 4px; font-size: 14px; color: #0f172a; border-bottom: 1px solid #cbd5e1; min-width: 120px; }
.hw-palette-min { gap: 3px; padding: 2px 4px; }
.pdpa-sign-label { position: absolute; top: 3px; left: 8px; font-size: 13px; color: #94a3b8; pointer-events: none; }
/* Palm can rest anywhere on the print cards without selecting text (kills the copy callout at rest too).
   NOTE: do this STATICALLY only — a per-stroke toggle of a `* ` selector forces a full-document style
   recalc on every pen up/down, which stalls the next pointerdown and breaks Thai (lift-pen) strokes. */
.opd-print-card { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.opd-print-card .editable-vital { -webkit-user-select: text; user-select: text; } /* except the tap-to-edit fields */
/* touch-action:none is ESSENTIAL — with pan-y, iPadOS treats the Pencil drag as a scroll gesture and
   fires pointercancel mid-stroke, so only disconnected dots render. none = the canvas owns the gesture
   and the pen draws continuously. (Finger-scroll starts elsewhere on the page.) */
.hw-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; touch-action: none; cursor: crosshair; background: transparent; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* toolbar sits ABOVE the writing box (in normal flow), NOT overlapping the ruled area — so tools never
   get in the way of the pen. Inserted as a sibling right before .handwriting-lines. */
.hw-palette { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; width: fit-content; max-width: 100%; margin: 4px 0 6px; padding: 4px 6px; background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 10px; }
.hw-palette button { min-width: 30px; height: 30px; padding: 0 5px; font-size: 13px; line-height: 1; border: 1px solid #cbd5e1; background: #f8fafc; color: #334155; border-radius: 6px; cursor: pointer; }
/* the visit-log card is display-only (no editable fields) — kill text selection + the iOS callout menu so
   a stray palm/pen tap on a label (e.g. "Doctor Handwriting") never selects text and pops the edit toolbar. */
#opdVisitLogPage, #opdVisitLogPage * { -webkit-user-select: none !important; user-select: none !important; -webkit-touch-callout: none !important; }
.hw-palette button.active { background: var(--tpl-100,#ede9fe); border-color: var(--tpl-bright,#a855f7); color: var(--tpl-main,#6d28d9); }
/* pen color swatches (ดำ / น้ำเงิน / แดง) — round; inline background sets the color */
.hw-palette button.hw-col { width: 24px; min-width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 2px solid #e2e8f0; }
.hw-palette button.hw-col.active { border-color: var(--tpl-main,#6d28d9); box-shadow: 0 0 0 2px #fff inset; }
@media (pointer: coarse) { .hw-palette button.hw-col { width: 32px; min-width: 32px; height: 32px; } }
.hw-palette .hw-status { font-size: 13px; color: #64748b; min-width: 30px; text-align: center; white-space: nowrap; }
.hw-palette .hw-status.dirty { color: #b45309; }
.hw-palette .hw-status.saved { color: #15803d; }
.handwriting-lines.hw-pulse { outline: 3px solid var(--tpl-bright,#a855f7); outline-offset: 2px; transition: outline-color .3s ease; }
@media (pointer: coarse) { .hw-palette button { min-width: 40px; height: 40px; font-size: 15px; } .hw-palette .hw-status { font-size: 12px; } }
@media print { .hw-palette { display: none !important; } }
body.printing-opd .hw-palette { display: none !important; }

/* iPad OPD: when a patient is ACTIVELY being worked on, lift the work area (.opd-panel = active-patient
   banner + เปิด OPD Card/เขียนโน้ต buttons + OPD card) ABOVE the 6 stacked queue lanes — otherwise it's
   buried at the very bottom of a long scroll on iPad portrait. Conditional via :has() (Safari 15.4+) so an
   idle queue still lists lanes first for picking the next patient. Touch-only → desktop/print untouched. */
@media (pointer: coarse) {
  /* 2026.11.14c — must carry .active: `#visits.opd-has-active` (1,1,0) beat `.view { display:none }` (0,1,0), so on
     every touch device the whole OPD page showed under Dashboard, Reports and every other page while a patient was open. */
  #visits.opd-has-active.active { display: flex; flex-direction: column; align-items: stretch; }
  #visits.opd-has-active.active > .opd-panel { order: -1; }
}

/* iPad OPD queue เฟส 5 — tap-to-move: forward advance buttons already exist (config.buttons);
   touch-size them + a ← back button so a card moves BACK a stage without dragging. */
/* ⚠️ ต้องเจาะจงกว่า `.visit-card button` (0,1,1) ที่ประกาศทีหลังและตั้ง background+border ทับ
   — เขียนแค่ `.visit-card-back` (0,1,0) สีพื้นไม่เคยติดเลย ตรวจด้วย getComputedStyle บนของจริงแล้ว */
.visit-card button.visit-card-back { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }
/* 🎟 ใช้คอร์สจากหน้าคิว — โผล่เฉพาะการ์ดที่คนไข้มีคอร์สใช้ได้จริง จึงย้อมให้เห็นชัด
   ไม่งั้นพนักงานมองข้ามแล้วลืมตัด = คลินิกให้บริการฟรี */
.visit-card button.visit-card-course { background: #ecfdf5; color: #047857; border: 1px solid #6ee7b7; font-weight: 700; }
.visit-card button.visit-card-course:hover { background: #d1fae5; }
@media (pointer: coarse) {
  .visit-card-actions button { min-height: 40px; padding: 4px 14px; font-size: 14px; }
}

/* ── 💵 รายจ่าย / บัญชี (accounting module Phase 1) ── */
.expense-pl-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 720px) { .expense-pl-grid { grid-template-columns: repeat(2, 1fr); } }
.expense-pl-card { background: var(--surface-2, #f8fafc); border: 1px solid var(--line, #e2e8f0); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.expense-pl-card span { font-size: 12.5px; color: #64748b; font-weight: 600; }
.expense-pl-card strong { font-size: 22px; font-weight: 800; color: #0f172a; }
.expense-pl-card.in strong { color: #047857; }
.expense-pl-card.out strong { color: #b45309; }
.expense-pl-card.profit { background: #ecfdf5; border-color: #a7f3d0; }
.expense-pl-card.profit strong { color: #047857; }
.expense-pl-card.loss { background: #fef2f2; border-color: #fecaca; }
.expense-pl-card.loss strong { color: #dc2626; }
.expense-pl-card.owe strong { color: var(--tpl-main,#7c3aed); }
.expense-table .table-row { grid-template-columns: 1.1fr 1.5fr 0.9fr 0.9fr 0.8fr 1.1fr; align-items: center; }
.expense-row.voided { opacity: 0.5; }
.expense-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.expense-badge.paid { background: #ecfdf5; color: #047857; }
.expense-badge.unpaid { background: #fef3c7; color: #92400e; }
.expense-badge.void { background: #f1f5f9; color: #94a3b8; }
.exp-f { display: flex; flex-direction: column; gap: 4px; }
.exp-f > span { font-size: 12.5px; font-weight: 600; color: #475569; }
.exp-f input, .exp-f select { padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px; box-sizing: border-box; width: 100%; }

/* ── Mobile nav collapse + home FAB (Dr.Golf 2026-07-25) ──────────────────────
   On phones .app-shell drops to one column, so the sidebar's 24 nav items sat ON TOP of
   every page — you scrolled a whole screen of menu before reaching the tab you just
   opened. Collapse it behind a toggle that also names the current page. Desktop keeps
   the permanent sidebar (the toggle is display:none there). */
.nav-mobile-toggle { display: none; }
.home-fab {
  position: fixed;
  right: 24px;
  bottom: 82px; /* clears the back-to-top FAB (24px + 48px + gap) */
  z-index: 24;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--tpl-main,#7c3aed) 0%, var(--tpl-bright,#a855f7) 100%);
  color: #fff;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 18px color-mix(in srgb,var(--tpl-main,#7c3aed) 35%,transparent);
}
.home-fab:hover { filter: brightness(1.08); }
@media (max-width: 820px) {
  .nav-mobile-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
  }
  .nav-mobile-caret { margin-left: auto; transition: transform .15s; }
  .sidebar.nav-open .nav-mobile-caret { transform: rotate(180deg); }
  .sidebar .nav-list { display: none; }
  .sidebar.nav-open .nav-list { display: block; }
  /* the language switch + version chip are settings, not per-visit work — hide them behind
     the same toggle so the collapsed header stays one line */
  /* !important is required: .lang-toggle-wrap carries an inline style="display:flex" in the
     markup, which otherwise wins over any selector here. */
  .sidebar:not(.nav-open) .lang-toggle-wrap { display: none !important; }
  .sidebar:not(.nav-open) .sidebar-version { display: none; }
}

/* ── Appointment calendar: week ⇄ month switch (Dr.Golf 2026-07-26) ───────────
   Month view revives the .calendar-mode-month / .calendar-month-day CSS that had been
   orphaned since the old month view was removed. */
.appt-mode-switch { display: inline-flex; gap: 4px; padding: 3px; background: #f1f5f9; border-radius: 9px; }
.appt-mode-switch .chip { border: none; background: transparent; font-weight: 700; }
.appt-mode-switch .chip.active { background: #fff; box-shadow: 0 1px 3px rgba(15,23,42,.12); }
/* แถวชื่อวันเป็นเซลล์ใน grid เดียวกับปฏิทิน (ห้ามแยกออกไปเป็น element ข้างนอก — .appointment-workbench
   เป็น grid 2 คอลัมน์ จะดันปฏิทินไปอยู่คอลัมน์แถบข้าง 280px). ต้องล้าง min-height:150px ที่
   .calendar-mode-month > div ตั้งไว้ — เจาะจงด้วย 3 class จึงชนะ (0-3-0 > 0-2-1) */
.calendar-grid.calendar-mode-month > .calendar-month-dow {
  min-height: 0;
  padding: 6px 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}
.calendar-month-day { padding: 8px; cursor: pointer; }
.calendar-month-day:hover { background: var(--tpl-50,#faf5ff); }
.calendar-month-day.is-today { background: var(--tpl-100,#ede9fe); box-shadow: inset 0 0 0 2px var(--tpl-main,#7c3aed); }
.calendar-month-day .cmd-num { font-size: 15px; font-weight: 800; }
.calendar-month-day.is-today .cmd-num { color: var(--tpl-main,#6d28d9); }
.calendar-mini-event.mini-arrived { background: #dcfce7; color: #166534; }
.calendar-mini-event.mini-more { background: #f1f5f9; color: #475569; font-weight: 700; }
@media (max-width: 820px) {
  /* phones: a 7-col month grid cannot be read at 130px per column — let it scroll sideways
     instead of squashing every day into an unreadable sliver */
  .calendar-grid.calendar-mode-month, .calendar-month-head { grid-template-columns: repeat(7, 118px); }
}

/* ── หน้านัดหมาย: เอาปฏิทินขึ้นก่อน (คุณหมอ 2026-08-01) ────────────────────────
   เดิม "การจองล่วงหน้า" อยู่บนสุด พอมีจองหลายรายการ (ของจริง 6+ ใบ) ปฏิทินถูกดันตกไป
   ข้างล่างจนหาไม่เจอ — คุณหมอถามว่า "รูปแบบที่เป็นตารางปฏิทินอยู่ไหน" ทั้งที่อยู่หน้าเดียวกัน.
   ปฏิทิน = ภาพรวมที่เปิดดูบ่อยสุด ต้องเห็นทันทีไม่ต้องเลื่อน · รายการจองเป็นคิวงาน
   อ่านทีหลังได้ (ของค้างยืนยันมีตัวเตือนแยกที่หน้าแรกอยู่แล้ว).
   ใช้ flex order สลับเฉพาะการแสดงผล ไม่ขยับโครงสร้าง HTML = ไม่กระทบ JS ที่อ้าง id เดิม */
#appointments.view.active {
  display: flex;
  flex-direction: column;
}
#appointments > .panel { order: 1; }
#appointments > #bookingPanel { order: 2; }

/* ── Week calendar like Google Calendar (2026.11.22d · owner: "ให้เพิ่ม UI ปฏิทินจริงเหมือน Google Calendar") ──
   Toolbar on one row, 7 day columns × hour rows, appointment = block at its time, tap → details card.
   Phones (≤700px) get a compact list by day (JS picks it). No calendar library. */
.appt-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin: 4px 0 14px; }
.appt-toolbar .appt-nav, .appt-toolbar .appt-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.appt-toolbar :is(select, input[type="date"]) { width: auto; min-width: 0; max-width: 220px; height: 38px; padding: 0 12px; font-size: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface, #fff); }
.appt-toolbar .appt-today-btn { height: 38px; padding: 0 16px; font-size: 14px; font-weight: 600; border-radius: 10px; }
.appt-toolbar .appt-arrow { width: 38px; height: 38px; padding: 0; font-size: 22px; line-height: 1; border-radius: 999px; border-color: transparent; background: transparent; }
.appt-toolbar .appt-arrow:hover { background: var(--quiet-bg, #f1f5f9); }
.appt-toolbar .appt-mode-switch .chip { height: 32px; font-size: 14px; }
.appt-toolbar details.appt-more { position: relative; }
.calendar-grid.calendar-mode-tgrid, .calendar-grid.calendar-mode-agenda { display: block; border: 0; border-radius: 0; overflow: visible; }
.calendar-grid.calendar-mode-tgrid > div, .calendar-grid.calendar-mode-agenda > div { min-height: 0; padding: 0; border-bottom: 0; }
.cal-wk { --cal-gutter: 56px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface, #fff); overflow: hidden; }
.cal-wk-head, .cal-wk-untimed { display: grid; grid-template-columns: var(--cal-gutter) repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.cal-wk-dayhead { display: grid; justify-items: center; gap: 2px; padding: 8px 4px 6px; border-left: 1px solid var(--line); }
.cal-wk-dayhead .cal-dow { font-size: 13px; color: var(--muted); }
.cal-wk-dayhead .cal-num { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 999px; font-size: 20px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.cal-wk-dayhead .cal-cnt { min-height: 16px; font-size: 12px; color: var(--muted); }
.cal-wk-dayhead.is-today .cal-dow { color: var(--primary); font-weight: 700; }
.cal-wk-dayhead.is-today .cal-num { background: var(--primary); color: #fff; }
.cal-wk-dayhead.is-past .cal-num { color: var(--muted); }
.cal-wk-gutter { display: grid; align-items: center; justify-items: end; padding-right: 8px; font-size: 12px; color: var(--muted); }
.cal-wk-untimed-day { display: grid; gap: 4px; padding: 4px; border-left: 1px solid var(--line); }
.cal-wk-body { position: relative; display: grid; grid-template-columns: var(--cal-gutter) repeat(7, minmax(0, 1fr)); }
.cal-wk-times { display: grid; grid-auto-rows: var(--cal-hour); }
.cal-wk-hour { position: relative; top: -8px; padding-right: 8px; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cal-wk-hour:first-child { visibility: hidden; }
.cal-wk-col { position: relative; border-left: 1px solid var(--line); background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--cal-hour) - 1px), var(--line) calc(var(--cal-hour) - 1px), var(--line) var(--cal-hour)); }
.cal-wk-col.is-today { background-color: color-mix(in srgb, var(--primary, #6d3d8e) 4%, transparent); }
.cal-ev { position: absolute; display: flex; flex-direction: column; justify-content: center; gap: 0; overflow: hidden; padding: 2px 6px; border: 0; border-left: 3px solid var(--primary); border-radius: 6px; background: color-mix(in srgb, var(--primary, #6d3d8e) 12%, #fff); color: var(--ink); font: inherit; font-size: 13px; line-height: 1.3; text-align: left; cursor: pointer; white-space: nowrap; }
.cal-ev:hover { filter: brightness(.97); box-shadow: 0 2px 8px rgba(15, 23, 42, .12); z-index: 2; }
.cal-ev:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; z-index: 2; }
.cal-ev-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.cal-ev-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.cal-ev.is-untimed { position: static; width: 100%; }
.cal-ev.st-confirmed { border-left-color: #2563eb; background: #eff6ff; }
.cal-ev.is-came { border-left-color: #16a34a; background: #f0fdf4; }
.cal-ev.is-came .cal-ev-name { color: #166534; }
.cal-ev.is-noshow { border-left-color: #dc2626; background: #fef2f2; }
.cal-ev.is-noshow .cal-ev-name { text-decoration: line-through; color: #991b1b; }
.cal-now { position: absolute; left: 0; right: 0; height: 2px; background: #dc2626; z-index: 3; pointer-events: none; }
.cal-now::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 999px; background: #dc2626; }
.appt-pill { display: inline-block; padding: 1px 8px; border: 1px solid; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.appt-popover { position: fixed; z-index: 9000; width: 300px; max-width: calc(100vw - 16px); padding: 16px; background: var(--surface, #fff); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(15, 23, 42, .18); }
.appt-popover-x { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-size: 16px; cursor: pointer; }
.appt-popover-x:hover { background: var(--quiet-bg, #f1f5f9); }
.appt-popover-name { padding-right: 30px; font-size: 17px; font-weight: 700; color: var(--ink); }
.appt-popover-when { margin-top: 4px; font-size: 14px; color: var(--ink); }
.appt-popover-meta { margin-top: 2px; font-size: 14px; color: var(--muted); }
.appt-popover-badge { margin-top: 10px; }
.appt-popover-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
/* attendance side panel: when nobody is on the roster, it stops taking a 280px column */
.appointment-workbench:has(> .attendance-panel [data-empty-state="attendance"]) { grid-template-columns: minmax(0, 1fr); }
.appointment-workbench:has(> .attendance-panel [data-empty-state="attendance"]) > .attendance-panel { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.appointment-workbench:has(> .attendance-panel [data-empty-state="attendance"]) > .attendance-panel h3 { margin: 0; font-size: 14px; }
.appointment-workbench:has(> .attendance-panel [data-empty-state="attendance"]) > .attendance-panel .empty-state { padding: 0; border: 0; background: none; font-size: 14px; }
/* phones: list by day */
.cal-ag-day { border: 1px solid var(--line); border-radius: 12px; background: var(--surface, #fff); margin-bottom: 8px; overflow: hidden; }
.cal-ag-day.is-empty { border-style: dashed; background: transparent; }
.cal-ag-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-size: 14px; font-weight: 700; color: var(--ink); }
.cal-ag-day.is-today .cal-ag-head { color: var(--primary); }
.cal-ag-day.is-empty .cal-ag-head { padding: 8px 14px; font-weight: 500; color: var(--muted); }
.cal-ag-cnt { font-size: 13px; font-weight: 500; color: var(--muted); }
.cal-ag-row { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 4px 10px; padding: 10px 14px; border-top: 1px solid var(--line); border-left: 3px solid var(--primary); }
.cal-ag-row.is-came { border-left-color: #16a34a; }
.cal-ag-row.st-confirmed { border-left-color: #2563eb; }
.cal-ag-row.st-no_show { border-left-color: #dc2626; }
.cal-ag-time { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-ag-main { display: grid; gap: 2px; min-width: 0; }
.cal-ag-name { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.cal-ag-meta { font-size: 13px; color: var(--muted); }
.cal-ag-acts { grid-column: 2; display: flex; flex-wrap: wrap; gap: 6px; }
@media (max-width: 700px) {
  .appt-toolbar { justify-content: flex-start; }
  .appt-toolbar :is(select, input[type="date"]) { max-width: 100%; flex: 1 1 140px; }
}

/* ── 📣 Recall (2026.11.08a) — หน้าการตลาด ─────────────────────────────── */
.recall-panel { margin-bottom: 16px; }
.recall-body { padding: 4px 16px 16px; }
.recall-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 14px; }
.recall-chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 7px 14px; font-size: var(--text-control); cursor: pointer; }
.recall-chip b { margin-left: 4px; color: var(--primary); }
.recall-chip.is-on { background: var(--primary); border-color: var(--primary); color: #fff; }
.recall-chip.is-on b { color: #fff; }
.recall-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.recall-list-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.recall-list-head input[type="search"] { flex: 1 1 200px; min-width: 0; padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 10px; font-size: var(--text-control); }
.recall-summary, .recall-help { color: var(--muted); font-size: var(--text-help); margin: 8px 0; line-height: 1.5; }
.recall-list { border: 1px solid var(--line); border-radius: 12px; max-height: 520px; overflow-y: auto; background: var(--surface); }
.recall-row { display: grid; grid-template-columns: 22px minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: var(--text-control); }
.recall-row:last-child { border-bottom: none; }
.recall-row input { width: 18px; height: 18px; }
.recall-row.is-off { cursor: default; opacity: 0.62; }
.recall-who, .recall-when { display: flex; flex-direction: column; min-width: 0; }
.recall-who strong { overflow-wrap: anywhere; }
.recall-who small, .recall-when small { color: var(--muted); font-size: var(--text-help); overflow-wrap: anywhere; }
.recall-badge { font-size: 12px; border-radius: 999px; padding: 3px 9px; white-space: nowrap; }
.recall-badge-ok { background: #dcfce7; color: #166534; }
.recall-badge-recent { background: #fef3c7; color: #92400e; }
.recall-badge-off { background: #f1f5f9; color: #475569; }
.recall-more { margin-top: 8px; }
.recall-label { display: block; font-weight: 700; font-size: var(--text-control); margin: 12px 0 6px; }
.recall-compose-col textarea { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px; font-size: var(--text-control); line-height: 1.55; font-family: inherit; resize: vertical; }
.recall-image-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.recall-thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.recall-upload { cursor: pointer; }
.recall-promos { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.recall-promo { flex: none; width: 96px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 4px; cursor: pointer; text-align: left; }
.recall-promo img { width: 100%; height: 72px; object-fit: cover; border-radius: 7px; display: block; }
.recall-promo span { display: block; font-size: 12px; color: var(--ink); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recall-phone { border-radius: 16px; overflow: hidden; border: 1px solid #cbd5e1; max-width: 360px; background: #8fa9c9; }
.recall-phone-head { background: #23324a; color: #fff; padding: 10px 14px; font-size: var(--text-control); font-weight: 700; }
.recall-phone-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.recall-bubble { align-self: flex-start; max-width: 88%; background: #fff; color: #111827; border-radius: 4px 16px 16px 16px; padding: 9px 12px; font-size: var(--text-control); line-height: 1.5; overflow-wrap: anywhere; }
.recall-bubble-img { padding: 0; overflow: hidden; background: transparent; }
.recall-bubble-img img { display: block; max-width: 220px; width: 100%; border-radius: 14px; }
.recall-phone-body .recall-help { color: #f8fafc; }
.recall-send { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }
.recall-send .primary-action:disabled { opacity: 0.5; cursor: not-allowed; }
.recall-confirm-backdrop { position: fixed; inset: 0; z-index: 10020; background: rgba(8, 22, 30, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.recall-confirm { background: var(--surface); border-radius: 14px; width: 440px; max-width: 100%; max-height: 92vh; overflow-y: auto; padding: 18px 20px; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3); }
.recall-confirm h2 { margin: 0 0 4px; font-size: 18px; }
.recall-confirm .recall-phone { margin: 12px 0; }
.recall-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
/* ── 📊 RFM (2026.11.08b) — หน้าการตลาด ───────────────────────────────── */
.recall-chips-label { align-self: center; font-size: var(--text-help); color: var(--muted); font-weight: 700; min-width: 64px; }
.rfm-panel { margin-bottom: 16px; }
.rfm-body { padding: 4px 16px 16px; }
.rfm-summary { color: var(--muted); font-size: var(--text-help); margin: 4px 0 12px; line-height: 1.5; }
.rfm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.rfm-card { border: 1px solid var(--line); border-left: 4px solid var(--rfm-tone, #94a3b8); border-radius: 12px; background: var(--surface); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.rfm-card.is-empty { opacity: 0.6; }
.rfm-card header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.rfm-card h3 { margin: 0; font-size: 16px; }
.rfm-count { font-size: var(--text-help); color: var(--muted); white-space: nowrap; }
.rfm-count b { font-size: 18px; color: var(--ink); }
.rfm-hint, .rfm-action { margin: 0; font-size: var(--text-help); color: var(--muted); line-height: 1.5; }
.rfm-action { color: var(--ink); }
.rfm-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin: 2px 0; }
.rfm-stats div { min-width: 0; }
.rfm-stats dt { font-size: 12px; color: var(--muted); }
.rfm-stats dd { margin: 0; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.rfm-bar { height: 6px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
.rfm-bar span { display: block; height: 100%; background: var(--rfm-tone, #94a3b8); }
.rfm-card .ghost-button { align-self: flex-start; margin-top: 4px; }
.rfm-champion { --rfm-tone: #16a34a; }
.rfm-loyal { --rfm-tone: #0d9488; }
.rfm-cant-lose { --rfm-tone: #dc2626; }
.rfm-at-risk { --rfm-tone: #ea580c; }
.rfm-new { --rfm-tone: #2563eb; }
.rfm-promising { --rfm-tone: #7c3aed; }
.rfm-lost { --rfm-tone: #64748b; }
.rfm-attention { --rfm-tone: #ca8a04; }
.rfm-how { margin-top: 12px; font-size: var(--text-help); color: var(--muted); }
.rfm-how summary { cursor: pointer; font-weight: 700; color: var(--ink); }
.rfm-how ul { margin: 6px 0 0; padding-left: 20px; line-height: 1.6; }
@media (max-width: 900px) {
  .recall-grid { grid-template-columns: minmax(0, 1fr); }
  .recall-row { grid-template-columns: 22px minmax(0, 1fr) auto; }
  .recall-when { grid-column: 2 / 3; }
  .recall-badge { grid-column: 3; grid-row: 1; }
}


/* Demo (demo.medcl.co): hide setup nags meant for a real clinic (2026.11.17a) */
html.is-demo #backupReminderBanner, html.is-demo #dashboardIntakeStrip { display: none !important; }

/* ── MedCloud HQ: clinic trial signups waiting for approval (2026.11.17a) ── */
.hq-signups { background: #fff; border: 2px solid var(--primary, #6d28d9); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
.hq-signups h2 { margin: 0 0 4px; font-size: 18px; }
.hq-signups-hint { margin: 0 0 12px; font-size: 14px; color: #475569; }
.hq-signups-sub { margin: 16px 0 0; font-size: 16px; }
.hq-signup { border: 1px solid #e2e8f0; border-radius: 12px; padding: 12px 14px; margin-top: 10px; }
.hq-signup-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; justify-content: space-between; font-size: 16px; }
.hq-signup-code { font-size: 14px; color: #475569; }
.hq-signup dl { margin: 8px 0 0; display: grid; gap: 4px; }
.hq-signup dl > div { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 8px; font-size: 14px; }
.hq-signup dt { color: #64748b; }
.hq-signup dd { margin: 0; overflow-wrap: anywhere; }
.hq-signup-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.hq-signup-result { margin-top: 10px; font-size: 14px; }
.hq-signup-result textarea { width: 100%; font-size: 14px; border: 1px solid #cbd5e1; border-radius: 10px; padding: 8px; box-sizing: border-box; margin: 6px 0; }
.hq-domain-line { margin: 8px 0 0; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.hq-domain-line.is-ok { color: #166534; }
.hq-domain-line.is-wait { color: #475569; }
.hq-domain-line.is-warn { color: #b45309; }

/* ── Standard sign-in 2026.11.15 (email code / Google / Apple on the owner tab) ── */
.login-alt { margin-top: 14px; display: grid; gap: 10px; }
.login-alt-or { display: flex; align-items: center; gap: 10px; color: #64748b; font-size: 13px; }
.login-alt-or::before, .login-alt-or::after { content: ""; flex: 1; height: 1px; background: #e2e8f0; }
.login-alt-btn { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 46px; border-radius: 12px; border: 1px solid #cbd5e1; background: #fff; color: #0f172a; font-size: 15px; font-weight: 600; cursor: pointer; }
.login-alt-btn:disabled { opacity: 0.6; cursor: wait; }
.login-alt-apple { background: #000; color: #fff; border-color: #000; }
.login-alt-btn:focus-visible { outline: 3px solid var(--primary, #6d28d9); outline-offset: 2px; }
.login-code-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6); z-index: 100000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-code-card { background: #fff; border-radius: 16px; padding: 24px; width: 100%; max-width: 360px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); }
.login-code-card h3 { margin: 0 0 6px; font-size: 18px; color: #0f172a; }
.login-code-card p { margin: 0 0 14px; font-size: 14px; color: #475569; line-height: 1.55; overflow-wrap: anywhere; }
.login-code-card input { width: 100%; max-width: 220px; text-align: center; letter-spacing: 8px; font-size: 26px; font-weight: 700; padding: 10px; border: 2px solid #cbd5e1; border-radius: 10px; box-sizing: border-box; }
/* 2026.11.22c email sign-in on a new device */
.login-code-card input.login-email-input { max-width: 100%; text-align: left; letter-spacing: 0; font-size: 16px; font-weight: 500; }
.login-code-error { color: #b91c1c !important; font-size: 14px; margin: 10px 0 0 !important; }
.login-connect-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.login-connect-actions > button { min-height: 44px; padding: 0 20px; font-size: 14px; }
.login-code-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.login-code-cancel { min-height: 44px; border-radius: 10px; border: 1px solid #cbd5e1; background: #fff; font-size: 15px; cursor: pointer; }

/* ═════════════════════════════════════════════════════════════════════════
   PRO LOOK 2026.11.21 — owner: "revise UI Medcloud Dash board ให้เป็น professional look
   ขึ้นอีก เหมือนคลิปตัวอย่าง" (two SaaS dashboards, 21 Nov). What made those read as
   professional, measured from the frames: a neutral near-white canvas, hairline 1px
   borders instead of shadows, small muted labels over strong numbers, a quiet white
   menu whose current page is a pale pill, outlined secondary buttons, and one accent.
   The accent stays each clinic's own colour (--primary). The one bold move: the
   dashboard numbers are one joined band split by hairlines, not four floating cards.
   Applies to every template except "แบบเดิม" (classic); colour tokens only to the
   default กรมท่า/เขียวการแพทย์ so the formal/document/executive/minimal looks keep theirs.
   body{zoom:1.1} stays (owner's readability decision) — sizes below are before zoom.
   ═════════════════════════════════════════════════════════════════════════ */
html:is([data-ui="navy"],[data-ui="teal"]):not([data-ui="classic"]){
  --ink:#111827; --muted:#5f6673;
  --page:#f6f7f9; --surface:#ffffff; --surface-2:#f8f9fb;
  --line:#e5e7eb; --line-2:#d5d9df;
  --shadow:none;
}
html[data-ui-brand]:is([data-ui="navy"],[data-ui="teal"]):not([data-ui="classic"]){
  --ink:color-mix(in srgb,var(--primary) 8%,#111318);
  --page:color-mix(in srgb,var(--primary) 2%,#f6f7f9);
  --surface-2:color-mix(in srgb,var(--primary) 2%,#f8f9fb);
  --line:color-mix(in srgb,var(--primary) 5%,#e4e6ea);
  --line-2:color-mix(in srgb,var(--primary) 8%,#d4d8de);
}
html[data-ui]:not([data-ui="classic"]){
  --pro-r-card:12px; --pro-r-ctl:8px;
  --pro-focus:0 0 0 3px color-mix(in srgb,var(--primary) 22%,transparent);
}
html[data-ui]:not([data-ui="classic"]) ::selection{ background:color-mix(in srgb,var(--primary) 20%,#fff); color:var(--ink); }
html[data-ui]:not([data-ui="classic"]) body{ background:var(--page); color:var(--ink); }

/* ── menu ── */
html[data-ui]:not([data-ui="classic"]) .sidebar{ background:var(--surface); border-right:1px solid var(--line); box-shadow:none; }
html[data-ui]:not([data-ui="classic"]) .brand strong{ font-size:16px; font-weight:600; letter-spacing:0; }
html[data-ui]:not([data-ui="classic"]) .brand span#brandLocation{ font-size:13px; line-height:1.4; color:var(--muted); }
@media (min-width: 821px){ html[data-ui]:not([data-ui="classic"]) .brand span#brandLocation{ display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; } }
html[data-ui]:not([data-ui="classic"]) .brand-mark,
html[data-ui]:not([data-ui="classic"]) .brand-logo{ border-radius:10px; }
html[data-ui]:not([data-ui="classic"]) .nav-group-label{ font-size:13px; font-weight:500; letter-spacing:0; opacity:1; color:var(--muted); padding:0 10px 4px; }
html[data-ui]:not([data-ui="classic"]) .nav-group + .nav-group{ margin-top:14px; }
html[data-ui]:not([data-ui="classic"]) .nav-list,
html[data-ui]:not([data-ui="classic"]) .nav-group{ gap:1px; }
html[data-ui]:not([data-ui="classic"]) .nav-item{ min-height:36px; padding:7px 10px; border-radius:var(--pro-r-ctl); font-size:14px; font-weight:500; color:color-mix(in srgb,var(--ink) 78%,#fff); background:transparent; }
html[data-ui]:not([data-ui="classic"]) .nav-item .ico{ color:var(--muted); }
html[data-ui]:not([data-ui="classic"]) .nav-item .ico svg{ width:18px; height:18px; stroke-width:1.75; }
html[data-ui]:not([data-ui="classic"]) .nav-item:hover{ background:var(--surface-2); color:var(--ink); }
html[data-ui]:not([data-ui="classic"]) .nav-item.active{ background:color-mix(in srgb,var(--primary) 9%,#fff); color:var(--primary); font-weight:600; }
html[data-ui]:not([data-ui="classic"]) .nav-item.active .ico{ color:var(--primary); }
html[data-ui]:not([data-ui="classic"]) .nav-item.active::before{ display:none; }
html[data-ui]:not([data-ui="classic"]) .nav-item:focus-visible{ outline:2px solid var(--primary) !important; outline-offset:-2px !important; }
html[data-ui]:not([data-ui="classic"]) .lang-toggle-wrap{ padding:6px 10px !important; }
html[data-ui]:not([data-ui="classic"]) .user-card{ background:var(--surface-2); border:1px solid var(--line); border-radius:var(--pro-r-card); box-shadow:none; }
html[data-ui]:not([data-ui="classic"]) .status-dot{ animation:none; }

/* ── page header ── */
html[data-ui]:not([data-ui="classic"]) .workspace > .topbar{ align-items:center; gap:12px 16px; flex-wrap:wrap; padding-bottom:16px; margin-bottom:20px; border-bottom:1px solid var(--line); }
html[data-ui]:not([data-ui="classic"]) .topbar > div:first-child{ min-width:0; }
html[data-ui]:not([data-ui="classic"]) .topbar h1{ font-size:26px; line-height:1.2; font-weight:600; letter-spacing:-.01em; margin:2px 0 0; white-space:nowrap; }
html[data-ui]:not([data-ui="classic"]) .topbar .eyebrow{ font-size:13px; font-weight:500; letter-spacing:0; text-transform:none; color:var(--muted); margin:0; white-space:nowrap; }
html[data-ui]:not([data-ui="classic"]) .topbar-actions{ display:flex; flex-wrap:wrap; align-items:center; justify-content:flex-end; gap:8px; margin-left:auto; }
html[data-ui]:not([data-ui="classic"]) .topbar-version-chip{ max-width:132px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; min-height:36px; padding:0 12px; border:1px solid var(--line); border-radius:var(--pro-r-ctl); background:var(--surface); color:var(--muted); font-size:13px; box-shadow:none; }
html[data-ui]:not([data-ui="classic"]) #cloudSyncBadge{ min-height:36px; max-width:150px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; padding:0 12px; border-radius:999px; border:1px solid color-mix(in srgb,currentColor 28%,#fff) !important; background:color-mix(in srgb,currentColor 7%,#fff) !important; box-shadow:none; }
html[data-ui]:not([data-ui="classic"]) #branchSelector{ min-height:36px; border-radius:var(--pro-r-ctl); border:1px solid var(--line-2); background-color:var(--surface); }
html[data-ui]:not([data-ui="classic"]) .topbar-actions > .icon-button{ width:36px; min-height:36px; height:36px; display:inline-grid; place-items:center; padding:0; border-radius:var(--pro-r-ctl); border:1px solid var(--line-2); background:var(--surface); color:var(--ink); box-shadow:none; }
html[data-ui]:not([data-ui="classic"]) .topbar-actions > .icon-button svg{ width:18px; height:18px; stroke-width:1.9; }
html[data-ui]:not([data-ui="classic"]) .topbar-actions > .icon-button:hover{ background:var(--surface-2); }

/* Desktop header = two rows, like the reference tools: page title (and the clinic's OPD banner,
   whose font/size/colour stay the clinic's own) on top, one toolbar row under it — context and
   status on the left (branch, sync, version), the person and today's actions on the right. */
@media (min-width: 821px){
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar{ display:grid; grid-template-columns:minmax(0,1fr) minmax(0,auto); grid-template-areas:"title banner" "actions actions"; align-items:center; gap:12px 20px; }
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > div:first-child{ grid-area:title; }
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > .opd-warning-banner{ grid-area:banner; justify-self:end; width:auto; max-width:min(520px,52vw); margin:0; }
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > .topbar-actions{ grid-area:actions; justify-content:flex-start; margin-left:0; flex-wrap:wrap; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions > #branchSelector{ order:1; width:auto; max-width:220px; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions > #cloudSyncBadge{ order:2; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions > #appVersionChip{ order:3; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions > #topbarUserChip{ order:4; margin-left:auto; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions > .icon-button{ order:5; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions > .primary-action{ order:6; }
}
@media (min-width: 821px) and (max-width: 1700px){
  html[data-ui]:not([data-ui="classic"]) .tuc .tuc-role{ display:none; }
}
/* iPad and narrow laptops: the workspace is only ~480–700px wide after the menu and zoom, so the
   title, the clinic's OPD banner and the toolbar each take their own row (the banner covered the
   title at 834px). */
@media (min-width: 821px) and (max-width: 1180px){
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar{ grid-template-columns:minmax(0,1fr); grid-template-areas:"title" "banner" "actions"; }
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > .opd-warning-banner{ justify-self:stretch; max-width:none; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions > #topbarUserChip{ margin-left:0; }
}

/* signed-in person + lock + switch (classes from _renderUserChip) */
.tuc{ display:inline-flex; align-items:center; gap:6px; }
.tuc .topbar-user-chip{ display:inline-flex; align-items:center; gap:8px; min-height:36px; padding:0 12px 0 4px; background:var(--surface,#fff); border:1px solid var(--line-2,#d5d9df); border-radius:999px; cursor:pointer; color:var(--ink,#111827); }
.tuc .topbar-user-chip:hover,.tuc .tuc-btn:hover{ background:var(--surface-2,#f8f9fb); }
.tuc .tuc-avatar{ width:28px; height:28px; border-radius:50%; overflow:hidden; background:var(--primary,#6d3d8e); color:#fff; display:inline-flex; align-items:center; justify-content:center; font-size:13px; font-weight:600; flex:none; }
.tuc .tuc-avatar img{ width:100%; height:100%; object-fit:cover; }
.tuc .tuc-name{ font-size:14px !important; font-weight:600; white-space:nowrap; max-width:180px; overflow:hidden; text-overflow:ellipsis; }
.tuc .tuc-role{ font-size:13px !important; color:var(--muted,#5f6673); white-space:nowrap; }
.tuc .tuc-btn{ display:inline-flex; align-items:center; gap:6px; min-height:36px; padding:0 10px; border:1px solid var(--line-2,#d5d9df); border-radius:var(--pro-r-ctl,8px); background:var(--surface,#fff); color:var(--ink,#111827); font-size:14px; cursor:pointer; }
.tuc .tuc-btn svg{ width:17px; height:17px; stroke-width:1.9; }

/* ── buttons and fields ── */
html[data-ui]:not([data-ui="classic"]) .primary-action{ border-radius:var(--pro-r-ctl); font-weight:600; box-shadow:none; background:var(--primary); border:1px solid var(--primary); }
html[data-ui]:not([data-ui="classic"]) .topbar-actions > .primary-action{ min-height:36px; padding:0 14px; font-size:14px; }
html[data-ui]:not([data-ui="classic"]) .primary-action:hover{ transform:none; filter:brightness(1.1); box-shadow:none; }
html[data-ui]:not([data-ui="classic"]) .ghost-button{ border-radius:var(--pro-r-ctl); box-shadow:none; }
html[data-ui]:not([data-ui="classic"]) .ghost-button:not(.danger-ghost):not(.danger-text):not(.danger){ background:var(--surface); border:1px solid var(--line-2); color:var(--ink); font-weight:500; }
html[data-ui]:not([data-ui="classic"]) .ghost-button:not(.danger-ghost):not(.danger-text):not(.danger):hover{ background:var(--surface-2); border-color:color-mix(in srgb,var(--ink) 22%,#fff); }
/* destructive buttons keep their red (the navy template's tint used to override them) */
html[data-ui]:not([data-ui="classic"]) .ghost-button:is(.danger-ghost,.danger){ color:#b91c1c; background:#fff7f7; border:1px solid #fecaca; }
html[data-ui]:not([data-ui="classic"]) .ghost-button:is(.danger-ghost,.danger):hover{ color:#991b1b; background:#fee2e2; border-color:#fca5a5; }
html[data-ui]:not([data-ui="classic"]) .ghost-button.danger-text{ color:#b91c1c; background:var(--surface); border:1px solid var(--line-2); }
html[data-ui]:not([data-ui="classic"]) .panel-head .ghost-button:not(.danger-ghost):not(.danger-text):not(.danger){ color:var(--ink); font-weight:500; }
html[data-ui]:not([data-ui="classic"]) :is(input,select,textarea):focus-visible{ outline:none; border-color:var(--primary); box-shadow:var(--pro-focus); }
html[data-ui]:not([data-ui="classic"]) :is(button,a,[role="button"],summary):focus-visible{ outline:2px solid var(--primary); outline-offset:2px; }

/* ── surfaces: one hairline, no drop shadow, one radius ── */
html[data-ui]:not([data-ui="classic"]) :is(.panel,.lane,.dashboard-intake-strip,.booking-dashboard-card,.receipt-preview){ border:1px solid var(--line); border-radius:var(--pro-r-card); box-shadow:none; background:var(--surface); }
html[data-ui]:not([data-ui="classic"]) .panel{ padding:20px; }
html[data-ui]:not([data-ui="classic"]) .panel-head{ margin-bottom:14px; gap:12px; }
html[data-ui]:not([data-ui="classic"]) .panel-head h2{ font-size:16px; font-weight:600; letter-spacing:0; }
html[data-ui]:not([data-ui="classic"]) .dashboard-grid{ gap:16px; }
/* "UI น้อยลง" (owner 21 Nov via the main session: "Minimal ขึ้น เห็นแล้วใช้ได้เลย"): an empty intake list is one
   quiet line, not a 120px dashed box; its hint text was #cbd5e1 on white (1.5:1, unreadable). */
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-empty{ flex-direction:row; flex-wrap:wrap; align-items:baseline; justify-content:flex-start; gap:4px 10px; padding:10px 12px; text-align:left; background:var(--surface-2); border:1px solid var(--line); color:var(--muted); font-size:14px; }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-empty small{ color:var(--muted); font-size:13px; }
html[data-ui]:not([data-ui="classic"]) .empty-state{ border:1px dashed var(--line-2); border-radius:10px; background:var(--surface-2); color:var(--muted); font-size:14px; }

/* ── the number band (dashboard, daily close, DF): one frame, cells split by hairlines.
   The lines are each cell's own left/top shadow, clipped by the frame, so a cell hidden by
   role (revenue needs "financial") leaves no stray border and an empty slot stays white. ── */
html[data-ui]:not([data-ui="classic"]) .metrics-grid{ display:grid; grid-template-columns:repeat(auto-fit,minmax(200px,1fr)) !important; gap:0 !important; background:var(--surface); border:1px solid var(--line); border-radius:var(--pro-r-card); overflow:hidden; margin-bottom:20px; }
html[data-ui]:not([data-ui="classic"]) .metrics-grid > .metric-card{ border:0 !important; border-radius:0 !important; box-shadow:-1px 0 0 var(--line),0 -1px 0 var(--line) !important; background:var(--surface); padding:18px 20px !important; min-height:0; transform:none !important; }
html[data-ui]:not([data-ui="classic"]) .metrics-grid > .metric-card:hover{ background:var(--surface-2); transform:none !important; }
html[data-ui]:not([data-ui="classic"]) .metrics-grid > .metric-card:focus-visible{ outline:2px solid var(--primary); outline-offset:-2px; }
html[data-ui]:not([data-ui="classic"]) .metric-card .mc-top{ margin-bottom:8px; font-size:14px; }
html[data-ui]:not([data-ui="classic"]) .metric-card .mc-top span:first-child,
html[data-ui]:not([data-ui="classic"]) .metric-card > span:first-child{ font-size:14px; font-weight:500; color:var(--muted); }
html[data-ui]:not([data-ui="classic"]) .metric-card .mc-ic{ width:30px !important; height:30px !important; border-radius:8px; background:var(--surface-2); color:var(--muted); border:1px solid var(--line); }
html[data-ui]:not([data-ui="classic"]) .metric-card .mc-ic svg{ width:16px; height:16px; }
html[data-ui]:not([data-ui="classic"]) .metric-card strong{ display:block; font-size:30px !important; line-height:1.15 !important; font-weight:600 !important; letter-spacing:-.02em; color:var(--ink) !important; margin:0 0 6px !important; font-variant-numeric:tabular-nums; }
html[data-ui]:not([data-ui="classic"]) .metric-card small{ font-size:13px !important; line-height:1.45; color:var(--muted) !important; font-weight:500; }

/* ── dashboard queue summary: three even columns that do not squeeze "ไม่มีคิว" onto two lines ── */
html[data-ui]:not([data-ui="classic"]) .queue-columns{ grid-template-columns:repeat(auto-fit,minmax(min(100%,220px),1fr)); gap:10px; }
html[data-ui]:not([data-ui="classic"]) .queue-columns > div{ min-width:0; background:var(--surface-2); border:1px solid var(--line); border-radius:10px; padding:12px; }
html[data-ui]:not([data-ui="classic"]) .queue-columns h3{ font-size:13px; font-weight:600; letter-spacing:0; color:var(--muted); margin:0 0 8px; }
html[data-ui]:not([data-ui="classic"]) .queue-columns p{ border-radius:8px; border-color:var(--line); font-size:14px; }

/* ── OPD board: grey columns, white cards (status tints of the cards stay) ── */
html[data-ui]:not([data-ui="classic"]) #visits .kanban{ gap:12px; }
html[data-ui]:not([data-ui="classic"]) #visits .lane{ background:var(--surface-2); padding:12px; }
html[data-ui]:not([data-ui="classic"]) #visits .lane.empty{ background:var(--surface-2); }
html[data-ui]:not([data-ui="classic"]) #visits .lane h2{ font-size:14px; font-weight:600; letter-spacing:0; color:var(--ink); margin:2px 2px 10px; }
html[data-ui]:not([data-ui="classic"]) .visit-card{ border-radius:10px; box-shadow:0 1px 2px rgba(16,24,40,.05); }
html[data-ui]:not([data-ui="classic"]) .visit-card > strong{ font-weight:600; letter-spacing:0; }
html[data-ui]:not([data-ui="classic"]) .visit-card > span{ font-size:14px; color:color-mix(in srgb,var(--ink) 72%,#fff); }
html[data-ui]:not([data-ui="classic"]) .visit-card .queue-hn{ font-weight:600; letter-spacing:0; }
html[data-ui]:not([data-ui="classic"]) .visit-card .queue-meta{ font-size:13px; font-weight:600; }
html[data-ui]:not([data-ui="classic"]) .visit-card:hover:not(.dragging){ transform:none !important; box-shadow:0 1px 3px rgba(16,24,40,.08) !important; }

/* ── bar charts: flat single-hue bars (no gradients, no glow), 4px data-ends, thin enough to read
   as marks. Dashboard: past days a pale step of the clinic colour, today the full colour + bold label.
   Reports keeps its target tiers (owner 28 Aug: darker = closer to the daily target, green = reached). ── */
html[data-ui]:not([data-ui="classic"]) .bar-chart{ gap:10px; }
html[data-ui]:not([data-ui="classic"]) .bar-chart span{ justify-self:center; width:min(100%,44px); border-radius:4px 4px 0 0; box-shadow:none !important; transform:none !important; background:color-mix(in srgb,var(--primary) 30%,#fff); }
html[data-ui]:not([data-ui="classic"]) .bar-chart span:hover{ transform:none !important; filter:none; background:color-mix(in srgb,var(--primary) 50%,#fff); }
html[data-ui]:not([data-ui="classic"]) .bar-chart span[data-today="1"]{ background:var(--primary); }
html[data-ui]:not([data-ui="classic"]) .bar-chart span[data-today="1"]::after{ color:var(--ink); font-weight:700; }
html[data-ui]:not([data-ui="classic"]) .bar-chart span:last-child:not([data-today="1"]):not([data-tier]){ background:color-mix(in srgb,var(--primary) 30%,#fff); }
html[data-ui]:not([data-ui="classic"]) .bar-chart span[data-tier="0"]{ background:color-mix(in srgb,var(--primary) 16%,#fff); }
html[data-ui]:not([data-ui="classic"]) .bar-chart span[data-tier="1"]{ background:color-mix(in srgb,var(--primary) 36%,#fff); }
html[data-ui]:not([data-ui="classic"]) .bar-chart span[data-tier="2"]{ background:color-mix(in srgb,var(--primary) 62%,#fff); }
html[data-ui]:not([data-ui="classic"]) .bar-chart span[data-tier="3"]{ background:var(--primary); }
html[data-ui]:not([data-ui="classic"]) .bar-chart span[data-tier="4"]{ background:#0f8a5f; }
html[data-ui]:not([data-ui="classic"]) .bar-chart span.bar-selected{ background:var(--ink); }
html[data-ui]:not([data-ui="classic"]) .bar-chart span:focus-visible{ outline:2px solid var(--ink); outline-offset:2px; }

/* ── tables ── */
html[data-ui]:not([data-ui="classic"]) .data-table th{ background:var(--surface-2); color:var(--muted); font-size:13px; font-weight:600; letter-spacing:0; text-transform:none; border-bottom:1px solid var(--line); }
html[data-ui]:not([data-ui="classic"]) .data-table td{ border-bottom:1px solid var(--line); font-variant-numeric:tabular-nums; }
html[data-ui]:not([data-ui="classic"]) .data-table tbody tr:hover > td{ background:var(--surface-2); }

/* ── small text the audit found under 12px (payments list HN line) ── */
html[data-ui]:not([data-ui="classic"]) .payment-row small,
html[data-ui]:not([data-ui="classic"]) #payments small{ font-size:13px; }

html[data-ui]:not([data-ui="classic"]) .modal{ border-radius:14px; }

/* ── phone ── */
@media (max-width: 820px){
  html[data-ui]:not([data-ui="classic"]) .sidebar{ border-right:0; border-bottom:1px solid var(--line); box-shadow:none; }
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar{ padding-bottom:10px; margin-bottom:14px; }
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar h1{ font-size:22px; }
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar .topbar-actions{ flex-wrap:nowrap; justify-content:flex-start; margin-left:0; }
  html[data-ui]:not([data-ui="classic"]) .metrics-grid{ grid-template-columns:repeat(2,minmax(0,1fr)) !important; }
  html[data-ui]:not([data-ui="classic"]) .metrics-grid > .metric-card{ padding:14px 14px !important; }
  html[data-ui]:not([data-ui="classic"]) .metric-card strong{ font-size:24px !important; }
  html[data-ui]:not([data-ui="classic"]) .panel{ padding:16px; }
}
@media (prefers-reduced-motion: reduce){
  html[data-ui]:not([data-ui="classic"]) :is(.nav-item,.metric-card,.visit-card){ transition:none !important; }
}

/* ══════════════════════════════════════════════════════════════════════════════════════════
   MINIMAL 2026.11.21b — owner: "ทำให้ Minimal ขึ้น ไม่ดูรก … ใช้ง่ายๆ เห็นแล้วเข้าใจได้เอง ต้องปรับทุกหน้า"
   Set 1: payments · customers · OPD queue. Look and layout only; every button/id kept (rarely used ones
   live under a "เพิ่มเติม" <details>). No display:!important on anything app.js hides.
   ══════════════════════════════════════════════════════════════════════════════════════════ */
html[data-ui]:not([data-ui="classic"]){
  --quiet-bg: color-mix(in srgb, var(--ink, #182231) 3%, #fff);
  --quiet-line: color-mix(in srgb, var(--ink, #182231) 10%, #fff);
}
/* "เพิ่มเติม" disclosure (shared by every page in this round) */
html[data-ui]:not([data-ui="classic"]) details.pay-more,
html[data-ui]:not([data-ui="classic"]) details.ui-more{
  margin-top:14px; border-top:1px solid var(--line); padding-top:4px;
}
html[data-ui]:not([data-ui="classic"]) :is(details.pay-more, details.ui-more) > summary{
  list-style:none; cursor:pointer; display:flex; align-items:center; gap:10px;
  min-height:44px; padding:0 4px; font-size:14px; font-weight:600; color:var(--ink);
  border-radius:8px;
}
html[data-ui]:not([data-ui="classic"]) :is(details.pay-more, details.ui-more) > summary::-webkit-details-marker{ display:none; }
html[data-ui]:not([data-ui="classic"]) :is(details.pay-more, details.ui-more) > summary::before{
  content:""; width:8px; height:8px; flex:none; margin:0 2px 0 4px;
  border-right:2px solid var(--muted); border-bottom:2px solid var(--muted);
  transform:rotate(-45deg); transition:transform .18s ease;
}
html[data-ui]:not([data-ui="classic"]) :is(details.pay-more, details.ui-more)[open] > summary::before{ transform:rotate(45deg); }
html[data-ui]:not([data-ui="classic"]) :is(details.pay-more, details.ui-more) > summary:hover{ background:var(--quiet-bg); }
html[data-ui]:not([data-ui="classic"]) :is(details.pay-more, details.ui-more) > summary:focus-visible{ outline:2px solid var(--primary); outline-offset:2px; }
html[data-ui]:not([data-ui="classic"]) .pay-more-hint{ font-size:13px; font-weight:400; color:var(--muted); }
html[data-ui]:not([data-ui="classic"]) details.pay-more > :not(summary){ margin-top:14px; }

/* ── Payments ── */
html[data-ui]:not([data-ui="classic"]) #payments .payment-layout > .panel > .panel-head.wide h2{ font-size:18px; }
/* bill header: merge / clear stay, but quiet */
html[data-ui]:not([data-ui="classic"]) #payments [data-action="open-merge-bill"],
html[data-ui]:not([data-ui="classic"]) #payments [data-action="clear-current-bill"]{
  background:transparent !important; border-color:transparent !important; box-shadow:none !important; font-size:13px !important;
}
html[data-ui]:not([data-ui="classic"]) #payments [data-action="clear-current-bill"]{ color:#b42318 !important; }
html[data-ui]:not([data-ui="classic"]) #payments [data-action="open-merge-bill"]{ color:var(--muted) !important; }
/* installment toggle: one quiet line instead of a purple box */
html[data-ui]:not([data-ui="classic"]) #installmentBox{
  background:transparent !important; border:0 !important; border-radius:0 !important; padding:10px 2px 0 !important;
}
html[data-ui]:not([data-ui="classic"]) #installmentBox > label{ color:var(--muted) !important; font-weight:500 !important; font-size:14px !important; }
html[data-ui]:not([data-ui="classic"]) #installmentBox:has(#installmentMode:checked){
  background:var(--quiet-bg) !important; border:1px solid var(--quiet-line) !important; border-radius:10px !important; padding:12px !important;
}
html[data-ui]:not([data-ui="classic"]) #installmentBox:has(#installmentMode:checked) > label{ color:var(--ink) !important; font-weight:600 !important; }
/* coupon: one slim row */
html[data-ui]:not([data-ui="classic"]) #payments .coupon-panel{ margin-top:12px; gap:8px; }
/* the confirm button is the one strong thing on this page */
html[data-ui]:not([data-ui="classic"]) #payments [data-action="confirm-payment"]{
  min-height:52px; font-size:17px !important; font-weight:700; letter-spacing:.01em; margin-top:18px !important;
}
html[data-ui]:not([data-ui="classic"]) #payments .pay-print-row{
  display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin-top:10px;
}
html[data-ui]:not([data-ui="classic"]) #payments .pay-print-row [data-action="print-receipt"]{
  background:var(--surface) !important; color:var(--ink) !important; border:1px solid var(--line) !important; box-shadow:none !important; font-weight:600 !important;
}
html[data-ui]:not([data-ui="classic"]) #payments [data-action="book-followup-appointment"]{
  background:transparent !important; border-color:transparent !important; color:var(--primary) !important; font-weight:600;
}
/* slip panels: flat sections with a hairline instead of nested boxes */
html[data-ui]:not([data-ui="classic"]) #payments :is(.payment-evidence-panel, .incoming-slips-panel){
  background:transparent !important; border:0 !important; border-top:1px solid var(--line) !important;
  border-radius:0 !important; box-shadow:none !important; padding:14px 0 0 !important; margin-top:16px !important;
}
html[data-ui]:not([data-ui="classic"]) #payments :is(.payment-evidence-panel, .incoming-slips-panel) h2{ font-size:15px; }
html[data-ui]:not([data-ui="classic"]) #payments .payment-slip-dropzone{ padding:14px; min-height:0; gap:2px; background:var(--quiet-bg); border-color:var(--quiet-line); }
html[data-ui]:not([data-ui="classic"]) #payments .incoming-slips-list{ max-height:360px; }
html[data-ui]:not([data-ui="classic"]) #payments .incoming-slips-list > .empty-state{ padding:10px 12px; min-height:0; font-size:13px; }
/* panels that live in "เพิ่มเติม": same flat look */
html[data-ui]:not([data-ui="classic"]) details.pay-more :is(.payment-link-panel, .split-payment, .installment-panel, .receipt-size, .approval-panel){
  background:transparent !important; border:0 !important; border-top:1px solid var(--line) !important; border-radius:0 !important;
  box-shadow:none !important; padding:12px 0 0 !important;
}
html[data-ui]:not([data-ui="classic"]) details.pay-more h2,
html[data-ui]:not([data-ui="classic"]) details.pay-more h3{ font-size:15px; }
html[data-ui]:not([data-ui="classic"]) details.pay-more [data-action="send-payment-link-line"]{
  background:var(--surface) !important; border-color:var(--line) !important; color:var(--ink) !important; font-weight:600 !important;
}
html[data-ui]:not([data-ui="classic"]) .pay-export-row{ display:flex; flex-wrap:wrap; gap:8px; }
/* receipt history: neutral toolbar */
html[data-ui]:not([data-ui="classic"]) #payments [data-action="refresh-receipt-history"]{
  background:var(--surface) !important; color:var(--ink) !important; border:1px solid var(--line) !important; font-weight:600 !important;
}

/* payment channel grid (drawn by renderPaymentSplit): neutral help, partner link, fee inputs */
html[data-ui]:not([data-ui="classic"]) #payments .pay-grid-help{ background:transparent !important; border:0 !important; padding:0 2px !important; }
html[data-ui]:not([data-ui="classic"]) #payments .pay-grid-help > summary{ color:var(--muted) !important; font-weight:500 !important; }
html[data-ui]:not([data-ui="classic"]) #payments [data-action="open-paid-by-partner"]{
  background:transparent !important; border:0 !important; color:var(--muted) !important; text-decoration:underline; text-underline-offset:3px;
}
html[data-ui]:not([data-ui="classic"]) #payments .pay-fee-row input{ width:56px !important; border-color:var(--line) !important; background:var(--surface) !important; box-shadow:none !important; }
html[data-ui]:not([data-ui="classic"]) #payments .barter-card-panel{ background:var(--quiet-bg) !important; border:1px solid var(--quiet-line) !important; }
html[data-ui]:not([data-ui="classic"]) #payments .barter-card-head strong{ color:var(--ink) !important; }
html[data-ui]:not([data-ui="classic"]) #payments .barter-card-flag{ background:transparent !important; color:var(--muted) !important; padding:0 !important; font-weight:500 !important; }
html[data-ui]:not([data-ui="classic"]) #payments .barter-card-panel :is(input, .barter-slip-btn){ border-color:var(--line) !important; }
html[data-ui]:not([data-ui="classic"]) #payments .barter-slip-btn{ background:var(--surface) !important; color:var(--ink) !important; }
/* receipt history rows: one quiet button style; cancel stays red text */
html[data-ui]:not([data-ui="classic"]) .receipt-history-table [data-action="reprint-receipt"],
html[data-ui]:not([data-ui="classic"]) #payments [data-action="loyalty-sales-sync"]{
  background:var(--surface) !important; color:var(--ink) !important; border:1px solid var(--line) !important;
}
html[data-ui]:not([data-ui="classic"]) .receipt-history-table [data-action="void-receipt"]{
  background:transparent !important; border-color:transparent !important; color:#b42318 !important;
}
html[data-ui]:not([data-ui="classic"]) .receipt-history-table [data-action="edit-receipt-no"]{
  background:transparent !important; border-color:transparent !important; color:var(--muted) !important;
}

/* ── Customers ── */
html[data-ui]:not([data-ui="classic"]) #customers .panel-actions{ gap:6px; }
html[data-ui]:not([data-ui="classic"]) #customers .panel-actions .ghost-button{
  background:transparent !important; border-color:transparent !important; color:var(--muted) !important; font-weight:500 !important; box-shadow:none !important;
}
html[data-ui]:not([data-ui="classic"]) #customers .panel-actions .ghost-button:hover{ background:var(--quiet-bg) !important; color:var(--ink) !important; }
@media (max-width: 820px){
  html[data-ui]:not([data-ui="classic"]) #customers .panel-head.wide > .panel-actions{ display:flex; flex-wrap:wrap; gap:4px 6px; }
  html[data-ui]:not([data-ui="classic"]) #customers .panel-head.wide > .panel-actions > .primary-action{ flex:1 1 100%; }
  html[data-ui]:not([data-ui="classic"]) #customers .panel-head.wide > .panel-actions > .ghost-button{ width:auto; flex:0 1 auto; padding-inline:10px; }
}
html[data-ui]:not([data-ui="classic"]) #customers .customer-workflow-guide-collapsed{ background:transparent !important; border:0 !important; padding:0 !important; margin:4px 0 8px !important; }
html[data-ui]:not([data-ui="classic"]) #customers .customer-workflow-guide-collapsed > summary{ color:var(--muted); font-size:13px; font-weight:500; padding:4px 2px; }
html[data-ui]:not([data-ui="classic"]) #customers .customer-filter-chips .chip:not(.active){ background:transparent; border-color:transparent; }
html[data-ui]:not([data-ui="classic"]) #customers .delete-row-button{
  background:transparent !important; border-color:transparent !important; color:var(--muted) !important; box-shadow:none !important;
}
html[data-ui]:not([data-ui="classic"]) #customers .delete-row-button:hover{ color:#b42318 !important; background:color-mix(in srgb,#b42318 8%,#fff) !important; }
html[data-ui]:not([data-ui="classic"]) .customer-next-actions{ display:flex; flex-wrap:wrap; gap:8px; }
html[data-ui]:not([data-ui="classic"]) details.cust-more{ margin-top:6px; }
html[data-ui]:not([data-ui="classic"]) .customer-more-actions{ display:flex; flex-wrap:wrap; gap:8px; padding:6px 0 4px; }
html[data-ui]:not([data-ui="classic"]) .customer-more-actions [data-action="pdpa-export-customer"]{
  background:var(--surface) !important; color:var(--ink) !important; border-color:var(--line) !important;
}
html[data-ui]:not([data-ui="classic"]) .customer-more-actions [data-action="pdpa-erase-customer"]{
  background:transparent !important; color:#b42318 !important; border-color:transparent !important;
}
/* status line under the profile buttons: plain text, not a callout box */
html[data-ui]:not([data-ui="classic"]) .selected-customer-next-step{
  background:transparent !important; border:0 !important; padding:4px 2px !important; color:var(--muted) !important;
  font-size:13px !important; font-weight:500 !important; line-height:1.5;
}

/* ── OPD queue: one clear next step per card, the rest quiet ── */
html[data-ui]:not([data-ui="classic"]) #visits .visit-card-actions{ gap:6px; }
html[data-ui]:not([data-ui="classic"]) #visits .visit-card-actions > button{
  background:transparent; border-color:transparent; box-shadow:none; color:var(--muted); font-weight:500;
}
html[data-ui]:not([data-ui="classic"]) #visits .visit-card-actions > button:hover{ background:var(--quiet-bg); color:var(--ink); }
html[data-ui]:not([data-ui="classic"]) #visits .visit-card-actions > [data-action="open-opd"],
html[data-ui]:not([data-ui="classic"]) #visits .visit-card-actions > [data-action="notify-doctor-current"]{
  background:var(--surface); border-color:var(--line); color:var(--ink);
}
html[data-ui]:not([data-ui="classic"]) #visits .visit-card[data-queue-status="waiting"] .visit-card-actions > [data-next-status="consult"],
html[data-ui]:not([data-ui="classic"]) #visits .visit-card[data-queue-status="numbing"] .visit-card-actions > [data-next-status="treatment"],
html[data-ui]:not([data-ui="classic"]) #visits .visit-card[data-queue-status="treatment"] .visit-card-actions > [data-next-status="recovery"],
html[data-ui]:not([data-ui="classic"]) #visits .visit-card[data-queue-status="recovery"] .visit-card-actions > [data-next-status="payment"],
html[data-ui]:not([data-ui="classic"]) #visits .visit-card[data-queue-status="payment"] .visit-card-actions > [data-view-target="payments"]{
  background:var(--primary); border-color:var(--primary); color:#fff; font-weight:600;
}
html[data-ui]:not([data-ui="classic"]) #visits .visit-card[data-queue-status] .visit-card-actions > [data-next-status]:not(.visit-card-back):hover{ filter:brightness(1.05); }
html[data-ui]:not([data-ui="classic"]) #visits .opd-start-guide{ background:transparent !important; border:0 !important; padding:0 2px !important; margin-bottom:10px !important; }
html[data-ui]:not([data-ui="classic"]) #visits .opd-start-guide > summary{ font-size:14px !important; color:var(--muted); }
html[data-ui]:not([data-ui="classic"]) #visits .opd-start-guide > summary strong{ font-weight:600; color:var(--ink); }
/* active OPD banner: one primary (OPD Card), the rest quiet */
html[data-ui]:not([data-ui="classic"]) #visits .opd-active-actions .opd-write-note-quick{
  background:var(--surface) !important; color:var(--ink) !important; border:1px solid var(--line) !important; box-shadow:none !important;
}

/* ── Top bar 2026.11.21c — owner (2000px screen): "อันนี้ดูโล่งแปลกๆไหม". One row on desktop:
   title+date → branch → sync → (stretch) → person and actions. The clinic's OPD warning becomes a thin
   full-width bar under it; its colour/font/size stay the clinic's own (inline from _applyOwbColors).
   Height is reserved from data-owb-full (the finished message) so the bar never grows while typing
   (owner's earlier "ห้ามขยายหุบ"). Display rules key on [data-owb-full], which renderOpdWarningBanner sets only while the bar shows and removes when it hides — so hiding always wins. ── */
@media (min-width: 1500px){
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar{
    grid-template-columns:auto minmax(0,1fr); grid-template-areas:"title actions" "banner banner"; gap:12px 28px;
  }
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > .topbar-actions{ grid-area:actions; justify-content:flex-end; flex-wrap:wrap; min-width:0; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions > #cloudSyncBadge{ margin-right:auto; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions > #topbarUserChip{ margin-left:0; }
}
@media (min-width: 821px) and (max-width: 1499px){
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar{ grid-template-columns:minmax(0,1fr); grid-template-areas:"title" "actions" "banner"; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions > #cloudSyncBadge{ margin-right:auto; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions > #topbarUserChip{ margin-left:0; }
}
@media (min-width: 1500px) and (max-width: 1600px){
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar{ gap:12px 18px; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions{ gap:6px; }
  html[data-ui]:not([data-ui="classic"]) .topbar-actions > #branchSelector{ max-width:168px; }
  html[data-ui]:not([data-ui="classic"]) .tuc .tuc-name{ max-width:120px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
}
@media (min-width: 821px){
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > .opd-warning-banner{
    grid-area:banner; justify-self:stretch; width:auto; max-width:none; margin:0;
  }
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > .opd-warning-banner[data-owb-full]{ padding:6px 16px; border-radius:10px !important; }
}
html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > .opd-warning-banner[data-owb-full]{
  display:grid !important; min-height:0; box-shadow:none !important; -webkit-line-clamp:unset; line-clamp:unset; overflow:hidden;
}
html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > .opd-warning-banner::before,
html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > .opd-warning-banner > .owb-line{
  grid-area:1 / 1; min-width:0; overflow-wrap:anywhere;
  display:-webkit-box; -webkit-box-orient:vertical; -webkit-line-clamp:2; line-clamp:2; overflow:hidden;
}
html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > .opd-warning-banner::before{
  content:attr(data-owb-full) "_"; visibility:hidden; pointer-events:none;
}
@media (max-width: 820px){
  /* the phone shell sets the text to 16px/1.35 — the reserved copy must match */
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > .opd-warning-banner::before,
  html[data-ui]:not([data-ui="classic"]) .workspace > .topbar > .opd-warning-banner > .owb-line{ font-size:16px; line-height:1.35; }
}
/* the typing cursor blinks a few times after the message lands, then rests (no endless loop) */
html[data-ui]:not([data-ui="classic"]) .opd-warning-banner .owb-cursor{ animation-iteration-count:6; }
@media (prefers-reduced-motion: reduce){
  html[data-ui]:not([data-ui="classic"]) .opd-warning-banner .owb-cursor{ animation:none; opacity:0; }
}

/* receipt panel: what was just saved (2026.11.21d) — a calm confirmation line, not a callout */
.receipt-saved-note{
  margin:0 0 12px; padding:10px 14px; border-radius:10px; font-size:14px; line-height:1.5; font-weight:600;
  color:#0b5d40; background:color-mix(in srgb, #0f8a5f 8%, #fff); border:1px solid color-mix(in srgb, #0f8a5f 28%, #fff);
}

/* ── Dashboard intake 2026.11.21e — owner: "ส่วนนี้มันยาวไป ให้แบ่งได้ 6-8 intake ดีไหม". Cards in a grid
   (4 across on desktop, 2 on tablets, 1 on a phone) with the receive button inside each card, next to the name. ── */
/* owner 22 Nov: "ทำไมไม่ซอยให้บรรทัดนึงมีสัก 4 กล่อง" → a fixed 4 across on desktop (8 shown = 2 even rows), 2 on tablets, 1 on phones */
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-list{ grid-template-columns:repeat(4, minmax(0, 1fr)); gap:10px; }
/* narrower desktops: give the name room — drop the initial circle, then go to 3 / 2 across */
@media (min-width: 601px) and (max-width: 1599px){
  html[data-ui]:not([data-ui="classic"]) .dashboard-intake-row .dashboard-intake-avatar{ display:none; }
  html[data-ui]:not([data-ui="classic"]) .dashboard-intake-row .dashboard-intake-view{ width:28px; }
}
@media (min-width: 1001px) and (max-width: 1299px){
  html[data-ui]:not([data-ui="classic"]) .dashboard-intake-list{ grid-template-columns:repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 601px) and (max-width: 1000px){
  html[data-ui]:not([data-ui="classic"]) .dashboard-intake-list{ grid-template-columns:repeat(2, minmax(0, 1fr)); }
}
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-list > .dashboard-intake-empty{ grid-column:1 / -1; }
/* owner's sketch 22 Nov: each box is ONE line tall — name on the left, "รับเข้าคิว" on the right — four boxes per row */
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-row{
  grid-template-columns:none; display:flex; flex-direction:row; align-items:center; gap:8px;
  padding:8px 10px; background:var(--surface); border:1px solid var(--line); border-radius:12px; min-width:0; cursor:default;
}
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-row .dashboard-intake-top{ flex:1; }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-row:hover{ transform:none; border-color:var(--line-2, var(--line)); box-shadow:none; }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-top{ display:flex; align-items:center; gap:10px; min-width:0; }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-avatar{
  flex:none; width:36px; height:36px; font-size:15px; font-weight:600;
  background:color-mix(in srgb, var(--primary) 12%, #fff); color:var(--primary);
}
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-info{ flex:1; min-width:0; }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-info strong{ font-size:15px; color:var(--ink); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-info span{ font-size:13px; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-view{
  flex:none; width:32px; height:32px; padding:0 !important; display:inline-grid; place-items:center;
  border:1px solid transparent; border-radius:8px; background:transparent; color:var(--muted); cursor:pointer;
}
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-view:hover{ background:var(--quiet-bg); color:var(--ink); }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-view svg{ width:18px; height:18px; }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-row .dashboard-intake-receive{ width:auto; flex:none; min-height:36px; padding:0 12px; font-size:14px; justify-content:center; white-space:nowrap; }
/* eight identical solid buttons shout; a tint of the clinic colour keeps "รับเข้าคิว" findable without dominating */
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-row .dashboard-intake-receive{ background:color-mix(in srgb, var(--primary) 10%, #fff) !important; color:var(--primary) !important; border:1px solid color-mix(in srgb, var(--primary) 22%, #fff) !important; box-shadow:none !important; font-weight:600; }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-row .dashboard-intake-receive:hover{ background:var(--primary) !important; color:#fff !important; }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-list > .dashboard-intake-more{
  grid-column:1 / -1; justify-self:start; font-style:normal; font-size:14px; margin:0; padding:0 14px; min-height:36px; background:var(--surface); color:var(--ink);
}
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-head strong{ color:var(--ink); }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-head .muted{ font-size:13px; color:var(--muted); }
html[data-ui]:not([data-ui="classic"]) .dashboard-intake-tools{ display:flex; align-items:center; gap:8px; }
html[data-ui]:not([data-ui="classic"]) details.intake-more{ position:relative; margin:0; border:0; padding:0; }
html[data-ui]:not([data-ui="classic"]) details.intake-more > summary{ min-height:36px; font-weight:500; color:var(--muted); font-size:14px; }
html[data-ui]:not([data-ui="classic"]) details.intake-more .intake-more-actions{
  position:absolute; right:0; top:calc(100% + 4px); z-index:20; display:flex; flex-direction:column; gap:6px; min-width:200px;
  padding:8px; background:var(--surface); border:1px solid var(--line); border-radius:10px; box-shadow:0 8px 24px rgba(15,23,42,.12);
}
@media (min-width: 601px){
  html[data-ui]:not([data-ui="classic"]) .dashboard-intake-list > .intake-more-phone-only{ display:none; }
}
/* phones: one column, each card a single row (name left, receive right), first 4 only + "ดูทั้งหมด" */
@media (max-width: 600px){
  html[data-ui]:not([data-ui="classic"]) .dashboard-intake-list{ grid-template-columns:1fr; gap:8px; }
  html[data-ui]:not([data-ui="classic"]) .dashboard-intake-row{ flex-direction:row; align-items:center; padding:8px 10px; gap:8px; }
  html[data-ui]:not([data-ui="classic"]) .dashboard-intake-row .dashboard-intake-top{ flex:1; }
  html[data-ui]:not([data-ui="classic"]) .dashboard-intake-row .dashboard-intake-receive{ width:auto; flex:none; min-height:40px; }
  html[data-ui]:not([data-ui="classic"]) .dashboard-intake-list > .dashboard-intake-row:nth-of-type(n+5){ display:none; }
}

/* ── Customers: HN range dropdown 2026.11.22b (was 60+ chips) ── */
.customer-range-picker{ display:inline-flex; align-items:center; gap:10px; margin:2px 0 6px; max-width:100%; }
.customer-range-picker > span{ font-size:14px; color:var(--muted); white-space:nowrap; }
.customer-range-picker select{
  min-width:min(340px, 100%); max-width:100%; min-height:40px; padding:0 36px 0 12px; font-size:14px;
  font-variant-numeric:tabular-nums; border:1px solid var(--line); border-radius:10px; background-color:var(--surface); color:var(--ink);
}
@media (max-width: 600px){
  .customer-range-picker{ display:flex; width:100%; }
  .customer-range-picker select{ flex:1; min-width:0; }
}

/* ── Mobile shell 2026.11.14a (owner's phone recording 14 Nov: "UI มือถือเราแย่มากเลย") ──────────────
   Measured at 412px before: menu block 367px + page header 324px → the page itself started at 730px of an
   892px screen, on every view. Now: one 56px sticky bar (logo · clinic name · menu), the user card,
   language and version live inside the opened menu, and the page header is one compact row. */
@media (max-width: 820px) {
  .sidebar {
    position: sticky; top: 0; z-index: 900;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px;
    padding: 8px 12px; min-height: 56px; box-sizing: border-box;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
  }
  .sidebar .brand { margin: 0; padding: 0; gap: 10px; min-width: 0; border: 0; }
  .sidebar .brand-mark, .sidebar .brand-logo { width: 36px; height: 36px; min-width: 36px; font-size: 14px; border-radius: 10px; }
  .sidebar .brand > div { min-width: 0; }
  .sidebar .brand strong { display: block; font-size: 16px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sidebar:not(.nav-open) #brandLocation { display: none; }
  .sidebar .nav-mobile-toggle { width: auto; max-width: 46vw; padding: 9px 12px; min-height: 40px; }
  .sidebar .nav-mobile-toggle #navMobileCurrent { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sidebar:not(.nav-open) .user-card { display: none; }
  /* opened menu = a full-height sheet over the page, scrolls on its own */
  .sidebar.nav-open {
    position: fixed; inset: 0; z-index: 1000; display: block; overflow-y: auto; overscroll-behavior: contain;
    padding: 10px 14px calc(24px + env(safe-area-inset-bottom, 0px));
  }
  .sidebar.nav-open .brand { margin-bottom: 8px; }
  .sidebar.nav-open .nav-mobile-toggle { width: 100%; max-width: none; margin-bottom: 8px; }
  .sidebar.nav-open .user-card { margin-top: 12px; }

  /* page header: date + title on one line, actions in one scrollable row */
  .workspace > .topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 0 6px; margin: 0; }
  .workspace > .topbar > div:first-child { display: flex; align-items: baseline; gap: 8px; flex: 1 1 100%; min-width: 0; }
  .workspace > .topbar .eyebrow { order: 2; margin: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .workspace > .topbar h1 { order: 1; margin: 0; font-size: 22px; line-height: 1.2; white-space: nowrap; }
  .workspace > .topbar .opd-warning-banner { flex: 1 1 100%; margin: 0; padding: 8px 12px; min-height: 0; border-radius: 10px; }
  .workspace > .topbar .opd-warning-banner .owb-text, .workspace > .topbar .opd-warning-banner .owb-cursor { font-size: 16px; line-height: 1.35; }
  .workspace > .topbar .topbar-actions {
    flex: 1 1 100%; display: flex; flex-wrap: nowrap; align-items: center; gap: 6px;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: 2px;
    /* 2026.11.14c — a scrolling row clips on both axes; the alert count badge sits ~12px above its button
       (owner's phone: "122" cut off at the top). Room inside the row, pulled back so the spacing stays. */
    padding-top: 12px; margin-top: -6px;
  }
  .workspace > .topbar .topbar-actions::-webkit-scrollbar { display: none; }
  .workspace > .topbar .topbar-actions > * { flex: 0 0 auto; }
  .workspace > .topbar #branchSelector { width: auto; max-width: 44vw; min-height: 40px; }
  .workspace > .topbar .primary-action[data-action="open-visit"] { min-height: 40px; }
  /* floating mascot / home / back-to-top must never hide the last buttons of a page */
  .workspace { padding-bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 820px) {
  .workspace > .topbar .topbar-actions { justify-content: flex-start; }
  .workspace > .topbar .opd-warning-banner { width: 100%; box-sizing: border-box; }
  /* dashboard numbers: 2 per row, compact (each card was ~400px tall at 412px) */
  #dashboard .metrics-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  #dashboard .metric-card { padding: 12px 14px; min-height: 0; border-radius: 14px; }
  #dashboard .metric-card .mc-top { font-size: 14px; gap: 6px; }
  #dashboard .metric-card .mc-ic { width: 30px; height: 30px; }
  #dashboard .metric-card strong { font-size: 26px; line-height: 1.15; margin: 6px 0 4px; }
  #dashboard .metric-card small { font-size: 13px; line-height: 1.35; }
}
@media (max-width: 820px) {
  /* the daily actions first in the row; status chips after them */
  .workspace > .topbar .topbar-actions > .primary-action[data-action="open-visit"] { order: -3; }
  .workspace > .topbar .topbar-actions > .icon-button { order: -2; }
  .workspace > .topbar .topbar-actions > #branchSelector { order: -1; }
}
@media (max-width: 820px) {
  /* queue lanes stack on a phone: an empty lane is one short row, not a 300px box (6 empty lanes = 2,050px) */
  #visits .lane { min-height: 0; padding: 10px 12px; }
  #visits .lane.empty { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  #visits .lane.empty h2 { margin: 0; font-size: 16px; }
  #visits .lane.empty::before { display: none; }
  #visits .lane.empty::after { min-height: 0; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; flex: 0 0 auto; }
  #visits .lane.empty > :not(h2) { display: none; }
}
@media (max-width: 820px) {
  /* a lane with no cards (only its title, maybe an empty helper) says so in a small pill on the title row */
  #visits .lane:not(:has(> :not(h2):not(:empty))) h2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0; font-size: 16px; }
  #visits .lane:not(:has(> :not(h2):not(:empty))) h2::after {
    content: "ไม่มีคิว"; flex: 0 0 auto; padding: 3px 10px; border: 1px dashed #cbd5e1; border-radius: 999px;
    color: #64748b; font-size: 13px; font-weight: 700;
  }
}
@media (max-width: 820px) {
  /* report tabs: one row that swipes sideways (9 tabs wrapped into 4 rows = 420px) */
  #reportsTabBar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; gap: 6px; padding: 6px; }
  #reportsTabBar::-webkit-scrollbar { display: none; }
  #reportsTabBar .reports-tab { flex: 0 0 auto; white-space: nowrap; padding: 9px 12px; }
}
@media (max-width: 640px) {
  /* mascot stays, smaller, so it covers less of the buttons under it */
  .mascot-figure, .mascot-dock.is-pixel .mascot-figure { width: 52px; height: 52px; }
  .mascot-dock.is-atlas .mascot-figure { width: 42px; height: 54px; }
  .mascot-dock { right: 6px; }
}
@media (max-width: 640px) {
  /* OPD card buttons: two even columns whose labels wrap ("เขียนโน้ต (Visit Card)" was cut to "เขียนโน้ต (Visit") */
  .opd-active-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .opd-active-actions > button { width: 100%; min-width: 0; min-height: 44px; white-space: normal; line-height: 1.3; padding: 8px 10px; text-align: center; overflow: visible; text-overflow: clip; }
}
@media (max-width: 820px) { #dashboardIntakeSubline { font-size: 13px; } }

/* ── Mobile customers 2026.11.14b — owner's phone recording 14 Nov 2026: on a phone the customer list was a
   5-column table squeezed to 344px (names and phone numbers broken over 3 lines, rows 133px tall), the four
   list buttons and the seven profile buttons stacked right-aligned, and the profile sat 1,400px below the
   list so a tap on a row seemed to do nothing. Phone only; desktop untouched. ── */
@media (max-width: 640px) {
  #customers .split-view { grid-template-columns: minmax(0, 1fr); }
  #customers .split-view > .panel { min-width: 0; }
  #customers .panel > .panel-head.wide { flex-direction: column; align-items: stretch; gap: 12px; }
  #customers .panel-head.wide > .panel-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; justify-content: stretch; }
  #customers .panel-head.wide > .panel-actions > button { width: 100%; min-width: 0; margin: 0; justify-content: center; white-space: normal; }
  #customers .panel-head.wide > .panel-actions > .primary-action { order: -1; grid-column: 1 / -1; }
  #customerTagChips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  #customerTagChips::-webkit-scrollbar { display: none; }
  #customerTagChips .chip { flex: 0 0 auto; }
  #customers .data-table > .table-row.head { display: none; }
  #customers .data-table > .customer-row { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; column-gap: 12px; row-gap: 4px; align-items: center; padding: 12px 14px; min-height: 0; }
  #customers .customer-row > span { min-width: 0; }
  #customers .customer-row > span:nth-child(1) { grid-column: 1 / 4; grid-row: 1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
  #customers .customer-row > span:nth-child(2) { grid-column: 1; grid-row: 2; font-size: 14px; white-space: nowrap; }
  #customers .customer-row > span:nth-child(3) { grid-column: 2; grid-row: 2; font-size: 13px; }
  #customers .customer-row > span:nth-child(4) { grid-column: 3; grid-row: 2; font-size: 13px; }
  #customers .customer-row > .row-actions { grid-column: 4; grid-row: 1 / 3; }
  #customers .customer-profile { scroll-margin-top: 72px; }
  #customers .customer-next-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  #customers .customer-next-actions > button { width: 100%; min-width: 0; margin: 0; justify-content: center; white-space: normal; }
  #customers .customer-next-actions > .primary-action { grid-column: 1 / -1; }
  #customers .consent-status-strip,
  #customers .profile-stats,
  #customers .customer-care-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  #customers .integration-strip { grid-template-columns: 1fr 1fr; gap: 8px; }
  #customers .consent-status-strip > div,
  #customers .profile-stats > div,
  #customers .customer-care-strip > div,
  #customers .integration-strip > div { padding: 10px; min-width: 0; }
  #customers .customer-profile > .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  #customers .customer-profile > .tabs > button { flex: 0 0 auto; }
}

/* ── Mobile OPD 2026.11.14b — the nine "Today Visit Completion" steps were 104px-tall cards one under another
   (1,500px) and the Admin worklist was 1,060px of stacked boxes with right-aligned buttons. Two-column steps,
   paired short boxes, and a button grid. Phone only. ── */
@media (max-width: 640px) {
  #opdCompletionGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  #opdCompletionGrid > div { min-height: 0; padding: 10px; grid-template-columns: auto minmax(0, 1fr); column-gap: 8px; row-gap: 2px; align-content: start; }
  #opdCompletionGrid > div > em { grid-column: 1 / -1; font-size: 13px; line-height: 1.35; }
  #opdCompletionGrid > div > strong { align-self: center; font-size: 14px; line-height: 1.25; }
  .opd-complete-panel > .visit-action-strip,
  .opd-admin-worklist > .opd-worklist-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; justify-content: stretch; }
  .opd-complete-panel > .visit-action-strip > button,
  .opd-admin-worklist > .opd-worklist-actions > button { width: 100%; min-width: 0; margin: 0; white-space: normal; justify-content: center; }
  .opd-admin-worklist > .opd-admin-decision { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .opd-admin-worklist > .opd-admin-decision > div:first-child { grid-column: 1 / -1; }
  /* each payment is already a stacked card on a phone; the column-name row was 150px of labels */
  #reportsPaymentList > .table-row.head { display: none; }
  /* 2026.11.15a — owner's phone: the daily sales chart packed 12 bars a row (20px each) under ~40px amount labels
     ("฿12k฿20k", "฿99k฿96k" overlapped). Six days a row gives each label ~48px; rows sized for label + bar + day. */
  #reportsDailyBarChart { grid-template-columns: repeat(6, minmax(0, 1fr)) !important; height: auto !important; grid-auto-rows: 64px; row-gap: 46px !important; column-gap: 8px !important; }
}

/* ── Compact stock + appointment cards (owner 19 Nov 2026: "กล่องดูใหญ่กินพื้นที่" · "นี้ก็ใหญ่ในมือถือ") ── */
/* ⋯ row menu: history / edit / move-merge / delete live behind one button instead of four. */
.row-more { position: relative; display: inline-block; }
.row-more > summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line, #e2e8f0); background: #fff;
  font-size: 20px; font-weight: 900; line-height: 1; color: #475569; user-select: none;
}
.row-more > summary::-webkit-details-marker { display: none; }
.row-more[open] > summary, .row-more > summary:hover { border-color: var(--primary); color: var(--primary); background: var(--acc-50, #f5f3ff); }
.row-more-menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 40; min-width: 200px;
  display: grid; padding: 6px; border: 1px solid var(--line, #e2e8f0); border-radius: 12px;
  background: #fff; box-shadow: 0 12px 28px rgba(15, 23, 42, .16);
}
.row-more-menu button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent; cursor: pointer;
  padding: 10px 12px; border-radius: 8px; font: inherit; font-size: 14px; font-weight: 600; color: #0f172a; min-height: 40px;
}
.row-more-menu button:hover { background: var(--acc-50, #f5f3ff); }
.row-more-menu .row-more-danger { color: #b91c1c; border-top: 1px solid #f1f5f9; border-radius: 0 0 8px 8px; }
.row-more-menu .row-more-danger:hover { background: #fee2e2; }
.products-table [data-cat-pick] { font-size: 14px !important; min-height: 34px; }

@media (max-width: 820px) {
  /* Product card: name block full width, then price · stock · status with ⋯ at the right, category picker last. */
  .products-table .table-row:not(.head) {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 12px;
  }
  .products-table .table-row:not(.head) > span:nth-child(1) { flex: 1 1 100%; min-width: 0; }
  .products-table .table-row:not(.head) > span:nth-child(3) { order: 1; }
  .products-table .table-row:not(.head) > span:nth-child(4) { order: 2; white-space: nowrap; }
  .products-table .table-row:not(.head) > span:nth-child(5) { order: 3; }
  .products-table .table-row:not(.head) > .row-actions { order: 4; margin-left: auto; }
  .products-table .table-row:not(.head) > span:nth-child(2) { order: 5; flex: 1 1 100%; min-width: 0; }
  .products-table .table-row:not(.head) [data-cat-pick] { max-width: 100% !important; padding: 4px 8px; min-height: 34px; }
  .products-table .table-row:not(.head) strong { font-size: 16px; }

  /* Dashboard appointment card: time · status · ✕ on the first line, name and service under it. */
  .appointment-row[data-dashboard-appointment] {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "time badge cancel" "info info info";
    gap: 4px 10px; padding: 10px 12px;
  }
  .appointment-row[data-dashboard-appointment] > time { grid-area: time; }
  .appointment-row[data-dashboard-appointment] > div { grid-area: info; min-width: 0; }
  .appointment-row[data-dashboard-appointment] > .badge { grid-area: badge; justify-self: start; width: auto; }
  .appointment-row[data-dashboard-appointment] > .dashboard-appointment-cancel { grid-area: cancel; width: 32px; height: 32px; min-height: 32px; padding: 0; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   🔴 ต้องอยู่ "ท้ายไฟล์" เสมอ — ทำให้ el.hidden = true ซ่อนได้จริง (9 ส.ค. 69)
   ═══════════════════════════════════════════════════════════════════════════
   `[hidden] { display: none }` ที่เราคิดว่ามีอยู่แล้ว เป็นกฎของ **เบราว์เซอร์ (UA stylesheet)**
   ซึ่งตามลำดับ cascade **แพ้กฎของเราทุกกฎ ไม่ว่า specificity จะต่ำแค่ไหน** — แค่
   `.badge { display: inline-block }` ธรรมดาก็ชนะแล้ว ⇒ สั่งซ่อนไปก็ไม่หายไปไหน

   อาการที่ผู้ใช้เจอไม่ใช่ "หน้าเพี้ยน" แต่คือ **"กดปุ่มแล้วไม่ตอบสนอง"** — โค้ดหลังปุ่ม
   ทำงานครบแล้ว แต่กล่อง/ป้ายไม่ยอมหาย เลยกดซ้ำหลายรอบ (เจอจริง 8 ส.ค. 69 หน้าต่าง
   "นำเข้าสมุดเงินสด" — ข้อมูลเข้าตั้งแต่กดครั้งแรก แต่หน้าต่างค้าง)

   ตรวจทั้งระบบด้วยเบราว์เซอร์จริง 9 ส.ค. 69 (66 element ที่ระบบสั่ง .hidden) พบซ่อนไม่ลง
   **11 จุด**: badge ตัวเลข 3 ตัว · ป้ายแพ้ยาบนคนไข้ที่กำลังตรวจ · แถบรวมคนไข้ซ้ำ ·
   ตารางเลือกสีคลินิก (ปิดไม่ได้เลย) · ตาราง metadata ของ visit (ปุ่ม "ซ่อน" ไม่ทำงาน) ·
   รายการสินค้าในใบเสร็จ · ป้าย role · ป้าย OmniDesk · placeholder รูป rich menu
   กฎบรรทัดเดียวนี้ปิดจบทั้ง 11 จุด และ **กันไม่ให้เกิดใหม่กับของที่เขียนทีหลัง**
   (รวมถึงกล่องที่ JS สร้างเองแล้วตั้ง display แบบ inline ซึ่ง .hidden ไม่มีวันชนะ)

   ⚠️ ทำไมต้องท้ายไฟล์: มีกฎ `display:<ไม่ใช่ none> !important` ที่ specificity เท่ากัน
      (0,1,0) อยู่ในไฟล์นี้ เช่น `.users-table-scroll-hint` — เสมอกันแล้วตัวที่อยู่หลังชนะ
      ถ้าย้ายกฎนี้ขึ้นไปข้างบน จุดพวกนั้นจะกลับมาซ่อนไม่ลงอีก


   ⚠️ จุดที่ *ตั้งใจ* ให้ [hidden] ยังโชว์ ต้องใช้ !important + specificity สูงกว่า (0,1,0)
      ของเดิมถูกอยู่แล้วทั้ง 2 จุด (ทดสอบในเบราว์เซอร์ยืนยันแล้วว่ายังทำงาน):
        · `html.mq-pre-login .login-overlay[hidden]`            (index.html)
        · `body[data-certificate-type="official"] #certOfficialFields[hidden]`
   เทสกันถอย: tests/test-hidden-display.mjs                                                */
[hidden] { display: none !important; }

/* 📇 ช่องทางติดต่อคลินิกท้ายใบรับรองแพทย์ — ต้องพิมพ์ติดกระดาษด้วย (ไม่ใช่แค่โชว์บนจอ)
   เพราะจุดประสงค์คือให้แพทย์ปลายทางที่ต่างประเทศติดต่อกลับได้ (10 ส.ค. 69) */
.certificate-clinic-contact {
  margin-top: 14px; padding-top: 8px; border-top: 1px solid #e2e8f0;
  font-size: 13px; color: #64748b; text-align: center; line-height: 1.5;
}

/* ── แถบเตือน "ข้อมูลยังไม่ขึ้นคลาวด์" ดันปุ่มลอยขึ้นให้พ้น (2026-08-12) ────────────
   แถบอยู่ bottom:0 เต็มความกว้าง · .back-to-top-fab เดิมอยู่ bottom:24px จึงถูกทับจนกดไม่ได้
   --push-bar-h ตั้งโดย _renderPendingPushBanner() จากความสูงจริงหลังวาด (0 เมื่อไม่มีแถบ)
   fallback 0px ⇒ ถ้า JS ไม่ทำงาน ปุ่มยังอยู่ที่เดิมเป๊ะ ไม่พังไปมากกว่าเดิม */
.back-to-top-fab { bottom: calc(24px + var(--push-bar-h, 0px)); }
.home-fab        { bottom: calc(82px + var(--push-bar-h, 0px)); }

/* ── การ์ดโปรโมชัน: ย่อข้อความยาวด้วย CSS ไม่ตัดสตริง (2026-08-12) ──────────────
   🔴 ห้าม .slice() ข้อความไทย/อิโมจิ — ตัดกลางตัวอักษรทำให้แตก (สระ/วรรณยุกต์หลุด)
   ใช้ line-clamp แทน: ข้อความยังครบทุกตัว แค่ซ่อนส่วนเกิน กด "อ่านต่อ" เห็นเต็ม */
.promo-cond > summary::-webkit-details-marker { display: none; }
.promo-cond > summary { list-style: none; }
.promo-cond[open] > summary { display: none; }

/* Payroll-only BT cases: readable on desktop and narrow devices. */
.bt-work-help { margin: 4px 0 12px; color: var(--muted); font-size: var(--text-control); line-height: 1.5; }
.bt-work-row { background: #fffbeb; font-size: var(--text-control); }
.bt-work-row small { font-size: var(--text-help); color: #64748b; }
.bt-work-row em { font-size: var(--text-control); font-style: normal; }
.bt-work-row-button { padding: 7px 9px; border: 1px solid #fdba74; border-radius: 7px; background: #fff7ed; color: #9a3412; font-size: var(--text-control); font-weight: 700; }
.bt-work-backdrop { position: fixed; inset: 0; z-index: 10020; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, .68); }
.bt-work-dialog { width: min(760px, 100%); max-height: 92vh; overflow: auto; padding: 22px; border-radius: 14px; background: #fff; box-shadow: 0 20px 60px #0004; font-size: var(--text-body); }
.bt-work-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.bt-work-dialog-head h2 { margin: 0; font-size: 22px; }
.bt-work-dialog-head button { min-width: 36px; min-height: 36px; border: 0; background: transparent; font-size: 26px; }
.bt-work-warning { margin: 10px 0 16px; padding: 10px; border: 1px solid #fed7aa; border-radius: 8px; background: #fff7ed; color: #9a3412; font-size: var(--text-control); line-height: 1.5; }
.bt-work-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.bt-work-wide { grid-column: 1 / -1; }
.bt-work-dialog label { display: grid; gap: 5px; font-size: var(--text-control); font-weight: 700; }
.bt-work-dialog input, .bt-work-dialog select, .bt-work-dialog textarea { width: 100%; min-height: 42px; padding: 9px 10px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: var(--ink); font-size: var(--text-body); }
.bt-work-hint { color: #64748b; font-size: var(--text-help); font-weight: 400; line-height: 1.5; }
.bt-work-matches { display: grid; gap: 3px; max-height: 190px; overflow: auto; }
.bt-work-matches button { padding: 9px; border: 1px solid #e2e8f0; border-radius: 6px; background: #f8fafc; text-align: left; font-size: var(--text-control); }
.bt-work-matches button:hover { background: #f0fdfa; }
.bt-work-team-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(110px, .7fr) minmax(120px, .7fr) auto; gap: 8px; align-items: end; margin: 12px 0; }
.bt-work-team-row .ghost-button { min-height: 42px; font-size: var(--text-control); }
.bt-work-team-row .bt-work-hint { grid-column: 1 / -1; }
.bt-work-reason { margin-top: 16px; }
.bt-work-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.bt-work-actions button { min-height: 42px; padding: 8px 14px; font-size: var(--text-control); }
.bt-work-danger { margin-right: auto; border: 1px solid #fca5a5; border-radius: 8px; background: #fef2f2; color: #b91c1c; font-weight: 700; }
@media (max-width: 700px) {
  .bt-work-grid { grid-template-columns: 1fr; }
  .bt-work-team-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bt-work-team-row .ghost-button { width: 100%; }
}

/* Shared readable type scale; never shrink text to make a panel fit. */
:root { --mc-type-body:16px; --mc-type-control:14px; --mc-type-support:13px; --mc-type-meta:12px; }
body { font-size:var(--mc-type-body); }
button,input,select,textarea,summary,label { font-size:var(--mc-type-control); }
:is(button,input,select,textarea,summary,label,[role="button"])[style*="font-size:13px"],
:is(button,input,select,textarea,summary,label,[role="button"])[style*="font-size: 13px"],
.login-tab,.login-footer,.login-connect-hint,.login-staff-role { font-size:var(--mc-type-control) !important; }
.login-card { max-height:calc(100dvh - 32px); overflow:auto; }
@media(max-width:600px) { .login-card { max-width:calc(100vw - 24px); } }

.sidebar button,.role-switcher,#cloudSyncBadge,#branchSelector,.primary-action,
:is(button,input,select,textarea,label,[role="button"])[style*="font-size:12px"],
:is(button,input,select,textarea,label,[role="button"])[style*="font-size: 12px"] { font-size:var(--mc-type-control) !important; }

/* The signed-in user control must remain readable as an interactive control. */
.topbar-user-chip, .topbar-user-chip span { font-size: var(--text-control) !important; }

/* ═════════════════════════════════════════════════════════════════════════
   UI TEMPLATES 2026.10 — app.js UI_TEMPLATES / applyUiTemplate
   <html data-ui="…"> sets colours, corners and shadows; --ui-font and
   --ui-font-head set the fonts. Without a template nothing below changes the
   original look. Printed OPD sheets, certificates and receipts keep their font.
   ═════════════════════════════════════════════════════════════════════════ */
body{ font-family:var(--ui-font,"IBM Plex Sans Thai"),"Inter",ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif; }
:where(h1,h2,h3,.metric-card strong,.brand strong):where(:not(#opdPrintRoot *,#opdVisitLogPage *,#opdPrintCard *,#opdIntakeCardPage *,.opd-print-card *,.paper-a4 *,[class*="medical-certificate"] *,.receipt-preview-paper *)){ font-family:var(--ui-font-head,inherit); }
/* Zero specificity: documents with their own font (certificates use Sarabun) keep it. */
:where(#opdPrintRoot,#opdVisitLogPage,#opdPrintCard,#opdIntakeCardPage,.opd-print-card,.paper-a4){ font-family:"IBM Plex Sans Thai","Inter",ui-sans-serif,system-ui,sans-serif; }
html[data-ui]:not([data-ui="classic"]) .metric-card strong{ font-variant-numeric:tabular-nums; }
html[data-ui]:not([data-ui="classic"]) .brand-mark{ box-shadow:none; background:var(--primary); }
/* Purple shades that used to be written out (badges, strips, the + button) follow
   the template; their fallback is the original colour, so the standard look keeps them. */
html[data-ui]:not([data-ui="classic"]){ --tpl-main:var(--primary); --tpl-deep:var(--acc-deep); --tpl-bright:var(--acc-bright); --tpl-200:var(--acc-200); --tpl-100:var(--acc-100); --tpl-50:var(--acc-50); }
:is(#opdPrintRoot,#opdVisitLogPage,#opdPrintCard,#opdIntakeCardPage,.opd-print-card,.paper-a4,.receipt-preview-paper){ --tpl-main:initial; --tpl-deep:initial; --tpl-bright:initial; --tpl-200:initial; --tpl-100:initial; --tpl-50:initial; }
html[data-ui]:not([data-ui="classic"]) .nav-item.active .ico{ color:inherit; }
/* Daily sales bars: tiers stay four clearly different strengths of one colour (the
   shared --tpl shades would make tiers 2 and 3 almost equal on a dark template). */
html[data-ui]:not([data-ui="classic"]) .bar-chart span[data-tier="0"]{ background:linear-gradient(180deg,color-mix(in srgb,var(--primary) 14%,#fff),color-mix(in srgb,var(--primary) 22%,#fff)); }
html[data-ui]:not([data-ui="classic"]) .bar-chart span[data-tier="1"]{ background:linear-gradient(180deg,color-mix(in srgb,var(--primary) 32%,#fff),color-mix(in srgb,var(--primary) 44%,#fff)); }
html[data-ui]:not([data-ui="classic"]) .bar-chart span[data-tier="2"]{ background:linear-gradient(180deg,color-mix(in srgb,var(--primary) 58%,#fff),color-mix(in srgb,var(--primary) 72%,#fff)); }
html[data-ui]:not([data-ui="classic"]) .bar-chart span[data-tier="3"]{ background:linear-gradient(180deg,color-mix(in srgb,var(--primary) 86%,#fff),var(--primary)); }
html[data-ui]:not([data-ui="classic"]) .ai-assistant-launcher{ background-image:linear-gradient(135deg,var(--acc-deep),var(--primary) 55%,var(--acc-bright)); }

/* ── กรมท่า (navy, the default) and เขียวการแพทย์ (teal) ─────────────────────
   Taken from the owner's MedCloud mock-up (12 Oct): white cards on a pale page,
   a dark main colour for the menu and main buttons, a brighter --ui-accent for
   links, notes and next-step buttons, and pale tinted pills. */
html[data-ui="navy"]{
  --ink:#0d2332; --muted:#5b6573;
  --page:#f8f9ff; --surface:#ffffff; --surface-2:#f4f7fd;
  --line:#e3e8f0; --line-2:#d3dce8;
  --acc-50:#f2f6ff; --acc-100:#e7f0ff; --acc-200:#cee5ff; --acc-bright:#016398; --acc-deep:#001628;
  --ui-accent:#016398;
  --shadow:0 1px 2px rgba(13,35,50,.04),0 8px 22px -14px rgba(13,35,50,.16);
}
html[data-ui="teal"]{
  --ink:#0c2624; --muted:#566b68;
  --page:#f5faf9; --surface:#ffffff; --surface-2:#f1f8f6;
  --line:#dce9e6; --line-2:#c9dcd8;
  --acc-50:#effaf7; --acc-100:#ddf3ee; --acc-200:#b4e4da; --acc-bright:#00796b; --acc-deep:#00201d;
  --ui-accent:#00796b;
  --shadow:0 1px 2px rgba(12,38,36,.04),0 8px 22px -14px rgba(12,38,36,.16);
}
html:is([data-ui="navy"],[data-ui="teal"]) :is(.metric-card,.panel,.lane,.receipt-preview,.dashboard-intake-strip){ border-radius:16px; border:1px solid var(--line); }
html:is([data-ui="navy"],[data-ui="teal"]) .nav-item{ border-radius:10px; color:#334155; }
html:is([data-ui="navy"],[data-ui="teal"]) .nav-item.active{ background:var(--primary); color:#fff; }
html:is([data-ui="navy"],[data-ui="teal"]) .nav-item.active::before{ display:none; }
html:is([data-ui="navy"],[data-ui="teal"]) .primary-action{ background:var(--primary); box-shadow:none; }
html:is([data-ui="navy"],[data-ui="teal"]) .primary-action:hover{ transform:none; filter:brightness(1.25); }
html:is([data-ui="navy"],[data-ui="teal"]) .ghost-button{ background:var(--acc-100); border-color:transparent; color:var(--primary); }
html:is([data-ui="navy"],[data-ui="teal"]) .ghost-button:hover{ background:var(--acc-200); }
html:is([data-ui="navy"],[data-ui="teal"]) .metric-card strong{ color:var(--ink); font-weight:700; }
html:is([data-ui="navy"],[data-ui="teal"]) .metric-card small{ color:var(--ui-accent); }
html:is([data-ui="navy"],[data-ui="teal"]) .mc-ic{ background:var(--acc-100); color:var(--ui-accent); }
html:is([data-ui="navy"],[data-ui="teal"]) :is(.chip,.badge,.status-badge){ border-color:transparent; }
html:is([data-ui="navy"],[data-ui="teal"]) .chip.active{ background:var(--acc-200) !important; color:var(--acc-deep) !important; border-color:transparent !important; }
html:is([data-ui="navy"],[data-ui="teal"]) .tabs button.active{ background:var(--primary); color:#fff; }
html:is([data-ui="navy"],[data-ui="teal"]) .data-table th{ background:var(--surface-2); }
html:is([data-ui="navy"],[data-ui="teal"]) .modal{ border-radius:16px; box-shadow:0 30px 70px -24px rgba(13,35,50,.35); }

/* ── The clinic's own colour (the default since 12 Oct) ────────────────────
   MedCloud serves many clinics, so a template paints with the clinic colour unless
   the person unticks it; app.js (_uiPaint) then sets <html data-ui-brand>. The
   pale fills, accent and tinted page come from that colour instead of the
   template's own blue, green or grey. */
html[data-ui-brand]:not([data-ui="classic"]){
  --acc-50:color-mix(in srgb,var(--primary) 5%,#fff);
  --acc-100:color-mix(in srgb,var(--primary) 10%,#fff);
  --acc-200:color-mix(in srgb,var(--primary) 22%,#fff);
  --acc-bright:color-mix(in srgb,var(--primary) 80%,#fff);
  --acc-deep:color-mix(in srgb,var(--primary) 45%,#000);
  --ui-accent:var(--primary);
}
html[data-ui-brand]:is([data-ui="navy"],[data-ui="teal"]){
  --ink:color-mix(in srgb,var(--primary) 14%,#101318);
  --page:color-mix(in srgb,var(--primary) 3%,#fbfcfd);
  --surface-2:color-mix(in srgb,var(--primary) 4%,#fafbfc);
  --line:color-mix(in srgb,var(--primary) 9%,#e4e7ec);
  --line-2:color-mix(in srgb,var(--primary) 13%,#d5dae1);
}

/* ── ทางการ (formal): looped type, square corners, hairlines, no shadows ── */
html[data-ui="formal"]{
  --ink:#1b2430; --muted:#5a6573;
  --page:#f2f4f7; --surface:#ffffff; --surface-2:#f6f7f9;
  --line:#d8dde4; --line-2:#c6ced8;
  --acc-50:#f3f5f9; --acc-100:#e6ebf2; --acc-200:#c4cfdd; --acc-bright:#2c4d77; --acc-deep:#14263d;
  --shadow:none;
}
html[data-ui="formal"] :is(.metric-card,.panel,.lane,.receipt-preview,.dashboard-intake-strip){ border-radius:6px; box-shadow:none; border:1px solid var(--line); }
html[data-ui="formal"] :is(.icon-button,.primary-action,.ghost-button,.visit-card button,.settings-menu button,input,select,textarea,#branchSelector){ border-radius:4px; }
html[data-ui="formal"] :is(.chip,.badge,.status-badge,.cloud-sync-badge,.calendar-toolbar select){ border-radius:4px; }
html[data-ui="formal"] :is(.nav-item,.sidebar-status,.user-card,.brand-mark){ border-radius:4px; }
html[data-ui="formal"] .nav-item.active{ background:var(--acc-100); color:var(--primary); }
html[data-ui="formal"] .nav-item.active::before{ height:100%; border-radius:0; }
html[data-ui="formal"] .primary-action{ background:var(--primary); box-shadow:none; }
html[data-ui="formal"] .primary-action:hover{ transform:none; box-shadow:none; filter:brightness(1.12); }
html[data-ui="formal"] .ghost-button{ background:#fff; border-color:var(--line-2); }
html[data-ui="formal"] .modal{ border-radius:8px; box-shadow:0 24px 60px -20px rgba(20,38,61,.35); }
html[data-ui="formal"] .data-table{ border-radius:4px; }
html[data-ui="formal"] .panel-head{ border-bottom:1px solid var(--line); padding-bottom:10px; }
html[data-ui="formal"] :is(h1,h2,h3){ letter-spacing:0; }

/* ── เอกสารราชการ (document): Sarabun, white paper, ruled tables ───────── */
html[data-ui="document"]{
  --ink:#111827; --muted:#4b5563;
  --page:#ffffff; --surface:#ffffff; --surface-2:#f8f9fb;
  --line:#cfd5dd; --line-2:#b8c0cb;
  --acc-50:#f5f7fb; --acc-100:#e9eef6; --acc-200:#c3cee0; --acc-bright:#2a4f8c; --acc-deep:#122647;
  --shadow:none;
}
html[data-ui="document"] .sidebar{ background:#f8f9fb; }
html[data-ui="document"] :is(.metric-card,.panel,.lane,.receipt-preview,.dashboard-intake-strip){ border-radius:2px; box-shadow:none; border:1px solid var(--line); }
html[data-ui="document"] :is(.icon-button,.primary-action,.ghost-button,.visit-card button,.settings-menu button,input,select,textarea,#branchSelector,.chip,.badge,.status-badge,.cloud-sync-badge,.nav-item,.sidebar-status,.user-card,.brand-mark,.modal,.data-table){ border-radius:2px; }
html[data-ui="document"] .nav-item.active{ background:var(--acc-100); color:var(--primary); font-weight:700; }
html[data-ui="document"] .nav-item.active::before{ height:100%; border-radius:0; width:4px; }
html[data-ui="document"] .primary-action{ background:var(--primary); box-shadow:none; }
html[data-ui="document"] .primary-action:hover{ transform:none; box-shadow:none; filter:brightness(1.12); }
html[data-ui="document"] .ghost-button{ background:#fff; border-color:var(--line-2); color:var(--primary); }
html[data-ui="document"] .panel-head{ border-bottom:2px solid var(--primary); padding-bottom:8px; }
html[data-ui="document"] .data-table th{ background:#eef1f5; color:var(--ink); }
html[data-ui="document"] .data-table :is(th,td){ border-bottom:1px solid var(--line); }
html[data-ui="document"] .modal{ box-shadow:0 20px 50px -20px rgba(17,24,39,.4); }

/* ── ผู้บริหาร (executive): serif headings, charcoal and gold, warm paper ── */
html[data-ui="executive"]{
  --ink:#1f2328; --muted:#6b6560;
  --page:#f7f5f0; --surface:#fffefb; --surface-2:#faf8f3;
  --line:#e6e0d4; --line-2:#d8cfbd;
  --acc-50:#f7f4ed; --acc-100:#efe9dc; --acc-200:#dccfb2; --acc-bright:#3a4552; --acc-deep:#15191e;
  --gold:#a8843f; --gold-deep:#8a6a2c; --gold-line:#d8c193;
  --shadow:0 1px 2px rgba(31,35,40,.05),0 12px 26px -18px rgba(31,35,40,.25);
}
html[data-ui="executive"] :is(.metric-card,.panel,.lane,.receipt-preview,.dashboard-intake-strip){ border-radius:10px; border:1px solid var(--line); }
html[data-ui="executive"] :is(.icon-button,.primary-action,.ghost-button,input,select,textarea,#branchSelector,.nav-item){ border-radius:8px; }
html[data-ui="executive"] .nav-item.active{ background:var(--acc-100); color:var(--ink); }
html[data-ui="executive"] .nav-item.active::before{ background:var(--gold); }
html[data-ui="executive"] .primary-action{ background:var(--primary); box-shadow:inset 0 -2px 0 var(--gold); }
html[data-ui="executive"] .primary-action:hover{ transform:none; filter:brightness(1.15); }
html[data-ui="executive"] .ghost-button{ color:var(--ink); border-color:var(--line-2); background:var(--surface); }
html[data-ui="executive"] .metric-card small{ color:var(--gold-deep); }
html[data-ui="executive"] :is(h1,h2,h3){ font-weight:600; letter-spacing:0; }
html[data-ui="executive"] .brand-mark{ box-shadow:0 0 0 1.5px var(--gold-line); }

/* ── มินิมอล (minimal): black and white, flat, big numbers ────────────── */
html[data-ui="minimal"]{
  --ink:#09090b; --muted:#71717a;
  --page:#fafafa; --surface:#ffffff; --surface-2:#f4f4f5;
  --line:#e4e4e7; --line-2:#d4d4d8;
  --acc-50:#f4f4f5; --acc-100:#ececee; --acc-200:#d4d4d8; --acc-bright:#3f3f46; --acc-deep:#000000;
  --shadow:none;
}
html[data-ui="minimal"] :is(.metric-card,.panel,.lane,.receipt-preview,.dashboard-intake-strip){ border-radius:12px; box-shadow:none; border:1px solid var(--line); }
html[data-ui="minimal"] :is(.icon-button,.primary-action,.ghost-button,input,select,textarea,#branchSelector,.nav-item){ border-radius:8px; }
html[data-ui="minimal"] .nav-item.active{ background:var(--primary); color:#fff; }
html[data-ui="minimal"] .nav-item.active::before{ display:none; }
html[data-ui="minimal"] .primary-action{ background:var(--primary); box-shadow:none; }
html[data-ui="minimal"] .primary-action:hover{ transform:none; filter:none; background:#3f3f46; }
html[data-ui="minimal"] .ghost-button{ color:var(--ink); border-color:var(--line-2); background:#fff; }
html[data-ui="minimal"] .metric-card strong{ font-weight:700; letter-spacing:-.5px; }
html[data-ui="minimal"] .metric-card small{ color:var(--muted); }

/* ── Picker ─────────────────────────────────────────────────────────────── */
.ui-picker-heading{ margin:14px 0 8px; font-size:15px; font-weight:700; color:#0f172a; }
.ui-template-picker{ display:grid; gap:12px; }
.ui-tpl-grid{ display:grid; grid-template-columns:repeat(auto-fill,minmax(190px,1fr)); gap:10px; }
.ui-tpl-card-btn{ min-width:0; overflow:hidden; display:flex; flex-direction:column; gap:8px; padding:10px; border:1px solid #e2e8f0; border-radius:12px; background:#fff; cursor:pointer; text-align:left; font:inherit; color:#0f172a; transition:border-color .12s, box-shadow .12s; }
.ui-tpl-card-btn:hover{ border-color:#94a3b8; }
.ui-tpl-card-btn.is-active{ border-color:var(--primary); box-shadow:0 0 0 2px color-mix(in srgb,var(--primary),transparent 75%); }
.ui-tpl-preview{ display:flex; gap:8px; padding:8px; height:116px; overflow:hidden; border:1px solid rgba(15,23,42,.06); }
.ui-tpl-side{ display:flex; flex-direction:column; gap:6px; width:30px; padding:6px 5px; border:1px solid; border-radius:6px; }
.ui-tpl-side i{ display:block; height:7px; border-radius:3px; background:#e2e8f0; }
.ui-tpl-side i:first-child{ height:14px; }
.ui-tpl-card{ flex:1; min-width:0; display:flex; flex-direction:column; gap:4px; padding:8px 10px; }
.ui-tpl-label{ font-size:12px; white-space:nowrap; }
.ui-tpl-num{ font-size:20px; font-weight:700; line-height:1.15; white-space:nowrap; }
.ui-tpl-btn{ align-self:flex-start; margin-top:auto; padding:2px 10px; color:#fff; font-size:12px; line-height:1.6; }
.ui-tpl-meta{ display:flex; flex-direction:column; gap:2px; }
.ui-tpl-meta strong{ font-size:15px; }
.ui-tpl-meta small{ font-size:13px; color:#475569; line-height:1.45; }
.ui-tpl-meta small.ui-tpl-font{ color:#64748b; }
.ui-tpl-options{ display:grid; gap:10px; padding:12px; border:1px solid #e2e8f0; border-radius:12px; background:#f8fafc; }
.ui-tpl-field{ display:grid; gap:4px; font-size:14px; font-weight:600; color:#0f172a; }
.ui-tpl-field select{ font-size:14px; padding:8px 10px; max-width:100%; }
.ui-tpl-check{ display:flex; align-items:center; gap:8px; font-size:14px; color:#0f172a; cursor:pointer; }
.ui-tpl-check input{ width:18px; height:18px; }
.ui-tpl-check small{ display:block; font-size:13px; color:#64748b; }
.ui-tpl-colour{ align-items:flex-start; margin:0 0 12px; padding:10px 12px; border:1px solid #e2e8f0; border-radius:12px; background:#f8fafc; }
.ui-tpl-colour input{ margin-top:2px; flex:none; }
.ui-tpl-colour-hint{ margin:0 0 12px; font-size:13px; color:#64748b; }
.ui-tpl-swatch{ display:inline-block; width:14px; height:14px; border-radius:4px; vertical-align:-2px; box-shadow:inset 0 0 0 1px rgba(0,0,0,.15); }
.ui-tpl-sample{ margin:0; font-size:16px; color:#0f172a; }
.ui-tpl-clinic-btn{ display:grid; gap:2px; padding:10px 14px; border:1px dashed var(--primary); border-radius:12px; background:#fff; cursor:pointer; text-align:left; font:inherit; font-size:14px; font-weight:600; color:#0f172a; }
.ui-tpl-clinic-btn small{ font-size:13px; font-weight:400; color:#475569; }
@media(max-width:520px){ .ui-tpl-grid{ grid-template-columns:repeat(2,minmax(0,1fr)); } .ui-tpl-preview{ height:100px; } .ui-tpl-side{ display:none; } .ui-tpl-num{ font-size:16px; } .ui-tpl-card{ padding:8px; } }


/* MedCloud trial → view-only banner (21g, launch item B). Fixed on top; the app pads body by its height. */
.billing-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100001;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 14px;
  padding: 8px 16px; color: #fff; font-size: 14px; line-height: 1.5; text-align: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.billing-banner.is-blocked { background: #be123c; }
.billing-banner.is-trial { background: #6d28d9; }
.billing-banner button {
  background: #fff; color: #be123c; border: none; border-radius: 7px; padding: 6px 14px;
  font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit;
}

/* 💳 ประวัติการชำระเงินในแฟ้มลูกค้า (28 ต.ค. 69) */
.pay-history-summary{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
.pay-history-summary>div{display:grid;gap:2px;padding:10px 12px;border:1px solid var(--line);border-radius:8px;background:#fff}
.pay-history-summary span{color:var(--muted);font-size:13px;font-weight:700}
.pay-history-summary strong{font-size:20px}
.pay-history-summary em{color:var(--muted);font-size:13px;font-style:normal}
.pay-history-summary .is-due{border-color:#fca5a5;background:#fef2f2}
.pay-history-summary .is-due strong{color:#b91c1c}
.pay-history-row strong{display:flex;flex-wrap:wrap;align-items:center;gap:6px}
.pay-history-row .pay-amount{font-size:17px;color:inherit}
.pay-history-row .pay-kind{font-size:12px;font-weight:700;padding:2px 8px;border-radius:999px;background:#ede9fe;color:#5b21b6}
.pay-history-row .pay-kind.void{background:#fee2e2;color:#b91c1c}
.pay-history-row.is-void{opacity:.7;border-left-color:#cbd5e1}
.pay-history-row.is-void .pay-amount{text-decoration:line-through}
.timeline-item .visit-paid{color:#047857;font-weight:600}
@media (max-width:560px){.pay-history-summary{grid-template-columns:1fr}}

