/* Prescription pad. Quiet, precise, and sized for a phone held in one hand. */

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh;
  font: 400 1rem/1.5 var(--f-ui); color: var(--ink); background: var(--mist-2);
  font-feature-settings: "cv11", "ss03"; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.caps { font-size: .7rem; font-weight: 500; letter-spacing: .09em; text-transform: uppercase; color: var(--grey); }

/* ---------- page frame ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .6rem; padding: .55rem 1rem; padding-top: calc(.55rem + env(safe-area-inset-top));
  background: var(--white); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 5;
}
.topbar .logo { width: 2rem; height: 2rem; border-radius: 6px; flex: none; }
.topbar .brand { font-weight: 600; font-size: 1rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.005em; }
.topbar .back, .topbar .tool {
  display: inline-flex; align-items: center; gap: .25rem; min-height: 2.4rem; padding: 0 .7rem 0 .4rem;
  border: 0; border-radius: var(--radius); background: transparent; color: var(--teal); font-weight: 500; font-size: .95rem; text-decoration: none;
}
.topbar .tool { padding: 0 .7rem; color: var(--ink-2); }
.topbar .back:hover, .topbar .tool:hover { background: var(--mist); }

.page { width: 100%; max-width: 38rem; margin: 0 auto; padding: 1.3rem 1rem calc(var(--bar-h) + 1.5rem); flex: 1; }
.page.wide { max-width: 62rem; }
.page.no-bar { padding-bottom: 2.5rem; }
.page > h1 { font-weight: 600; font-size: 1.45rem; line-height: 1.2; letter-spacing: -.015em; margin-bottom: .9rem; }
.lede { color: var(--ink-2); margin-bottom: 1rem; font-size: .95rem; }

.steps { display: flex; gap: .35rem; margin: 0 0 1.3rem; padding: 0; list-style: none; }
.steps li { flex: 1 1 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: .5rem 0 .2rem; border-top: 3px solid var(--rule); color: var(--faint); font-weight: 500; font-size: .75rem; letter-spacing: .02em; }
.steps li.done { border-color: var(--teal); color: var(--teal); }
.steps li.now { border-color: var(--ink); color: var(--ink); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 2.9rem; padding: 0 1.2rem; border-radius: var(--radius);
  border: 1px solid var(--rule-strong); background: var(--white); color: var(--ink);
  font-weight: 500; font-size: 1rem; text-decoration: none; text-align: center; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--mist); border-color: var(--teal); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-press); border-color: var(--teal-press); }
.btn.ink { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ink:hover { background: #2a3d52; }
.btn.quiet { border-color: transparent; background: transparent; color: var(--teal); min-height: 2.4rem; padding: 0 .5rem; font-weight: 500; }
.btn.quiet:hover { background: var(--mist); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.btn svg { flex: none; }

.actionbar {
  position: fixed; inset: auto 0 0 0; z-index: 4; display: flex; gap: .6rem; justify-content: center;
  padding: .65rem 1rem calc(.65rem + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, .96);
  border-top: 1px solid var(--rule); backdrop-filter: blur(8px);
}
.actionbar .inner { width: 100%; max-width: 38rem; display: flex; gap: .6rem; }
.actionbar.wide .inner { max-width: 62rem; }
.actionbar .btn { flex: 1; white-space: nowrap; }
.actionbar .btn.small { flex: 0 0 auto; padding: 0 1rem; }
@media (max-width: 36rem) { .actionbar .btn.small { display: none; } }

/* ---------- fields ---------- */
.field { margin-bottom: 1rem; }
.field > label, .field > .label { display: block; font-weight: 500; font-size: .8rem; color: var(--grey); margin-bottom: .3rem; letter-spacing: .01em; }
.field .opt { font-weight: 400; color: var(--faint); }
.input, .pick {
  display: flex; align-items: center; width: 100%; min-height: 2.9rem; padding: .45rem .8rem;
  border: 1px solid var(--rule-strong); border-radius: var(--radius); background: var(--white);
  font-size: 1rem; text-align: left;
}
textarea.input { min-height: 4.4rem; resize: vertical; line-height: 1.45; }
.input::placeholder, .pick .ph { color: var(--faint); opacity: 1; }
.input:focus { border-color: var(--teal); outline: 3px solid rgba(11, 122, 158, .16); outline-offset: 0; }
.input.bad { border-color: var(--danger); background: var(--danger-soft); }
.pick { justify-content: space-between; gap: .6rem; }
.pick .val { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.pick .ph { flex: 1; }
.pick .chev { color: var(--teal); flex: none; }
.pick:hover { border-color: var(--teal); }
.err { color: var(--danger); font-weight: 500; font-size: .9rem; margin-top: .3rem; }
.age-row { display: grid; grid-template-columns: 4.6rem 1fr; gap: .5rem; }
.age-row .input { padding-inline: .6rem; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border: 1px solid var(--rule-strong); border-radius: var(--radius); overflow: hidden; background: var(--white); }
.seg button { min-height: 2.8rem; border: 0; border-left: 1px solid var(--rule); background: transparent; font-weight: 500; font-size: .95rem; padding: 0 .2rem; }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* ---------- home ---------- */
.hello { font-weight: 600; font-size: 1.45rem; letter-spacing: -.015em; line-height: 1.2; }
.date { color: var(--grey); margin: .2rem 0 1.3rem; font-size: .9rem; }
.tile {
  display: flex; align-items: center; gap: .9rem; width: 100%; padding: 1rem 1.05rem; margin-bottom: .7rem;
  border-radius: var(--radius); border: 1px solid var(--rule); background: var(--white); text-align: left; text-decoration: none; color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
.tile .t { flex: 1; min-width: 0; }
.tile .t strong { display: block; font-weight: 600; font-size: 1.1rem; letter-spacing: -.01em; }
.tile .t span { color: var(--grey); font-size: .9rem; }
.tile.main { background: var(--ink); border-color: var(--ink); color: #fff; }
.tile.main .t span { color: #b9c9d6; }
.tile:hover { border-color: var(--teal); box-shadow: 0 2px 10px rgba(27, 42, 58, .08); }
.tile[aria-disabled="true"] { opacity: .55; }
.tile .bubble { width: 2.6rem; height: 2.6rem; border-radius: var(--radius); background: var(--teal); color: #fff; display: grid; place-items: center; flex: none; }
.tile:not(.main) .bubble { background: var(--mist); color: var(--teal); }

.section-h { font-size: .7rem; font-weight: 500; letter-spacing: .09em; text-transform: uppercase; color: var(--grey); margin: 1.8rem 0 .5rem; }
.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); background: var(--white); border-radius: var(--radius); border: 1px solid var(--rule); overflow: hidden; }
.list li + li { border-top: 1px solid var(--rule); }
.list .item { display: flex; align-items: center; gap: .7rem; width: 100%; min-height: 3.4rem; padding: .5rem .9rem; background: none; border: 0; text-align: left; }
.list .item:hover { background: var(--mist-2); }
.list .main { flex: 1; min-width: 0; }
.list .main b { display: block; overflow-wrap: anywhere; font-weight: 600; }
.list .sub { color: var(--grey); font-size: .85rem; }
.list .when { color: var(--faint); font-size: .8rem; white-space: nowrap; }
.empty { color: var(--grey); padding: .9rem 0; font-size: .95rem; }

.search { position: relative; margin-bottom: .6rem; }
.search svg { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--teal); pointer-events: none; }
.search .input { padding-left: 2.7rem; }
.found { margin-bottom: 1.2rem; }
.divider { border: 0; border-top: 1px solid var(--rule); margin: 1.3rem 0; }

/* ---------- prescription page ---------- */
.who {
  display: flex; align-items: center; gap: .8rem; padding: .75rem .95rem; margin-bottom: 1.1rem;
  background: var(--mist); border-radius: var(--radius);
}
.who b { font-weight: 600; font-size: 1.05rem; }
.who .sub { color: var(--ink-2); font-size: .85rem; }
.who .warn { color: var(--danger); font-weight: 600; font-size: .85rem; }
.med {
  position: relative; margin-bottom: .9rem; padding: .9rem .95rem .3rem; background: var(--white);
  border: 1px solid var(--rule); border-radius: var(--radius);
}
.med-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: .6rem; }
.med-h h2 { font-size: .7rem; font-weight: 500; letter-spacing: .09em; text-transform: uppercase; color: var(--teal); }
.med .grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0 .7rem; }
.med .grid .c2 { grid-column: span 2; } .med .grid .c3 { grid-column: span 3; }
.med .grid .c4 { grid-column: span 4; } .med .grid .c6 { grid-column: span 6; }
.med .grid .f-medicine { order: -1; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .1rem 0 .7rem; }
.chip { min-width: 2.6rem; min-height: 2.5rem; padding: 0 .6rem; border: 1px solid var(--rule-strong); border-radius: var(--radius); background: var(--white); font-weight: 500; font-size: .95rem; }
.chip:hover { border-color: var(--teal); }
.chip[aria-pressed="true"] { background: var(--teal); border-color: var(--teal); color: #fff; }
.add { width: 100%; min-height: 3.2rem; border: 1px dashed var(--teal); border-radius: var(--radius); background: transparent; color: var(--teal); font-weight: 500; display: flex; gap: .5rem; align-items: center; justify-content: center; }
.add:hover { background: var(--mist); }

/* ---------- preview ---------- */
.paper-wrap { background: #dbe6ec; border-radius: var(--radius); padding: .8rem; margin-bottom: 1.1rem; }
.paper { display: block; width: 100%; height: auto; background: #fff; box-shadow: 0 1px 2px rgba(27, 42, 58, .2), 0 10px 28px rgba(27, 42, 58, .16); }
.note { padding: .75rem .95rem; border-radius: var(--radius); background: var(--white); border: 1px solid var(--rule); margin-bottom: 1rem; font-size: .95rem; }
.note.warn { background: var(--warn-soft); border-color: #e6c86a; }
.note.ok { background: var(--ok-soft); border-color: var(--ok); }
.seal { display: flex; gap: .7rem; align-items: flex-start; padding: .8rem .95rem; border-radius: var(--radius); background: var(--mist); margin-bottom: .9rem; font-size: .9rem; color: var(--ink-2); }
.seal svg { color: var(--teal); flex: none; margin-top: .1rem; }
.seal b { display: block; color: var(--ink); font-weight: 600; }
.send-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: 1rem; }
.send-grid .btn { min-height: 3.1rem; }
.send-grid .btn.full { grid-column: 1 / -1; }
.issued { display: flex; align-items: center; gap: .5rem; font-weight: 600; color: var(--ok); margin-bottom: .8rem; font-size: .95rem; }
.devices { list-style: none; margin: 0 0 1rem; padding: 0; background: var(--white); border: 1px solid var(--rule); border-radius: var(--radius); }
.devices li { display: flex; align-items: center; gap: .7rem; padding: .6rem .9rem; }
.devices li + li { border-top: 1px solid var(--rule); }
.devices .d { flex: 1; min-width: 0; }
.devices .d b { font-weight: 600; display: block; }
.devices .d small { color: var(--grey); display: block; font-size: .8rem; }
.devices .tag { font-size: .7rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--teal); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 1.2rem; background: linear-gradient(180deg, var(--mist) 0, var(--mist-2) 60%); }
.login .card { width: 100%; max-width: 24rem; background: var(--white); border-radius: 10px; padding: 1.8rem 1.5rem; border: 1px solid var(--rule); box-shadow: 0 12px 40px rgba(27, 42, 58, .1); }
.login .mark { width: 3.4rem; height: 3.4rem; border-radius: 10px; display: block; margin-bottom: 1.1rem; }
.login h1 { font-weight: 600; font-size: 1.35rem; letter-spacing: -.015em; margin-bottom: .4rem; }
.login p { color: var(--ink-2); margin-bottom: 1.2rem; font-size: .95rem; }
.login .btn + .btn { margin-top: .6rem; }
.login .fine { margin: 1.1rem 0 0; font-size: .75rem; color: var(--faint); text-align: center; }

/* ---------- picker sheet ---------- */
.sheet-overlay { position: fixed; inset: 0; z-index: 20; background: rgba(27, 42, 58, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 38rem; max-height: 88dvh; display: flex; flex-direction: column;
  background: var(--white); border-radius: 12px 12px 0 0; animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 700px) { .sheet-overlay { align-items: center; } .sheet { border-radius: 10px; max-height: 80dvh; } }
.sheet-head { display: flex; align-items: center; gap: .6rem; padding: .9rem 1rem .6rem; }
.sheet-head h2 { flex: 1; font-weight: 600; font-size: 1.1rem; letter-spacing: -.01em; }
.sheet-x { width: 2.5rem; height: 2.5rem; border-radius: var(--radius); border: 0; background: var(--mist); display: grid; place-items: center; }
.sheet .search { padding: 0 1rem; margin-bottom: .5rem; }
.sheet .search svg { left: 1.85rem; }
.sheet-list { list-style: none; margin: 0; padding: 0 0 1rem; overflow-y: auto; overscroll-behavior: contain; }
.sheet-group { padding: .8rem 1rem .3rem; font-weight: 500; color: var(--grey); font-size: .7rem; letter-spacing: .09em; text-transform: uppercase; }
.sheet-item { display: flex; flex-direction: column; justify-content: center; width: 100%; min-height: 3rem; padding: .4rem 1rem; border: 0; border-top: 1px solid var(--rule); background: none; text-align: left; font-size: 1rem; color: var(--grey); }
.sheet-item:hover, .sheet-item:focus-visible { background: var(--mist-2); }
.sheet-item b { color: var(--ink); font-weight: 600; }
.sheet-item small { color: var(--faint); font-size: .8rem; }
.sheet-item.use { color: var(--teal); font-weight: 600; }
.sheet-item.sel { background: var(--mist); color: var(--ink); }
.sheet-none { padding: 1rem; color: var(--grey); }
.sheet-foot { padding: .6rem 1rem calc(.6rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--rule); display: flex; justify-content: space-between; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--bar-h) + 1rem); transform: translateX(-50%); z-index: 30; max-width: min(92vw, 28rem); padding: .75rem 1rem; border-radius: var(--radius); background: var(--ink); color: #fff; font-weight: 500; font-size: .95rem; box-shadow: 0 8px 24px rgba(27, 42, 58, .3); }
.toast.bad { background: var(--danger); }
.spin { width: 1.1rem; height: 1.1rem; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: turn .8s linear infinite; }
@keyframes turn { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .spin { animation-duration: 2s; } }

/* ---------- wide screens: one line per medicine ---------- */
@media (min-width: 62rem) {
  .med .grid { grid-template-columns: 6rem 1.5fr 1fr 1.7fr 5.6rem 5.4rem; }
  .med .grid > .field { grid-column: auto; order: 0; }
  .med .chips { margin: -.2rem 0 .8rem; }
}

/* ---------- review and send ---------- */
.page > .paper-wrap { max-width: 34rem; margin-inline: auto; }
.split { display: grid; gap: 1.2rem; }
@media (min-width: 56rem) {
  .split { grid-template-columns: minmax(0, 28rem) minmax(0, 1fr); gap: 2rem; align-items: start; }
  .split-b { position: sticky; top: 5rem; }
  .actionbar .inner:has(> .btn:only-child) { justify-content: center; }
  .actionbar .inner:has(> .btn:only-child) .btn { max-width: 22rem; }
}
.qr-preview { width: 9rem; height: 9rem; }
.paper-wrap:has(.qr-preview) { display: inline-block; max-width: none; margin-bottom: .6rem; }
textarea.input { min-height: 7rem; }
.field .sub { color: var(--grey); font-size: .85rem; margin: -.15rem 0 .35rem; }

/* ---------- public check page ---------- */
.verdict { display: flex; gap: .8rem; align-items: flex-start; padding: 1rem; border-radius: var(--radius); margin: 1rem 0; }
.verdict.good { background: var(--ok-soft); border: 1px solid var(--ok); }
.verdict.bad { background: var(--danger-soft); border: 1px solid var(--danger); }
.verdict b { display: block; font-weight: 600; font-size: 1.05rem; }
.verdict small { color: var(--ink-2); }
.drop { display: block; border: 1px dashed var(--rule-strong); border-radius: var(--radius); padding: 1.2rem; text-align: center; color: var(--ink-2); cursor: pointer; background: var(--mist-2); }
.drop:hover { border-color: var(--teal); background: var(--mist); }
.or { text-align: center; color: var(--faint); font-size: .8rem; margin: .9rem 0; letter-spacing: .08em; text-transform: uppercase; }
.code-in { text-transform: uppercase; letter-spacing: .12em; font-weight: 600; }

/* ---------- records and lookup ---------- */
.row2 { display: grid; grid-template-columns: 1fr 1.6fr; gap: .7rem; }
.pin { max-width: 11rem; font-size: 1.6rem; letter-spacing: .5em; text-align: center; font-weight: 600; }
.recbar { display: flex; gap: .6rem; align-items: center; justify-content: space-between; margin: 1rem 0 2rem; }
.sub.okline { color: var(--ok); font-weight: 500; margin: -.3rem 0 .8rem; }
