/* =====================================================================
   app.css — ระบบส่งต่อคนไข้ สูติ-นรีเวชกรรม รพ.พุทธชินราช (mobile-first)
   ===================================================================== */
:root {
  --brand:        #1f7a8c;
  --brand-dark:   #146073;
  --brand-soft:   #e3f0f3;
  --accent:       #d64550;
  --bg:           #f3f5f7;
  --surface:      #ffffff;
  --surface-2:    #eef1f4;
  --text:         #17202a;
  --text-soft:    #5b6672;
  --border:       #dfe3e8;
  --danger:       #d64550;
  --warn:         #b26a00;
  --ok:           #1a8f4c;
  --radius:       14px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --maxw:         560px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand:      #4bb3c7;
    --brand-dark: #7fd0df;
    --brand-soft: #1d2b30;
    --bg:         #14171a;
    --surface:    #1e2226;
    --surface-2:  #272c31;
    --text:       #e8eaec;
    --text-soft:  #9aa3ad;
    --border:     #333a41;
    --shadow:     0 1px 3px rgba(0,0,0,.4);
  }
}

/* ===== ธีมสีที่ผู้ใช้เลือกได้ (localStorage: bd_theme + จำไว้ในโปรไฟล์) ===== */
:root[data-theme="teal"]   { --brand:#1f7a8c; --brand-dark:#146073; --brand-soft:#e3f0f3; }
:root[data-theme="blue"]   { --brand:#2563eb; --brand-dark:#1d4ed8; --brand-soft:#e7eefe; }
:root[data-theme="indigo"] { --brand:#4f46e5; --brand-dark:#4338ca; --brand-soft:#ebe9fe; }
:root[data-theme="green"]  { --brand:#0f9d58; --brand-dark:#0b7c44; --brand-soft:#e3f5ec; }
:root[data-theme="rose"]   { --brand:#e11d63; --brand-dark:#be1250; --brand-soft:#fde7f0; }
:root[data-theme="orange"] { --brand:#e8710a; --brand-dark:#c85e05; --brand-soft:#fdece0; }
:root[data-theme="slate"]  { --brand:#475569; --brand-dark:#334155; --brand-soft:#e9edf2; }
:root[data-theme="purple"] { --brand:#7c3aed; --brand-dark:#6d28d9; --brand-soft:#f0e9fe; }
:root[data-theme="red"]     { --brand:#dc2626; --brand-dark:#b91c1c; --brand-soft:#fce8e8; }
:root[data-theme="amber"]   { --brand:#d97706; --brand-dark:#b45309; --brand-soft:#fdf1e0; }
:root[data-theme="lime"]    { --brand:#65a30d; --brand-dark:#4d7c0f; --brand-soft:#eef6e0; }
:root[data-theme="cyan"]    { --brand:#0891b2; --brand-dark:#0e7490; --brand-soft:#e0f4f8; }
:root[data-theme="fuchsia"] { --brand:#c026d3; --brand-dark:#a21caf; --brand-soft:#f9e5fb; }
:root[data-theme="brown"]   { --brand:#8b5e34; --brand-dark:#6b4423; --brand-soft:#f2e8dd; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="teal"]   { --brand:#4bb3c7; --brand-dark:#7fd0df; --brand-soft:#1d2b30; }
  :root[data-theme="blue"]   { --brand:#5b8def; --brand-dark:#93b4f7; --brand-soft:#1b2536; }
  :root[data-theme="indigo"] { --brand:#8b83f0; --brand-dark:#aca6f5; --brand-soft:#232135; }
  :root[data-theme="green"]  { --brand:#3fc27f; --brand-dark:#74d6a3; --brand-soft:#17271f; }
  :root[data-theme="rose"]   { --brand:#f0578c; --brand-dark:#f58bb0; --brand-soft:#331d27; }
  :root[data-theme="orange"] { --brand:#f0913f; --brand-dark:#f5b273; --brand-soft:#332619; }
  :root[data-theme="slate"]  { --brand:#8797ad; --brand-dark:#a9b6c7; --brand-soft:#232830; }
  :root[data-theme="red"]     { --brand:#f87171; --brand-dark:#fca5a5; --brand-soft:#331c1c; }
  :root[data-theme="amber"]   { --brand:#fbbf24; --brand-dark:#fcd34d; --brand-soft:#332a12; }
  :root[data-theme="lime"]    { --brand:#a3e635; --brand-dark:#bef264; --brand-soft:#212b16; }
  :root[data-theme="cyan"]    { --brand:#22d3ee; --brand-dark:#67e8f9; --brand-soft:#16292d; }
  :root[data-theme="fuchsia"] { --brand:#e879f9; --brand-dark:#f0abfc; --brand-soft:#2e1a30; }
  :root[data-theme="brown"]   { --brand:#c08552; --brand-dark:#d9a876; --brand-soft:#2b2117; }
  :root[data-theme="purple"] { --brand:#a279f2; --brand-dark:#c0a3f7; --brand-soft:#271f36; }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sarabun",
               "Helvetica Neue", Arial, "Noto Sans Thai", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
[hidden] { display: none !important; }
img { max-width: 100%; }

/* ---------- layout ---------- */
.app-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top, 0));
  background: var(--brand); color: #fff;
}
.app-bar__left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-bar__back { color: #fff; text-decoration: none; font-size: 1.3rem; line-height: 1; }
.app-bar__title { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-bar__right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.app-bar__role {
  font-size: .74rem; background: rgba(255,255,255,.2); padding: 3px 9px;
  border-radius: 999px; white-space: nowrap; flex: 0 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; max-width: 55%;
}
.app-bar__title { min-width: 0; }

/* ปุ่มเปลี่ยนธีมบน app-bar — ไอคอนถาดสีขาวบนแถบสีแบรนด์ */
.theme-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; cursor: pointer;
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.55);
  color: #fff; padding: 0; transition: background .15s;
}
.theme-dot:hover { background: rgba(255,255,255,.3); }
.theme-dot:active { background: rgba(255,255,255,.4); }
.theme-dot svg { display: block; }

/* theme picker */
.theme-swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-swatch {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; border: 2px solid var(--border);
  padding: 0; background-clip: padding-box;
}
.theme-swatch.is-active { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--brand); }
.theme-swatch--teal   { background:#1f7a8c; } .theme-swatch--blue { background:#2563eb; }
.theme-swatch--indigo { background:#4f46e5; } .theme-swatch--green { background:#0f9d58; }
.theme-swatch--rose   { background:#e11d63; } .theme-swatch--orange { background:#e8710a; }
.theme-swatch--slate  { background:#475569; } .theme-swatch--purple { background:#7c3aed; }
.theme-swatch--red    { background:#dc2626; } .theme-swatch--amber { background:#d97706; }
.theme-swatch--lime   { background:#65a30d; } .theme-swatch--cyan  { background:#0891b2; }
.theme-swatch--fuchsia{ background:#c026d3; } .theme-swatch--brown { background:#8b5e34; }
.container { max-width: var(--maxw); margin: 0 auto; padding: 18px 16px 40px; }
.app-foot {
  max-width: var(--maxw); margin: 0 auto;
  padding: 18px 16px calc(24px + env(safe-area-inset-bottom, 0));
  color: var(--text-soft); font-size: .78rem; text-align: center;
}
.app-foot__sub { font-size: .72rem; }

/* ---------- welcome ---------- */
.welcome {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  margin-bottom: 22px;
}
.welcome__pic { width: 54px; height: 54px; border-radius: 50%; object-fit: cover; flex: none; background: var(--surface-2); }
.welcome__hi { margin: 0; color: var(--text-soft); font-size: .85rem; }
.welcome__name { margin: 2px 0 0; font-size: 1.2rem; }
.welcome__sub { margin: 3px 0 0; font-size: .82rem; color: var(--text-soft); }

.section-title { margin: 26px 4px 12px; font-size: .95rem; color: var(--text-soft); font-weight: 700; }
.crumb { color: var(--text-soft); font-size: .85rem; margin: 0 2px 14px; }
.crumb a { color: var(--brand-dark); text-decoration: none; }
.hint { color: var(--text-soft); font-size: .88rem; margin: 0 2px 14px; }

/* ---------- menu grid ---------- */
.menu-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.menu-card {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; text-decoration: none;
  box-shadow: var(--shadow); transition: transform .12s ease, border-color .12s ease;
}
.menu-card:active { transform: scale(.98); border-color: var(--brand); }
.menu-card__icon { font-size: 1.7rem; line-height: 1; }
.menu-card__name { font-weight: 700; }
.menu-card__desc { font-size: .8rem; color: var(--text-soft); }
.menu-card__badge {
  align-self: flex-start; margin-top: 2px; font-size: .72rem; font-weight: 700;
  background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 8px;
}

/* ---------- dashboard: อัปเดตสถานะคนไข้ ---------- */
.update-card { border-color: var(--brand); }
.update-card > h3 { color: var(--brand-dark); }
.update-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.update-list li { font-size: .9rem; line-height: 1.6; }
.update-list .badge-status { margin-right: 6px; }

/* ---------- stat row ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; text-align: center;
}
.stat__num { font-size: 1.5rem; font-weight: 800; color: var(--brand-dark); }
.stat__lbl { font-size: .76rem; color: var(--text-soft); }

/* ---------- form ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.form__section {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 14px 16px; display: flex; flex-direction: column; gap: 14px;
}
.form__section > h3 {
  margin: 0; font-size: .86rem; text-transform: uppercase; letter-spacing: .03em;
  color: var(--brand-dark); border-bottom: 1px solid var(--border); padding-bottom: 8px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: .9rem; font-weight: 600; }
.field__label b { color: var(--danger); font-weight: 700; }
.field input, .field select, .field textarea {
  font: inherit; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); color: var(--text); width: 100%;
}
.field textarea { resize: vertical; min-height: 68px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand);
}
.field--invalid input, .field--invalid select, .field--invalid textarea {
  border-color: var(--danger);
  background: rgba(214,69,80,.05);
}
.field--invalid .field__label { color: var(--danger); }
.field__err { color: var(--danger); font-size: .82rem; font-weight: 600; min-height: 1em; margin-top: 2px; }
.field__err:not(:empty)::before { content: "⚠ "; }
.field__hint { color: var(--text-soft); font-size: .78rem; }
.field__hint.is-ok { color: var(--ok); font-weight: 600; }

/* Lab Investigation: ค่าผิดปกติ (นอกช่วงปกติ) */
.lab-warn { display: none; color: var(--danger); }
.field--labwarn .field__label { color: var(--danger); }
.field--labwarn .lab-warn { display: inline; }
.field--labwarn .lab-input { border-color: var(--danger); background: rgba(214,69,80,.05); color: var(--danger); font-weight: 700; }

.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; min-width: 0; }

.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 999px; padding: 7px 12px;
  font-size: .88rem; cursor: pointer; background: var(--surface);
}
.check input { width: auto; }
.check:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }

.form__msg { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: .9rem; white-space: pre-wrap; word-break: break-word; }
.form__msg--error { background: rgba(214,69,80,.12); color: var(--danger); }
.form__msg--ok { background: rgba(26,143,76,.14); color: var(--ok); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; padding: 13px 18px; border-radius: 12px;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background .12s ease, opacity .12s ease;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-block { width: 100%; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-sm { padding: 9px 13px; font-size: .85rem; border-radius: 9px; }
.btn.is-loading::after {
  content: ""; width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,.5); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
.btn-bar { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-bar .btn { flex: 1 1 auto; }

/* ---------- case list ---------- */
.filter-bar {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; margin-bottom: 14px; display: flex; gap: 8px; flex-wrap: wrap;
}
.filter-bar select, .filter-bar input {
  font: inherit; flex: 1 1 130px; min-width: 0; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text);
}

.case-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.case-item {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 14px; text-decoration: none; box-shadow: var(--shadow);
}
.case-item:active { border-color: var(--brand); }
.case-item__body { display: block; text-decoration: none; color: inherit; }
.case-item__top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.case-item__no { font-weight: 700; font-size: .92rem; color: var(--brand-dark); }
.case-item__name { font-weight: 700; margin-top: 3px; }
.case-item__meta { font-size: .82rem; color: var(--text-soft); margin-top: 2px; }
.case-item__meta b { color: var(--text); font-weight: 600; }
.case-item__actions {
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border);
  display: flex; gap: 8px; flex-wrap: wrap;
}
.case-item__actions .btn { text-decoration: none; }

/* ---------- status badge ---------- */
.badge-status {
  font-size: .72rem; font-weight: 700; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-soft); white-space: nowrap;
}
.st-DRAFT     { background: var(--surface-2); color: var(--text-soft); }
.st-SENT      { background: rgba(31,122,140,.15); color: var(--brand-dark); }
.st-ACCEPTED  { background: rgba(178,106,0,.16); color: var(--warn); }
.st-SCHEDULED { background: rgba(31,122,140,.2); color: var(--brand-dark); }
.st-VISITED   { background: rgba(101,74,153,.16); color: #6a4a99; }
.st-COMPLETED { background: rgba(26,143,76,.16); color: var(--ok); }
.st-REJECTED  { background: rgba(214,69,80,.14); color: var(--danger); }
.st-CANCELLED { background: var(--surface-2); color: var(--text-soft); text-decoration: line-through; }
.badge-urgent { background: rgba(214,69,80,.14); color: var(--danger); }
.badge-soft   { background: var(--surface-2); color: var(--text-soft); }

/* ---------- detail view ---------- */
.detail-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.detail-card > h3 {
  margin: 0 0 10px; font-size: .84rem; text-transform: uppercase; letter-spacing: .03em;
  color: var(--brand-dark);
}
.kv { display: flex; flex-direction: column; gap: 8px; }
.kv__row { display: flex; gap: 12px; justify-content: space-between; align-items: baseline; }
.kv__k { font-size: .82rem; color: var(--text-soft); flex: 0 0 40%; }
.kv__v { font-weight: 600; text-align: right; word-break: break-word; }
.kv__v--block { text-align: left; white-space: pre-wrap; font-weight: 500; }
.kv--stack .kv__row { flex-direction: column; align-items: stretch; gap: 2px; }
.kv--stack .kv__v { text-align: left; }

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; }
.timeline li::before {
  content: ""; position: absolute; left: 4px; top: 4px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--brand);
}
.timeline li::after {
  content: ""; position: absolute; left: 8px; top: 14px; bottom: 0; width: 1px; background: var(--border);
}
.timeline li:last-child::after { display: none; }
.timeline__label { font-weight: 700; font-size: .9rem; }
.timeline__time { font-size: .78rem; color: var(--text-soft); }
.timeline__note { font-size: .84rem; color: var(--text-soft); white-space: pre-wrap; }

/* ---------- feedback thread ---------- */
.thread { display: flex; flex-direction: column; gap: 10px; }
.fb {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px;
}
.fb--PBH { border-left: 3px solid var(--brand); }
.fb--REFERRER { border-left: 3px solid var(--accent); }
.fb__head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .8rem; color: var(--text-soft); }
.fb__who { font-weight: 700; color: var(--text); }
.fb__type { font-size: .7rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); }
.fb__type--RESULT { background: rgba(26,143,76,.16); color: var(--ok); }
.fb__msg { margin-top: 6px; white-space: pre-wrap; font-size: .92rem; }
.fb__img { margin-top: 8px; border-radius: 8px; max-height: 220px; }

/* ---------- upload grid ---------- */
.upload-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.upload-item { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.upload-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.upload-item__del {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%;
  border: none; background: rgba(0,0,0,.6); color: #fff; font-size: .8rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.upload-add {
  aspect-ratio: 1; border: 2px dashed var(--border); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  color: var(--text-soft); font-size: .85rem; text-align: center;
}
.upload-add:active { border-color: var(--brand); color: var(--brand-dark); }
.upload-input { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; opacity: 0; }

/* ---------- pager ---------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 16px; }
.pager__btn {
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: .9rem; text-decoration: none;
}
.pager__btn.is-disabled { color: var(--text-soft); opacity: .5; pointer-events: none; }
.pager__info { font-size: .9rem; color: var(--text-soft); }

/* ---------- empty ---------- */
.empty, .empty-state { color: var(--text-soft); text-align: center; }
.empty-state { padding: 48px 16px; }
.empty-state__icon { font-size: 2.6rem; margin-bottom: 8px; }

/* ---------- typeahead ---------- */
.typeahead { position: relative; }
.typeahead__list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  max-height: 240px; overflow-y: auto; box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.typeahead__opt { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: .9rem; }
.typeahead__opt:last-child { border-bottom: 0; }
.typeahead__opt:hover, .typeahead__opt.is-active { background: var(--brand-soft); }
.typeahead__opt small { color: var(--text-soft); }

/* ---------- modal ---------- */
.modal { border: none; padding: 0; background: transparent; max-width: 380px; width: calc(100% - 40px); color: var(--text); }
.modal::backdrop { background: rgba(0,0,0,.45); }
.modal__box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: 0 12px 40px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 12px;
}
.modal__title { margin: 0; font-size: 1.05rem; }
.modal__actions { display: flex; gap: 8px; }
.modal__actions .btn { flex: 1; }

/* ---------- Thai date picker (vanilla) ---------- */
/* ---------- treatment records + chemo ---------- */
.tx-rec { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-top: 8px; }
.tx-rec__hd { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.chemo-row { display: grid; grid-template-columns: 1.6fr .8fr .7fr auto .6fr .5fr auto; gap: 5px; align-items: center; margin-bottom: 6px; }
.chemo-row input, .chemo-row select { padding: 7px 6px; font-size: .82rem; border: 1px solid var(--border); border-radius: 7px; min-width: 0; }
.chemo-row .c-mg { font-size: .78rem; font-weight: 700; color: var(--brand-dark); white-space: nowrap; }
.chemo-row .c-del { border: 0; background: var(--surface-2); color: var(--text-soft); border-radius: 6px; padding: 4px 7px; cursor: pointer; }
@media (max-width: 520px) { .chemo-row { grid-template-columns: 1fr 1fr; } .chemo-row .c-mg { grid-column: 1 / -1; } }

.thaidp { position: relative; }
.thaidp__display {
  width: 100%; font: inherit; cursor: pointer; color: var(--text); font-weight: 600;
  padding: 12px 34px 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238a8f98' stroke-width='2' viewBox='0 0 24 24'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E") no-repeat right 10px center;
}
.thaidp__display:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.thaidp__display::placeholder { color: var(--text-soft); font-weight: 400; }
.thaidp__clear {
  position: absolute; top: 9px; right: 8px; width: 22px; height: 22px; border-radius: 50%;
  border: none; background: var(--surface-2); color: var(--text-soft); font-size: .72rem; cursor: pointer; z-index: 3;
}
.thaidp__pop {
  position: absolute; left: 0; top: calc(100% + 4px); z-index: 60; width: 268px; max-width: 90vw;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px;
  box-shadow: 0 14px 40px rgba(0,0,0,.22);
}
.thaidp__pop[hidden] { display: none; }
.thaidp__hd { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 2px 2px 8px; font-weight: 700; }
.thaidp__hd > button[data-nav], .thaidp__hd > button[data-nav-y] { flex: 0 0 30px; width: 30px; height: 30px; border: 0; border-radius: 8px; background: var(--surface-2); color: var(--text); font-size: 1.2rem; line-height: 1; cursor: pointer; }
.thaidp__hd > span, .thaidp__hd > .thaidp__lbl { flex: 1 1 auto; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thaidp__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; text-align: center; }
.thaidp__grid b { color: var(--text-soft); font-weight: 600; font-size: .78rem; padding: 4px 0; }
.thaidp__day { padding: 7px 0; border-radius: 8px; cursor: pointer; font-size: .88rem; }
.thaidp__day:hover { background: var(--surface-2); }
.thaidp__day.is-sel { background: var(--brand); color: #fff; font-weight: 700; }
.thaidp__lbl { border: 0; background: transparent; font: inherit; font-weight: 700; color: var(--text); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.thaidp__lbl:hover { background: var(--surface-2); }
.thaidp__grid--mm { grid-template-columns: repeat(3, 1fr); gap: 4px; }
.thaidp__cell { padding: 12px 0; border-radius: 8px; cursor: pointer; font-size: .9rem; text-align: center; }
.thaidp__cell:hover { background: var(--surface-2); }
.thaidp__cell.is-sel { background: var(--brand); color: #fff; font-weight: 700; }

/* ---------- custom modal (ไม่พึ่ง <dialog> เพราะ LINE WebView บางรุ่นไม่รองรับ) ---------- */
.otp-modal, .bd-modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.otp-modal[hidden], .bd-modal[hidden] { display: none !important; }
.otp-modal__backdrop, .bd-modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.otp-modal__box, .bd-modal__box {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; width: 100%; max-width: 380px;
  box-shadow: 0 16px 48px rgba(0,0,0,.35); display: flex; flex-direction: column; gap: 12px;
  max-height: 88vh; overflow-y: auto;
}
.otp-input {
  font: inherit; font-size: 1.6rem; font-weight: 700;
  letter-spacing: .45em; text-indent: .45em; text-align: center;
  padding: 12px 10px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
.otp-input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }

/* ---------- auth bootstrap ---------- */
.screen-center { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.loader-box { text-align: center; max-width: 320px; }
.spinner { width: 38px; height: 38px; margin: 0 auto 16px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.error-text { color: var(--danger); font-size: .88rem; word-break: break-word; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- misc ---------- */
.notice {
  background: var(--brand-soft); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-size: .88rem; margin-bottom: 14px;
}
.divider { height: 1px; background: var(--border); margin: 18px 0; border: 0; }
.text-danger { color: var(--danger); }
.text-soft { color: var(--text-soft); }
table.report-tbl { width: 100%; border-collapse: collapse; font-size: .86rem; }
table.report-tbl th, table.report-tbl td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; }
table.report-tbl th { color: var(--text-soft); font-weight: 600; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
