/* PharmD.AI — scalable pickers
   Dropdown sheet + date wheel. No build step, no dependencies.
   Every size derives from --ui-scale, which pharmdai-picker.js sets from the
   patient's iOS text-size setting. Never hardcode a px font size in here. */

:root {
  --ui-scale: 1;

  --pdai-text:   calc(17px * var(--ui-scale));
  --pdai-small:  calc(14px * var(--ui-scale));
  --pdai-label:  calc(13px * var(--ui-scale));
  --pdai-head:   calc(19px * var(--ui-scale));
  --pdai-row:    calc(54px * var(--ui-scale));
  /* The closed field matches the ones already on the page (portal.html's
     .md-sel / #pfSex): 42px tall, 14px text, 8px corners, hairline border.
     The sheet keeps its own larger type — that is the part being read. */
  --pdai-field:  calc(42px * var(--ui-scale));
  --pdai-field-text: calc(14px * var(--ui-scale));
  --pdai-tap:    calc(44px * var(--ui-scale));
  --pdai-gap:    calc(12px * var(--ui-scale));
  --pdai-pad:    calc(18px * var(--ui-scale));

  --pdai-wheel-item: calc(44px * var(--ui-scale));
  --pdai-wheel-h:    calc(var(--pdai-wheel-item) * 5);

  --pdai-olive:  #404A26;
  --pdai-deep:   #5A6A18;
  --pdai-lime:   #D4F084;
  --pdai-ink:    #1F2410;
  --pdai-canvas: #F4F4EC;
  --pdai-card:   #F7F9EE;
  --pdai-border: #C9CFB4;
  --pdai-hair:   #E3E5D6;
}

/* The original <select> / <input> stays in the form as the source of truth. */
/* !important on the sizes, not just the positioning. Several of these selects
   carry an inline style="width:100%" from the page, and an inline declaration
   beats a class rule — so the hidden original stayed full width, sat absolute
   beside its container, and pushed the document 44px wider than the phone.
   The page then scrolled sideways and the sticky header slid with it. */
.pdai-native-hidden {
  position: absolute !important;
  width: 1px !important; height: 1px !important;
  min-width: 0 !important; max-width: 1px !important;
  padding: 0 !important; margin: -1px !important;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0 !important;
}

/* ---------- Trigger button ---------- */

.pdai-trigger {
  width: 100%;
  min-height: var(--pdai-field);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(8px * var(--ui-scale));
  padding: calc(9px * var(--ui-scale)) calc(14px * var(--ui-scale));
  background: #FFFFFF;
  border: 1.5px solid #E0E5D8;
  border-radius: calc(8px * var(--ui-scale));
  font-family: Inter, -apple-system, system-ui, sans-serif;
  font-size: var(--pdai-field-text);
  line-height: 1.3;
  color: var(--pdai-ink);
  text-align: left;
  cursor: pointer;
}
.pdai-trigger:hover { border-color: #C9D6AC; }
.pdai-trigger:focus-visible { outline: 3px solid var(--pdai-deep); outline-offset: 2px; }
/* Colour only. Swapping the border WIDTH on open would shift the field by
   half a pixel every time the sheet appears. Same cue as .md-sel:focus. */
.pdai-trigger[aria-expanded="true"] { border-color: #7A9020; }
.pdai-trigger .pdai-trigger-text { flex: 1 1 auto; min-width: 0; }
.pdai-trigger.is-placeholder .pdai-trigger-text { color: #6B7355; }
/* Nothing to choose from yet — Dose before a medication is picked. Muted
   rather than hidden: the field still has to say what it is waiting for. */
.pdai-trigger.is-empty { cursor: default; background: var(--pdai-canvas); }
.pdai-trigger.is-empty .pdai-trigger-text { color: #8A9178; }
.pdai-trigger.is-empty .pdai-chev { opacity: .35; }
.pdai-trigger .pdai-chev { flex: 0 0 auto; width: calc(14px * var(--ui-scale)); height: calc(14px * var(--ui-scale)); }

/* ---------- Inline variant ----------
   For a choice that sits inside a line of text rather than in a form, like
   the 30/60/90 day supply in the price footer. Sized to its own content, so
   it cannot push the line it lives on past the edge of the card. */
.pdai-trigger-inline {
  width: auto;
  display: inline-flex;
  min-height: 0;
  vertical-align: baseline;
  gap: calc(4px * var(--ui-scale));
  padding: calc(3px * var(--ui-scale)) calc(9px * var(--ui-scale));
  border-radius: calc(6px * var(--ui-scale));
  background: var(--pdai-canvas);
  font-size: calc(13.5px * var(--ui-scale));
  font-weight: 600;
  color: var(--pdai-deep);
  max-width: 100%;
}
.pdai-trigger-inline .pdai-trigger-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdai-trigger-inline .pdai-chev { width: calc(11px * var(--ui-scale)); height: calc(11px * var(--ui-scale)); }

/* ---------- Sheet ---------- */

.pdai-backdrop {
  position: fixed; inset: 0;
  background: rgba(31, 36, 16, 0.42);
  z-index: 9998;
  opacity: 0;
  transition: opacity .18s ease;
}
.pdai-backdrop.is-open { opacity: 1; }

.pdai-sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  max-height: 88vh;
  background: var(--pdai-card);
  border-top-left-radius: calc(22px * var(--ui-scale));
  border-top-right-radius: calc(22px * var(--ui-scale));
  box-shadow: 0 -8px 28px rgba(31, 36, 16, 0.22);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transform: translateY(100%);
  transition: transform .22s cubic-bezier(.22,.61,.36,1);
  font-family: Inter, -apple-system, system-ui, sans-serif;
  color: var(--pdai-ink);
}
.pdai-sheet.is-open { transform: translateY(0); }

/* ---------- Popover, on a pointer device with room for one ----------
   A bottom sheet is right on a phone and absurd on a desktop, where two
   options were spanning the whole window. On a wide screen the same markup
   is anchored under the field instead, at the field's own width. JS sets
   left/top/width; everything else is here. */
.pdai-sheet.pdai-pop {
  left: auto; right: auto; bottom: auto;
  border-radius: calc(12px * var(--ui-scale));
  border: 1px solid var(--pdai-border);
  box-shadow: 0 12px 32px rgba(31, 36, 16, 0.18);
  max-height: min(52vh, calc(var(--pdai-row) * 8));
  padding-bottom: 0;
  transform: translateY(calc(-6px * var(--ui-scale)));
  opacity: 0;
  transition: opacity .12s ease, transform .12s ease;
}
.pdai-sheet.pdai-pop.is-open { transform: translateY(0); opacity: 1; }
.pdai-sheet.pdai-pop .pdai-grip { display: none; }
.pdai-sheet.pdai-pop .pdai-sheet-head { padding: calc(10px * var(--ui-scale)) calc(14px * var(--ui-scale)); }
.pdai-sheet.pdai-pop .pdai-sheet-title { font-size: var(--pdai-text); }
.pdai-sheet.pdai-pop .pdai-option { min-height: 0; padding: calc(10px * var(--ui-scale)) calc(14px * var(--ui-scale)); }
/* Picking an option closes the popover, so Done has nothing left to do. */
.pdai-sheet.pdai-pop .pdai-sheet-foot { display: none; }
.pdai-sheet.pdai-pop .pdai-wheels,
.pdai-sheet.pdai-pop .pdai-wheel-heads { padding-left: calc(14px * var(--ui-scale)); padding-right: calc(14px * var(--ui-scale)); }
.pdai-sheet.pdai-pop .pdai-wheels::after { left: calc(14px * var(--ui-scale)); right: calc(14px * var(--ui-scale)); }
/* The date wheel needs its Done: nothing is committed until then. */
.pdai-sheet.pdai-pop.pdai-pop-date { max-height: none; }
.pdai-sheet.pdai-pop.pdai-pop-date .pdai-sheet-foot { display: block; padding: calc(10px * var(--ui-scale)) calc(14px * var(--ui-scale)) calc(12px * var(--ui-scale)); }
/* No dimming behind a popover — it is not a modal interruption. */
.pdai-backdrop.pdai-pop-backdrop { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  .pdai-sheet, .pdai-backdrop { transition: none; }
}

.pdai-grip {
  flex: 0 0 auto;
  margin: calc(10px * var(--ui-scale)) auto 0;
  width: calc(42px * var(--ui-scale));
  height: calc(4px * var(--ui-scale));
  border-radius: 999px;
  background: var(--pdai-border);
}

.pdai-sheet-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--pdai-gap);
  padding: calc(12px * var(--ui-scale)) var(--pdai-pad);
  border-bottom: 1px solid var(--pdai-hair);
}
.pdai-sheet-title {
  font-family: Fraunces, Georgia, serif;
  font-size: var(--pdai-head);
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
}
.pdai-sheet-sub {
  font-size: var(--pdai-small);
  color: var(--pdai-deep);
  margin-top: calc(2px * var(--ui-scale));
  line-height: 1.3;
}
.pdai-close {
  flex: 0 0 auto;
  width: var(--pdai-tap); height: var(--pdai-tap);
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; border-radius: 999px;
  cursor: pointer;
}
.pdai-close:focus-visible { outline: 3px solid var(--pdai-deep); outline-offset: -3px; }

/* ---------- Option list ---------- */

.pdai-list {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Without this, reaching the end of the list hands the scroll to the page
     behind the sheet — so the patient swipes the options and the portal moves
     instead. Same for each wheel column. */
  overscroll-behavior: contain;
  margin: 0; padding: 0;
  list-style: none;
}
/* Keeping the page still is done WITHOUT locking it.

   overflow:hidden on the scrolling element makes the browser clamp scrollTop
   to 0, so the page jumped to the top when a sheet opened and jumped back
   when it closed. Containing the scroll at each edge instead leaves the page
   exactly where it was: the list and the wheels do not chain their scroll
   outward, and the chrome around them does not take a drag at all. */
.pdai-sheet { overscroll-behavior: contain; }
.pdai-backdrop,
.pdai-sheet-head,
.pdai-sheet-foot,
.pdai-grip,
.pdai-wheel-heads { touch-action: none; }
.pdai-option {
  min-height: var(--pdai-row);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: var(--pdai-gap);
  padding: calc(15px * var(--ui-scale)) var(--pdai-pad);
  font-size: var(--pdai-text);
  line-height: 1.3;
  border-bottom: 1px solid #E8EADC;
  cursor: pointer;
}
/* The [hidden] attribute sets display:none from the UA stylesheet, which a
   class rule of ours outranks - so a filtered-out row stayed on screen while
   the DOM insisted it was hidden. Caught by looking at it; the search filter
   had been setting .hidden correctly and changing nothing. */
.pdai-option[hidden], .pdai-group[hidden] { display: none !important; }
.pdai-option:focus-visible { outline: 3px solid var(--pdai-deep); outline-offset: -3px; }
.pdai-option[aria-selected="true"] { background: #EDF4D8; font-weight: 600; }
/* The tick sits at the trailing edge, so an unselected option starts at the
   same left edge as the sheet title instead of being indented past a column
   that is empty on every row but one. */
.pdai-option .pdai-tick { order: 2; flex: 0 0 auto; width: calc(18px * var(--ui-scale)); height: calc(18px * var(--ui-scale)); visibility: hidden; }
.pdai-option[aria-selected="true"] .pdai-tick { visibility: visible; }
.pdai-option-label { order: 1; flex: 1 1 auto; min-width: 0; }
/* The second name, in the margin: "Vietnamese" beside "Tiếng Việt". Muted
   and smaller, because it is there for the person helping rather than the
   person choosing. It may be the longer of the two, so it is allowed to
   shrink and clip rather than push the real name off the row. */
.pdai-option-alt {
  order: 1;
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
  font-size: calc(12.5px * var(--ui-scale));
  color: #8A9178;
}

/* ---------- Search, on long lists ---------- */

.pdai-search {
  flex: 0 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  gap: calc(8px * var(--ui-scale));
  margin: calc(10px * var(--ui-scale)) var(--pdai-pad) calc(4px * var(--ui-scale));
  padding: calc(8px * var(--ui-scale)) calc(14px * var(--ui-scale));
  background: var(--pdai-canvas);
  border: 1.5px solid var(--pdai-border);
  border-radius: 999px;
}
.pdai-search:focus-within { border-color: #7A9020; }
.pdai-search svg {
  flex: 0 0 auto;
  width: calc(15px * var(--ui-scale));
  height: calc(15px * var(--ui-scale));
  color: #8A9178;
}
.pdai-search input {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  background: none;
  padding: 0;
  font-family: Inter, -apple-system, system-ui, sans-serif;
  font-size: var(--pdai-field-text);
  color: var(--pdai-ink);
}
.pdai-search input:focus { outline: none; }
/* Safari draws its own clear button on type=search and it lands on top of
   the rounded edge. */
.pdai-search input::-webkit-search-decoration,
.pdai-search input::-webkit-search-cancel-button { -webkit-appearance: none; }
/* Sits under the field rather than in the list, so "nothing matches" does
   not scroll away with the rows it is talking about. */
.pdai-search-none {
  position: absolute;
  left: 0; right: 0; top: 100%;
  margin: calc(10px * var(--ui-scale)) 0 0;
  text-align: center;
  font-size: calc(13px * var(--ui-scale));
  color: #8A9178;
}

/* ---------- Footer ---------- */

.pdai-sheet-foot {
  flex: 0 0 auto;
  padding: calc(14px * var(--ui-scale)) var(--pdai-pad) calc(24px * var(--ui-scale));
  border-top: 1px solid var(--pdai-hair);
}
.pdai-done {
  width: 100%;
  min-height: calc(50px * var(--ui-scale));
  border: none;
  border-radius: calc(12px * var(--ui-scale));
  background: var(--pdai-olive);
  color: var(--pdai-canvas);
  font-family: Inter, -apple-system, system-ui, sans-serif;
  font-size: var(--pdai-text);
  font-weight: 600;
  cursor: pointer;
}
.pdai-done:focus-visible { outline: 3px solid var(--pdai-ink); outline-offset: 2px; }

/* ---------- Date wheel ---------- */

.pdai-wheels {
  flex: 0 0 auto;
  position: relative;
  display: flex;
  gap: calc(6px * var(--ui-scale));
  padding: calc(8px * var(--ui-scale)) var(--pdai-pad);
}

/* The centre band that shows which values are chosen. */
.pdai-wheels::after {
  content: "";
  position: absolute;
  left: var(--pdai-pad); right: var(--pdai-pad);
  top: calc(8px * var(--ui-scale) + (var(--pdai-wheel-h) - var(--pdai-wheel-item)) / 2);
  height: var(--pdai-wheel-item);
  border-top: 1px solid var(--pdai-border);
  border-bottom: 1px solid var(--pdai-border);
  background: rgba(212, 240, 132, 0.28);
  border-radius: calc(10px * var(--ui-scale));
  pointer-events: none;
}

.pdai-wheel {
  flex: 1 1 0;
  min-width: 0;
  /* border-box, or the padding below is added to the height instead of
     living inside it: --pdai-wheel-h is five rows (220px) and the padding
     that centres a row within those five is 88px a side, which under
     content-box made the real viewport 396px - nine rows. The band stayed
     where five rows put it while the list scrolled against nine, so the
     wheels could not bring their last entries under it. December was not
     selectable, and on a two-year range neither was the second year. */
  box-sizing: border-box;
  height: var(--pdai-wheel-h);
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  padding-block: calc((var(--pdai-wheel-h) - var(--pdai-wheel-item)) / 2);
  margin: 0;
  list-style: none;
  text-align: center;
}
.pdai-wheel::-webkit-scrollbar { display: none; }
.pdai-wheel:focus-visible { outline: 3px solid var(--pdai-deep); outline-offset: 2px; border-radius: calc(10px * var(--ui-scale)); }
.pdai-wheel[data-unit="month"] { flex-grow: 1.6; }
.pdai-wheel[data-unit="year"]  { flex-grow: 1.1; }

.pdai-wheel-item {
  height: var(--pdai-wheel-item);
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: center;
  font-size: var(--pdai-text);
  line-height: 1.2;
  color: #6B7355;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pdai-wheel-item.is-current { color: var(--pdai-ink); font-weight: 600; }

.pdai-wheel-heads {
  flex: 0 0 auto;
  display: flex;
  gap: calc(6px * var(--ui-scale));
  padding: 0 var(--pdai-pad);
}
.pdai-wheel-heads span {
  flex: 1 1 0;
  text-align: center;
  font-size: var(--pdai-label);
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--pdai-deep);
}
.pdai-wheel-heads span[data-unit="month"] { flex-grow: 1.6; }
.pdai-wheel-heads span[data-unit="year"]  { flex-grow: 1.1; }

/* ---- Group headings ----
   Sticky, so the patient scrolling the pediatric list always knows whether
   they are looking at an over-the-counter medicine or a prescription one.
   Not selectable and not in the tab order — it is a label, not a choice. */
.pdai-group {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: calc(9px * var(--ui-scale)) var(--pdai-pad) calc(5px * var(--ui-scale));
  background: var(--pdai-card);
  border-bottom: 1px solid var(--pdai-hair);
  font-size: var(--pdai-label);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--pdai-deep);
  list-style: none;
  cursor: default;
}
