@layer components {
  .study-workspace { max-width: 1100px; margin-inline: auto; padding: 1.5rem clamp(1rem, 3vw, 2.5rem) 4rem; }
  .study-workspace .app-page-header { padding-inline: 0; margin-bottom: 1.5rem; }
  .study-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.5rem 0 1rem; }
  .study-section-heading h2 { font-size: 1.5rem; }
  .study-list { list-style: none; padding: 0; margin: 0; }
  .study-list li { display: flex; align-items: center; gap: 1rem; justify-content: space-between; padding: 1rem .25rem; border-bottom: 1px solid var(--line-strong); }
  .study-list li > div { display: grid; gap: .25rem; }
  .study-list li > div > span { color: var(--muted); font-size: .875rem; }
  .study-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
  .study-field-wide { grid-column: 1 / -1; }
  .study-edit-form { display: grid; gap: 1.5rem; max-width: 760px; }
  .study-fields .field { display: grid; gap: .35rem; align-content: start; }
  .study-fields [hidden], .study-file-choice[hidden] { display: none; }
  .study-note-entry { border-radius: 8px; margin: 1rem 0; background: var(--surface); }
  .study-note-entry > .button { justify-self: end; }
  .study-actions, .study-note-actions { display: flex; flex-wrap: wrap; gap: .65rem; align-items: center; }
  .study-actions > .field-error { flex-basis: 100%; }
  .study-context, .study-draft-notice, .study-muted { color: var(--muted); font-size: .875rem; }
  .study-draft-notice { margin-top: .75rem; }
  .study-file-choice { display: flex; gap: .7rem; align-items: flex-start; padding: .7rem 0; font-weight: 500; }
  .study-file-choice input { width: 1.1rem; height: 1.1rem; flex: 0 0 1.1rem; margin-top: .2rem; accent-color: var(--periwinkle); }
  .study-file-choice small { margin-top: .2rem; }
  .study-existing-files summary, .study-history summary { font-weight: 700; cursor: pointer; }
  .study-documents, .study-history { margin-top: 2rem; max-width: 760px; }
  .study-document-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .75rem; padding: 1rem 0; border-bottom: 1px solid var(--line-strong); overflow-wrap: anywhere; }
  .study-history li { padding: .5rem 0; }
  .study-history li span { display: block; color: var(--muted); font-size: .8rem; }
  .study-overview { padding: 1rem 1.5rem 2rem; }
  .study-status { font-size: .8rem; color: var(--muted); }
  .study-status[data-status="received"], .study-status.is-received { color: var(--success); }
  .study-patient-workspace { max-width: 760px; }
  .study-patient-workspace h1 { font-size: clamp(2rem, 5vw, 3rem); line-height: 1.08; }
  .study-patient-workspace .care-header .study-back { color: #fff; text-decoration: underline; text-underline-offset: .2em; }
  .study-patient-workspace .care-header .study-status { color: var(--lilac-soft); margin-top: .8rem; }
  .study-selected-files { font-size: .875rem; overflow-wrap: anywhere; }
  .study-upload .document-file-trigger { display: inline-flex; width: fit-content; }
  .study-back { display: inline-block; margin-bottom: 1.25rem; font-size: .875rem; }
  .study-patient-section { padding: 1.5rem 0; border-top: 1px solid var(--line-strong); }
  .study-patient-section h2 { font-size: 1.45rem; margin-bottom: 1rem; }
  .study-patient-row { display: flex; align-items: center; gap: 1rem; padding: 1rem .15rem; border-bottom: 1px solid var(--line); color: var(--ink); }
  .study-patient-row-body { display: grid; gap: .3rem; flex: 1; min-width: 0; }
  .study-patient-row-body > span { color: var(--muted); font-size: .875rem; }
  .study-patient-row > .study-status { max-width: 9rem; text-align: right; }
  .study-native-summary { padding-block: 1rem; }
  .native-patient-portal .study-patient-workspace > .study-patient-section:first-child { border-top: 0; }
  .study-upload-matching summary { cursor: pointer; font-weight: 600; padding-block: .75rem; }
  .study-upload form { display: grid; gap: 1rem; }
  .study-upload-choices { border-radius: 8px; gap: 0; padding-block: .25rem; }
  .study-upload input[type="file"] { padding: .75rem; }
  .study-upload input[type="submit"] { width: auto; justify-self: start; }
  .study-request-details p + p { margin-top: .75rem; }
  .study-files { padding-left: 1.25rem; overflow-wrap: anywhere; }
  .study-files li { padding-block: .6rem; }
  @media (max-width: 600px) {
    .study-fields { grid-template-columns: minmax(0, 1fr); }
    .study-list li { align-items: flex-start; flex-direction: column; }
    .study-patient-row { gap: .6rem; }
    .study-patient-row > .study-status { max-width: 6.5rem; }
    .study-actions > .button { width: 100%; }
    .study-overview { padding-inline: 1rem; }
  }
}

@layer components {
  .study-patient-workspace[data-controller="study-workspace"] { padding-bottom: calc(var(--study-bar-height, 10rem) + 2rem); }
  .study-patient-workspace [hidden] { display: none !important; }
  .study-pending { border-top: 0; }
  .study-selection-hint { margin-bottom: 1.25rem; }
  .study-selectable { padding: 1rem 0; border-bottom: 1px solid var(--line-strong); scroll-margin-top: 1rem; }
  .study-selectable:has(input:checked) { background: var(--coral-soft); margin-inline: -.75rem; padding-inline: .75rem; }
  .study-selectable .study-file-choice { padding: .25rem 0; min-height: 48px; }
  .study-selectable .study-file-choice > span { display: grid; gap: .25rem; }
  .study-selectable .study-file-choice input { width: 1.25rem; height: 1.25rem; flex-basis: 1.25rem; accent-color: var(--coral); }
  .study-selectable .study-file-choice small { color: var(--muted); font-size: .875rem; font-weight: 400; }
  .study-selectable:has(input:disabled) { opacity: .65; }
  .study-instructions { font-size: .875rem; margin-block: .75rem; white-space: pre-line; }
  .study-selectable .study-status { margin-top: .6rem; }
  .study-file-guidance { margin-block: 1rem; font-size: .8rem; }
  .study-batch-bar { position: fixed; inset: auto 0 0; z-index: 20; max-width: 760px; margin-inline: auto; background: var(--surface); padding: 1rem max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--line-strong); }
  .study-selection-count { font-size: .875rem; margin-bottom: .65rem; }
  .study-batch-bar .study-choose, .study-batch-bar .study-actions > input { width: 100%; justify-content: center; }
  .study-batch-bar .study-choose { background: var(--coral); color: white; border-color: var(--coral); }
  .study-choose.is-disabled { opacity: .55; cursor: default; }
  .study-choose { min-height: 48px; gap: .5rem; }
  .study-choose svg { width: 20px; height: 20px; flex: none; }
  .study-upload-selection { flex-basis: 100%; background: var(--lilac-soft); padding: .85rem; border-radius: 10px; }
  .study-upload-selection .study-actions { margin-top: .75rem; }
  .study-upload-selection .study-muted { margin-top: .5rem; }
  .study-file-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-top: .75rem; }
  .study-replace-form { display: contents; }
  .study-file-actions > .field-error { flex-basis: 100%; }
  .study-history-request { padding-block: 1.25rem; border-bottom: 1px solid var(--line-strong); scroll-margin-top: 1rem; }
  .study-history-request h3 { font: 700 1rem/1.4 var(--font-sans); margin: 0 0 .4rem; }
  .study-history-request .study-status { display: flex; gap: .3rem; align-items: center; margin-block: .65rem; }
  .study-history-request .study-status svg { width: 16px; height: 16px; }
  .study-file { margin-top: .75rem; }
  .study-file-name { display: flex; gap: .5rem; align-items: flex-start; font-size: .875rem; overflow-wrap: anywhere; }
  .study-file-name svg { width: 18px; height: 18px; flex: none; margin-top: .15rem; }
  .study-file-name small { display: block; font-size: .8rem; color: var(--muted); }
  .study-file-preview { border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); padding: .75rem; margin-top: .85rem; }
  .study-file-preview .document-preview-image { display: block; width: 100%; max-height: none; }
  .study-file-preview [aria-busy="true"] { min-height: 5rem; background: var(--lilac-soft); }
  .study-receipt-meaning { margin-top: 1rem; }
  .study-upload-receipt:not(:empty) { color: var(--success); margin-block: 1rem; }
  .study-empty { margin-block: 1.5rem; }
  .study-today-summary { display: block; padding: 1rem; border: 1px solid var(--line-strong); border-radius: 14px; }
  .study-today-summary.has-pending { background: var(--coral-soft); border-color: #e0af99; }
  .study-today-summary > .study-today-label { display: flex; gap: .75rem; align-items: center; }
  .study-today-label > img { width: 56px; height: 56px; flex: none; }
  .study-today-label > span { color: var(--ink); display: grid; gap: .3rem; }
  .study-today-label > span > span { color: var(--muted); font-size: .875rem; }
  .study-today-summary.has-pending .study-today-label > span > span { color: var(--coral-ink); font-weight: 700; }
  .study-today-summary > .study-today-action { display: flex; justify-content: space-between; align-items: center; gap: .75rem; border-top: 1px solid var(--line-strong); padding-top: .75rem; margin-top: .75rem; font-size: .875rem; color: var(--ink); font-weight: 700; }
}

@layer components { .native-patient-portal .study-patient-workspace { padding-inline: 1rem; } }

@layer components {
  .note-study-picker > input[type="search"] { margin: 0 0 .8rem; }
  .note-study-toolbar { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: baseline; margin-bottom: 1.25rem; color: var(--muted); font-size: .75rem; }
  .note-study-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .note-study-label-copy { display: flex; flex-wrap: wrap; align-items: baseline; gap: .15rem .45rem; min-width: 0; }
  .note-study-label-copy [data-study-date] { color: var(--muted); font-size: .68rem; font-weight: 400; line-height: 1.3; }
  .note-study-selected { padding: 0 .35rem 0 0; }
  .note-study-entry { margin: 0; padding: 0; border: 0; min-width: 0; }
  .note-study-entry + .note-study-entry { border-top: 1px solid var(--line); }
  .note-study-dialog { width: min(36rem, calc(100vw - 2rem)); }
  .note-study-dialog .appointment-modal-header { position: sticky; top: -24px; z-index: 1; margin: -24px -24px 1rem; padding: 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
  .note-study-dialog .appointment-modal-header h2 { font: 1.25rem var(--font-serif); }
  .note-study-dialog-actions { position: sticky; bottom: -24px; z-index: 1; display: flex; flex-wrap: wrap; gap: .6rem; justify-content: flex-end; align-items: center; margin: 1rem -24px -24px; padding: 1rem 24px; border-top: 1px solid var(--line); background: var(--surface); }
  .note-study-dialog-actions .field-error { flex-basis: 100%; }
  .note-study-entry-fields { display: grid; gap: .75rem; padding: .5rem 0 .75rem; }
  .note-study-entry-fields .field { display: grid; gap: .35rem; min-width: 0; }
  .note-study-entry-fields input, .note-study-entry-fields select, .note-study-entry-fields textarea { min-width: 0; width: 100%; }
  .patient-note-form .note-study-entry-fields textarea[data-entry-instructions] { min-height: 80px; padding: .65rem .75rem; line-height: 1.45; }
  .note-study-entry-fields label { color: var(--navy); font-size: .74rem; }
  .note-study-entry-fields .note-study-validation:empty { display: none; }
  .note-study-entry-fields .note-study-validation:not(:empty) { margin: -.25rem 0 .1rem; padding: .6rem .75rem; border: 1px solid #f6cdb9; border-left: 3px solid var(--coral); border-radius: 8px; background: var(--coral-soft); color: var(--coral-ink); font-size: .8rem; font-weight: 600; line-height: 1.4; }
  .note-study-entry-fields .note-study-validation:not(:empty)::before { content: "!"; display: inline-grid; place-items: center; width: 1.1rem; height: 1.1rem; margin-inline-end: .45rem; border-radius: 50%; background: var(--coral); color: white; font-size: .7rem; font-weight: 700; }
  .note-study-entry-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
  [data-study-rows] > .note-study-entry:not(:last-child) [data-entry-add] { display: none; }
  .note-study-selected > .laboratory-study-detail-toggle { padding-inline: .5rem; color: var(--navy); }
  .note-study-private { padding-block: .5rem; font-size: .72rem; }
  .note-study-private summary { cursor: pointer; min-height: 44px; align-content: center; }
  .note-study-private label { display: block; margin: .5rem 0; }
  .note-study-picker [hidden] { display: none; }
  @media (max-width: 600px) {
    .note-study-item { grid-template-columns: minmax(0, 1fr); }
    .note-study-selected { padding: 0 0 .35rem 2rem; }
    .note-study-selected > .laboratory-study-detail-toggle { min-height: 44px; padding: 0; }
    .note-study-dialog .appointment-modal-header { top: -16px; margin: -16px -16px 1rem; padding: 16px; }
    .note-study-dialog-actions { bottom: -16px; margin: 1rem -16px -16px; padding: 1rem 16px; }
  }
}

.appointment-modal.note-study-dialog { width: min(36rem, calc(100vw - 2rem)); }
