:root {
  color-scheme: light;
  font-family: Inter, "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --teal-soft: #ccfbf1;
  --ink: #17252a;
  --muted: #64748b;
  --line: #dbe4e7;
  --surface: #ffffff;
  --background: #f3f7f7;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: linear-gradient(180deg, #e6fffb 0, var(--background) 240px); color: var(--ink); }
button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.app-shell { width: min(100%, 680px); margin: 0 auto; padding: env(safe-area-inset-top) 16px calc(32px + env(safe-area-inset-bottom)); }
.topbar { min-height: 92px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topbar h1 { margin: 2px 0 0; font-size: 1.45rem; }
.eyebrow, .section-kicker { margin: 0; color: var(--teal); font-size: .72rem; font-weight: 800; letter-spacing: .12em; }
.card { background: rgba(255,255,255,.96); border: 1px solid rgba(15,118,110,.12); border-radius: 22px; padding: 22px; box-shadow: 0 16px 44px rgba(15, 60, 57, .09); }
.card h2 { margin: 5px 0 5px; font-size: 1.35rem; }
.step-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.back-button { min-height: 36px; padding: 7px 10px; border: 0; border-radius: 10px; color: var(--teal-dark); background: #f0fdfa; font-size: .78rem; font-weight: 800; }
.back-button:hover { background: var(--teal-soft); }
.card-icon { font-size: 2rem; }
.login-card { margin-top: 44px; }
.muted { color: var(--muted); margin: 0 0 20px; line-height: 1.55; }
.form-stack, .form-grid { display: grid; gap: 14px; }
.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: 1 / -1; }
label { display: grid; gap: 7px; color: #334155; font-size: .88rem; font-weight: 700; }
input { width: 100%; min-height: 48px; padding: 11px 13px; border: 1px solid #cbd5e1; border-radius: 12px; background: #fff; color: var(--ink); outline: none; }
input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13,148,136,.14); }
.readonly-input { color: #64748b; background: #f1f5f9; }
.pin-input { text-align: center; font-size: 1.55rem; font-weight: 800; letter-spacing: .45em; padding-left: calc(13px + .45em); }
.field-help { margin-top: -7px; color: var(--muted); font-size: .76rem; text-align: center; }
.primary-button, .secondary-button, .outline-button, .text-button, .photo-button { min-height: 48px; border-radius: 13px; border: 0; font-weight: 800; }
.primary-button { width: 100%; padding: 12px 16px; color: white; background: var(--teal); box-shadow: 0 7px 16px rgba(15,118,110,.18); }
.primary-button:hover { background: var(--teal-dark); }
.primary-button:disabled { opacity: .55; cursor: wait; }
.secondary-button { padding: 11px 16px; color: var(--teal-dark); background: var(--teal-soft); }
.outline-button { width: 100%; margin-top: 12px; padding: 11px 16px; color: var(--teal-dark); background: white; border: 1px solid #99f6e4; }
.outline-button:hover { background: #f0fdfa; }
.text-button { min-height: auto; padding: 9px 10px; color: var(--teal-dark); background: transparent; }
.stepper { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin: 6px 0 14px; }
.step { display: grid; place-items: center; min-height: 52px; border-radius: 13px; background: rgba(255,255,255,.62); color: #94a3b8; font-weight: 900; }
.step small { font-size: .62rem; font-weight: 700; }
.step.active { color: white; background: var(--teal); }
.reader-frame { overflow: hidden; margin: 16px 0; border-radius: 16px; background: #0f172a; }
#barcode-reader video { border-radius: 16px; }
.camera-button { margin-top: 8px; }
.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: #94a3b8; font-size: .76rem; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.summary-box, .selected-box { margin: 14px 0; padding: 13px 15px; border-radius: 14px; background: #f0fdfa; color: #134e4a; line-height: 1.55; }
.medicine-card { margin: 14px 0 18px; padding: 18px; border: 1px solid #99f6e4; border-radius: 16px; background: #f0fdfa; }
.medicine-card strong { display: block; font-size: 1.08rem; }
.medicine-card span { color: var(--muted); }
.segmented-control { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 17px 0; padding: 4px; border-radius: 14px; background: #e8eff0; }
.segment { min-height: 42px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 800; }
.segment.active { background: white; color: var(--teal-dark); box-shadow: 0 2px 8px rgba(15,23,42,.08); }
.result-list { display: grid; gap: 8px; max-height: 260px; overflow-y: auto; margin: 10px 0; }
.result-item { width: 100%; padding: 12px 13px; border: 1px solid var(--line); border-radius: 12px; background: #fff; text-align: left; color: var(--ink); }
.result-item strong, .result-item span { display: block; }
.result-item span { margin-top: 3px; color: var(--muted); font-size: .78rem; }
.lot-fields { margin: 18px 0; padding-top: 18px; border-top: 1px solid var(--line); }
.photo-button { display: flex; align-items: center; justify-content: center; width: 100%; padding: 12px; color: var(--teal-dark); background: var(--teal-soft); cursor: pointer; }
.photo-button input { display: none; }
.ocr-preview { width: 100%; max-height: 260px; object-fit: contain; margin-top: 14px; border-radius: 14px; background: #0f172a; }
.progress-box { margin: 14px 0; color: var(--muted); font-size: .78rem; }
.progress-track { height: 8px; margin-bottom: 7px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
#ocr-progress-bar { width: 0; height: 100%; background: var(--teal); transition: width .2s ease; }
details { margin: 12px 0; color: var(--muted); font-size: .8rem; }
pre { max-height: 150px; overflow: auto; padding: 10px; white-space: pre-wrap; background: #f8fafc; border-radius: 10px; }
.confirm-check { display: flex; grid-template-columns: none; align-items: flex-start; gap: 10px; margin: 18px 0; line-height: 1.5; }
.confirm-check input { width: 21px; min-height: 21px; flex: 0 0 auto; accent-color: var(--teal); }
.final-summary { display: grid; gap: 1px; margin: 16px 0 20px; border: 1px solid var(--line); border-radius: 15px; overflow: hidden; }
.summary-row { display: grid; grid-template-columns: 42% 1fr; gap: 10px; padding: 11px 13px; background: #fff; }
.summary-row + .summary-row { border-top: 1px solid #edf2f3; }
.summary-row span:first-child { color: var(--muted); }
.button-row { display: grid; grid-template-columns: auto 1fr; gap: 9px; }
.success-card { text-align: center; }
.success-mark { display: grid; place-items: center; width: 70px; height: 70px; margin: 0 auto 12px; border-radius: 50%; background: var(--teal-soft); color: var(--teal); font-size: 2.2rem; font-weight: 900; }
.toast { position: fixed; z-index: 30; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); width: min(calc(100% - 32px), 520px); transform: translateX(-50%); padding: 13px 16px; border-radius: 13px; color: white; background: #0f172a; box-shadow: 0 12px 28px rgba(15,23,42,.28); }
.toast.error { background: var(--danger); }

@media (max-width: 460px) {
  .card { padding: 18px; border-radius: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .step small { display: none; }
  .summary-row { grid-template-columns: 38% 1fr; font-size: .88rem; }
}
