/* Opaque companion surfaces for documents, administration and curator workflows.
   Keep all screen styling outside the black-and-white print document layout. */
@media screen {
  html[data-theme] .documents-page {
    container-type: inline-size;
  }
  html[data-theme] {
    --mac-component-danger: #9d354c;
    --mac-component-danger-bg: #fff0f3;
    --mac-component-danger-line: #dcaaba;
    --mac-component-warning: #805c14;
    --mac-component-warning-bg: #fff6df;
    --mac-component-warning-line: #dac28b;
    --mac-component-success: #27664f;
    --mac-component-success-bg: #eaf5ef;
    --mac-component-success-line: #a8cbb9;
  }

  html[data-theme='dark'] {
    --mac-component-danger: #ffc0cf;
    --mac-component-danger-bg: #4c2f3c;
    --mac-component-danger-line: #a67384;
    --mac-component-warning: #f4d38e;
    --mac-component-warning-bg: #433a2b;
    --mac-component-warning-line: #a48a56;
    --mac-component-success: #b3e2cb;
    --mac-component-success-bg: #294339;
    --mac-component-success-line: #618c77;
  }

  /* Document workspace: raised controls and two quiet, distinct document cards. */
  html[data-theme] :is(.documents-selector, .documents-card, .documents-history) {
    background: var(--mac-surface);
    color: var(--mac-text);
    border: 1px solid var(--mac-line);
    border-radius: var(--mac-radius);
    box-shadow: var(--mac-shadow);
  }

  html[data-theme] .documents-selector {
    padding: 24px;
  }

  html[data-theme] .documents-card {
    padding: 28px;
    gap: 16px;
  }

  html[data-theme] .documents-card-icon {
    width: 54px;
    height: 54px;
    border: 1px solid var(--mac-line);
    border-radius: 17px;
    background: var(--mac-accent-soft);
    color: var(--mac-accent);
    box-shadow: 0 3px 0 var(--mac-raised);
  }

  html[data-theme] .documents-card h2,
  html[data-theme] .documents-history h2 {
    color: var(--mac-text);
    font-size: 22px;
    font-weight: 650;
    letter-spacing: -0.45px;
  }

  html[data-theme]
    :is(
      .documents-fields > label,
      .documents-selection strong,
      .documents-history h3,
      .documents-history dd,
      .documents-history-filter
    ) {
    color: var(--mac-text);
  }

  html[data-theme]
    :is(
      .documents-card p,
      .documents-selection span,
      .documents-history-heading p,
      .documents-history dt,
      .documents-history-origin,
      .documents-history-actions p,
      .documents-history-pagination span,
      .documents-print-note
    ) {
    color: var(--mac-secondary);
  }

  html[data-theme] :is(.documents-fields :is(input, select), .documents-history-filter select) {
    min-height: 46px;
    border: 1px solid var(--mac-line);
    border-radius: 11px;
    background: var(--mac-raised);
    color: var(--mac-text);
    box-shadow: inset 0 1px 0 var(--mac-surface);
    font-size: 16px;
  }

  html[data-theme]
    :is(
      .documents-fields :is(input, select):disabled,
      .documents-card > .btn:disabled,
      .documents-history .btn:disabled
    ) {
    background: var(--mac-raised);
    color: var(--mac-secondary);
    border-color: var(--mac-line);
    opacity: 1;
    box-shadow: none;
  }

  html[data-theme] .documents-selection {
    border-color: var(--mac-line);
  }

  html[data-theme] .documents-history-item {
    padding: 22px;
    border: 1px solid var(--mac-line);
    border-radius: 15px;
    background: var(--mac-raised);
  }

  html[data-theme] .documents-history-kind {
    border-radius: 7px;
    padding: 4px 9px;
    background: var(--mac-accent-soft);
    color: var(--mac-accent);
  }

  html[data-theme] :is(.documents-history-empty, .documents-history-error) {
    border-color: var(--mac-line);
    border-radius: 12px;
    background: var(--mac-raised);
    color: var(--mac-secondary);
  }

  html[data-theme] .documents-history-legacy {
    border-left-color: var(--mac-accent);
    background: var(--mac-accent-soft);
    color: var(--mac-text);
    border-radius: 10px;
  }

  html[data-theme] .documents-history-pagination {
    border-color: var(--mac-line);
  }

  /* Administration and account cards use the same solid surface language. */
  html[data-theme] .admin-grid {
    gap: 20px;
  }

  html[data-theme] .admin-group {
    padding: 22px;
    background: var(--mac-surface);
    border: 1px solid var(--mac-line);
    border-radius: var(--mac-radius);
    box-shadow: var(--mac-shadow);
  }

  html[data-theme] .admin-group h3 {
    color: var(--mac-text);
    font-size: 16px;
    line-height: 1.55;
    font-weight: 600;
    margin-top: 18px;
    min-height: 0;
    overflow-wrap: anywhere;
  }

  html[data-theme] .admin-group > p {
    color: var(--mac-secondary);
    font-size: 14px;
    line-height: 1.65;
  }

  html[data-theme] .admin-group-actions {
    border-top-color: var(--mac-line);
    padding-top: 12px;
    gap: 4px 14px;
    flex-wrap: wrap;
  }

  html[data-theme] .admin-group-actions .text-button {
    min-height: 44px;
    padding: 7px 0;
    font-size: 14px;
  }

  html[data-theme] .admin-group-actions .icon {
    width: 17px;
    height: 17px;
  }

  html[data-theme] :is(.account-explanation, .user-assignment-note, .first-user) {
    background: var(--mac-accent-soft);
    border-color: var(--mac-line);
    border-radius: 15px;
    color: var(--mac-text);
  }

  html[data-theme] :is(.account-explanation strong, .users-table td > strong, .access-card h3) {
    color: var(--mac-text);
  }

  html[data-theme]
    :is(
      .account-explanation p,
      .user-assignment-note,
      .user-login,
      .field-hint,
      .password-strength-note,
      .curator-hint,
      .role-mini,
      .first-user span,
      .first-password-card > p,
      .first-password-card form > label,
      #user-form .report-form-grid > label
    ) {
    color: var(--mac-secondary);
  }

  html[data-theme] .user-actions .text-button {
    min-height: 44px;
  }

  html[data-theme] .user-pending {
    color: var(--mac-component-warning);
  }

  html[data-theme] .access-card {
    background: var(--mac-raised);
    border-color: var(--mac-line);
    border-radius: 16px;
    padding: 22px;
  }

  html[data-theme] .access-card code {
    color: var(--mac-accent);
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 18px;
  }

  html[data-theme] .first-password-page {
    background: var(--mac-raised);
  }

  html[data-theme] .first-password-card {
    border-radius: 24px;
    border-color: var(--mac-line);
    background: var(--mac-surface);
    color: var(--mac-text);
    box-shadow: var(--mac-shadow);
  }

  html[data-theme] .first-password-card h1 {
    color: var(--mac-text);
    letter-spacing: -0.8px;
  }

  html[data-theme] .first-password-card > .eyebrow {
    color: var(--mac-accent);
  }

  /* Dialog chrome is opaque. The actual paper/canvas keeps its original styling. */
  html[data-theme] .modal {
    background: var(--mac-surface);
    border: 1px solid var(--mac-line);
    border-radius: 23px;
    color: var(--mac-text);
    box-shadow: 0 24px 70px #101b2940;
    max-height: calc(100svh - 48px);
  }

  html[data-theme] .modal::backdrop {
    background: #aab6c4;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  html[data-theme='dark'] .modal::backdrop {
    background: #18212d;
  }

  html[data-theme] .modal-head {
    background: var(--mac-raised);
    border-color: var(--mac-line);
    padding: 19px 24px;
  }

  html[data-theme] .modal-head h2 {
    color: var(--mac-text);
    font-size: 21px;
    line-height: 1.4;
    font-weight: 650;
    letter-spacing: -0.4px;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  html[data-theme] .modal-head > .icon-button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    flex: 0 0 44px;
    border: 1px solid var(--mac-line);
    border-radius: 50%;
    background: var(--mac-surface);
    color: var(--mac-secondary);
  }

  html[data-theme] .modal-body {
    color: var(--mac-text);
    padding: 24px;
  }

  html[data-theme] .modal-body > p {
    color: var(--mac-secondary);
    font-size: 14px;
  }

  html[data-theme] .modal-body > p strong {
    color: var(--mac-text);
  }

  html[data-theme] .modal-body :is(label, legend) {
    color: var(--mac-text);
    font-size: 14px;
    line-height: 1.55;
  }

  html[data-theme]
    .modal-body
    :is(input, select, textarea):not([type='checkbox']):not([type='radio']) {
    border: 1px solid var(--mac-line);
    border-radius: 11px;
    background: var(--mac-raised);
    color: var(--mac-text);
    min-height: 46px;
    font-size: 16px;
    line-height: 1.5;
  }

  html[data-theme] .modal-body :is(input, textarea)::placeholder {
    color: var(--mac-secondary);
    opacity: 1;
  }

  html[data-theme] .modal-body :is(input[type='checkbox'], input[type='radio']) {
    accent-color: var(--mac-accent);
  }

  html[data-theme] :is(.modal-body .btn, .modal-body .text-button) {
    min-height: 44px;
    font-size: 14px;
  }

  html[data-theme] :is(.characteristic-section, .group-archive-list article) {
    border-color: var(--mac-line);
    border-radius: 15px;
    background: var(--mac-raised);
  }

  html[data-theme] :is(.characteristic-student, .care-student-header) {
    border-color: var(--mac-line);
  }

  html[data-theme]
    :is(
      .characteristic-student span,
      .characteristic-note,
      .group-delete-form > p,
      .group-archive > p,
      .group-archive-list span,
      .group-archive-empty,
      .document-preview-intro,
      .document-preview-hint,
      .document-preview-status,
      .document-preview-paper > figcaption
    ) {
    color: var(--mac-secondary);
  }

  html[data-theme] :is(.group-delete-context, .group-confirmation-status) {
    background: var(--mac-accent-soft);
    border-color: var(--mac-line);
    border-radius: 13px;
    color: var(--mac-text);
  }

  html[data-theme] .group-confirmation-status.is-confirmed {
    background: var(--mac-component-success-bg);
    color: var(--mac-component-success);
    border-color: var(--mac-component-success-line);
  }

  html[data-theme] .document-preview-pages {
    background: var(--mac-raised);
    border-color: var(--mac-line);
    border-radius: 14px;
  }

  html[data-theme] .roster-list {
    background: var(--mac-raised);
    border-radius: 13px;
    border: 1px solid var(--mac-line);
  }

  html[data-theme] .roster-list > div {
    color: var(--mac-text);
    border-color: var(--mac-line);
  }

  html[data-theme] .roster-list strong {
    color: var(--mac-text);
    font-size: 14px;
    line-height: 1.6;
  }

  html[data-theme] .roster-list .roster-number {
    color: var(--mac-secondary);
    font-size: 12px;
  }

  /* Early signals and curator work retain clear, calm status colours. */
  html[data-theme] .care-page {
    color: var(--mac-text);
  }

  html[data-theme]
    :is(.care-stat, .care-signal-history-item, .care-action-record, .care-case-details) {
    background: var(--mac-surface);
    border: 1px solid var(--mac-line);
    border-radius: var(--mac-radius);
    box-shadow: var(--mac-shadow);
    color: var(--mac-text);
  }

  html[data-theme] .care-stat {
    padding: 22px;
  }

  html[data-theme] .care-stat > strong {
    color: var(--mac-accent);
    font-size: 34px;
    letter-spacing: -1px;
  }

  html[data-theme] :is(.care-signal-card, .care-case-card) {
    border: 1px solid var(--mac-line);
    border-radius: 16px;
    background: var(--mac-raised);
    color: var(--mac-text);
    padding: 20px;
  }

  html[data-theme] .care-signal-card {
    border-left: 4px solid var(--mac-component-danger-line);
  }

  html[data-theme]
    :is(
      .care-page h2,
      .care-page h3,
      .care-student-header,
      .care-student-header h3,
      .care-work-heading h3,
      .care-action-field > strong,
      .care-comparison-head > h4,
      .care-observation h4,
      .care-coverage > strong,
      .care-observation dd,
      .care-action-student > strong
    ) {
    color: var(--mac-text);
  }

  html[data-theme]
    :is(
      .care-stat > span,
      .care-stat > small,
      .care-note,
      .care-empty,
      .care-case-card > p,
      .care-review-date > span,
      .care-student-header p,
      .care-action-field > p,
      .care-recorded-basis > strong,
      .care-observation > p,
      .care-coverage > span,
      .care-observation dt,
      .care-comparison-note,
      .care-action-record summary small,
      .care-field-hint,
      .care-action-student > span
    ) {
    color: var(--mac-secondary);
  }

  html[data-theme]
    :is(
      .care-method-note,
      .care-evidence-item,
      .care-review-date,
      .care-action-student,
      .care-recorded-basis,
      .care-observation
    ) {
    border-color: var(--mac-line);
    border-radius: 13px;
    background: var(--mac-raised);
    color: var(--mac-text);
  }

  html[data-theme]
    :is(.care-method-note > strong, .care-review-date > strong, .care-evidence-item > b) {
    color: var(--mac-accent);
  }

  html[data-theme] .care-evidence-item > time {
    color: var(--mac-secondary);
  }

  html[data-theme] .care-evidence-unknown {
    background: var(--mac-surface);
    border-style: dashed;
  }

  html[data-theme] .care-evidence-unknown > b {
    color: var(--mac-secondary);
  }

  html[data-theme]
    :is(
      .care-stat-danger,
      .care-signal-basis,
      .care-form-error:not(:empty),
      .group-delete-error:not(:empty)
    ) {
    background: var(--mac-component-danger-bg);
    border-color: var(--mac-component-danger-line);
    color: var(--mac-component-danger);
  }

  html[data-theme]
    :is(.care-stat-danger > strong, .care-signal-basis > strong, .care-signal-basis > p) {
    color: var(--mac-component-danger);
  }

  html[data-theme]
    :is(.care-stat-warning, .care-review-due, .care-readonly-note, .care-history-correction) {
    background: var(--mac-component-warning-bg);
    border-color: var(--mac-component-warning-line);
    color: var(--mac-component-warning);
  }

  html[data-theme] :is(.care-stat-warning > strong, .care-review-due > strong) {
    color: var(--mac-component-warning);
  }

  html[data-theme] .care-change-summary {
    background: var(--mac-component-success-bg);
    color: var(--mac-component-success);
    border-color: var(--mac-component-success-line);
    border-radius: 12px;
  }

  html[data-theme]
    :is(
      .care-filters > label,
      .care-case-filter,
      .care-form-grid > label,
      .care-form-grid > div > label,
      .care-case-form label,
      .care-form-grid .care-checkbox
    ) {
    color: var(--mac-text);
  }

  html[data-theme]
    :is(
      .care-filters :is(input, select),
      .care-case-filter select,
      .care-case-form :is(input, select, textarea),
      .care-form-grid :is(input, select, textarea),
      .care-print-choice select
    ):not([type='checkbox']) {
    background: var(--mac-raised);
    border-color: var(--mac-line);
    border-radius: 11px;
    color: var(--mac-text);
    min-height: 46px;
    font-size: 16px;
  }

  html[data-theme] .care-filters .search-field {
    background: var(--mac-raised);
    border-color: var(--mac-line);
  }

  html[data-theme] .care-filters .search-field input {
    border: 0;
    box-shadow: none;
    background: var(--mac-raised);
  }

  html[data-theme] :is(.care-history-switch) {
    background: var(--mac-raised);
    border: 1px solid var(--mac-line);
    border-radius: 15px;
    padding: 5px;
    gap: 5px;
    width: fit-content;
    max-width: 100%;
  }

  html[data-theme] :is(.care-history-switch > button) {
    background: var(--mac-raised);
    border: 1px solid var(--mac-raised);
    border-radius: 10px;
    color: var(--mac-secondary);
    min-height: 44px;
    font-size: 14px;
  }

  html[data-theme] :is(.care-history-switch > button.active) {
    background: var(--mac-surface);
    border-color: var(--mac-line);
    color: var(--mac-accent);
    box-shadow: 0 2px 4px #17253614;
  }

  html[data-theme]
    :is(.care-action-record > summary, .care-case-details > summary, .care-history-work > summary) {
    background: var(--mac-raised);
    color: var(--mac-text);
    border-color: var(--mac-line);
  }

  html[data-theme] :is(.care-action-record > summary:after, .care-case-details > summary:after) {
    color: var(--mac-accent);
  }

  html[data-theme] :is(.care-history-work) {
    background: var(--mac-surface);
    border-color: var(--mac-line);
    border-radius: 13px;
    color: var(--mac-text);
  }

  html[data-theme]
    :is(
      .care-signal-history-body,
      .care-protocol-actions,
      .care-comparison,
      .care-observation dl > div,
      .care-pagination
    ) {
    border-color: var(--mac-line);
  }

  html[data-theme]
    :is(
      .care-protocol-actions > span,
      .care-history-facts dd,
      .care-pagination,
      .care-signal-history-item > summary > span:first-child > strong
    ) {
    color: var(--mac-text);
  }

  html[data-theme]
    :is(
      .care-history-work > summary > small,
      .care-signal-history-item > summary small,
      .care-history-facts dt,
      .care-history-events li > span,
      .care-pagination > label,
      .care-topbar-notice
    ) {
    color: var(--mac-secondary);
  }

  html[data-theme] .care-topbar-notice {
    background: var(--mac-raised);
    border-color: var(--mac-line);
    border-radius: 11px;
    min-height: 44px;
  }

  html[data-theme] .care-topbar-notice:hover {
    background: var(--mac-accent-soft);
    border-color: var(--mac-accent);
    color: var(--mac-accent);
  }

  html[data-theme] :is(.care-scope-note) {
    color: var(--mac-accent);
  }

  html[data-theme] :is(.form-error, .care-form-error, .characteristic-error) {
    color: var(--mac-component-danger);
  }

  html[data-theme]
    :is(
      .modal :is(button, a, summary, input, select, textarea),
      .documents-page :is(button, a, input, select, textarea),
      .care-page :is(button, a, summary, input, select, textarea)
    ):focus-visible {
    outline: 3px solid var(--mac-accent);
    outline-offset: 3px;
  }
}

@container (max-width: 620px) {
  @media screen {
    html[data-theme] .documents-cards {
      grid-template-columns: minmax(0, 1fr);
    }
  }
}

@media screen and (max-width: 760px) {
  html[data-theme] .admin-group {
    padding: 20px;
  }

  html[data-theme] .care-stat {
    padding: 18px;
  }

  html[data-theme] :is(.care-signal-card, .care-case-card) {
    padding: 17px;
  }

  html[data-theme] .modal {
    max-height: calc(100svh - 24px);
    border-radius: 20px;
  }

  html[data-theme] .modal-head {
    padding: 15px 18px;
    gap: 12px;
  }

  html[data-theme] .modal-head h2 {
    font-size: 20px;
  }

  html[data-theme] .modal-body {
    padding: 20px;
  }
}

@media screen and (max-width: 600px) {
  html[data-theme] :is(.documents-selector, .documents-history, .documents-card) {
    padding: 20px;
    border-radius: 18px;
  }

  html[data-theme] .documents-history-item {
    padding: 17px;
  }

  html[data-theme] .care-history-switch {
    width: 100%;
  }

  html[data-theme] .care-history-switch > button {
    font-size: 13px;
  }

  html[data-theme] :is(.document-preview-actions, .characteristic-actions, .group-delete-actions) {
    gap: 10px;
  }

  html[data-theme] .modal-body {
    padding: 17px;
  }

  html[data-theme] .modal-body :is(.care-document-button, .document-preview-actions > .btn) {
    min-width: 0;
    overflow-wrap: normal;
    word-break: normal;
  }

  html[data-theme] .characteristic-section {
    padding: 14px;
  }
}
