/* My visits (patient app) only: greeting, the upcoming appointment, the arrival steps,
   visit history and the booking and cancel dialogs. Shared parts (header, footer and its current
   page, page-top rhythm, section headings, buttons, quiet and compact actions, card, icon tile,
   step badge, chip, tag, select, inline errors, status notes, motion, forced colours) are in
   styles.css; tokens are in brand.css. */

.app { overflow-x: clip; }
/* The three page sections take the shared section heading (28 / 34, 24 / 30 on phones). */
.app section > h2 { margin-bottom: 1rem; }

/* ---------- Greeting ---------- */
.hello {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem;
  color: var(--ink-muted);
}
.hello-name { font: 600 1rem/1.5rem var(--font-body); color: var(--text); }
.avatar {
  display: grid; place-items: center; width: 2.5rem; height: 2.5rem; flex: none; border-radius: 50%;
  font: 700 .875rem/1.25rem var(--font-body); letter-spacing: .02em; color: var(--plum);
  background: var(--avatar-fill);
  box-shadow: inset 0 0 0 1px rgb(48 36 67 / .07), inset 0 1px 0 rgb(255 255 255 / .9), var(--shadow-1);
}
.greeting h1 { margin-top: .875rem; }

/* ---------- Layout ---------- */
.app-grid { display: grid; gap: 2.5rem; margin-top: 2.5rem; }
.next-visit, .visit-path { display: flex; flex-direction: column; min-width: 0; }
.visit-card, .handoff { flex: 1; }
@media (min-width: 64rem) {
  .app-grid { grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); column-gap: 2rem; }
}

/* ---------- Upcoming appointment: the one raised surface, with a Butter and Periwinkle glow ---------- */
.next-visit { position: relative; isolation: isolate; }
/* closest-side sizing ends each glow at the nearest edge of its box, so no edge of the box
   shows on wide screens where the content column sits away from the viewport edge. */
.next-visit::before {
  content: ""; position: absolute; z-index: -1; pointer-events: none;
  inset: 0 calc(-1 * var(--gutter)) -3rem;
  background:
    radial-gradient(closest-side at 34% 58%, rgb(255 241 199 / .9), rgb(255 241 199 / .45) 55%, rgb(255 241 199 / 0)),
    radial-gradient(closest-side at 76% 44%, rgb(182 185 255 / .34), rgb(182 185 255 / 0));
}
.visit-card { display: grid; align-content: start; gap: 1.5rem; padding: 1.75rem; }
/* Side by side, the card's rhythm opens up to match the height of the handoff list. */
@media (min-width: 64rem) { .visit-card { gap: 1.75rem; padding: 2rem; } }

/* The copy's children sit on the card's own grid, so the timing chip can take the top right
   and, on phones, the time and place can run the full width under the date tile. */
#appointment {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .375rem 1.5rem;
  grid-template-areas: "tile title when" "tile time time" "tile place place";
}
.appointment-copy { display: contents; }
.date-card { grid-area: tile; }
#next-dept { grid-area: title; }
.visit-when { grid-area: when; justify-self: end; align-self: start; }
.visit-time { grid-area: time; }
.visit-place { grid-area: place; }
/* A Poppy dot: the next position in the patient's sequence. */
.visit-when .chip { gap: .4375rem; padding-inline: .625rem .75rem; }
.visit-when .chip::before {
  content: ""; width: .4375rem; height: .4375rem; border-radius: 50%;
  background: var(--poppy); box-shadow: 0 0 0 3px rgb(243 107 83 / .16);
}
.visit-when .chip:empty { display: none; }
/* Radiant date tile: one item of visit context (brand.md, radiant-butter). */
.date-card {
  position: relative;
  display: grid; justify-items: center; align-content: center; flex: none;
  width: 5.5rem; height: 6rem; border-radius: 1.25rem;
  color: var(--plum); background: var(--radiant-butter); text-align: center;
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / .95), inset 0 0 0 1px rgb(48 36 67 / .06),
    inset 0 -8px 16px rgb(252 217 184 / .45),
    0 2px 4px rgb(48 36 67 / .06), 0 14px 26px -14px rgb(48 36 67 / .32);
}
#card-month { font: 700 .875rem/1.25rem var(--font-body); letter-spacing: .04em; color: var(--ink-muted); }
#card-day { font: 700 2.5rem/2.75rem var(--font-display); letter-spacing: -.035em; }

#next-dept { min-width: 0; overflow-wrap: anywhere; }
.visit-meta { display: flex; align-items: flex-start; gap: .5rem; min-width: 0; overflow-wrap: anywhere; }
.visit-meta .icon { width: 1.125rem; height: 1.125rem; margin-top: .1875rem; stroke-width: 1.9; color: var(--ink-muted); }
.clinic-context { color: var(--ink-muted); }

#empty { display: flex; align-items: center; gap: 1rem; }
#empty p { max-width: 40ch; }

.visit-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem;
  padding-top: 1.5rem; border-top: 1px solid var(--hairline);
}
/* Change visit opens a dialog in place, so its well holds the action's own glyph (a calendar,
   brand.md §2) and stays still on hover instead of nudging like an arrow. Cancel visit is the
   shared quiet action (.btn-quiet). */
.visit-actions .btn-primary:hover .btn-arrow .icon { transform: none; }

/* Status messages are the shared status note (styles.css). */

/* ---------- When you arrive: the steps ahead, numbered with the shared step badge ---------- */
/* None of these steps has happened yet, so the list shows only the dotted track between them, and
   the radiant tile marks the next step (check in). The Poppy handoff line is drawn only up to a
   current stage (brand.md §2), so it has no segment to draw here. */
.handoff {
  --step-gap: 2rem;
  list-style: none; margin: 0; padding: 1.75rem 1.5rem;
  display: grid; align-content: start; gap: var(--step-gap);
  border-radius: var(--radius-card); background: rgb(255 255 255 / .6);
  box-shadow: inset 0 0 0 1px var(--hairline);
}
.handoff li {
  position: relative;
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 1rem;
}
.handoff-text { display: grid; gap: .125rem; min-width: 0; padding-top: .25rem; overflow-wrap: break-word; }
.handoff-title { font: 700 1rem/1.5rem var(--font-body); }
.handoff-caption { font-size: var(--type-small); line-height: var(--leading-small); color: var(--ink-muted); }

/* A dotted track from each tile to the next. */
.handoff li:not(:last-child)::before {
  content: ""; position: absolute; left: 1.625rem; width: 2px; margin-left: -1px; border-radius: 2px;
  top: calc(3.25rem + .3125rem); bottom: calc(-1 * var(--step-gap) + .3125rem);
  pointer-events: none;
  background: repeating-linear-gradient(180deg, var(--divider) 0 3px, rgb(203 194 205 / 0) 3px 7px);
}

/* Tablets: the list is a full-width row, so the three steps sit side by side and the line runs
   across from tile to tile, as on the homepage stage cards. */
@media (min-width: 40rem) and (max-width: 63.99rem) {
  .handoff { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 1.75rem; }
  .handoff li { grid-template-columns: minmax(0, 1fr); gap: .875rem; }
  .handoff-text { padding-top: 0; }
  .handoff li:not(:last-child)::before {
    left: calc(3.25rem + .3125rem); right: calc(-1 * var(--step-gap) + .3125rem);
    top: 1.625rem; bottom: auto; width: auto; height: 2px; margin: -1px 0 0;
    background: repeating-linear-gradient(90deg, var(--divider) 0 3px, rgb(203 194 205 / 0) 3px 7px);
  }
}

/* ---------- Visit history ---------- */
.records { margin-top: 3.5rem; }
.history {
  list-style: none; margin: 0; padding: 0;
  border-radius: var(--radius-card); background: rgb(255 255 255 / .78);
  box-shadow: inset 0 0 0 1px var(--hairline), var(--shadow-1);
}
.history-item { padding: 1.25rem 1.5rem; }
.history-item + .history-item { border-top: 1px solid var(--hairline); }
.history-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: .75rem 1.25rem;
  grid-template-areas: "tile text chip pdf";
}
.history-row > .icon-tile { grid-area: tile; }
.history-text { grid-area: text; display: grid; gap: .125rem; min-width: 0; overflow-wrap: anywhere; }
.history-text strong { font: 700 1rem/1.5rem var(--font-body); }
.history-text small { font-size: var(--type-small); line-height: var(--leading-small); color: var(--ink-muted); }
.history-chip { grid-area: chip; }
.download { grid-area: pdf; }  /* the shared compact pill, .btn-compact */
.download:disabled { opacity: .6; cursor: progress; transform: none; }

.history-item details, #export-status { margin-left: calc(3.25rem + 1.25rem); }
.history-item details { margin-top: .5rem; }
.history-item summary {
  display: inline-flex; align-items: center; gap: .375rem; min-height: 2.75rem; padding-inline: .125rem;
  border-radius: .375rem; list-style: none;
  font-weight: 650; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: .35em;
  text-decoration-color: var(--periwinkle);
  transition: text-decoration-color var(--dur-quick) ease;
}
.history-item summary::-webkit-details-marker { display: none; }
.history-item summary .icon { width: 1.125rem; height: 1.125rem; stroke-width: 2; transition: transform var(--dur-base) var(--ease-out); }
@media (hover: hover) { .history-item summary:hover { text-decoration-color: var(--plum); } }
.history-item details[open] summary .icon { transform: rotate(180deg); }
.record-content {
  max-width: 44rem; margin-top: .5rem; padding: .25rem 1.25rem; border-radius: 1rem;
  background: var(--chalk); box-shadow: inset 0 0 0 1px var(--hairline);
}
#released-details > div {
  display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: .25rem 1rem; padding-block: .75rem;
}
#released-details > div + div { border-top: 1px solid var(--hairline); }
#released-details dt { font-size: var(--type-small); line-height: var(--leading-small); color: var(--ink-muted); }
#released-details dd { min-width: 0; overflow-wrap: anywhere; font: 650 var(--type-small)/var(--leading-small) var(--font-body); }
#export-status { margin-top: .75rem; }

.storage-note {
  display: flex; align-items: flex-start; gap: .5rem; margin-top: 1.25rem;
  font-size: var(--type-small); line-height: var(--leading-small); color: var(--ink-muted);
}
.storage-note .icon { width: 1.125rem; height: 1.125rem; margin-top: 1px; stroke-width: 1.6; }

/* ---------- Dialogs ---------- */
.app-dialog {
  width: min(calc(100% - 2rem), 34rem); max-width: none;
  max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem);
  padding: 0; border: 0; border-radius: var(--radius-card);
  color: var(--text); background: var(--raised);
  box-shadow: inset 0 0 0 1px rgb(48 36 67 / .05), var(--shadow-3);
  overflow-y: auto; overscroll-behavior: contain; overflow-wrap: anywhere;
}
.app-dialog::backdrop { background: rgb(48 36 67 / .5); }
.app-dialog h2 { font-size: 1.5rem; line-height: 1.875rem; }
.app-dialog .btn-primary { padding: 0 1.5rem; }

.dialog-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.75rem 1.75rem 0; }
.dialog-heading { min-width: 0; }
.dialog-sub { margin-top: .25rem; font-size: var(--type-small); line-height: var(--leading-small); color: var(--ink-muted); }
.dialog-title .icon-button { margin: -.25rem -.5rem 0 0; }

.dialog-body { display: grid; gap: 1.5rem; padding: 1.5rem 1.75rem .5rem; }
.dialog-body label[for], .dialog-body legend { display: block; margin: 0 0 .5rem; padding: 0; font: 650 1rem/1.5rem var(--font-body); }
.dialog-body fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }

/* The clinic select is the shared text field (styles.css: .field select). */
.dialog-body select { display: block; }

/* Choice chips: Soft iris plus a 2 px Plum edge, a weight change and a check badge when selected. */
.choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .625rem; }
.choices label { position: relative; display: block; cursor: pointer; }
.choices input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.choices label > span {
  position: relative; display: grid; align-content: center; min-height: 4rem; padding: .625rem .875rem;
  border-radius: var(--radius-input); background: var(--white);
  box-shadow: inset 0 0 0 1px var(--edge), var(--shadow-1);
  font: 650 1rem/1.5rem var(--font-body); color: var(--text);
  transition: background-color var(--dur-quick) ease, box-shadow var(--dur-quick) ease;
}
.choices small { font: 400 var(--type-small)/var(--leading-small) var(--font-body); color: var(--ink-muted); }
#times label > span { display: flex; align-items: baseline; gap: .25rem; min-height: 3rem; }
@media (hover: hover) { .choices input:hover + span { box-shadow: inset 0 0 0 1px var(--ink-muted), var(--shadow-1); } }
.choices input:checked + span {
  font-weight: 700; background: var(--selection-bg);
  box-shadow: inset 0 0 0 2px var(--plum), 0 6px 14px -8px rgb(48 36 67 / .35);
}
.choices input:checked + span small { color: var(--plum); }
.choices input:checked + span::after {
  content: ""; position: absolute; top: -.4375rem; right: -.4375rem;
  width: 1.375rem; height: 1.375rem; border-radius: 50%;
  background: var(--plum) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23FFFBF5' stroke-width='2.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 12.5l3.75 3.75L18 8'/%3E%3C/svg%3E") center / .875rem no-repeat;
  box-shadow: 0 0 0 2px var(--raised), 0 3px 6px -2px rgb(48 36 67 / .5);
}
.choices input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }
.choices input[aria-invalid="true"] + span { box-shadow: inset 0 0 0 2px var(--error); }
.dialog-body .field-error { margin-top: .5rem; }

.booking-review {
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: .875rem;
  padding: .875rem 1rem; border-radius: 1rem;
  background: var(--butter-wash);
  box-shadow: inset 0 0 0 1px rgb(48 36 67 / .06);
}
.review-icon {
  grid-row: span 2; display: grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: 50%;
  background: var(--white); box-shadow: inset 0 0 0 1px var(--hairline), var(--shadow-1);
}
.review-icon .icon { width: 1.25rem; height: 1.25rem; }
.review-label { font-size: var(--type-small); line-height: var(--leading-small); color: var(--ink-muted); }
#booking-review { font-weight: 650; }

/* The primary action stays in reach while the form scrolls. */
.dialog-foot {
  position: sticky; bottom: 0; z-index: 2;
  padding: 1.25rem 1.75rem 1.75rem;
  background: linear-gradient(180deg, rgb(255 255 255 / 0), var(--raised) 1.25rem);
}
.save { width: 100%; }

.confirm-dialog { width: min(calc(100% - 2rem), 28rem); }
.confirm-body { padding: 2rem 2rem 0; }
.confirm-body .icon-tile { margin-bottom: 1.25rem; }
#cancel-context { margin-top: .5rem; color: var(--ink-muted); text-wrap: pretty; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: .75rem; padding: 1.75rem 2rem 2rem; }
.dialog-actions .btn { flex: 1 1 9rem; }

@media (prefers-reduced-motion: no-preference) {
  .app-dialog[open] { animation: dialog-in var(--dur-state) var(--ease-out); }
  .app-dialog[open]::backdrop { animation: backdrop-in var(--dur-base) ease; }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 47.99rem) {
  .app-dialog[open] { animation-name: sheet-in; }
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(.75rem) scale(.985); } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(2.5rem); } }
@keyframes backdrop-in { from { opacity: 0; } }

/* ---------- Phone ---------- */
@media (max-width: 47.99rem) {
  .greeting h1 { margin-top: .625rem; }
  .app-grid { gap: 2.25rem; margin-top: 1.75rem; }
  .next-visit::before { inset: 1rem calc(-1 * var(--gutter)) -2rem; }
  .visit-card { gap: 1.25rem; padding: 1.25rem; }
  #appointment {
    grid-template-columns: auto minmax(0, 1fr); gap: .25rem 1rem;
    grid-template-areas: "tile title" "tile when" "time time" "place place";
  }
  #next-dept { align-self: end; }
  .visit-when { justify-self: start; align-self: start; }
  .visit-time { margin-top: 1rem; }
  .date-card { width: 4.75rem; height: 5.25rem; border-radius: 1.125rem; }
  #card-day { font-size: 2.125rem; line-height: 2.375rem; }
  .visit-actions { flex-direction: column; align-items: stretch; gap: .25rem; padding-top: 1.25rem; }
  /* As on the homepage: the quiet secondary sits under the full-width pill, on its left edge. */
  .visit-actions .btn-quiet { align-self: flex-start; }
  .handoff { padding: 1.5rem 1.25rem; }

  .records { margin-top: 2.75rem; }
  .history-item { padding: 1.125rem 1rem 1rem; }
  .history-row {
    grid-template-columns: auto minmax(0, 1fr); gap: .25rem 1rem;
    grid-template-areas: "tile text" "tile chip" "pdf pdf";
  }
  .history-row > .icon-tile { align-self: start; }
  .history-chip { justify-self: start; margin-top: .25rem; }
  .download { width: 100%; margin-top: .75rem; }
  .history-item details, #export-status { margin-left: 0; }
  #released-details > div { grid-template-columns: minmax(0, 1fr); }

  /* Dialogs become bottom sheets with the primary action pinned to the bottom edge. */
  .app-dialog, .confirm-dialog {
    width: 100%; max-height: calc(100vh - 1rem); max-height: calc(100dvh - 1rem);
    margin: auto 0 0; border-radius: var(--radius-card) var(--radius-card) 0 0;
  }
  .dialog-title { padding: 1.25rem 1rem 0 1.25rem; }
  .dialog-title .icon-button { margin: -.375rem 0 0; }
  .dialog-body { gap: 1.25rem; padding: 1.25rem 1.25rem 1rem; }
  .dialog-foot {
    padding: .75rem 1.25rem max(1rem, env(safe-area-inset-bottom));
    background: var(--raised); box-shadow: 0 -1px 0 var(--hairline), 0 -12px 20px -12px rgb(48 36 67 / .12);
  }
  .confirm-body { padding: 1.75rem 1.25rem 0; }
  .dialog-actions { flex-direction: column; gap: .5rem; padding: 1.5rem 1.25rem max(1.25rem, env(safe-area-inset-bottom)); }
  .dialog-actions .btn { flex: none; width: 100%; }
}
@media (max-width: 23.75rem) {
  .choices { gap: .5rem; }
  .choices label > span { padding-inline: .75rem; }
}

/* viewport-fit=cover lets the installed app reach the screen edges, so on a phone turned
   sideways the content keeps clear of the notch. env() is 0 everywhere else. */
.site-header.wrap, .app.wrap, .site-footer.wrap {
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
}

/* Forced colours (Windows contrast themes) drop shadows and tints, so choice chips get a system
   edge and the selected chip a thicker Highlight edge. Buttons, cards, chips and status notes
   are covered in styles.css. */
@media (forced-colors: active) {
  .choices label > span { border: 1px solid CanvasText; }
  .choices input:checked + span { border: 3px solid Highlight; }
  .choices input:checked + span::after { forced-color-adjust: none; }
  .choices input[aria-invalid="true"] + span { border-style: dashed; }
  .history, .handoff, .record-content, .booking-review, .app-dialog { border: 1px solid CanvasText; }
}
