﻿:root {
  --ink: #0f172a;
  --muted: #64748b;
  --line: #dbe4ee;
  --bg: #f5f8fb;
  --panel: #ffffff;
  --teal: #0f766e;
  --teal-2: #115e59;
  --soft: #ecfeff;
  --amber: #f59e0b;
  --red: #dc2626;
  --green: #16a34a;
  --blue: #2563eb;
  font-family: "Sarabun", "Noto Sans Thai", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; }
body.modal-open { overflow: hidden; }
button, input, select, textarea { font: inherit; }
button { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 13px; cursor: pointer; color: var(--ink); }
button.primary { background: var(--teal); color: white; border-color: var(--teal); font-weight: 700; }
button.danger { color: var(--red); }
button:disabled { opacity: .55; cursor: not-allowed; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; color: var(--ink); }
.app { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.side { background: #082f2c; color: #e6fffb; padding: 18px 14px; display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: #14b8a6; color: white; font-weight: 900; font-size: 22px; }
.brand strong { display: block; font-size: 18px; }
.brand span { color: #b7dfd8; font-size: 13px; }
.nav { display: grid; gap: 7px; }
.nav button { text-align: left; background: transparent; color: #dffdf8; border-color: transparent; padding: 10px 12px; }
.nav button.active { background: rgba(20, 184, 166, .17); border-color: rgba(125, 211, 252, .24); }
.side-note { margin-top: auto; color: #b7dfd8; font-size: 13px; line-height: 1.45; }
.main { padding: 22px 26px 40px; min-width: 0; }
.top { display: flex; gap: 14px; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; }
h1 { font-size: 28px; margin: 0 0 4px; line-height: 1.2; }
h2 { font-size: 20px; margin: 0; }
h3 { font-size: 17px; margin: 0; }
p { margin: 0; color: var(--muted); }
.user-box { min-width: 220px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 11px 13px; }
.user-box b { display: block; }
.user-box span { color: var(--muted); font-size: 13px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.panel-head { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.grid { display: grid; gap: 12px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.workflow-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.workflow-strip .step { border: 1px solid var(--line); border-left: 4px solid var(--teal); background: #fff; border-radius: 14px; padding: 13px 14px; text-align: left; }
.workflow-strip .step b, .workflow-strip .step span { display: block; }
.workflow-strip .step b { font-size: 17px; }
.workflow-strip .step span { color: var(--muted); font-size: 13px; margin-top: 3px; }
.workflow-strip .step.active { background: #f0fdfa; border-color: #99f6e4; border-left-color: var(--teal); }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.metric span { color: var(--muted); font-size: 13px; }
.metric b { display: block; font-size: 24px; margin-top: 5px; }
.metric.allergy-metric { background: #fff1f2; border-color: #fecaca; }
.metric.allergy-metric span, .metric.allergy-metric b { color: #991b1b; }
.metric.disease-metric { background: #fff7ed; border-color: #fed7aa; }
.metric.disease-metric span, .metric.disease-metric b { color: #9a3412; }
.controls { display: grid; grid-template-columns: 160px 180px minmax(180px, 1fr) auto; gap: 10px; align-items: end; }
.calendar-date-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0 8px; }
.calendar-date-tools button { padding: 7px 10px; }
.date-chip-list { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.date-chip-list button { background: #f8fafc; color: var(--teal-2); font-size: 13px; }
.details { border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; background: #f8fafc; }
.details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.source-row { display: grid; grid-template-columns: minmax(180px, 1fr) auto; gap: 8px; margin-top: 10px; }
.appointment-list { display: grid; gap: 8px; }
.test-brief-panel { border-left: 4px solid var(--teal); }
.test-brief-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.test-brief-grid p { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); font-size: 13px; line-height: 1.45; padding: 10px; }
.test-brief-grid b { color: var(--teal-2); }
.appt { display: grid; grid-template-columns: 82px minmax(0, 1fr) auto; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; background: #fff; }
.appt-time b { display: block; font-size: 20px; }
.appt-time span, .small { color: var(--muted); font-size: 12px; }
.appt-main b { display: block; font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.appt-main span { color: var(--muted); font-size: 13px; }
.appt-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
#goal1CashierPanel { display: grid; gap: 14px; }
#goal1CashierPanel > .panel-head { margin-top: 8px; }
#goal1CashierPanel > .panel-head:first-child { margin-top: 0; }
.finance-row { align-items: start; grid-template-columns: minmax(150px, .55fr) minmax(0, 1fr) minmax(180px, .45fr); }
.finance-row.waiting { border-left: 4px solid #f59e0b; }
.finance-row.partial { border-left: 4px solid #2563eb; }
.finance-row.overdue { border-left: 4px solid #dc2626; }
.finance-row.paid { border-left: 4px solid #16a34a; }
.finance-row.credit { border-left: 4px solid var(--teal); }
.finance-status { align-items: flex-start; display: flex; flex-direction: column; gap: 6px; }
.finance-amounts { display: grid; gap: 6px; justify-items: end; text-align: right; }
.finance-amounts span { color: var(--muted); font-size: 12px; }
.finance-amounts b { font-size: 18px; }
button.secondary { background: #f8fafc; border-color: #99f6e4; color: var(--teal-2); font-weight: 700; }
button.tertiary { background: #fff; color: #475569; }
button.credit-action { background: #ecfeff; border-color: #99f6e4; color: #115e59; font-weight: 700; }
.patients-panel .panel-head .appt-actions { align-items: center; }
.patient-list { display: grid; gap: 8px; margin-top: 12px; }
.patient-row { align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 14px; display: grid; gap: 12px; grid-template-columns: minmax(140px, 210px) minmax(0, 1fr) auto; min-height: 72px; padding: 12px; }
.patient-code { align-items: center; display: flex; gap: 8px; min-width: 0; }
.patient-code .pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.patient-main { min-width: 0; }
.patient-main b { display: block; font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.patient-main span { color: var(--muted); display: block; font-size: 13px; margin-top: 3px; overflow-wrap: anywhere; }
.allergy-alert { background: #fee2e2; border: 1px solid #fecaca; border-radius: 12px; color: #991b1b; display: inline-flex; font-weight: 800; line-height: 1.35; padding: 8px 10px; overflow-wrap: anywhere; }
.allergy-alert.compact { border-radius: 999px; font-size: 12px; margin-top: 6px; padding: 4px 9px; }
.disease-alert { background: #ffedd5; border: 1px solid #fed7aa; border-radius: 12px; color: #9a3412; display: inline-flex; font-weight: 800; line-height: 1.35; padding: 8px 10px; overflow-wrap: anywhere; }
.disease-alert.compact { border-radius: 999px; font-size: 12px; margin-top: 6px; padding: 4px 9px; }
.patient-profile-alert, .patient-chart-header-alert { margin: 8px 0 12px; }
.patient-profile-alert, .patient-chart-header-alert { display: flex; flex-wrap: wrap; gap: 8px; }
.patient-avatar { align-items: center; background: #ccfbf1; border: 1px solid #99f6e4; border-radius: 999px; color: var(--teal-2); display: inline-flex; flex: 0 0 auto; font-size: 13px; font-weight: 900; height: 38px; justify-content: center; overflow: hidden; width: 38px; }
.patient-avatar.large { font-size: 22px; height: 92px; width: 92px; }
.patient-avatar img { display: block; height: 100%; object-fit: cover; width: 100%; }
.patient-profile-head { align-items: center; display: flex; gap: 14px; margin-bottom: 12px; }
.appt-badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 999px; background: #eef2ff; color: #1e40af; font-size: 12px; font-weight: 700; }
.pill.waiting { background: #fef3c7; color: #92400e; }
.pill.partial { background: #dbeafe; color: #1d4ed8; }
.pill.overdue { background: #fee2e2; color: #991b1b; }
.pill.paid { background: #dcfce7; color: #166534; }
.pill.present { background: #dcfce7; color: #166534; }
.pill.absent { background: #fee2e2; color: #991b1b; }
.pill.danger { background: #fee2e2; color: #991b1b; }
.pill.early { background: #e0f2fe; color: #075985; }
.late-note { color: var(--red); font-size: 13px; font-weight: 800; }
.status { min-height: 22px; color: var(--muted); font-size: 13px; margin-top: 8px; }
.walkin-toast { position: fixed; right: 20px; bottom: 20px; z-index: 90; background: #ecfdf5; border: 1px solid #86efac; border-radius: 12px; color: #166534; padding: 10px 14px; box-shadow: 0 14px 40px rgba(15, 23, 42, .16); }
.empty { padding: 26px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 14px; background: #fff; }
.mobile-photo-panel { border-left: 4px solid var(--teal); }
.mobile-photo-grid { display: grid; grid-template-columns: minmax(0, 1fr) 210px; gap: 12px; align-items: stretch; }
.mobile-photo-link { display: grid; gap: 8px; min-width: 0; }
.mobile-photo-link input { font-family: Consolas, "Courier New", monospace; font-size: 13px; }
.mobile-photo-qr { border: 1px dashed var(--line); border-radius: 14px; background: #f8fafc; display: grid; gap: 6px; justify-items: center; min-height: 220px; padding: 12px; text-align: center; }
.mobile-photo-qr b { color: var(--teal-2); }
.mobile-photo-qr span { color: var(--muted); font-size: 12px; line-height: 1.35; }
.qr-svg { width: 180px; height: 180px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.mobile-photo-inbox { border-top: 1px solid var(--line); color: var(--muted); display: grid; gap: 4px; font-size: 13px; margin-top: 12px; padding-top: 10px; }
.mobile-photo-inbox b { color: var(--ink); }
.mobile-photo-inbox-summary { display: grid; gap: 2px; }
.mobile-photo-inbox-row { align-items: center; border: 1px solid var(--line); border-radius: 12px; display: grid; gap: 10px; grid-template-columns: 58px minmax(0, 1fr); padding: 8px; }
.mobile-photo-inbox-row div { display: grid; gap: 3px; min-width: 0; }
.mobile-photo-inbox-row a { color: var(--teal-2); font-weight: 700; text-decoration: none; }
.mobile-photo-thumb { background: #fff; border: 1px solid var(--line); border-radius: 10px; height: 54px; overflow: hidden; width: 54px; }
.mobile-photo-thumb img { display: block; height: 100%; object-fit: cover; width: 100%; }
.mobile-photo-history-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.mobile-photo-history-card { border: 1px solid var(--line); border-radius: 12px; color: var(--ink); display: grid; gap: 5px; overflow: hidden; padding: 8px; text-decoration: none; }
.mobile-photo-history-card img { aspect-ratio: 1 / 1; border-radius: 8px; object-fit: cover; width: 100%; }
.mobile-photo-history-card b { font-size: 13px; }
.mobile-photo-history-card span { color: var(--muted); font-size: 12px; line-height: 1.3; }
.login-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, .42); display: grid; place-items: center; padding: 20px; }
.login-card { width: min(420px, 100%); background: #fff; border-radius: 18px; padding: 22px; box-shadow: 0 24px 90px rgba(15, 23, 42, .28); }
.login-card h2 { margin-bottom: 4px; }
.login-card .grid { margin-top: 16px; }
.patient-chart-backdrop { overflow: hidden; padding: 24px; }
.patient-chart-backdrop .patient-chart-card {
  width: min(1200px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, .9fr);
  align-content: start;
  gap: 12px;
  padding: 0 18px 18px;
}
.patient-chart-card > .panel-head {
  position: sticky;
  top: 0;
  z-index: 2;
  grid-column: 1 / -1;
  background: #fff;
  border-bottom: 1px solid var(--line);
  margin: 0 -18px 4px;
  padding: 16px 18px;
}
.patient-chart-card > .grid,
.patient-chart-card > .mobile-photo-panel,
.patient-chart-card > .panel:not(.patient-chart-treatment),
.patient-chart-card > .status { grid-column: 1; }
.patient-chart-card > .patient-chart-treatment {
  grid-column: 2;
  grid-row: 2 / span 6;
  align-self: start;
  margin-bottom: 0;
}
.patient-chart-card > .panel { margin-bottom: 0; }
.patient-chart-card textarea { min-height: 108px; resize: vertical; }
.patient-related-backdrop { z-index: 70; }
.patient-related-card { max-height: 86vh; overflow-y: auto; width: min(860px, 94vw); }
.patient-related-card > .panel-head { position: sticky; top: 0; z-index: 2; background: #fff; border-bottom: 1px solid var(--line); margin: -22px -22px 12px; padding: 16px 22px; }
#goal1PaymentModal { overflow: hidden; padding: 24px; }
#goal1PaymentModal .finance-payment-card {
  width: min(980px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
}
#goal1PaymentModal .finance-payment-card > .panel-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  border-bottom: 1px solid var(--line);
  margin: -22px -22px 8px;
  padding: 16px 22px;
}
.finance-payment-summary .metric b { font-size: 20px; overflow-wrap: anywhere; }
.finance-payment-form .small { display: block; margin-top: 5px; }
.patient-create-card { max-height: 92vh; overflow-y: auto; width: min(980px, 94vw); }
.patient-create-card .panel { margin-bottom: 0; }
.patient-create-card h3 { margin: 16px 0 8px; }
.patient-photo-create { align-items: center; border: 1px dashed var(--line); border-radius: 14px; display: grid; gap: 12px; grid-template-columns: 110px minmax(0, 1fr); padding: 12px; }
.patient-photo-create-grid { display: grid; gap: 12px; grid-template-columns: minmax(260px, .85fr) minmax(320px, 1.15fr); }
.patient-photo-create p { font-size: 13px; }
.sticky-actions { background: #fff; bottom: 0; border-top: 1px solid var(--line); margin: 14px -16px -16px; padding: 12px 16px; position: sticky; }
.suggestion-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.suggestion-chips button { background: #f8fafc; color: var(--teal-2); font-size: 12px; padding: 6px 9px; }
.suggestion-chips .suggestion-toggle { border-style: dashed; color: var(--ink); font-weight: 700; }
.suggestion-label { color: var(--muted); display: block; font-size: 12px; font-weight: 700; margin: 4px 0 5px; }
.login-help { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.login-help span { background: #eef2f7; color: #475569; border-radius: 999px; padding: 5px 9px; font-size: 12px; }
.hidden { display: none !important; }
.receipt-modal-card { width: min(860px, 100%); }
.receipt-print-card { display: grid; gap: 12px; }
.receipt-print-head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.receipt-print-head b, .receipt-print-head span { display: block; }
.receipt-print-head b { font-size: 18px; }
.receipt-print-head span { color: var(--muted); font-size: 13px; margin-top: 3px; }
.receipt-print-head div:last-child { text-align: right; }
.receipt-line { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 12px; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; background: #fff; }
.receipt-line span { color: var(--muted); }
.receipt-line b { overflow-wrap: anywhere; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; z-index: 5; flex-direction: row; align-items: center; overflow-x: auto; }
  .side-note { display: none; }
  .nav { display: flex; min-width: max-content; }
  .main { padding: 16px; }
  .top, .panel-head { align-items: stretch; flex-direction: column; }
  .grid.cols-4, .grid.cols-3, .controls, .source-row, .mobile-photo-grid, .appt, .patient-row { grid-template-columns: 1fr; }
  .patient-chart-backdrop { align-items: stretch; padding: 10px; }
  .patient-chart-backdrop .patient-chart-card {
    width: min(100%, 94vw);
    max-height: 92vh;
    grid-template-columns: 1fr;
    padding: 0 12px 12px;
  }
  .patient-chart-card > .panel-head { margin: 0 -12px 4px; padding: 13px 12px; }
  .patient-chart-card > .grid,
  .patient-chart-card > .mobile-photo-panel,
  .patient-chart-card > .panel,
  .patient-chart-card > .status,
  .patient-chart-card > .patient-chart-treatment { grid-column: 1; grid-row: auto; }
  .calendar-date-tools button, .date-chip-list button { flex: 1 1 140px; }
  .workflow-strip { grid-template-columns: 1fr; }
  .appt-actions { justify-content: stretch; }
  .appt-actions button { flex: 1 1 120px; }
  .finance-row { grid-template-columns: 1fr; }
  .finance-amounts { justify-items: stretch; text-align: left; }
  .patient-photo-create, .patient-photo-create-grid, .patient-profile-head { grid-template-columns: 1fr; flex-direction: column; align-items: flex-start; }
  .receipt-print-head, .receipt-line { grid-template-columns: 1fr; flex-direction: column; }
  .receipt-print-head div:last-child { text-align: left; }
}
@media print {
  body * { visibility: hidden !important; }
  #goal1ReceiptModal, #goal1ReceiptModal * { visibility: visible !important; }
  #goal1ReceiptModal { position: static !important; inset: auto !important; display: block !important; background: #fff !important; padding: 0 !important; }
  #goal1ReceiptModal .login-card { width: 100% !important; box-shadow: none !important; border-radius: 0 !important; padding: 0 !important; }
  #goal1ReceiptModal .no-print { display: none !important; }
  #goal1ReceiptModal .receipt-print-card { border: 0 !important; border-radius: 0 !important; margin: 0 !important; padding: 0 !important; }
  #goal1ReceiptModal .receipt-summary { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
  #goal1ReceiptModal button { display: none !important; }
}
