:root {
  --brand: #0f9d8a;
  --brand-d: #0b7a6b;
  --brand-l: #e6f6f3;
  --accent: #f97316;
  --blue: #2563eb;
  --red: #dc2626;
  --amber: #d97706;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f4f7f8;
  --card: #fff;
  --r: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  font-family: 'Sarabun', 'Prompt', system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #dfe7e9; }
h1, h2, h3, h4, .btn, .tabbar, .topbar { font-family: 'Prompt', 'Sarabun', sans-serif; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }

.device {
  position: relative; max-width: 480px; height: 100dvh; margin: 0 auto;
  background: var(--bg); display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 0 40px rgba(0, 0, 0, .08);
}
@media (min-width: 520px) {
  .device { height: min(100dvh - 32px, 920px); margin-top: 16px; border-radius: 28px; }
}

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: var(--card); border-bottom: 1px solid var(--line); min-height: 58px; z-index: 2;
}
.topbar .title { font-weight: 600; font-size: 17px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; }
.topbar .back:hover { background: var(--bg); }
.logo { display: flex; align-items: center; gap: 8px; flex: 1; font-weight: 700; font-size: 18px; color: var(--brand-d); }
.logo img { width: 32px; height: 32px; }
.logo small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }
.icon-btn { position: relative; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; background: var(--bg); }
.badge { position: absolute; top: -4px; right: -4px; background: var(--accent); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; font-weight: 700; }

.view { flex: 1; overflow-y: auto; padding: 16px 16px 24px; scroll-behavior: smooth; }
.view.flush { padding: 0; display: flex; flex-direction: column; }

/* tab bar */
.tabbar { display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px; font-size: 11.5px; color: var(--muted); }
.tabbar a .ti { font-size: 21px; filter: grayscale(1); opacity: .7; }
.tabbar a.active { color: var(--brand-d); font-weight: 600; }
.tabbar a.active .ti { filter: none; opacity: 1; }
.tabbar.hidden { display: none; }

/* generic */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; }
.section { margin-top: 22px; }
.section-h { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.section-h h3 { font-size: 16px; }
.section-h a { font-size: 13px; color: var(--brand-d); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.hr { height: 1px; background: var(--line); margin: 12px 0; }
.center { text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px;
  background: var(--brand); color: #fff; transition: transform .05s, background .15s;
}
.btn:hover { background: var(--brand-d); }
.btn:active { transform: scale(.98); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--brand-l); color: var(--brand-d); }
.btn.ghost:hover { background: #d3efe9; }
.btn.outline { background: #fff; border: 1.5px solid var(--line); color: var(--ink); }
.btn.danger { background: var(--red); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; pointer-events: none; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px; background: #fff; border: 1.5px solid var(--line); font-size: 13px; white-space: nowrap; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.tag { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 6px; background: var(--bg); color: var(--muted); font-weight: 500; }
.tag.green { background: #dcfce7; color: #166534; }
.tag.amber { background: #fef3c7; color: #92400e; }
.tag.red { background: #fee2e2; color: #991b1b; }
.tag.blue { background: #dbeafe; color: #1e40af; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; display: inline-block; box-shadow: 0 0 0 3px #dcfce7; }
.dot.off { background: #94a3b8; box-shadow: 0 0 0 3px #f1f5f9; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.input { width: 100%; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; font-size: 15px; }
.input:focus { outline: none; border-color: var(--brand); }
.search { position: relative; }
.search .input { padding-left: 40px; }
.search::before { content: '🔍'; position: absolute; left: 13px; top: 50%; transform: translateY(-50%); font-size: 15px; }

/* home */
.hero {
  background: linear-gradient(135deg, #0f9d8a 0%, #12b39b 55%, #4fd1b5 100%); color: #fff;
  border-radius: 22px; padding: 18px; position: relative; overflow: hidden;
}
.hero::after { content: '💊'; position: absolute; right: -8px; bottom: -18px; font-size: 110px; opacity: .14; transform: rotate(-20deg); }
.hero h2 { font-size: 20px; }
.hero .live { display: inline-flex; align-items: center; gap: 6px; background: rgba(255, 255, 255, .2); padding: 4px 10px; border-radius: 999px; font-size: 12.5px; margin-bottom: 10px; }
.hero .live .dot { box-shadow: 0 0 0 3px rgba(255, 255, 255, .3); }
.hero-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; position: relative; z-index: 1; }
.hero-actions button { background: #fff; color: var(--brand-d); border-radius: 14px; padding: 10px 4px; font-weight: 600; font-size: 13px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-family: 'Prompt'; }
.hero-actions button span { font-size: 22px; }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.quick a { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; font-size: 12px; line-height: 1.25; }
.quick .qi { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; font-size: 26px; background: var(--card); box-shadow: var(--shadow); }

.promo { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.promo > div { flex: 0 0 85%; scroll-snap-align: start; color: #fff; border-radius: 18px; padding: 16px; min-height: 96px; }
.promo h4 { font-size: 17px; }
.promo p { font-size: 13px; opacity: .92; margin-top: 4px; }

.points-card { display: flex; align-items: center; gap: 12px; }
.points-card .pt { font-size: 22px; font-weight: 700; color: var(--accent); font-family: 'Prompt'; }

/* pharmacist */
.ph { display: flex; gap: 12px; align-items: flex-start; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--brand-l); display: grid; place-items: center; font-size: 28px; flex: none; position: relative; }
.avatar .dot { position: absolute; bottom: 2px; right: 2px; box-shadow: 0 0 0 2px #fff; }
.ph h4 { font-size: 15px; }
.stars { color: #f59e0b; font-weight: 600; }

.mode { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mode button { background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 14px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 600; font-family: 'Prompt'; }
.mode button span { font-size: 26px; }
.mode button small { font-weight: 400; color: var(--muted); font-size: 11.5px; font-family: 'Sarabun'; }
.mode button.on { border-color: var(--brand); background: var(--brand-l); color: var(--brand-d); }

/* chat */
.chat { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: #eef3f4; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 18px; font-size: 15px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 6px; }
.msg.them { align-self: flex-start; background: #fff; border-bottom-left-radius: 6px; box-shadow: var(--shadow); }
.msg.sys { align-self: center; background: transparent; color: var(--muted); font-size: 12.5px; text-align: center; padding: 2px 8px; }
.msg .time { display: block; font-size: 10.5px; opacity: .65; margin-top: 4px; text-align: right; }
.msg.rec { background: #fff; border: 1.5px solid var(--brand); max-width: 92%; white-space: normal; }
.msg.rec h5 { margin: 0 0 6px; font-family: 'Prompt'; font-size: 14px; color: var(--brand-d); }
.typing { align-self: flex-start; background: #fff; padding: 12px 16px; border-radius: 18px; display: flex; gap: 4px; }
.typing i { width: 7px; height: 7px; background: #94a3b8; border-radius: 50%; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }
.composer { display: flex; gap: 8px; padding: 10px 12px; background: #fff; border-top: 1px solid var(--line); align-items: center; }
.composer .input { border-radius: 999px; padding: 10px 16px; }
.composer .send { width: 44px; height: 44px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 18px; flex: none; }
.composer .attach { width: 40px; height: 40px; border-radius: 50%; background: var(--bg); font-size: 18px; flex: none; }
.quick-replies { display: flex; gap: 6px; padding: 8px 12px 0; overflow-x: auto; background: #fff; scrollbar-width: none; }

/* video */
.video { flex: 1; background: #0b1220; position: relative; display: flex; align-items: center; justify-content: center; color: #fff; overflow: hidden; }
.video .remote { text-align: center; }
.video .remote .big { font-size: 110px; }
.video .self { position: absolute; right: 14px; top: 14px; width: 110px; height: 150px; border-radius: 14px; background: #1e293b; overflow: hidden; border: 2px solid rgba(255, 255, 255, .25); display: grid; place-items: center; font-size: 13px; color: #94a3b8; }
.video .self video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.video .timer { position: absolute; top: 16px; left: 16px; background: rgba(0, 0, 0, .4); padding: 4px 10px; border-radius: 999px; font-size: 13px; }
.video .controls { position: absolute; bottom: 24px; left: 0; right: 0; display: flex; justify-content: center; gap: 18px; }
.video .controls button { width: 58px; height: 58px; border-radius: 50%; background: rgba(255, 255, 255, .15); font-size: 24px; color: #fff; }
.video .controls button.end { background: var(--red); }
.video .controls button.offb { background: #fff; color: var(--ink); }
.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* products */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.prod { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.prod .pimg { height: 86px; border-radius: 12px; background: var(--brand-l); display: grid; place-items: center; font-size: 42px; }
.prod h4 { font-size: 13.5px; font-family: 'Sarabun'; font-weight: 600; line-height: 1.35; min-height: 36px; }
.prod .price { font-family: 'Prompt'; font-weight: 700; color: var(--brand-d); font-size: 16px; }
.add { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: #fff; font-size: 20px; font-weight: 700; display: grid; place-items: center; }

.qty { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; }
.qty button { width: 32px; height: 32px; font-size: 18px; font-weight: 700; }
.qty span { min-width: 28px; text-align: center; font-weight: 600; }
.line { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.thumb { width: 52px; height: 52px; border-radius: 12px; background: var(--brand-l); display: grid; place-items: center; font-size: 26px; flex: none; }

.opt { display: flex; gap: 12px; align-items: center; padding: 12px; border: 2px solid var(--line); border-radius: 14px; background: #fff; width: 100%; text-align: left; margin-bottom: 8px; }
.opt.on { border-color: var(--brand); background: var(--brand-l); }
.opt .oi { font-size: 24px; }

.notice { padding: 12px 14px; border-radius: 12px; font-size: 13.5px; line-height: 1.5; }
.notice.warn { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
.notice.info { background: #eff6ff; color: #1e3a8a; border: 1px solid #bfdbfe; }
.notice.danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.notice.ok { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

.sumrow { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14.5px; }
.sumrow.total { font-weight: 700; font-size: 17px; font-family: 'Prompt'; padding-top: 10px; }
.sticky-bottom { position: sticky; bottom: -24px; background: linear-gradient(transparent, var(--bg) 30%); padding: 16px 0 8px; margin-top: 8px; }

/* timeline */
.timeline { position: relative; padding-left: 26px; }
.timeline .st { position: relative; padding-bottom: 16px; }
.timeline .st::before { content: ''; position: absolute; left: -20px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.timeline .st::after { content: ''; position: absolute; left: -15px; top: 18px; bottom: -2px; width: 2px; background: var(--line); }
.timeline .st:last-child::after { display: none; }
.timeline .st.done::before { background: var(--brand); }
.timeline .st.done::after { background: var(--brand); }
.timeline .st.now::before { background: var(--accent); box-shadow: 0 0 0 4px #ffedd5; }

/* map placeholder */
.map { height: 170px; border-radius: var(--r); background:
  linear-gradient(90deg, rgba(255,255,255,.6) 2px, transparent 2px) 0 0/40px 40px,
  linear-gradient(rgba(255,255,255,.6) 2px, transparent 2px) 0 0/40px 40px, #cfe9e3;
  position: relative; overflow: hidden; }
.map .pin { position: absolute; font-size: 26px; transform: translate(-50%, -100%); }
.map .me { position: absolute; left: 50%; top: 55%; width: 16px; height: 16px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 6px rgba(37, 99, 235, .25); transform: translate(-50%, -50%); }

/* reminders */
.rem { display: flex; align-items: center; gap: 12px; }
.rem .time { font-family: 'Prompt'; font-weight: 700; font-size: 18px; width: 64px; }
.check { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 16px; color: #fff; }
.check.on { background: var(--brand); border-color: var(--brand); }
.progress { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 4px; transition: width .3s; }

/* sheet & toast */
.sheet { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); z-index: 20; display: flex; align-items: flex-end; }
.sheet[hidden] { display: none; }
.sheet .panel { background: #fff; width: 100%; border-radius: 22px 22px 0 0; padding: 18px 16px 24px; max-height: 88%; overflow-y: auto; animation: up .2s ease-out; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: -6px auto 12px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.toast { position: absolute; left: 50%; bottom: 84px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 30; max-width: 90%; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .ei { font-size: 56px; margin-bottom: 8px; }

.list-item { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .li { width: 38px; height: 38px; border-radius: 10px; background: var(--brand-l); display: grid; place-items: center; font-size: 19px; flex: none; }
.chev { color: #cbd5e1; font-size: 20px; }

.tier { background: linear-gradient(135deg, #1e293b, #334155); color: #fff; border-radius: 20px; padding: 18px; }
.tier .lvl { font-family: 'Prompt'; font-weight: 700; color: #fcd34d; }

.upload { border: 2px dashed #94a3b8; border-radius: 16px; padding: 24px; text-align: center; background: #fff; display: block; cursor: pointer; }
.upload img { max-width: 100%; max-height: 220px; border-radius: 10px; }
