/* Light-only shortened upload wording; legacy wording is retained for dark themes and print. */
.care-upload-requirement-light { display: none; }
/* Lucent source artwork: wordmark #2d2010, symbol #928578 / #c8bdb2.
   Semantic tokens apply on screen only. Original declaration fallbacks preserve
   the existing dark design and print/PDF/document appearance. */
@media screen {
  :root[data-theme="light"] {
    --appearance-scheme: light;
    --theme-canvas: #eee8e0;
    --theme-surface: #fffdfa;
    --theme-surface-raised: #e4dbcf;
    --theme-surface-hover: #d8cbbb;
    --theme-text: #2d2010;
    --theme-text-muted: #514536;
    --theme-border: #928578;
    --theme-border-strong: #746553;
    --theme-accent: #51381e;
    --theme-accent-border: #746553;
    --theme-accent-surface: #e9e0d5;
    --theme-link: #51381e;
    --theme-link-border: #746553;
    --theme-link-surface: #f3ede5;
    --theme-success: #493823;
    --theme-success-border: #928578;
    --theme-success-surface: #e4dbcf;
    --theme-warning: #604020;
    --theme-warning-border: #775d43;
    --theme-warning-surface: #eee2d3;
    --theme-danger: #a12d32;
    --theme-danger-border: #b96b6b;
    --theme-danger-surface: #fbe9e8;
  }
  :root[data-theme="dark"] { --appearance-scheme: dark; }
  :root[data-theme="light"] .practice-branding-logo { filter: brightness(0) saturate(100%) !important; }
  :root[data-theme="dark"] :is(.site-brand img,.landing-welcome img) { filter: brightness(0) invert(.88); }
  /* Signed-out landing uses the same preference as the clinical workspace. */
  :root[data-theme="dark"] .patients-home[data-account-state="signed-out"] {
    --landing-background: #16181c; --landing-text: #f5f5f5;
    --landing-muted: #d0d4dd; --landing-accent: #c8bdb2; color-scheme: dark;
  }
  :root[data-theme] .patients-home .account-landing .account-microsoft { background: #2d2010; color: #fffdfa; border-color: #928578; }
  :root[data-theme] .patients-home .account-landing .account-microsoft:hover { background: #4c4033; }
  :root[data-theme="dark"] .patients-home .account-landing [role="status"] { color: #f1bb75; }
  :root[data-theme] :focus-visible { outline: 2px solid var(--theme-accent, #c8bdb2); outline-offset: 3px; }
  :root[data-theme] input::placeholder, :root[data-theme] textarea::placeholder { color: var(--theme-text-muted, #b1b8c4); opacity: 1; }
  :root[data-theme] :is(input[type="checkbox"],input[type="radio"]) { accent-color: var(--theme-accent, #b69ce1); }
  .appearance-control { display: flex; align-items: center; justify-content: space-between; gap: 1rem; color: var(--theme-text, #f5f5f5); font: 400 .85rem/1.5 Nunito, sans-serif; }
  .appearance-switch { display: inline-flex; align-items: center; justify-content: space-between; gap: .65rem; min-height: 2.25rem; padding: .25rem .4rem; border: 1px solid transparent; border-radius: .35rem; background: transparent; color: var(--theme-text, #f5f5f5); font: inherit; white-space: nowrap; cursor: pointer; }
  .appearance-switch:hover { background: var(--theme-surface-hover, #303741); }
  .appearance-switch:disabled { cursor: wait; opacity: .65; }
  .appearance-switch-track { position: relative; flex: 0 0 2.5rem; width: 2.5rem; height: 1.4rem; border: 1px solid var(--theme-border-strong, #8c96a5); border-radius: 2rem; background: var(--theme-surface-raised, #343c48); }
  .appearance-switch-track::after { content: ''; position: absolute; top: .15rem; left: .15rem; width: 1.1rem; height: 1.1rem; border-radius: 50%; background: var(--theme-text-muted, #e5e8ed); }
  .appearance-switch[aria-checked="true"] .appearance-switch-track { background: #c8bdb2; border-color: #c8bdb2; }
  .appearance-switch[aria-checked="true"] .appearance-switch-track::after { left: 1.25rem; background: #2d2010; }

  .site-settings-menu .appearance-control { padding: .65rem .35rem; border-top: 1px solid var(--theme-border, #414853); }
}
@media screen {
  :root[data-theme="light"] .patients-home[data-account-state="signed-out"] { --landing-background: #f6f3ee; --landing-text: #2d2010; --landing-muted: #655a4e; --landing-accent: #2d2010; }
  :root[data-theme] .site-brand img { background: transparent; }
  .site-appearance { position: relative; }
  .site-appearance .appearance-control { gap: .45rem; }
  .appearance-status { position: absolute; top: 100%; right: 0; z-index: 15; max-width: 18rem; background: var(--theme-surface, #20232a); color: var(--theme-text, #f5f5f5); font-size: .7rem; line-height: 1.4; padding: .2rem .4rem; border-radius: .2rem; }
  .appearance-status:empty { display: none; }
  .appearance-control { position: relative; }

}

@media screen {
  :root[data-theme="light"] .history-arrow { stroke: var(--theme-accent); }
  :root[data-theme="light"] .history-clock-hands { stroke: var(--theme-link); }
}

@media screen {
  /* The same Settings popover is available on the signed-out landing. */
  :root[data-theme] .patients-home[data-account-state="signed-out"] .site-header { display: block !important; position: absolute; top: 1rem; right: 1rem; width: auto; margin: 0 !important; padding: 0; border: 0; }
  :root[data-theme] .patients-home[data-account-state="signed-out"] .site-header .site-tabs { display: none; }
}

/* Light status hierarchy uses Lucent brown / taupe / stone. State comes only
   from the existing completion calculation and existing upload markup. */
@media screen {
  :root[data-theme="light"] {
    --theme-input: #f6f1ea;
    --theme-complete-surface: #2d2010;
    --theme-complete-text: #fffdfa;
    --theme-incomplete-surface: #eee2d3;
    --theme-incomplete-text: #49331c;
    --theme-incomplete-border: #775d43;
  }
  :root[data-theme="light"] body { font-weight: 400; }
  :root[data-theme="light"] :is(h1,h2,h3,legend,label) { font-weight: 600; }
  :root[data-theme="light"] :is(input:not([type="checkbox"],[type="radio"],[type="range"],[type="file"]),select,textarea) {
    background-color: var(--theme-input); color: var(--theme-text); border-color: var(--theme-border-strong);
  }
  :root[data-theme="light"] .refraction-number { background: var(--theme-input); border-color: var(--theme-border-strong); }
  /* Keep inputs legible even where the worksheet uses transparent inner controls. */
  :root[data-theme="light"] :is(input,select,textarea):disabled { opacity: 1; color: var(--theme-text-muted); background-color: var(--theme-surface-raised); }
  :root[data-theme="light"] .completion-status[data-complete]:not([hidden]) {
    display: inline-block; max-width: 100%; box-sizing: border-box;
    padding: .2rem .45rem; border: 1px solid var(--theme-incomplete-border); border-radius: .3rem;
    background: var(--theme-incomplete-surface); color: var(--theme-incomplete-text) !important;
    font-size: .74rem; font-weight: 700 !important; line-height: 1.4; text-transform: none;
  }
  :root[data-theme="light"] .completion-status[data-complete="false"]::before { content: '! '; font-weight: 800; }
  :root[data-theme="light"] .completion-status[data-complete="true"]:not([hidden]) {
    background: var(--theme-complete-surface); color: var(--theme-complete-text) !important; border-color: var(--theme-complete-surface);
  }
  :root[data-theme="light"] .completion-status[data-complete="true"]::before { content: '✓ '; }
  :root[data-theme="light"] .patient-card:has(> .completion-status[data-complete="false"]:not([hidden])),
  :root[data-theme="light"] .patient-card:has(> h2 > .completion-status[data-complete="false"]:not([hidden])),
  :root[data-theme="light"] .patient-card:has(> .patient-details-header > .completion-status[data-complete="false"]:not([hidden])) {
    border: 2px dashed var(--theme-incomplete-border);
  }
  :root[data-theme="light"] .patient-card:has(> .completion-status[data-complete="true"]:not([hidden])),
  :root[data-theme="light"] .patient-card:has(> h2 > .completion-status[data-complete="true"]:not([hidden])),
  :root[data-theme="light"] .patient-card:has(> .patient-details-header > .completion-status[data-complete="true"]:not([hidden])) {
    border: 2px solid var(--theme-success-border);
  }
  :root[data-theme="light"] .unanswered-question :is(input:not([type="checkbox"],[type="radio"],[type="range"]),select,textarea) {
    background-color: var(--theme-incomplete-surface); border-color: var(--theme-incomplete-border);
  }
  :root[data-theme="light"] label.unanswered-question::after,
  :root[data-theme="light"] fieldset.unanswered-question > legend::after {
    content: ' · Required — missing'; color: var(--theme-incomplete-text); font-size: .7rem; font-weight: 700;
  }
  :root[data-theme="light"] #care-uploads .care-upload-item:not(.care-upload-placeholder) {
    border: 1px solid var(--theme-border-strong); background: var(--theme-surface-raised); color: var(--theme-text);
  }
  :root[data-theme="light"] #care-uploads .care-upload-item:not(.care-upload-placeholder) .care-upload-requirement {
    color: var(--theme-text-muted); font-weight: 600;
  }
  :root[data-theme="light"] #care-uploads .care-upload-placeholder {
    background: var(--theme-surface); border: 1px dashed var(--theme-border); color: var(--theme-text-muted);
  }
  :root[data-theme="light"] #care-uploads .care-upload-placeholder:is([data-upload-state="required-missing"],[data-upload-state="unavailable"]) {
    background: var(--theme-incomplete-surface); border: 2px dashed var(--theme-incomplete-border); color: var(--theme-incomplete-text);
  }
  :root[data-theme="light"] #care-uploads .care-upload-placeholder:is([data-upload-state="required-missing"],[data-upload-state="unavailable"]) .care-upload-info small {
    color: var(--theme-incomplete-text); font-weight: 700;
  }
  :root[data-theme="light"] #care-uploads .care-upload-item:hover:not(:disabled) { outline: 2px solid var(--theme-accent); outline-offset: 1px; }
}

@media screen {
  /* Page-specific heading rules must not override the renderer's hidden state. */
  .completion-status[hidden] { display: none !important; }
}

/* Optional third appearance. Light and the original Dark retain their tokens. */
@media screen {
  .appearance-selector { display: flex; align-items: center; gap: .6rem; width: 100%; margin: 0; color: var(--theme-text, #f5f5f5); font: inherit; }
  .appearance-select { flex: 1; min-width: 0; width: auto; min-height: 2.25rem; padding: .35rem .5rem; background: var(--theme-surface, #20232a); border: 1px solid var(--theme-border-strong, #8c96a5); border-radius: .35rem; color: var(--theme-text, #f5f5f5); font: inherit; }
  .appearance-select:disabled { opacity: .65; cursor: wait; }
  :root[data-theme="lucent-dark"] {
    --appearance-scheme: dark;
    --theme-canvas: #2d2010;
    --theme-surface: #3b2d1d;
    --theme-surface-raised: #4a3a28;
    --theme-surface-hover: #5b4934;
    --theme-text: #f7f1e9;
    --theme-text-muted: #d0c3b3;
    --theme-border: #897966;
    --theme-border-strong: #b6a28b;
    --theme-accent: #e2c8a5;
    --theme-accent-border: #b6a28b;
    --theme-accent-surface: #58422b;
    --theme-link: #e6cfae;
    --theme-link-border: #a99172;
    --theme-link-surface: #392a1a;
    --theme-success: #b9d8d1;
    --theme-success-border: #80c7ad;
    --theme-success-surface: #253a38;
    --theme-warning: #f1bb75;
    --theme-warning-border: #bd9569;
    --theme-warning-surface: #503a22;
    --theme-danger: #ffb8b5;
    --theme-danger-border: #d08d89;
    --theme-danger-surface: #4a292b;
    --theme-input: #312313;
    --theme-complete-surface: #c8bdb2;
    --theme-complete-text: #2d2010;
    --theme-incomplete-surface: #503a22;
    --theme-incomplete-text: #f1c790;
    --theme-incomplete-border: #bd9569;
    /* Questionnaire uses these aliases; other routes use shared semantic tokens. */
    --bg: var(--theme-canvas); --surface: var(--theme-surface); --text: var(--theme-text); --border: var(--theme-border-strong);
    color-scheme: dark;
  }
  :root[data-theme="lucent-dark"] body { background: var(--theme-canvas); }
  :root[data-theme="lucent-dark"] :is(.site-brand img,.landing-welcome img,#questionnaire > header img) { filter: brightness(0) invert(.9); }
  :root[data-theme="lucent-dark"] .patients-home[data-account-state="signed-out"] {
    --landing-background: #2d2010; --landing-text: #f7f1e9; --landing-muted: #d0c3b3; --landing-accent: #c8bdb2; color-scheme: dark;
  }
  :root[data-theme="lucent-dark"] :is(.history-arrow,.history-clock-hands) { stroke: var(--theme-accent); }
  :root[data-theme="lucent-dark"] :is(#questionnaire-next,#questionnaire-finish,#questionnaire-start) { background: var(--theme-complete-surface); color: var(--theme-complete-text); }
  :root[data-theme="lucent-dark"] #questionnaire :is(input,progress) { accent-color: var(--theme-accent); }
  :root[data-theme="lucent-dark"] #questionnaire :focus-visible { outline-color: var(--theme-accent); }
  :root[data-theme="lucent-dark"] body { font-weight: 400; }
  :root[data-theme="lucent-dark"] :is(h1,h2,h3,legend,label) { font-weight: 600; }
  :root[data-theme="lucent-dark"] :is(input:not([type="checkbox"],[type="radio"],[type="range"],[type="file"]),select,textarea) {
    background-color: var(--theme-input); color: var(--theme-text); border-color: var(--theme-border-strong);
  }
  :root[data-theme="lucent-dark"] .refraction-number { background: var(--theme-input); border-color: var(--theme-border-strong); }
  /* Keep inputs legible even where the worksheet uses transparent inner controls. */
  :root[data-theme="lucent-dark"] :is(input,select,textarea):disabled { opacity: 1; color: var(--theme-text-muted); background-color: var(--theme-surface-raised); }
  :root[data-theme="lucent-dark"] .completion-status[data-complete]:not([hidden]) {
    display: inline-block; max-width: 100%; box-sizing: border-box;
    padding: .2rem .45rem; border: 1px solid var(--theme-incomplete-border); border-radius: .3rem;
    background: var(--theme-incomplete-surface); color: var(--theme-incomplete-text) !important;
    font-size: .74rem; font-weight: 700 !important; line-height: 1.4; text-transform: none;
  }
  :root[data-theme="lucent-dark"] .completion-status[data-complete="false"]::before { content: '! '; font-weight: 800; }
  :root[data-theme="lucent-dark"] .completion-status[data-complete="true"]:not([hidden]) {
    background: var(--theme-complete-surface); color: var(--theme-complete-text) !important; border-color: var(--theme-complete-surface);
  }
  :root[data-theme="lucent-dark"] .completion-status[data-complete="true"]::before { content: '✓ '; }
  :root[data-theme="lucent-dark"] .patient-card:has(> .completion-status[data-complete="false"]:not([hidden])),
  :root[data-theme="lucent-dark"] .patient-card:has(> h2 > .completion-status[data-complete="false"]:not([hidden])),
  :root[data-theme="lucent-dark"] .patient-card:has(> .patient-details-header > .completion-status[data-complete="false"]:not([hidden])) {
    border: 2px dashed var(--theme-incomplete-border);
  }
  :root[data-theme="lucent-dark"] .patient-card:has(> .completion-status[data-complete="true"]:not([hidden])),
  :root[data-theme="lucent-dark"] .patient-card:has(> h2 > .completion-status[data-complete="true"]:not([hidden])),
  :root[data-theme="lucent-dark"] .patient-card:has(> .patient-details-header > .completion-status[data-complete="true"]:not([hidden])) {
    border: 2px solid var(--theme-success-border);
  }
  :root[data-theme="lucent-dark"] .unanswered-question :is(input:not([type="checkbox"],[type="radio"],[type="range"]),select,textarea) {
    background-color: var(--theme-incomplete-surface); border-color: var(--theme-incomplete-border);
  }
  :root[data-theme="lucent-dark"] label.unanswered-question::after,
  :root[data-theme="lucent-dark"] fieldset.unanswered-question > legend::after {
    content: ' · Required — missing'; color: var(--theme-incomplete-text); font-size: .7rem; font-weight: 700;
  }
  :root[data-theme="lucent-dark"] #care-uploads .care-upload-item:not(.care-upload-placeholder) {
    border: 1px solid var(--theme-border-strong); background: var(--theme-surface-raised); color: var(--theme-text);
  }
  :root[data-theme="lucent-dark"] #care-uploads .care-upload-item:not(.care-upload-placeholder) .care-upload-requirement {
    color: var(--theme-text-muted); font-weight: 600;
  }
  :root[data-theme="lucent-dark"] #care-uploads .care-upload-placeholder {
    background: var(--theme-surface); border: 1px dashed var(--theme-border); color: var(--theme-text-muted);
  }
  :root[data-theme="lucent-dark"] #care-uploads .care-upload-placeholder:is([data-upload-state="required-missing"],[data-upload-state="unavailable"]) {
    background: var(--theme-incomplete-surface); border: 2px dashed var(--theme-incomplete-border); color: var(--theme-incomplete-text);
  }
  :root[data-theme="lucent-dark"] #care-uploads .care-upload-placeholder:is([data-upload-state="required-missing"],[data-upload-state="unavailable"]) .care-upload-info small {
    color: var(--theme-incomplete-text); font-weight: 700;
  }
  :root[data-theme="lucent-dark"] #care-uploads .care-upload-item:hover:not(:disabled) { outline: 2px solid var(--theme-accent); outline-offset: 1px; }
}

/* Matt-approved Aubergine actions in Light; reading/status colors stay Lucent brown. */
@media screen {
  :root[data-theme="light"] { --theme-action: #4b3557; --theme-action-hover: #3d2848; --theme-action-tint: #eae2ec; --theme-action-text: #faf7f2; }
  :root[data-theme="light"] a[href] { color: var(--theme-action); }
  :root[data-theme="light"] :is(button[type="submit"],#patients-questionnaire,#review-save-settings,#questionnaire-start,#questionnaire-next,#questionnaire-finish,.questionnaire-launch-actions > button:first-child) {
    background: var(--theme-action); color: var(--theme-action-text); border-color: var(--theme-action);
  }
  :root[data-theme="light"] :is(button[type="submit"],#patients-questionnaire,#review-save-settings,#questionnaire-start,#questionnaire-next,#questionnaire-finish,.questionnaire-launch-actions > button:first-child):hover:not(:disabled) { background: var(--theme-action-hover); }
  :root[data-theme="light"] :is(#patients-add,#view-patient-summary,#summary-return-link) { color: var(--theme-action); border-color: var(--theme-action); }
  :root[data-theme="light"] :is(.patient-view-nav,.care-stage-nav,.care-section-nav,.site-tabs) [aria-current],
  :root[data-theme="light"] [role="tab"][aria-selected="true"] { background: var(--theme-action-tint); color: var(--theme-action); border-color: var(--theme-action); }
  :root[data-theme="light"] :focus-visible,
  :root[data-theme="light"] .refraction-number:focus-within { outline-color: var(--theme-action); }
}

@media screen {
  :root[data-theme="light"] #bilateral-editor .preop-save-actions button[type="submit"] { background: var(--theme-action); color: var(--theme-action-text); border-color: var(--theme-action); }
  :root[data-theme="light"] #bilateral-editor .preop-save-actions button[type="submit"]:hover:not(:disabled) { background: var(--theme-action-hover); }
}

/* Approved Light accents: table headings, documented-complete badges and
   available-upload UI glyphs. Document/source/scan image pixels stay untouched. */
@media screen {
  :root[data-theme="light"] { --theme-complete-surface: #4b3557; --theme-complete-text: #faf7f2; }
  :root[data-theme="light"] table > thead > tr > :is(th,td) { background-color: var(--theme-action) !important; color: var(--theme-action-text) !important; border-color: var(--theme-action-hover); }
  :root[data-theme="light"] table > thead :is(span,small,a) { color: var(--theme-action-text) !important; }
  :root[data-theme="light"] #care-uploads .care-upload-item[data-upload-state="uploaded"] .care-upload-icon > svg { color: var(--theme-action); }
}
@media screen {
  :root[data-theme="light"] table > thead :focus-visible { outline-color: var(--theme-action-text); }
}
@media screen {
  /* Available-file frame includes source logos and thumbnails without altering image pixels or layout. */
  :root[data-theme="light"] #care-uploads .care-upload-item[data-upload-state="uploaded"] .care-upload-icon { outline: 2px solid var(--theme-action); outline-offset: 2px; border-radius: .25rem; box-sizing: border-box; }
  :root[data-theme="light"] .care-upload-requirement-legacy,
  :root[data-theme="light"] .care-upload-requirement[data-light-empty="true"] { display: none; }
  :root[data-theme="light"] .care-upload-requirement-light { display: inline; }
  /* Selection is separate from the explicit recorded/complete progress states. */
  :root[data-theme="light"] .care-stage-nav button[aria-current]:not([data-progress="recorded"],[data-progress="complete"]) { background: var(--theme-surface-raised); color: var(--theme-text); border-color: var(--theme-border-strong); }
  :root[data-theme="light"] .care-stage-nav button[aria-current]:not([data-progress="recorded"],[data-progress="complete"]) .care-stage-number { background: var(--theme-surface); color: var(--theme-text); }
  :root[data-theme="light"] .care-stage-nav button:is([data-progress="recorded"],[data-progress="complete"]) { background: var(--theme-action-tint); color: var(--theme-action); }
  :root[data-theme="light"] .care-stage-nav button:is([data-progress="recorded"],[data-progress="complete"]) .care-stage-number { background: var(--theme-action); color: var(--theme-action-text); border-color: var(--theme-action); }
  :root[data-theme="light"] .care-stage-nav button.care-stage-reached:is([data-progress="recorded"],[data-progress="complete"]) .care-stage-number { box-shadow: 0 0 0 3px var(--theme-action-tint),0 0 0 4px var(--theme-action); }
  :root[data-theme="light"] .care-stage-nav button[aria-current]:is([data-progress="recorded"],[data-progress="complete"]) { border-color: var(--theme-action); box-shadow: inset 0 -2px var(--theme-action); }
}

/* Light upload availability: white/purple available files, darker neutral missing files.
   File availability remains separate from clinical review/completion. */
@media screen {
  :root[data-theme="light"] #care-uploads .care-upload-item[data-upload-state="uploaded"] {
    background: #fff; border-color: var(--theme-action);
    box-shadow: 0 2px 5px rgba(75, 53, 87, .14);
  }
  :root[data-theme="light"] #care-uploads .care-upload-item[data-upload-state="uploaded"] .care-upload-icon {
    background: #fff; box-shadow: 0 2px 4px rgba(75, 53, 87, .16);
  }
  :root[data-theme="light"] #care-uploads .care-upload-item:is([data-upload-state="required-missing"],[data-upload-state="optional-missing"],[data-upload-state="unavailable"]) {
    background: var(--theme-surface-raised); border-color: var(--theme-border-strong); box-shadow: none;
  }
}
