/* รักครอบครัว: ตัวอักษรใหญ่ ปุ่มใหญ่ อ่านง่ายสำหรับผู้สูงอายุ */
:root {
  --coral: #E2574C;
  --coral-dark: #C2443A;
  --peach: #FFEDE6;
  --cream: #FBF8F4;
  --ink: #1C2430;
  --muted: #5F6875;
  --line: #EADFD7;
  --card: #FFFFFF;
  --green: #2E8B57;
  --green-bg: #E6F4EC;
  --amber: #B7791F;
  --amber-bg: #FFF4DC;
  --red: #C53030;
  --red-bg: #FDE8E8;
  --blue: #2a68d1;
  --blue-bg: #E8F0FC;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(28, 36, 48, .06), 0 4px 14px rgba(28, 36, 48, .05);
  --font-head: 'Mitr', 'IBM Plex Sans Thai', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans Thai', 'Mitr', system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font: 18px/1.55 var(--font-body);
  min-height: 100dvh;
}
h1, h2, h3 { font-family: var(--font-head); font-weight: 500; line-height: 1.3; margin: 0 0 .4em; }
h1 { font-size: 26px; }
h2 { font-size: 21px; }
h3 { font-size: 18px; }
p { margin: 0 0 .8em; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40vh 16px; text-align: center; color: var(--muted); }

/* โครงหน้า */
.shell { max-width: 560px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(251, 248, 244, .94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .title { flex: 1; min-width: 0; }
.topbar .title b { display: block; font-family: var(--font-head); font-weight: 500; font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { color: var(--muted); font-size: 14px; }
.topbar .mascot { width: 40px; height: 40px; flex: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar nav { display: flex; width: 100%; max-width: 560px; }
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 9px; text-decoration: none; color: var(--muted); font-size: 13px;
  min-height: 60px;
}
.tabbar a svg { width: 26px; height: 26px; }
.tabbar a.on { color: var(--coral); font-weight: 600; }
.tabbar a.scan { color: #fff; }
.tabbar a.scan .bubble {
  width: 52px; height: 52px; margin-top: -22px; border-radius: 50%;
  background: var(--coral); display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(226, 87, 76, .35);
}
.tabbar a.scan span { color: var(--coral); }

/* การ์ด */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 14px 0; }
.card.soft { background: var(--peach); box-shadow: none; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.center { text-align: center; }
.stack > * + * { margin-top: 10px; }
.hide { display: none !important; }

/* ปุ่ม */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 10px 18px; border-radius: 14px;
  border: 0; cursor: pointer; text-decoration: none;
  background: var(--coral); color: #fff; font-family: var(--font-head); font-weight: 500; font-size: 18px;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; }
.btn.big { min-height: 64px; font-size: 22px; border-radius: 18px; }
.btn.ghost { background: #fff; color: var(--ink); border: 1.5px solid var(--line); }
.btn.green { background: var(--green); }
.btn.blue { background: var(--blue); }
.btn.line { background: #06C755; }
.btn.google { background: #fff; color: var(--ink); border: 1.5px solid var(--line); }
.btn.text { background: none; color: var(--blue); min-height: 44px; padding: 6px 8px; }
.btn.danger { background: #fff; color: var(--red); border: 1.5px solid #F2C4C4; }
.btn.sm { min-height: 42px; font-size: 16px; padding: 6px 14px; border-radius: 12px; }

/* ฟอร์ม */
label.field { display: block; margin: 12px 0; }
label.field > span { display: block; font-size: 16px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=time], select, textarea {
  width: 100%; min-height: 52px; padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: 12px; background: #fff; font-size: 18px;
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(42, 104, 209, .25); border-color: var(--blue); }
.check { display: flex; gap: 12px; align-items: center; padding: 12px 0; min-height: 52px; }
.check input { width: 26px; height: 26px; accent-color: var(--coral); }
.inline2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* แท็บคนในบ้าน */
.people { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 2px; scrollbar-width: none; }
.people::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 6px 16px; border-radius: 999px;
  border: 1.5px solid var(--line); background: #fff; cursor: pointer; font-size: 17px;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips .chip { min-height: 46px; }
.chips .chip.on { background: var(--coral); border-color: var(--coral); }

/* มื้อยา */
.dose { border-left: 6px solid var(--line); }
.dose.taken { border-left-color: var(--green); }
.dose.missed { border-left-color: var(--red); }
.dose.due { border-left-color: var(--amber); }
.dose.upcoming { border-left-color: var(--blue); }
.dose .time { font-family: var(--font-head); font-size: 28px; font-weight: 500; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 15px; font-weight: 600; }
.badge.taken { background: var(--green-bg); color: var(--green); }
.badge.missed { background: var(--red-bg); color: var(--red); }
.badge.due { background: var(--amber-bg); color: var(--amber); }
.badge.upcoming { background: var(--blue-bg); color: var(--blue); }
.badge.pro { background: var(--ink); color: #fff; }
.badge.beta { background: var(--peach); color: var(--coral-dark); }
.medlist { list-style: none; padding: 0; margin: 10px 0; }
.medlist li { padding: 8px 0; border-top: 1px dashed var(--line); }
.medlist li:first-child { border-top: 0; }
.medlist b { font-weight: 600; }
.note { font-size: 15px; color: var(--muted); }

/* สรุปวันนี้ */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.summary div { background: #fff; border-radius: 14px; padding: 10px 6px; text-align: center; }
.summary b { display: block; font-family: var(--font-head); font-size: 24px; font-weight: 500; }
.summary span { font-size: 14px; color: var(--muted); }

/* ผลสแกน */
.scanitem { border: 1.5px solid var(--line); border-radius: 16px; padding: 14px; margin: 12px 0; background: #fff; }
.scanitem.unclear { border-color: #F0C36D; background: #FFFBF0; }
.warn { background: var(--amber-bg); color: #7A4E0B; border-radius: 14px; padding: 12px 14px; margin: 12px 0; }
.danger-box { background: var(--red-bg); color: #8B1E1E; border-radius: 14px; padding: 12px 14px; margin: 12px 0; }
.photo-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border: 2px dashed #E8BFB3; border-radius: 20px; background: var(--peach);
  padding: 28px 16px; text-align: center; cursor: pointer; min-height: 180px;
}
.photo-drop svg { width: 56px; height: 56px; color: var(--coral); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.kinds { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kind {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 14px; border-radius: 16px; border: 1.5px solid var(--line); background: #fff; cursor: pointer; text-align: left; min-height: 96px;
}
.kind.on { border-color: var(--coral); background: var(--peach); }
.kind b { font-family: var(--font-head); font-weight: 500; font-size: 18px; }
.kind span { font-size: 14px; color: var(--muted); }

/* ค่าความดัน */
.reading { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border: 0; border-top: 1px solid var(--line); width: 100%; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.reading:first-child { border-top: 0; }
.reading .val { font-family: var(--font-head); font-size: 22px; font-weight: 500; }
.reading .val.bad { color: var(--red); }
.chart { width: 100%; height: auto; display: block; }
.lock { display: flex; gap: 10px; align-items: center; background: var(--peach); border-radius: 14px; padding: 12px; }

/* สมาชิก */
.member { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.member:first-child { border-top: 0; }
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--peach); color: var(--coral-dark); font-family: var(--font-head); font-size: 19px; flex: none; }
.avatar.cg { background: var(--blue-bg); color: var(--blue); }

/* หน้าเข้าสู่ระบบ */
.hero { text-align: center; padding: calc(40px + env(safe-area-inset-top)) 8px 10px; }
.hero .mascot { width: 140px; height: 140px; }
.hero h1 { font-size: 32px; margin-top: 8px; }
.hero .slogan { color: var(--coral-dark); font-family: var(--font-head); font-size: 19px; }
.features { list-style: none; padding: 0; margin: 18px 0; display: grid; gap: 10px; }
.features li { display: flex; gap: 12px; align-items: center; background: #fff; border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.features li i { font-style: normal; font-size: 24px; width: 32px; text-align: center; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); z-index: 20;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 17px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
}
#toast.error { background: var(--red); }

/* หน้าต่างยืนยัน */
.sheet-bg { position: fixed; inset: 0; background: rgba(28, 36, 48, .45); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 90dvh; overflow: auto;
  background: #fff; border-radius: 22px 22px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
.spinner { width: 46px; height: 46px; border: 5px solid var(--peach); border-top-color: var(--coral); border-radius: 50%; animation: spin 0.9s linear infinite; margin: 10px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.empty { text-align: center; padding: 26px 10px; color: var(--muted); }
.empty .mascot { width: 90px; height: 90px; opacity: .95; }

.famswitch { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
.famswitch .caret { font-size: 14px; color: var(--muted); }
.sheet .mascot { width: 72px; height: 72px; }

.thumb { position: relative; }
.thumb img { cursor: pointer; }
.thumb-x {
  position: absolute; top: -8px; right: -8px; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid #fff; background: var(--ink); color: #fff; font-size: 14px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; padding: 0;
}

.kind.locked { opacity: .7; }
.kind .badge.pro { font-size: 12px; padding: 2px 8px; vertical-align: middle; }

/* ไทม์ไลน์แผล */
.wimg { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.wgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.wcell { border: 0; padding: 0; background: none; cursor: pointer; text-align: center; font-size: 13px; color: var(--muted); }
.wcell img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block; margin-bottom: 2px; }

/* สวิตช์ */
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: #D8D2CC; border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--coral); }
.switch input:checked + span::after { transform: translateX(22px); }

/* ตัวอักษรใหญ่ */
html.big body { font-size: 21px; }
html.big h1 { font-size: 30px; } html.big h2 { font-size: 24px; } html.big h3 { font-size: 21px; }
html.big .small, html.big .note { font-size: 17px; }
html.big .btn { min-height: 58px; font-size: 20px; }
html.big .btn.big { min-height: 70px; font-size: 25px; }
html.big .btn.sm { min-height: 48px; font-size: 18px; }
html.big .dose .time { font-size: 34px; }
html.big .chip { font-size: 19px; min-height: 50px; }
html.big .tabbar a { font-size: 15px; }
html.big input, html.big select, html.big textarea { font-size: 20px; min-height: 58px; }

/* พิมพ์รายงาน */
@media print {
  .topbar, .tabbar, .no-print, #toast { display: none !important; }
  body { background: #fff; }
  .shell { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .report h3 { break-after: avoid; }
}

/* หน้าถ่ายรูป: กระชับ ให้เห็นปุ่มโดยไม่ต้องเลื่อน (ตัวอักษรใหญ่ใช้แบบเดิม) */
.scan-title { font-size: 22px; margin: 12px 0 8px; }
.kinds { grid-template-columns: repeat(5, 1fr); gap: 5px; }
.kind { min-height: 0; padding: 8px 2px 6px; align-items: center; text-align: center; gap: 2px; border-radius: 14px; position: relative; }
.kind i { font-style: normal; font-size: 22px; line-height: 1.2; }
.kind b { font-size: 13.5px; line-height: 1.2; white-space: nowrap; }
.kind .badge.pro { position: absolute; top: -6px; right: -4px; }
.kind b .long, .kind > span { display: none; }
.kind b em { font-style: normal; }
.kind .badge.pro { font-size: 10px; padding: 1px 6px; }
.kind-hint { font-size: 14px; color: var(--muted); margin: 6px 0 2px; text-align: center; }
.scan-who { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.scan-who .people { padding: 6px 0; flex: 1; }
.scan-who .chip { min-height: 38px; padding: 4px 14px; font-size: 16px; }
.photo-drop { min-height: 0; padding: 14px 12px; gap: 4px; margin-top: 8px; }
.photo-drop.has { flex-direction: row; padding: 8px 12px; justify-content: center; }
.photo-drop.has svg { width: 26px; height: 26px; }
.photo-drop.has .small { display: none; }
.photo-drop svg { width: 38px; height: 38px; }
.thumbs img { width: 66px; height: 66px; }
html.big .scan-title { font-size: 30px; }
html.big .kinds { grid-template-columns: 1fr 1fr; gap: 10px; }
html.big .kind { min-height: 96px; padding: 14px; align-items: flex-start; text-align: left; }
html.big .kind b { font-size: 19px; } html.big .kind b .long { display: inline; } html.big .kind b .short { display: none; }
html.big .kind > span { display: block; font-size: 16px; }
html.big .kind-hint { display: none; }
html.big .photo-drop, html.big .photo-drop.has { min-height: 180px; padding: 28px 16px; flex-direction: column; }
html.big .kind .badge.pro { position: static; }
html.big .photo-drop svg { width: 56px; height: 56px; }
html.big .thumbs img { width: 84px; height: 84px; }

.langbar { display: flex; justify-content: flex-end; padding: calc(10px + env(safe-area-inset-top)) 0 0; }
.langsw { gap: 4px; flex-wrap: nowrap; }
.langsw .chip { min-height: 36px; padding: 4px 12px; font-size: 15px; }

/* รายการยา: ข้อมูลเต็มความกว้าง ปุ่มเรียงด้านล่าง */
.medrow { padding: 14px 0; border-bottom: 1px solid var(--line, #eee3dc); }
.medrow:last-child { border-bottom: 0; }
.medbtns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.medbtns .btn { flex: 1 1 auto; }
.medbtns .btn.danger { flex: 0 0 auto; margin-left: auto; }
#items.editing [data-f="keep"] { display: none; }
#items.editing .check:has([data-f="keep"]) { display: none; }

/* เลือกรูปจากคลังภาพ (ปุ่มรองใต้กล่องถ่ายรูป) */
.gallery-btn { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; margin: 8px 0 4px;
  border: 1.5px solid var(--line); border-radius: 14px; background: #fff; font-weight: 600; cursor: pointer; }
.gallery-btn:active { background: var(--cream, #fbf3ee); }

/* เชื่อม LINE */
.linecode { font: 700 34px/1.2 ui-monospace, Menlo, monospace; letter-spacing: 6px; text-align: center; padding: 14px; margin: 10px 0 14px;
  background: var(--cream, #fbf3ee); border-radius: 14px; }
.btn.line { background: #06C755; border-color: #06C755; color: #fff; }
ol.steps { padding-left: 22px; margin: 8px 0; line-height: 1.6; }

/* ความยินยอม PDPA */
.consent .csum { padding: 8px 0; border-bottom: 1px solid var(--line); }
.consent .check { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); line-height: 1.5; }
.consent .check:last-child { border-bottom: 0; }
.consent .check input { width: 26px; height: 26px; flex: none; margin-top: 2px; accent-color: var(--coral); }
.consent .check.all { padding-top: 0; }
.consent .btn[disabled] { opacity: .45; }
.policy h3 { margin-top: 18px; }
.policy p { line-height: 1.7; }
.consent details summary { color: var(--blue, #2a68d1); cursor: pointer; margin-top: 4px; }

/* รูปโปรไฟล์ */
img.avatar { object-fit: cover; background: var(--peach); }
.avatar.emo { font-size: 24px; font-family: 'Apple Color Emoji','Segoe UI Emoji','Noto Color Emoji',sans-serif; }
.avatar.xs { width: 26px; height: 26px; font-size: 13px; margin: -4px 6px -4px -6px; display: inline-grid; vertical-align: middle; }
.avatar.xs.emo { font-size: 15px; }
.chip { display: inline-flex; align-items: center; }
.avbtn { position: relative; border: 0; padding: 0; background: none; cursor: pointer; flex: none; }
.avbtn i { position: absolute; right: -4px; bottom: -4px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.2); font-size: 12px; font-style: normal; display: grid; place-items: center; color: var(--ink); }
.avbg { display: flex; gap: 10px; margin: 6px 0 10px; }
.avc { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; }
.avc.on { border: 3px solid var(--ink); }
.avgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.avpick { aspect-ratio: 1; border-radius: 50%; border: 0; font-size: 30px; cursor: pointer; font-family: 'Apple Color Emoji','Segoe UI Emoji','Noto Color Emoji',sans-serif; }

/* นัดหมอ: สลับมุมมอง + หัวกลุ่ม */
.seg { display: flex; background: #EFE8DF; border-radius: 14px; padding: 4px; gap: 4px; margin: 10px 0 4px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 10px; padding: 8px 4px; font: inherit; font-size: 15px; color: var(--ink); cursor: pointer; }
.seg button.on { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.1); font-weight: 600; }
h3.grp { margin: 16px 2px 6px; }

/* โน้ตในบ้าน */
.nc { color: var(--coral-dark); font-size: 14px; font-weight: 600; }
.notes { margin: 8px 0 12px; }
.note-item { background: #FFF8E7; border: 1px solid #F3E2B5; border-radius: 14px; padding: 8px 12px; margin-bottom: 8px; line-height: 1.5; }
.nc.zero { opacity: .35; font-weight: 400; }
.nrep { margin-top: 6px; border: 1px solid #E8D9B0; background: #fff; border-radius: 10px; font: inherit; font-size: 14px; padding: 3px 10px; color: var(--quiet); cursor: pointer; }
.nrep.on { background: #E6F4EC; border-color: #B7DEC6; color: var(--green); }
.rnote { background: #FFF8E7; border-left: 4px solid #F2B84B; border-radius: 8px; padding: 6px 10px; margin: 6px 0; break-inside: avoid; }
