/* =====================================================================
   ui-refined.css: the Dermics PRO refined UI layer

   Loaded after unified-styles.css. It holds the shared tokens and components
   of the redesigned views, and the styles specific to each redesigned view.

   Rules of the layer
   - Shell-level changes (navbar, context bar, footer) hang off body.ui-refined,
     which init-base.js sets only on the views listed in REFINED_VIEWS, so views
     that have not been migrated look exactly as before.
   - Colors come from tokens. --ui-* tokens are built on the brand tokens of
     unified-styles.css (--override-*); do not introduce new hex values in a view.
   - Do not edit unified-styles.css to change a migrated view's look. When a view
     is migrated, delete its legacy rules from unified-styles.css in the same PR.
   - End state: once every view is migrated, drop the body.ui-refined prefix and
     fold this file into unified-styles.css.
   Guide: docs/guides/unified-styles-system.md and docs/guides/ux-redesign-playbook.md
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
  --ui-accent: var(--override-primary-dark); /* #0f6f7d: white text on it is 5.85:1 */
  --ui-accent-hover: var(--override-primary-complement);
  --ui-accent-active: #094b55;
  --ui-accent-text: var(--override-primary-dark); /* teal text on light surfaces */
  --ui-accent-tint: rgba(15, 111, 125, 0.1);
  --ui-field-border: #868e96; /* 3:1 against the page (WCAG 1.4.11) */
}

[data-bs-theme="dark"] {
  --ui-accent-hover: #14808f;
  --ui-accent-active: #0c5d6a;
  --ui-accent-text: #3bb8cc; /* lighter teal for text on dark surfaces */
  --ui-accent-tint: rgba(59, 184, 204, 0.16);
  --ui-field-border: #8a8a8a;
}

/* ---------- Shared: tokens (modals and toasts) ----------
   Overlay surfaces (modal, toast) read these tokens only. Every text/icon color
   below is >= 4.5:1 on its surface; --ui-field-border and the status colors are
   >= 3:1 (WCAG 1.4.11). Measured values are listed in docs/guides/ux-redesign-playbook.md. */
:root {
  /* Surfaces and text */
  --ui-surface: #ffffff;
  --ui-surface-sunken: #f8f9fa;
  --ui-text: #212529; /* 15.4:1 on --ui-surface */
  --ui-text-muted: #495057; /* 8.2:1 on --ui-surface */
  --ui-border: #dee2e6;
  --ui-border-strong: var(--ui-field-border);

  /* Primary action fill in overlays: white text is >= 5.8:1 in both themes
     (--ui-accent turns lighter in dark mode, where white on it is only 4.4:1) */
  --ui-action: #0f6f7d;
  --ui-action-hover: #0c5d6a;
  --ui-action-active: #094b55;

  /* Status: text/icon color, soft tint, and solid fill (white text on the fill) */
  --ui-success: #1b7a3a; /* 5.4:1 on --ui-surface */
  --ui-success-tint: rgba(27, 122, 58, 0.1);
  --ui-danger: #b42335; /* 6.5:1 on --ui-surface */
  --ui-danger-tint: rgba(180, 35, 53, 0.1);
  --ui-danger-solid: #b42335; /* white text 6.5:1 */
  --ui-danger-solid-hover: #9a1d2d;
  --ui-danger-solid-active: #80182a;
  --ui-warning: #9a5b00; /* 5.4:1 on --ui-surface */
  --ui-warning-tint: rgba(154, 91, 0, 0.1);
  --ui-info: var(--ui-accent-text); /* 5.85:1 on --ui-surface */
  --ui-info-tint: var(--ui-accent-tint);

  /* Shape, elevation and scrim */
  --ui-radius-sm: 0.375rem;
  --ui-radius-md: 0.625rem;
  --ui-radius-lg: 0.875rem;
  --ui-shadow-overlay: 0 12px 32px rgba(16, 24, 32, 0.18), 0 2px 6px rgba(16, 24, 32, 0.08);
  --ui-scrim: rgba(16, 24, 32, 0.5);

  /* Motion and focus */
  --ui-duration-fast: 120ms;
  --ui-duration: 200ms;
  --ui-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ui-focus: var(--ui-accent-text);

  /* Layers: toasts sit above modals (Bootstrap: modal 1055, toast 1090) */
  --ui-z-toast: 1090;

  /* Component sizes */
  --ui-toast-width: 22rem;
  --ui-toast-gap: 0.5rem;
  --ui-modal-sm: 26rem;
  --ui-modal-md: 34rem;
  --ui-modal-lg: 50rem;
}

[data-bs-theme="dark"] {
  --ui-surface: #2a2a2a;
  --ui-surface-sunken: #333333;
  --ui-text: #f0f0f0; /* 12.6:1 on --ui-surface */
  --ui-text-muted: #b8bec4; /* 7.7:1 on --ui-surface */
  --ui-border: #444444;

  --ui-success: #4cc38a; /* 6.5:1 on --ui-surface */
  --ui-success-tint: rgba(76, 195, 138, 0.16);
  --ui-danger: #ff8a96; /* 6.4:1 on --ui-surface */
  --ui-danger-tint: rgba(255, 138, 150, 0.16);
  --ui-danger-solid: #c9303f; /* white text 5.3:1 */
  --ui-danger-solid-hover: #b42335;
  --ui-danger-solid-active: #9a1d2d;
  --ui-warning: #ffc247; /* 8.9:1 on --ui-surface */
  --ui-warning-tint: rgba(255, 194, 71, 0.16);

  --ui-shadow-overlay: 0 12px 32px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.4);
  --ui-scrim: rgba(0, 0, 0, 0.65);
}

/* ---------- Shared: page states ----------
   A load failure or an empty condition shown where the content should be (js/page-state.js).
   Not scoped to body.ui-refined: it is new markup, no legacy view uses these classes. */
.ui-page-state {
  max-width: 28rem;
  margin: 2rem auto;
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--ui-text);
}

.ui-page-state__icon {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--ui-danger);
  font-size: 2.5rem;
  line-height: 1;
}

.ui-page-state--info .ui-page-state__icon {
  color: var(--ui-info);
}

.ui-page-state__title {
  margin: 0 0 0.25rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.ui-page-state__message {
  margin: 0 0 1rem;
  color: var(--ui-text-muted);
}

.ui-page-state__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.ui-page-state__retry {
  min-block-size: 2.75rem;
  padding-inline: 1.25rem;
  font-weight: 600;
}

/* ---------- Shared: toasts ----------
   Built by showToast() in init-base.js for every view. A neutral surface with a colored
   icon and a 4 px bar per variant: the text keeps its own color, so contrast does not
   depend on the status color. Bootstrap's own .toast rules are the only base. */
#toast-container {
  position: fixed !important;
  z-index: var(--ui-z-toast) !important;
  inset-block-start: max(5rem, calc(env(safe-area-inset-top, 0px) + 4.5rem)) !important;
  inset-block-end: auto !important;
  inset-inline-end: 1rem !important;
  inset-inline-start: auto !important;
  inline-size: min(var(--ui-toast-width), calc(100vw - 2rem)) !important;
  max-inline-size: none !important;
  display: flex;
  flex-direction: column;
  gap: var(--ui-toast-gap);
  pointer-events: none !important;
}

@media (max-width: 575.98px) {
  #toast-container {
    inset-inline: 1rem !important;
    inline-size: auto !important;
  }
}

#toast-container .ui-toast {
  --ui-toast-accent: var(--ui-info);
  position: relative !important;
  inset: auto !important;
  z-index: auto !important;
  margin: 0 !important;
  inline-size: 100% !important;
  max-inline-size: none !important;
  padding: 0.75rem 0.25rem 0.75rem 0.875rem !important;
  gap: 0.75rem;
  align-items: start;
  animation: none !important;
  border: 1px solid var(--ui-border) !important;
  border-inline-start: 4px solid var(--ui-toast-accent) !important;
  border-radius: var(--ui-radius-md) !important;
  background-color: var(--ui-surface) !important;
  background-image: none !important;
  color: var(--ui-text) !important;
  box-shadow: var(--ui-shadow-overlay) !important;
  font-size: 0.9375rem;
  line-height: 1.4;
  pointer-events: auto !important;
  transition:
    opacity var(--ui-duration) var(--ui-ease),
    transform var(--ui-duration) var(--ui-ease) !important;
}

#toast-container .ui-toast.show,
#toast-container .ui-toast.showing {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
}

/* Enter and exit along the same path: from just above, toward where it rests */
#toast-container .ui-toast.showing,
#toast-container .ui-toast.fade:not(.show) {
  opacity: 0;
  transform: translateY(-0.5rem);
}

#toast-container .ui-toast--success {
  --ui-toast-accent: var(--ui-success);
}

#toast-container .ui-toast--danger {
  --ui-toast-accent: var(--ui-danger);
}

#toast-container .ui-toast--warning {
  --ui-toast-accent: var(--ui-warning);
}

#toast-container .ui-toast__icon {
  color: var(--ui-toast-accent) !important;
  font-size: 1.375rem !important;
  line-height: 1 !important;
  opacity: 1 !important;
  margin-block-start: 0.125rem;
}

#toast-container .ui-toast__content {
  min-inline-size: 0;
  padding-block-start: 0.125rem;
}

#toast-container .ui-toast__message {
  margin: 0;
  overflow-wrap: anywhere;
}

#toast-container .ui-toast__action {
  min-block-size: 2rem;
  margin-block-start: 0.25rem;
  padding: 0.25rem 0;
  border: 0;
  border-radius: var(--ui-radius-sm);
  background: none;
  color: var(--ui-accent-text);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

#toast-container .ui-toast__close {
  box-sizing: border-box;
  inline-size: 2.75rem;
  block-size: 2.75rem;
  margin: -0.5rem 0 !important;
  padding: 0 !important;
  background-size: 0.75rem;
  opacity: 0.7 !important;
  align-self: start !important;
}

#toast-container .ui-toast__close:hover {
  opacity: 1 !important;
  transform: none !important;
}

#toast-container .ui-toast__action:focus-visible,
#toast-container .ui-toast__close:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 2px;
  box-shadow: none;
}

@media (pointer: coarse) {
  #toast-container .ui-toast__action {
    min-block-size: 2.75rem;
  }
}

/* Translucent material where the browser can blur what is behind */
@supports (backdrop-filter: blur(1px)) {
  #toast-container .ui-toast {
    background-color: color-mix(in srgb, var(--ui-surface) 94%, transparent) !important;
    backdrop-filter: blur(14px) saturate(160%) !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  #toast-container .ui-toast {
    background-color: var(--ui-surface) !important;
    backdrop-filter: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  #toast-container .ui-toast {
    transition: opacity var(--ui-duration-fast) linear !important;
  }

  #toast-container .ui-toast.showing,
  #toast-container .ui-toast.fade:not(.show) {
    transform: none;
  }
}

@media (prefers-contrast: more) {
  #toast-container .ui-toast {
    border-color: var(--ui-text) !important;
    border-inline-start: 6px solid var(--ui-toast-accent) !important;
  }
}

/* ---------- Shared: modals ----------
   Anatomy: header (title + X), body, footer ([Cancel] [Primary action], the action at the
   end). The markup carries the variant on .modal:
     .ui-modal--form         fields; body scrolls, footer stays; full screen under 768 px
     .ui-modal--confirm      one sentence of consequence and an action (compact, centered)
     .ui-modal--destructive  like confirm, with a danger action
     .ui-modal--info         read-only content; X (and an optional Close) only
   It applies to every view (no body.ui-refined needed); the legacy button rules in
   unified-styles.css use !important, hence the specificity and !important below. The scrim
   token only applies under body.ui-refined. */
body.ui-refined .modal-backdrop {
  --bs-backdrop-bg: var(--ui-scrim);
  --bs-backdrop-opacity: 1;
}

/* Sizes: confirm and destructive are compact; forms and info use the width asked in the markup */
body .ui-modal--confirm .modal-dialog,
body .ui-modal--destructive .modal-dialog {
  --bs-modal-width: var(--ui-modal-sm);
}

body .ui-modal--form .modal-dialog:not(.modal-lg),
body .ui-modal--info .modal-dialog:not(.modal-lg) {
  --bs-modal-width: var(--ui-modal-md);
}

@media (min-width: 992px) {
  body .ui-modal .modal-dialog.modal-lg {
    --bs-modal-width: var(--ui-modal-lg);
  }
}

/* The dialog rises a few pixels and settles; it leaves along the same path */
body .modal.ui-modal.fade .modal-dialog {
  transform: translateY(0.75rem) scale(0.985);
  transition: transform var(--ui-duration) var(--ui-ease);
}

body .modal.ui-modal.show .modal-dialog {
  transform: none;
}

body .ui-modal .modal-content {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-lg);
  background-color: var(--ui-surface);
  color: var(--ui-text);
  box-shadow: var(--ui-shadow-overlay);
}

body .ui-modal .modal-header,
body .ui-modal .modal-footer {
  background-color: transparent !important;
  border-color: var(--ui-border) !important;
}

body .ui-modal .modal-header {
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom-width: 1px;
}

body .ui-modal--confirm .modal-header,
body .ui-modal--destructive .modal-header {
  border-bottom-color: transparent !important;
  padding-bottom: 0.25rem;
}

body .ui-modal .modal-title {
  margin: 0;
  color: var(--ui-text);
  font-size: 1.25rem !important;
  font-weight: 600 !important;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

body .ui-modal .modal-title .material-symbols-rounded {
  margin-inline-end: 0.5rem;
  color: var(--ui-accent-text);
  font-size: 1.375rem;
  vertical-align: -0.2em;
}

body .ui-modal--destructive .modal-title .material-symbols-rounded {
  color: var(--ui-danger);
}

/* X: 44 px target, 14 px glyph, at the end of the header (left in RTL) */
body .ui-modal .modal-header .btn-close {
  box-sizing: border-box;
  inline-size: 2.75rem;
  block-size: 2.75rem;
  margin-block: -0.625rem;
  margin-inline: auto -0.75rem;
  padding: 0;
  border-radius: var(--ui-radius-sm);
  background-size: 0.875rem;
  opacity: 0.75;
  flex-shrink: 0;
}

body .ui-modal .modal-header .btn-close:hover {
  opacity: 1;
}

/* A <form> wrapping body and footer keeps the footer fixed and the body scrolling */
body .ui-modal .modal-dialog-scrollable .modal-content > form {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-block-size: 0;
  overflow: hidden;
}

body .ui-modal .modal-body {
  padding: 1rem 1.5rem;
  overscroll-behavior: contain;
  color: var(--ui-text);
}

body .ui-modal--confirm .modal-body,
body .ui-modal--destructive .modal-body {
  padding-block: 0.5rem 1rem;
}

body .ui-modal .modal-body .text-muted {
  color: var(--ui-text-muted) !important;
}

/* Required-field asterisks: Bootstrap's red is 3.2:1 on the dark surface */
body .ui-modal .text-danger {
  color: var(--ui-danger) !important;
}

/* One sentence of consequence at the top of confirm and destructive modals */
body .ui-modal__lead {
  margin: 0 0 1rem;
  color: var(--ui-text);
}

/* Titled groups of fields inside a form modal (<fieldset> + <legend>) */
body .ui-modal-section {
  min-inline-size: 0;
  margin: 0 0 1.25rem;
  padding: 0;
  border: 0;
}

body .ui-modal-section:last-child {
  margin-bottom: 0;
}

body .ui-modal-section__title {
  float: none;
  inline-size: 100%;
  margin: 0 0 0.75rem;
  padding: 0 0 0.375rem;
  border-bottom: 1px solid var(--ui-border);
  color: var(--ui-text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.4;
  text-transform: uppercase;
}

/* Patient photo (add/edit patient modal) */
body .ui-patient-photo {
  display: flex;
  flex-direction: column;
  align-items: center;
  inline-size: 8.75rem;
  margin-inline: auto;
}

body .ui-patient-photo__frame {
  position: relative;
  inline-size: 7.5rem;
  block-size: 7.5rem;
}

body .ui-patient-photo__img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  border: 1px solid var(--ui-border);
  border-radius: 50%;
}

body .ui-patient-photo__action {
  position: absolute;
  inset-block-end: 0;
  inset-inline-end: 0;
}

body .ui-patient-photo__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  inline-size: 2.75rem;
  block-size: 2.75rem;
  padding: 0;
  border-radius: 50%;
}

body .ui-patient-photo__btn .material-symbols-rounded {
  font-size: 1.125rem;
}

/* Selected body areas panel (add wound modal) */
body .ui-wound-areas__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.5rem;
  color: var(--ui-text);
  font-size: 0.875rem;
  font-weight: 600;
}

body .ui-wound-areas__count {
  min-inline-size: 1.5rem;
  padding: 0.0625rem 0.5rem;
  border-radius: 999px;
  background: var(--ui-border);
  color: var(--ui-text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
}

/* Image drop zone (new assessment modal) */
body #newAssessmentModal .wound-image-area {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-block-size: 16rem;
  overflow: hidden;
  border: 2px dashed var(--ui-border);
  border-radius: 0.75rem;
  background: var(--bs-tertiary-bg);
}

body #newAssessmentModal .wound-image-area.interactive {
  cursor: pointer;
}

body #newAssessmentModal .wound-image-area.interactive:hover {
  border-color: var(--bs-primary);
}

body #newAssessmentModal .wound-image-preview {
  inline-size: 100%;
  max-block-size: 20rem;
  object-fit: contain;
}

body .ui-image-tips {
  margin-block-start: 0.75rem;
  color: var(--ui-text-muted);
  font-size: 0.75rem;
  line-height: 1.5;
}

/* Segmented Yes/No control built on radio inputs */
body .ui-segmented {
  display: flex;
  inline-size: 100%;
}

body .ui-segmented > .btn {
  flex: 1 1 0;
}

body .ui-segmented > .btn {
  min-block-size: 2.75rem;
}

/* The hidden radio inputs make the first label a second child, so Bootstrap's
   first-child/last-child rounding skips it. Round the outer corners explicitly
   (the global .btn-group rules are !important). */
body .btn-group.ui-segmented > label.btn:first-of-type {
  border-start-start-radius: var(--ui-radius-sm) !important;
  border-end-start-radius: var(--ui-radius-sm) !important;
}

body .btn-group.ui-segmented > label.btn:last-of-type {
  border-start-end-radius: var(--ui-radius-sm) !important;
  border-end-end-radius: var(--ui-radius-sm) !important;
}

/* !important: the generic modal outline-secondary rule below also uses it */
body .ui-modal .ui-segmented > .btn:hover:not(:disabled) {
  background-color: var(--ui-accent-tint) !important;
  border-color: var(--ui-accent) !important;
  color: var(--ui-accent-text) !important;
}

body .ui-modal .ui-segmented > .btn-check:checked + .btn,
body .ui-modal .ui-segmented > .btn-check:checked + .btn:hover {
  background-color: var(--ui-accent) !important;
  border-color: var(--ui-accent) !important;
  color: #ffffff !important;
}

body .ui-segmented > .btn-check:focus-visible + .btn {
  outline: 2px solid var(--ui-focus);
  outline-offset: 2px;
  box-shadow: none;
}

@media (max-width: 767.98px) {
  body #newAssessmentModal .wound-image-area {
    min-block-size: 11rem;
  }
}

/* Upload row: button + file name on one line */
body .ui-consent-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

body .ui-consent-row .btn {
  display: inline-flex;
  align-items: center;
}

/* Optional upload: neutral outline, same look as the cancel button */
body .ui-consent-row .ui-consent-btn {
  min-block-size: 2.75rem;
  padding-inline: 1.25rem;
  border-radius: var(--ui-radius-sm);
  background-color: transparent;
  border: 1px solid var(--ui-field-border);
  color: var(--ui-text);
}

body .ui-consent-row .ui-consent-btn .material-symbols-rounded {
  color: var(--ui-accent-text);
}

body .ui-consent-row .ui-consent-btn:hover:not(:disabled) {
  background-color: var(--ui-surface-sunken);
  border-color: var(--ui-accent);
  color: var(--ui-text);
}

body .ui-consent-row .ui-consent-btn:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 2px;
}

body .ui-consent-row #consentFileName.is-selected {
  color: var(--ui-text) !important; /* beats .text-muted */
}

body .ui-consent-row .ui-consent-btn:active {
  background-color: var(--ui-surface-sunken);
  border-color: var(--ui-accent-active);
}

body .ui-modal .modal-footer {
  gap: 0.5rem;
  justify-content: flex-end;
  padding: 1rem 1.5rem 1.25rem;
  border-top-width: 1px;
}

body .ui-modal--confirm .modal-footer,
body .ui-modal--destructive .modal-footer {
  border-top-color: transparent !important;
  padding-top: 0.25rem;
}

/* Footer buttons: 44 px, one look for every modal */
body .ui-modal .modal-footer .btn {
  min-block-size: 2.75rem;
  margin: 0;
  padding-inline: 1.25rem;
  border-radius: var(--ui-radius-sm);
  font-weight: 600;
  transition:
    background-color var(--ui-duration-fast) var(--ui-ease),
    border-color var(--ui-duration-fast) var(--ui-ease),
    transform var(--ui-duration-fast) var(--ui-ease);
}

body .ui-modal .modal-footer .btn:active:not(:disabled) {
  transform: scale(0.97);
}

body .ui-modal .modal-footer .btn.btn-primary,
body .ui-modal .modal-body .btn.btn-primary {
  background-color: var(--ui-action) !important;
  border-color: var(--ui-action) !important;
  background-image: none !important;
  color: #ffffff !important;
}

body .ui-modal .modal-footer .btn.btn-primary:hover:not(:disabled),
body .ui-modal .modal-body .btn.btn-primary:hover:not(:disabled) {
  background-color: var(--ui-action-hover) !important;
  border-color: var(--ui-action-hover) !important;
}

body .ui-modal .modal-footer .btn.btn-primary:active:not(:disabled),
body .ui-modal .modal-body .btn.btn-primary:active:not(:disabled) {
  background-color: var(--ui-action-active) !important;
  border-color: var(--ui-action-active) !important;
}

body .ui-modal .modal-footer .btn.btn-danger,
body .ui-modal .modal-body .btn.btn-danger {
  background-color: var(--ui-danger-solid) !important;
  border-color: var(--ui-danger-solid) !important;
  background-image: none !important;
  color: #ffffff !important;
}

body .ui-modal .modal-footer .btn.btn-danger:hover:not(:disabled),
body .ui-modal .modal-body .btn.btn-danger:hover:not(:disabled) {
  background-color: var(--ui-danger-solid-hover) !important;
  border-color: var(--ui-danger-solid-hover) !important;
}

body .ui-modal .modal-footer .btn.btn-danger:active:not(:disabled),
body .ui-modal .modal-body .btn.btn-danger:active:not(:disabled) {
  background-color: var(--ui-danger-solid-active) !important;
  border-color: var(--ui-danger-solid-active) !important;
}

body .ui-modal .modal-footer .btn.ui-modal-cancel {
  background-color: transparent !important;
  border: 1px solid var(--ui-field-border) !important;
  background-image: none !important;
  color: var(--ui-text) !important;
}

body .ui-modal .modal-footer .btn.ui-modal-cancel:hover:not(:disabled) {
  background-color: var(--ui-surface-sunken) !important;
  border-color: var(--ui-text-muted) !important;
}

body .ui-modal .btn:focus-visible,
body .ui-modal .btn-close:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 2px;
  box-shadow: none;
}

/* Fields inside refined modals: visible borders (3:1), 44 px tall, clear focus */
body .ui-modal .form-control,
body .ui-modal .form-select {
  border-color: var(--ui-field-border) !important;
  border-radius: var(--ui-radius-sm);
  background-color: var(--ui-surface);
  color: var(--ui-text);
}

body .ui-modal .form-control:not(textarea),
body .ui-modal .form-select,
body .ui-modal .modal-body .btn:not(.btn-sm) {
  min-block-size: 2.75rem;
}

body .ui-modal .form-control:focus,
body .ui-modal .form-select:focus {
  border-color: var(--ui-focus) !important;
  outline: 2px solid var(--ui-focus);
  outline-offset: 0;
  box-shadow: none;
}

body .ui-modal .form-control.is-invalid,
body .ui-modal .form-select.is-invalid {
  border-color: var(--ui-danger) !important;
}

body .ui-modal .invalid-feedback {
  color: var(--ui-danger);
}

/* Content colors: everything inside a modal reads the tokens, never Bootstrap's fixed
   light-theme colors (labels, helper text, links, status text, outline buttons, alerts).
   Rule for new modals: use these classes, do not set colors by hand. */
body .ui-modal label,
body .ui-modal .form-label,
body .ui-modal .form-check-label,
body .ui-modal legend,
body .ui-modal .modal-body strong,
body .ui-modal .text-dark {
  color: var(--ui-text) !important;
}

body .ui-modal .text-muted,
body .ui-modal .form-text,
body .ui-modal .text-secondary,
body .ui-modal .small.text-muted {
  color: var(--ui-text-muted) !important;
}

body .ui-modal .text-success {
  color: var(--ui-success) !important;
}

body .ui-modal .text-danger {
  color: var(--ui-danger) !important;
}

body .ui-modal .text-warning {
  color: var(--ui-warning) !important;
}

body .ui-modal .text-info,
body .ui-modal .text-primary {
  color: var(--ui-info) !important;
}

body .ui-modal a:not(.btn) {
  color: var(--ui-accent-text);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

body .ui-modal .form-control::placeholder,
body .ui-modal textarea::placeholder {
  color: var(--ui-text-muted);
  opacity: 1;
}

body .ui-modal .form-control:disabled,
body .ui-modal .form-select:disabled {
  background-color: var(--ui-surface-sunken);
  color: var(--ui-text-muted);
}

body .ui-modal .form-check-input {
  border-color: var(--ui-field-border);
  background-color: var(--ui-surface);
}

body .ui-modal .form-check-input:checked {
  border-color: var(--ui-action);
  background-color: var(--ui-action);
}

body .ui-modal .input-group-text {
  border-color: var(--ui-field-border);
  background-color: var(--ui-surface-sunken);
  color: var(--ui-text-muted);
}

/* Secondary buttons inside a modal (outline): neutral, readable in both themes */
body .ui-modal .btn-outline-secondary,
body .ui-modal .btn-outline-info {
  border-color: var(--ui-field-border) !important;
  background-color: transparent !important;
  color: var(--ui-text) !important;
}

body .ui-modal .btn-outline-secondary:hover:not(:disabled),
body .ui-modal .btn-outline-info:hover:not(:disabled) {
  border-color: var(--ui-text-muted) !important;
  background-color: var(--ui-surface-sunken) !important;
  color: var(--ui-text) !important;
}

body .ui-modal .btn-outline-danger {
  border-color: var(--ui-danger) !important;
  background-color: transparent !important;
  color: var(--ui-danger) !important;
}

/* Alerts: a calm surface with a colored bar; the text keeps the primary text color */
body .ui-modal .alert {
  --ui-alert-accent: var(--ui-info);
  border: 1px solid var(--ui-border);
  border-inline-start: 4px solid var(--ui-alert-accent);
  border-radius: var(--ui-radius-sm);
  background-color: var(--ui-surface-sunken);
  color: var(--ui-text);
}

body .ui-modal .alert-danger {
  --ui-alert-accent: var(--ui-danger);
}

body .ui-modal .alert-warning {
  --ui-alert-accent: var(--ui-warning);
}

body .ui-modal .alert-success {
  --ui-alert-accent: var(--ui-success);
}

body .ui-modal .alert .material-symbols-rounded {
  color: var(--ui-alert-accent);
}

body .ui-modal .alert .alert-heading {
  color: var(--ui-text);
}

/* Full screen under 768 px for forms (Bootstrap modal-fullscreen-md-down): the footer
   stays reachable and respects the home indicator */
@media (max-width: 767.98px) {
  body .ui-modal .modal-dialog.modal-fullscreen-md-down .modal-content {
    border: 0;
    border-radius: 0;
  }

  body .ui-modal .modal-dialog.modal-fullscreen-md-down .modal-header {
    padding-block-start: max(1.25rem, env(safe-area-inset-top, 0px));
  }

  body .ui-modal .modal-dialog.modal-fullscreen-md-down .modal-footer {
    padding-block-end: max(1.25rem, env(safe-area-inset-bottom, 0px));
  }
}

/* Compact modals on phones: the actions share the width */
@media (max-width: 575.98px) {
  body .ui-modal--confirm .modal-footer .btn,
  body .ui-modal--destructive .modal-footer .btn {
    flex: 1 1 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  body .modal.ui-modal.fade .modal-dialog {
    transform: none;
    transition: none;
  }

  body .ui-modal .modal-footer .btn {
    transition: none;
  }

  body .ui-modal .modal-footer .btn:active:not(:disabled) {
    transform: none;
  }
}

@media (prefers-contrast: more) {
  body .ui-modal .modal-content {
    border: 2px solid var(--ui-text);
  }
}

/* ---------- Shared: panels ----------
   Read-only side panels (Bootstrap offcanvas) for reference content that is consulted
   while looking at the page, e.g. how the progress is decided. Same surface, text and
   header as the modals; full width under 576 px. Close with the X, Escape or outside click. */
body .offcanvas.ui-panel {
  --bs-offcanvas-width: min(34rem, 100vw);
  background-color: var(--ui-surface);
  color: var(--ui-text);
  border-inline-start: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow-overlay);
}

body .ui-panel .offcanvas-header {
  align-items: flex-start;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--ui-border);
}

body .ui-panel .offcanvas-title {
  color: var(--ui-text);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

body .ui-panel .offcanvas-header .btn-close {
  box-sizing: border-box;
  inline-size: 2.75rem;
  block-size: 2.75rem;
  margin: -0.625rem -0.75rem -0.625rem auto;
  padding: 0;
  background-size: 0.875rem;
  flex-shrink: 0;
}

body .ui-panel .offcanvas-body {
  padding: 1rem 1.5rem 1.5rem;
  overscroll-behavior: contain;
}

body .ui-panel .btn-close:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 2px;
  box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  body .offcanvas.ui-panel {
    transition: none;
  }
}

/* ---------- View: patient-list ---------- */

/* ===== Patient list — sortable headers and clamped observations ===== */
.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.sort-btn .sort-icon {
  font-size: 1rem;
  opacity: 0.55;
}

.sort-btn.is-active .sort-icon,
.sort-btn:hover .sort-icon,
.sort-btn:focus-visible .sort-icon {
  opacity: 1;
}

.patient-observation {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  min-width: 14rem;
  max-width: 28rem;
  white-space: normal;
}

@media (max-width: 991.98px) {
  .patient-observation {
    min-width: 0;
    max-width: none;
  }
}

/* ===== Patient list — merged progress column (one line per wound) ===== */
.progress-grid {
  display: grid;
  grid-template-columns: 7rem 7.5rem 7.5rem;
  align-items: center;
  column-gap: 0.25rem;
}

.progress-grid > .progress-chip,
.progress-grid > button {
  justify-self: center;
}

.progress-header-title {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.3rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid currentColor;
  font-size: var(--fs-sm, 0.8125rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.progress-info-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  cursor: pointer;
}

.progress-info-btn .material-symbols-rounded {
  font-size: 1.05rem;
}

.progress-info-btn:focus-visible,
.progress-name--cut:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* The three columns read as one block: a soft divider on each side */
.progress-group-th,
.progress-group-td {
  border-inline: 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.1));
}

.progress-subheads {
  font-weight: 600;
  opacity: 0.85;
}

.progress-name--cut {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline dotted;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
  text-underline-offset: 3px;
  cursor: pointer;
}

.progress-line {
  padding: 0.1rem 0;
}

.progress-line .progress-name {
  text-align: start;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.progress-card-head {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
  text-align: center;
}

@media (max-width: 991.98px) {
  .table-cards tbody td.align-middle:has(.progress-grid) {
    align-items: flex-start;
  }
}

/* Segmented Active | Discharged control: the hidden radio inputs make the first label
   a second child, so the global .btn-group first-child rules skip it. Round the outer
   corners explicitly (the global rules are !important, hence the specificity). */
.btn-group.patient-status-group > label.btn:first-of-type {
  border-top-left-radius: 0.375rem !important;
  border-bottom-left-radius: 0.375rem !important;
}

.btn-group.patient-status-group > label.btn:last-of-type {
  border-top-right-radius: 0.375rem !important;
  border-bottom-right-radius: 0.375rem !important;
}

/* ===== Patient list — flat page, no banner card =====
   The list sits directly on the page: plain header, one-row toolbar and the
   table as the only raised surface. Keep .card on the element so the shared
   card hooks (pagination insertion) still work. */
.patient-list-flat.card {
  background: transparent;
  border: 0;
  box-shadow: none;
}

.patient-list-flat .card-header {
  background: transparent;
  border: 0;
  box-shadow: none;
}

.patient-list-flat .patient-list-surface {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius);
  overflow: hidden;
}

.patient-list-flat #pagination-container {
  padding: 0 0.25rem;
}

/* Primary action of the flat page header uses the brand turquoise (AA with white text) */
#main-content .patient-list-flat .card-header .btn-primary {
  background-color: var(--override-primary-dark);
  border-color: var(--override-primary-dark);
  color: var(--override-white);
}

#main-content .patient-list-flat .card-header .btn-primary:hover,
#main-content .patient-list-flat .card-header .btn-primary:focus-visible {
  background-color: var(--override-primary-complement);
  border-color: var(--override-primary-complement);
}

/* Below lg each patient is already its own card, so the table surface drops its frame */
@media (max-width: 991.98px) {
  .patient-list-flat .patient-list-surface {
    background: transparent;
    border: 0;
    border-radius: 0;
    overflow: visible;
  }
}

/* Patient list filters: label above each control, one wrapping row with real gaps */
.patient-list-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
  padding-bottom: 1rem;
}

.patient-list-filter {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.patient-list-filter-search {
  flex: 1 1 16rem;
  max-width: 30rem;
}

.patient-list-filter-label {
  margin: 0;
  font-size: var(--fs-xs, 0.75rem);
  font-weight: 600;
  color: var(--bs-secondary-color);
}

/* Dark mode: the themed .card rules re-paint the flat container, so undo them here */
[data-bs-theme="dark"] #main-content .patient-list-flat.card,
[data-bs-theme="dark"] #main-content .patient-list-flat .card-header {
  background-color: transparent;
  border-color: transparent;
}

/* Controls now sit on the page, not on a card: give them a visible edge */
[data-bs-theme="dark"] #main-content .patient-list-filters .form-control,
[data-bs-theme="dark"] #main-content .patient-list-filters .form-select {
  border-color: #666;
}

/* =====================================================================
   Patient list — Apple Design pass
   Every rule below is scoped to body.ui-refined, which init-base.js sets only
   on the patient list view, so the shared navbar, context bar and footer
   look the same on every other view.
   ===================================================================== */

/* --- Navbar: translucent material with a hairline, steady geometry --- */
body.ui-refined .sticky-navbar {
  background-color: rgba(255, 255, 255, 0.72) !important;
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid rgba(18, 129, 147, 0.35) !important;
  box-shadow: none !important;
  transition: background-color 0.25s ease, box-shadow 0.25s ease;
}

body.ui-refined .sticky-navbar.scrolled {
  padding: 1rem 0; /* the bar keeps its height: no jump while scrolling */
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06) !important;
}

/* Up to 768px the navbar is 8px-padded (unified-styles), so the scrolled state must keep that
   too; with 16px it grew from 68px to 84px as soon as the page scrolled. */
@media (max-width: 768px) {
  body.ui-refined .sticky-navbar.scrolled {
    padding: 0.5rem 0;
  }
}

/* The page is offset by the measured navbar and context bar heights (--ui-navbar-h and
   --ui-bar-h, published by trackShellHeights in init-base.js). The navbar is 68px up to
   768px and 84px above, and the bar grows when its links take a 44px touch target, so a
   fixed 80px left a gap on small screens and let the bar cover the page header. */
body.ui-refined,
body.ui-refined.navbar-scrolled {
  padding-top: var(--ui-navbar-h, 80px);
}

body.ui-refined .app-context-bar,
body.ui-refined.navbar-scrolled .app-context-bar {
  top: var(--ui-navbar-h, 80px);
}

/* Content starts right under the bar, whatever its height (segmentation jobs included) */
body.ui-refined.context-bar-visible:not(.context-bar-trivial) .main-content,
body.ui-refined.context-bar-visible.context-bar-segmentation-active .main-content {
  padding-top: calc(var(--ui-bar-h, 40px) + 0.25rem);
}

[data-bs-theme="dark"] body.ui-refined .sticky-navbar,
body.ui-refined[data-bs-theme="dark"] .sticky-navbar {
  background-color: rgba(33, 37, 41, 0.72) !important;
  border-bottom-color: rgba(23, 162, 184, 0.45) !important;
}

/* --- Context bar: hidden when it would only repeat the page title ---
   body.context-bar-trivial is set by initializeContextBar (one crumb, no demo badge,
   no back link); running segmentation jobs live in this bar, so it stays then. */
body.ui-refined.context-bar-trivial:not(.context-bar-segmentation-active) #app-context-bar {
  display: none !important;
}

body.ui-refined.context-bar-trivial.context-bar-visible:not(.context-bar-segmentation-active)
  .main-content {
  padding-top: 2rem;
}

/* Where the sticky table header must stop: under the navbar and, if shown, the context bar */
body.ui-refined {
  --ui-sticky-top: calc(var(--ui-navbar-h, 80px) + var(--ui-bar-h, 0px) + 4px);
}

/* --- Page header typography: size-specific tracking, hierarchy through weight --- */
body.ui-refined .patient-list-flat .card-header h5 {
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 700;
}

body.ui-refined .patient-list-flat .card-header .d-flex.align-items-center > i {
  display: none;
}

body.ui-refined .patient-list-flat #patientListCount {
  font-size: 0.9375rem;
  letter-spacing: 0;
}

/* Column headers: sentence case, quiet, no tracking */
body.ui-refined .patient-list-surface thead th {
  text-transform: none !important;
  letter-spacing: 0;
  font-size: 0.8125rem !important;
  font-weight: 600 !important;
  color: var(--bs-secondary-color) !important;
  opacity: 1 !important;
}

/* --- Sticky, translucent table header (only where the table is a table) --- */
@media (min-width: 992px) {
  body.ui-refined .patient-list-flat .patient-list-surface,
  body.ui-refined .patient-list-flat .table-responsive {
    overflow: visible; /* an overflow container would stop the header from sticking */
  }

  body.ui-refined .patient-list-surface thead th {
    position: sticky;
    top: var(--ui-sticky-top);
    z-index: 5;
    --bs-table-bg: transparent;
    box-shadow: none;
    background-color: color-mix(in srgb, var(--bs-body-bg) 78%, transparent);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--bs-border-color);
  }

  body.ui-refined .patient-list-surface thead th:first-child {
    border-top-left-radius: var(--border-radius);
  }

  body.ui-refined .patient-list-surface thead th:last-child {
    border-top-right-radius: var(--border-radius);
  }
}

@media (min-width: 992px) {
  [data-bs-theme="dark"] body.ui-refined .patient-list-surface thead th,
  body.ui-refined[data-bs-theme="dark"] .patient-list-surface thead th {
    background-color: rgba(45, 48, 52, 0.78) !important;
  }
}

/* --- Footer: one quiet line --- */
.footer-compact-text {
  display: none;
}

body.ui-refined .footer-unified {
  padding: 0.75rem 0 !important;
}

body.ui-refined .footer-unified .footer-inline-row {
  display: none !important;
}

body.ui-refined .footer-unified .footer-compact-text {
  display: block;
}

/* --- Press feedback: instant, on pointer-down --- */
body.ui-refined #patients-tbody tr {
  transition: background-color 0.12s ease-out;
}

body.ui-refined #patients-tbody tr[data-patient-id]:active {
  background-color: var(--bs-secondary-bg);
}

body.ui-refined .patient-list-flat .btn,
body.ui-refined .patient-list-filters .btn,
body.ui-refined .patient-list-flat .pagination .page-link {
  transition: transform 0.1s ease-out, background-color 0.15s ease-in-out,
    border-color 0.15s ease-in-out, color 0.15s ease-in-out;
}

body.ui-refined .patient-list-flat .btn:active,
body.ui-refined .patient-list-filters .btn:active,
body.ui-refined .patient-status-group > label.btn:active {
  transform: scale(0.97);
}

/* --- Touch targets: 44px on touch screens --- */
@media (pointer: coarse), (max-width: 991.98px) {
  body.ui-refined .patient-list-filters .form-control,
  body.ui-refined .patient-list-filters .form-select,
  body.ui-refined .patient-list-filters .btn,
  body.ui-refined .patient-list-flat .card-header .btn,
  body.ui-refined #patientPageSizeSelect {
    min-height: 44px;
  }
}

/* --- Reduced motion / transparency / contrast --- */
@media (prefers-reduced-motion: reduce) {
  body.ui-refined .patient-list-flat .btn:active,
  body.ui-refined .patient-list-filters .btn:active,
  body.ui-refined .patient-status-group > label.btn:active {
    transform: none;
  }

  body.ui-refined .sticky-navbar,
  body.ui-refined #patients-tbody tr {
    transition: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  body.ui-refined .sticky-navbar {
    background-color: #ffffff !important;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  [data-bs-theme="dark"] body.ui-refined .sticky-navbar,
  body.ui-refined[data-bs-theme="dark"] .sticky-navbar {
    background-color: #212529 !important;
  }

  body.ui-refined .patient-list-surface thead th,
  [data-bs-theme="dark"] body.ui-refined .patient-list-surface thead th {
    background-color: var(--bs-body-bg) !important;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  body.ui-refined .sticky-navbar {
    border-bottom: 2px solid var(--override-primary) !important;
  }

  body.ui-refined .patient-list-surface thead th {
    border-bottom: 2px solid var(--bs-body-color);
  }
}

/* --- One accent for the whole list: add button, status control and pagination ---
   Fill #0f6f7d carries white text at 5.85:1 in both themes; text on dark surfaces uses the
   lighter teal. Field borders reach 3:1 (WCAG 1.4.11). */
/* Accent and field-border tokens: defined once in the tokens block at the top of this file. */

/* Add patient: hover lifts and tints, press sinks, focus gets a ring */
body.ui-refined #main-content .patient-list-flat .card-header .btn-primary {
  background-color: var(--ui-accent);
  border-color: var(--ui-accent);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease,
    transform 0.1s ease-out;
}

body.ui-refined #main-content .patient-list-flat .card-header .btn-primary:hover {
  background-color: var(--ui-accent-hover);
  border-color: var(--ui-accent-hover);
  box-shadow: 0 4px 12px rgba(15, 111, 125, 0.35);
  transform: translateY(-1px);
}

body.ui-refined #main-content .patient-list-flat .card-header .btn-primary:active {
  background-color: var(--ui-accent-active);
  border-color: var(--ui-accent-active);
  box-shadow: none;
  transform: scale(0.97);
  transition-duration: 0.05s;
}

body.ui-refined #main-content .patient-list-flat .card-header .btn-primary:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

body.ui-refined #main-content .patient-list-flat .card-header .btn-primary .material-symbols-rounded {
  transition: transform 0.2s ease;
}

body.ui-refined #main-content .patient-list-flat .card-header .btn-primary:hover .material-symbols-rounded {
  transform: scale(1.1);
}

/* Active | Discharged: same accent when selected, body-colored text and a visible edge otherwise */
body.ui-refined #main-content .patient-status-group > label.btn {
  color: var(--bs-body-color) !important;
  background-color: transparent !important;
  border-color: var(--ui-field-border) !important;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease-out;
}

body.ui-refined #main-content .patient-status-group > label.btn:hover {
  background-color: var(--ui-accent-tint) !important;
  color: var(--ui-accent-text) !important;
  border-color: var(--ui-accent-text) !important;
}

body.ui-refined #main-content .patient-status-group > .btn-check:checked + label.btn,
body.ui-refined #main-content .patient-status-group > .btn-check:checked + label.btn:hover {
  background-color: var(--ui-accent) !important;
  border-color: var(--ui-accent) !important;
  color: #ffffff !important;
}

body.ui-refined #main-content .patient-status-group > .btn-check:focus-visible + label.btn {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
  box-shadow: none;
}

/* Clear filters (toolbar and empty state): quiet outline button; hover tints with the accent
   instead of the grey fill that left the text unreadable (1.34:1) */
body.ui-refined #main-content #resetFiltersBtn,
body.ui-refined #main-content #emptyStateResetBtn {
  color: var(--ui-accent-text) !important;
  background-color: transparent !important;
  border-color: var(--ui-field-border) !important;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease-out;
}

body.ui-refined #main-content #resetFiltersBtn:hover,
body.ui-refined #main-content #emptyStateResetBtn:hover {
  color: var(--ui-accent-text) !important;
  background-color: var(--ui-accent-tint) !important;
  border-color: var(--ui-accent-text) !important;
}

body.ui-refined #main-content #resetFiltersBtn:active,
body.ui-refined #main-content #emptyStateResetBtn:active {
  background-color: var(--ui-accent-tint) !important;
  transform: scale(0.97);
}

body.ui-refined #main-content #resetFiltersBtn:focus-visible,
body.ui-refined #main-content #emptyStateResetBtn:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
  box-shadow: none;
}

body.ui-refined #main-content #resetFiltersBtn .material-symbols-rounded,
body.ui-refined #main-content #emptyStateResetBtn .material-symbols-rounded {
  transition: transform 0.35s ease;
}

body.ui-refined #main-content #resetFiltersBtn:hover .material-symbols-rounded,
body.ui-refined #main-content #emptyStateResetBtn:hover .material-symbols-rounded {
  transform: rotate(-180deg);
}

/* Pagination: brand accent, disabled controls stay quiet */
body.ui-refined #pagination-container .pagination .page-link {
  color: var(--ui-accent-text);
  background-color: transparent;
  border-color: var(--bs-border-color);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease,
    transform 0.1s ease-out;
}

body.ui-refined #pagination-container .pagination .page-item:not(.active):not(.disabled) .page-link:hover {
  background-color: var(--ui-accent-tint);
  color: var(--ui-accent-text);
  border-color: var(--ui-accent-text);
}

body.ui-refined #pagination-container .pagination .page-link:active {
  transform: scale(0.97);
}

body.ui-refined #pagination-container .pagination .page-item.active .page-link {
  background-color: var(--ui-accent);
  border-color: var(--ui-accent);
  color: #ffffff;
}

body.ui-refined #pagination-container .pagination .page-item.disabled .page-link {
  background-color: transparent;
  border-color: var(--bs-border-color);
  color: var(--bs-secondary-color);
  opacity: 0.7;
}

body.ui-refined #pagination-container .pagination .page-link:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
  box-shadow: none;
}

/* Filter fields and the rows-per-page select: visible edge in both themes */
body.ui-refined .patient-list-filters .form-control,
body.ui-refined .patient-list-filters .form-select,
body.ui-refined #patientPageSizeSelect {
  border-color: var(--ui-field-border);
}

body.ui-refined .patient-list-filters .form-control:focus,
body.ui-refined .patient-list-filters .form-select:focus,
body.ui-refined #patientPageSizeSelect:focus {
  border-color: var(--ui-accent-text);
  box-shadow: 0 0 0 0.2rem var(--ui-accent-tint);
}

@media (prefers-reduced-motion: reduce) {
  body.ui-refined #main-content .patient-list-flat .card-header .btn-primary:hover,
  body.ui-refined #main-content .patient-list-flat .card-header .btn-primary:active,
  body.ui-refined #main-content .patient-list-flat .card-header .btn-primary:hover .material-symbols-rounded,
  body.ui-refined #pagination-container .pagination .page-link:active,
  body.ui-refined #main-content #resetFiltersBtn:active,
  body.ui-refined #main-content #emptyStateResetBtn:active,
  body.ui-refined #main-content #resetFiltersBtn:hover .material-symbols-rounded,
  body.ui-refined #main-content #emptyStateResetBtn:hover .material-symbols-rounded {
    transform: none;
  }
}

/* ---------- View: patient ---------- */

/* Flat page: a header surface, then plain sections (wounds, evolution, data). Surfaces use
   the body background and the theme border, like the patient list. Every rule is scoped to
   .patient-view; headings and buttons carry #main-content to win over the legacy globals. */
.patient-view .hidden {
  display: none !important;
}

/* Filled controls: white text needs 4.5:1, and in dark mode the brand teal is lighter, so the
   fill steps one tone darker there. */
.patient-view {
  --pt-fill: var(--ui-accent);
  --pt-fill-hover: var(--ui-accent-hover);
  --pt-fill-active: var(--ui-accent-active);
}

[data-bs-theme="dark"] .patient-view {
  --pt-fill: var(--ui-accent-active);
  --pt-fill-hover: var(--ui-accent-hover);
  --pt-fill-active: var(--ui-accent);
}

.patient-view #patientMain {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

/* Buttons: one primary (filled accent), one secondary (outline), one quiet (text) */
#main-content .patient-view .btn.pt-btn-primary,
#main-content .patient-view .btn.pt-btn-secondary,
#main-content .patient-view .btn.pt-btn-quiet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-height: 38px;
  padding: 0.4rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.25;
  box-shadow: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

#main-content .patient-view .btn .material-symbols-rounded {
  font-size: 1.125rem;
  line-height: 1;
}

#main-content .patient-view .btn.pt-btn-primary {
  background-color: var(--pt-fill);
  border: 1px solid var(--pt-fill);
  color: #fff;
}

#main-content .patient-view .btn.pt-btn-primary:hover:not(:disabled) {
  background-color: var(--pt-fill-hover);
  border-color: var(--pt-fill-hover);
  color: #fff;
}

#main-content .patient-view .btn.pt-btn-primary:active:not(:disabled) {
  background-color: var(--pt-fill-active);
  border-color: var(--pt-fill-active);
  transform: scale(0.97);
}

#main-content .patient-view .btn.pt-btn-secondary {
  background-color: transparent;
  border: 1px solid var(--ui-field-border);
  color: var(--bs-body-color);
}

#main-content .patient-view .btn.pt-btn-secondary:hover:not(:disabled) {
  background-color: var(--ui-accent-tint);
  border-color: var(--ui-accent);
  color: var(--ui-accent-text);
}

#main-content .patient-view .btn.pt-btn-secondary:active:not(:disabled) {
  transform: scale(0.97);
}

#main-content .patient-view .btn.pt-btn-quiet {
  background-color: transparent;
  border: 1px solid transparent;
  color: var(--ui-accent-text);
}

#main-content .patient-view .btn.pt-btn-quiet:hover:not(:disabled) {
  background-color: var(--ui-accent-tint);
  color: var(--ui-accent-text);
}

#main-content .patient-view .btn.pt-btn-quiet:active:not(:disabled) {
  transform: scale(0.97);
}

#main-content .patient-view .btn:disabled {
  opacity: 0.55;
}

#main-content .patient-view .btn:focus-visible,
#main-content .patient-view .pt-chip:focus-visible,
#main-content .patient-view .pt-wound:focus-visible,
#main-content .patient-view .pt-data-summary:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
  box-shadow: none;
}

/* Discharged patient: the main action is to reactivate, the report steps back */
.pt-header.is-discharged #generateReportBtn {
  background-color: transparent;
  border-color: var(--ui-field-border);
  color: var(--bs-body-color);
}

/* --- Header --- */
.pt-header {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius, 0.75rem);
  padding: 1.25rem 1.5rem;
}

.pt-header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 1.5rem;
}

.pt-identity {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.pt-avatar {
  flex: none;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--bs-border-color);
}

.pt-identity-text {
  min-width: 0;
}

.pt-name-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
}

#main-content .patient-view .pt-name {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--bs-body-color);
  overflow-wrap: anywhere;
}

.pt-meta {
  margin: 0.25rem 0 0;
  font-size: 0.9375rem;
  color: var(--bs-secondary-color);
}

/* Status: dot + text, never color alone */
.pt-status {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.125rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.pt-status::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
}

.pt-status.is-active {
  background: var(--ui-accent-tint);
  color: var(--ui-accent-text);
}

.pt-status.is-discharged {
  background: var(--bs-secondary-bg);
  color: var(--bs-body-color);
}

.pt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.pt-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.625rem;
  border: 1px solid var(--bs-border-color);
  border-radius: 999px;
  background: transparent;
  color: var(--bs-body-color);
  font-size: 0.8125rem;
  font-weight: 500;
}

.pt-chip.is-muted {
  color: var(--bs-secondary-color);
}

.pt-chip .material-symbols-rounded {
  font-size: 1rem;
}

.pt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* --- Sections --- */
.pt-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

#main-content .patient-view .pt-section-title {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-weight: 700;
  color: var(--bs-body-color);
}

/* --- Wounds --- */
.pt-wounds-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.pt-wounds-grid.pt-wounds-empty {
  display: block;
}

#main-content .patient-view a.pt-wound {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius, 0.75rem);
  color: var(--bs-body-color);
  text-decoration: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

#main-content .patient-view a.pt-wound:hover {
  border-color: var(--ui-accent);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  color: var(--bs-body-color);
}

#main-content .patient-view a.pt-wound:active {
  transform: scale(0.985);
}

.pt-wound-media {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  aspect-ratio: 4 / 3;
  padding: 1rem;
  background: var(--bs-tertiary-bg);
  color: var(--bs-secondary-color);
  font-size: 0.875rem;
  text-align: center;
}

.pt-wound-media:has(img) {
  padding: 0;
}

.pt-wound-media {
  position: relative;
  overflow: hidden;
}

/* The photo fills the 4:3 frame (absolute) so its own ratio never stretches the card */
.pt-wound-media img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pt-wound-media .material-symbols-rounded {
  font-size: 2rem;
}

.pt-wound-media.is-failed {
  background: var(--bs-danger-bg-subtle);
  color: var(--bs-danger-text-emphasis);
}

.pt-wound-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.875rem 1rem 1rem;
}

.pt-wound-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

#main-content .patient-view .pt-wound-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
  font-weight: 700;
  color: var(--bs-body-color);
  overflow-wrap: anywhere;
}

.pt-wound-status {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.pt-wound-status::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
}

.pt-wound-status.is-active {
  color: var(--ui-accent-text);
}

.pt-wound-status.is-closed {
  color: var(--bs-secondary-color);
}

.pt-wound-region,
.pt-wound-meta {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

.pt-wound-meta strong {
  color: var(--bs-body-color);
  font-weight: 600;
}

/* Latest note: two lines, the full text in the tooltip */
.pt-wound-note {
  margin: 0;
  font-size: 0.875rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- Evolution --- */
.pt-segmented {
  display: inline-flex;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--ui-field-border);
  border-radius: 0.5rem;
  background: var(--bs-body-bg);
}

.pt-segmented label {
  margin: 0;
  padding: 0.375rem 0.75rem;
  border-inline-start: 1px solid var(--bs-border-color);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  color: var(--bs-body-color);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.pt-segmented .btn-check:first-child + label {
  border-inline-start: 0;
}

.pt-segmented label:hover {
  background: var(--ui-accent-tint);
  color: var(--ui-accent-text);
}

.pt-segmented .btn-check:checked + label {
  background: var(--pt-fill);
  color: #fff;
}

.pt-segmented .btn-check:focus-visible + label {
  outline: 2px solid var(--ui-accent);
  outline-offset: -2px;
}

.pt-chart-custom {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.pt-chart-custom[hidden] {
  display: none;
}

.pt-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.pt-field label {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--bs-secondary-color);
}

#main-content .patient-view .pt-field .form-control {
  border-color: var(--ui-field-border);
}

.pt-chart-surface {
  padding: 1rem;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius, 0.75rem);
}

.patient-view .chart {
  min-height: 300px;
}

.patient-view .chart-canvas {
  box-shadow: none;
}

/* --- Personal data panel --- */
.pt-data {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius, 0.75rem);
}

.pt-data-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0.875rem 1.25rem;
  border-radius: inherit;
  cursor: pointer;
  list-style: none;
}

.pt-data-summary::-webkit-details-marker {
  display: none;
}

.pt-data-chevron {
  color: var(--bs-secondary-color);
  transition: transform 0.2s ease;
}

.pt-data[open] .pt-data-chevron {
  transform: rotate(180deg);
}

.pt-data-body {
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid var(--bs-border-color);
}

.pt-dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem 1.5rem;
  margin: 0;
}

.pt-dl > div {
  min-width: 0;
}

.pt-dl .pt-dl-wide {
  grid-column: 1 / -1;
}

.pt-dl dt {
  margin: 0 0 0.125rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--bs-secondary-color);
}

.pt-dl dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* Informed consent: one more line of the patient identity. Amber while missing, grey once loaded */
.pt-consent {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.5rem;
  width: fit-content;
  max-width: 100%;
}

.pt-consent-icon {
  flex: none;
  font-size: 1.125rem;
  color: var(--ui-accent-text);
}

.pt-consent.is-pending {
  padding: 0.25rem 0.5rem;
  border-radius: 0.5rem;
  background: var(--bs-warning-bg-subtle);
  color: var(--bs-warning-text-emphasis);
}

.pt-consent.is-pending .pt-consent-icon {
  color: inherit;
}

.pt-consent.is-pending .pt-consent-text {
  font-weight: 600;
}

.pt-consent-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

/* Compact controls inside the line */
#main-content .patient-view .pt-consent .btn {
  min-height: 0;
  padding: 0.125rem 0.5rem;
  font-size: 0.875rem;
}

.pt-consent.is-pending .btn.pt-btn-secondary {
  color: var(--bs-warning-text-emphasis);
  border-color: var(--bs-warning-text-emphasis);
}

.pt-subtitle {
  margin: 1.5rem 0 0.75rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--bs-border-color);
  font-size: 1rem;
  font-weight: 700;
}

/* --- States: error, empty, loading --- */
.pt-state,
.pt-chart-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2.5rem 1rem;
  text-align: center;
}

.pt-state {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius, 0.75rem);
}

.pt-state.d-none {
  display: none;
}

.pt-state-inline {
  background: transparent;
  border-style: dashed;
}

.pt-state-icon {
  font-size: 2.5rem;
  color: var(--bs-secondary-color);
}

#woundsError .pt-state-icon {
  color: var(--bs-danger-text-emphasis);
}

#main-content .patient-view .pt-state-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--bs-body-color);
}

.pt-state-body,
.pt-state-hint {
  margin: 0;
  max-width: 44ch;
  color: var(--bs-secondary-color);
}

.pt-state-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.pt-state-actions:empty {
  display: none;
}

.pt-skel {
  background: linear-gradient(
    90deg,
    var(--bs-tertiary-bg) 25%,
    var(--bs-secondary-bg) 50%,
    var(--bs-tertiary-bg) 75%
  );
  background-size: 200% 100%;
  animation: pt-shimmer 1.5s infinite;
  border-radius: 6px;
}

@keyframes pt-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.pt-skel-stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pt-skel-line {
  height: 16px;
  max-width: 100%;
}

.pt-skel-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
}

.pt-skel-btn {
  width: 110px;
  height: 38px;
  border-radius: 0.5rem;
}

.pt-skel-media {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 0;
}

.pt-wound-skel {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius, 0.75rem);
  overflow: hidden;
}

/* --- Phones: compact header, full-width actions --- */
@media (max-width: 575.98px) {
  .pt-header {
    padding: 1rem;
  }

  .pt-avatar,
  .pt-skel-avatar {
    width: 56px;
    height: 56px;
  }

  #main-content .patient-view .pt-name {
    font-size: 1.5rem;
  }

  .pt-actions {
    width: 100%;
  }

  .pt-actions .btn {
    flex: 1 1 calc(50% - 0.25rem);
  }

  .pt-wounds-grid {
    grid-template-columns: 1fr;
  }

  .pt-wound-media {
    aspect-ratio: 16 / 10;
  }

  .patient-view .chart {
    min-height: 240px;
  }

  .pt-segmented {
    width: 100%;
  }
}

/* Touch screens: 44px targets */
@media (pointer: coarse), (max-width: 991.98px) {
  #main-content .patient-view .btn.pt-btn-primary,
  #main-content .patient-view .btn.pt-btn-secondary,
  #main-content .patient-view .btn.pt-btn-quiet,
  #main-content .patient-view .pt-field .form-control,
  #main-content .patient-view .pt-consent .btn {
    min-height: 44px;
  }

  .pt-segmented label {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
}

/* Patient view: breadcrumb links get a 44px hit area without growing the context bar */
body.ui-refined .context-breadcrumb-item a {
  position: relative;
}

body.ui-refined .context-breadcrumb-item a::after {
  content: "";
  position: absolute;
  inset: -14px -8px;
}

@media (prefers-reduced-motion: reduce) {
  .pt-skel {
    animation: none;
  }

  #main-content .patient-view .btn,
  #main-content .patient-view a.pt-wound,
  .pt-data-chevron,
  .pt-segmented label {
    transition: none;
  }

  #main-content .patient-view .btn:active:not(:disabled),
  #main-content .patient-view a.pt-wound:active {
    transform: none;
  }
}

@media (prefers-contrast: more) {
  .pt-header,
  .pt-chart-surface,
  .pt-data,
  .pt-state,
  #main-content .patient-view a.pt-wound,
  .pt-chip {
    border-color: var(--bs-body-color);
  }
}

/* ---------- View: wound ---------- */

/* ===== Wound — shell: narrow context bar =====
   Below 640px the crumbs before the current page are dropped and the back link shrinks to its
   arrow (the label stays available to screen readers), so nothing overlaps the demo badge. */
@media (max-width: 639.98px) {
  body.ui-refined[data-view="wound"] .context-breadcrumb-item:not(.active) {
    display: none;
  }

  body.ui-refined[data-view="wound"] .context-breadcrumb-item.active::before {
    content: none;
  }

  body.ui-refined[data-view="wound"] .context-bar-action-link {
    justify-content: center;
    min-width: 44px;
    min-height: 32px;
  }

  body.ui-refined[data-view="wound"] .context-bar-back-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}


/* ===== Wound — flat page: header, sections, facts ===== */
body.ui-refined .wound-page {
  --wound-surface: var(--bs-body-bg);
  --wound-edge: var(--bs-border-color);
  max-width: 90rem;
}

body.ui-refined .wound-header {
  padding: 1.25rem 1.5rem 1.5rem;
  margin-bottom: 2rem;
  background: var(--wound-surface);
  border: 1px solid var(--wound-edge);
  border-radius: 0.875rem;
}

body.ui-refined .wound-header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

body.ui-refined .wound-header-heading {
  display: flex;
  flex: 1 1 20rem;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  min-width: 0;
}

body.ui-refined .wound-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-align: start !important;
  overflow-wrap: anywhere;
}

body.ui-refined #main-content .wound-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--ui-accent-tint) !important;
  color: var(--ui-accent-text) !important;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  box-shadow: none;
}

body.ui-refined #main-content .wound-status-badge[data-state="closed"] {
  background: var(--bs-secondary-bg) !important;
  border-color: var(--wound-edge);
  color: var(--bs-secondary-color) !important;
}

body.ui-refined .wound-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Primary action: one filled accent button, same on header, sticky bar and empty state */
body.ui-refined .wound-action-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0.5rem 1rem;
  background-color: var(--ui-accent);
  border: 1px solid var(--ui-accent);
  border-radius: 0.625rem;
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease-out;
}

body.ui-refined .wound-action-primary:hover:not(:disabled) {
  background-color: var(--ui-accent-hover);
  border-color: var(--ui-accent-hover);
  color: #ffffff;
}

body.ui-refined .wound-action-primary:active:not(:disabled) {
  background-color: var(--ui-accent-active);
  transform: scale(0.97);
}

body.ui-refined .wound-action-primary:focus-visible,
body.ui-refined .wound-more-btn:focus-visible,
body.ui-refined .wound-section-action:focus-visible,
body.ui-refined .wound-icon-btn:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
}

body.ui-refined .wound-action-primary:disabled {
  background-color: var(--bs-secondary-bg);
  border-color: var(--wound-edge);
  color: var(--bs-secondary-color);
  box-shadow: none;
  opacity: 1;
  cursor: not-allowed;
}

body.ui-refined .wound-action-primary .material-symbols-rounded {
  font-size: 1.25rem;
}

body.ui-refined .wound-more-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--ui-field-border);
  border-radius: 0.625rem;
  color: var(--bs-body-color);
  transition: background-color 0.15s ease, transform 0.1s ease-out;
}

body.ui-refined .wound-more-btn:hover,
body.ui-refined .wound-more-btn[aria-expanded="true"] {
  background-color: var(--ui-accent-tint);
}

body.ui-refined .wound-more-btn:active {
  transform: scale(0.97);
}

body.ui-refined .wound-more-menu .dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
}

body.ui-refined .wound-more-menu .dropdown-item .material-symbols-rounded {
  font-size: 1.25rem;
}

body.ui-refined .wound-closed-banner {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  background: var(--bs-warning-bg-subtle);
  border: 1px solid var(--bs-warning-border-subtle);
  border-radius: 0.625rem;
  color: var(--bs-warning-text-emphasis);
  font-size: 0.9375rem;
}

body.ui-refined .wound-closed-banner.d-none {
  display: none !important;
}

/* Header body: diagram | key facts | zones and notes */
body.ui-refined .wound-header-grid {
  display: grid;
  grid-template-columns: minmax(9rem, 12rem) minmax(17rem, 26rem) minmax(0, 1fr);
  gap: 1.5rem 2rem;
  align-items: start;
  margin-top: 1.25rem;
}

body.ui-refined .wound-diagram #body-diagram-container {
  max-width: 13rem;
  margin: 0 auto;
}

body.ui-refined .wound-diagram svg {
  display: block;
  width: 100%;
  max-height: 17rem;
  height: auto;
}

body.ui-refined .wound-facts {
  margin: 0;
}

body.ui-refined .wound-fact {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--wound-edge);
}

body.ui-refined .wound-fact dt {
  margin: 0;
  white-space: nowrap;
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
  font-weight: 600;
}

body.ui-refined .wound-fact dd {
  margin: 0;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
  text-align: end;
}

body.ui-refined .wound-facts-wide {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  column-gap: 2rem;
}

body.ui-refined .wound-subtitle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.5rem;
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0;
  text-align: start;
}

body.ui-refined .wound-subtitle .material-symbols-rounded {
  font-size: 1.1rem;
}

body.ui-refined .wound-progress {
  margin-top: 1rem;
}

body.ui-refined .wound-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

body.ui-refined .wound-progress-head .wound-subtitle {
  margin: 0;
}

body.ui-refined .wound-icon-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: -0.5rem -0.75rem -0.5rem 0;
  padding: 0;
  color: var(--ui-accent-text);
}

body.ui-refined .wound-progress-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0;
  font-size: 0.9375rem;
}

body.ui-refined .wound-progress-value {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
  text-align: end;
}

body.ui-refined .wound-progress-detail {
  font-size: var(--fs-xs, 0.75rem);
  color: var(--bs-secondary-color);
}

body.ui-refined .wound-areas {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

body.ui-refined #main-content #wound-areas .wound-area-badge,
body.ui-refined #main-content #wound-areas .wound-area-badge:hover {
  margin: 0 !important;
  background: var(--ui-accent-tint) !important;
  border: 1px solid transparent !important;
  color: var(--ui-accent-text) !important;
  font-weight: 600;
  box-shadow: none !important;
}

body.ui-refined .wound-observations {
  margin: 0;
  max-width: 70ch;
  font-size: 0.9375rem;
  line-height: 1.55;
  white-space: pre-line;
}

body.ui-refined .wound-closure {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--wound-edge);
}

body.ui-refined .wound-closure-notes {
  margin: 0.75rem 0 0;
  color: var(--bs-secondary-color);
  white-space: pre-line;
}

body.ui-refined .wound-header-skeleton {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

body.ui-refined .wound-header-skeleton.d-none {
  display: none !important;
}

body.ui-refined .wound-header-skeleton-grid {
  display: grid;
  grid-template-columns: minmax(9rem, 12rem) minmax(17rem, 26rem) minmax(0, 1fr);
  gap: 1.5rem 2rem;
}

/* Sections: title row with a quiet optional action, then the content */
body.ui-refined .wound-section {
  margin-bottom: 2.5rem;
}

body.ui-refined .wound-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

body.ui-refined .wound-section-title {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

body.ui-refined .wound-section-body {
  padding: 1rem 1.25rem 1.25rem;
  background: var(--wound-surface);
  border: 1px solid var(--wound-edge);
  border-radius: 0.875rem;
}

body.ui-refined .wound-section-action {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0.25rem 0.75rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0.625rem;
  color: var(--ui-accent-text);
  font-weight: 600;
  transition: background-color 0.15s ease, transform 0.1s ease-out;
}

body.ui-refined .wound-section-action:hover {
  background: var(--ui-accent-tint);
}

body.ui-refined .wound-section-action:active {
  transform: scale(0.97);
}

body.ui-refined .wound-section-action.d-none {
  display: none !important;
}

/* No assessments yet: one empty state, no charts */
body.ui-refined .wound-page:not(.wound-has-evaluations) #wound-charts {
  display: none;
}

/* Compact bar: translucent material under the navbar and context bar */
body.ui-refined .wound-sticky-wrap {
  position: sticky;
  top: var(--ui-sticky-top);
  z-index: 20;
  height: 0;
}

body.ui-refined .wound-sticky-bar {
  position: absolute;
  inset-inline: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background-color: color-mix(in srgb, var(--bs-body-bg) 78%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--wound-edge);
  opacity: 0;
  transform: translateY(-0.5rem);
  pointer-events: none;
  transition: opacity 0.15s ease-out, transform 0.15s ease-out;
}

body.ui-refined .wound-sticky-bar.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

body.ui-refined .wound-sticky-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.ui-refined .wound-sticky-progress {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
  font-weight: 600;
}

body.ui-refined .wound-sticky-bar .wound-action-primary {
  min-height: 36px;
  padding: 0.25rem 0.85rem;
}

@media (max-width: 991.98px) {
  body.ui-refined .wound-header-grid,
  body.ui-refined .wound-header-skeleton-grid {
    grid-template-columns: minmax(9rem, 13rem) minmax(0, 1fr);
  }

  body.ui-refined .wound-notes {
    grid-column: 1 / -1;
  }
}

@media (max-width: 575.98px) {
  body.ui-refined .wound-header {
    padding: 1rem;
  }

  body.ui-refined .wound-title {
    font-size: 1.5rem;
  }

  body.ui-refined .wound-header-grid,
  body.ui-refined .wound-header-skeleton-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  body.ui-refined .wound-header-actions {
    width: 100%;
  }

  body.ui-refined .wound-header-actions .wound-action-primary {
    flex: 1 1 auto;
  }

  body.ui-refined .wound-section-body {
    padding: 0.75rem;
  }

  body.ui-refined #wound-sticky-status,
  body.ui-refined .wound-sticky-progress {
    display: none;
  }

  body.ui-refined .wound-sticky-bar .wound-action-primary span {
    display: none;
  }

  body.ui-refined .wound-sticky-bar .wound-action-primary {
    min-width: 44px;
    min-height: 44px;
    padding: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.ui-refined .wound-action-primary,
  body.ui-refined .wound-more-btn,
  body.ui-refined .wound-section-action,
  body.ui-refined .wound-sticky-bar {
    transition: none;
  }

  body.ui-refined .wound-action-primary:active:not(:disabled),
  body.ui-refined .wound-more-btn:active,
  body.ui-refined .wound-section-action:active {
    transform: none;
  }

  body.ui-refined .wound-sticky-bar {
    transform: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  body.ui-refined .wound-sticky-bar {
    background-color: var(--bs-body-bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  body.ui-refined .wound-header,
  body.ui-refined .wound-section-body {
    border-color: var(--bs-body-color);
  }

  body.ui-refined .wound-sticky-bar {
    border-bottom: 2px solid var(--bs-body-color);
  }
}

/* ===== Wound — charts: shared period filter, fixed-height charts, text alternatives ===== */
body.ui-refined .wound-chart-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}

body.ui-refined .wound-chart-filter-label {
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
  font-weight: 600;
}

/* Segmented control: the radios are visually hidden and each label is a 44px segment */
body.ui-refined .wound-segmented {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--ui-field-border);
  border-radius: 0.625rem;
  overflow: hidden;
}

body.ui-refined .wound-segmented-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

body.ui-refined .wound-segmented label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin: 0;
  padding: 0.25rem 0.9rem;
  border-inline-start: 1px solid var(--ui-field-border);
  color: var(--bs-body-color);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.12s ease-out, transform 0.1s ease-out;
}

body.ui-refined .wound-segmented label:first-of-type {
  border-inline-start: 0;
}

body.ui-refined .wound-segmented label:hover {
  background: var(--ui-accent-tint);
}

body.ui-refined .wound-segmented label:active {
  transform: scale(0.97);
}

body.ui-refined .wound-segmented-input:checked + label {
  background: var(--ui-accent);
  color: #ffffff;
  font-weight: 600;
}

body.ui-refined .wound-segmented-input:focus-visible + label {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: -3px;
}

body.ui-refined .wound-chart-custom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

body.ui-refined .wound-chart-custom.d-none {
  display: none !important;
}

body.ui-refined .wound-chart-custom label {
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
  font-weight: 600;
}

body.ui-refined .wound-chart-custom .form-control {
  width: auto;
  min-height: 44px;
  border-color: var(--ui-field-border);
}

/* Three charts: area, perimeter and tissues */
body.ui-refined .wound-charts-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.5rem;
}

@media (max-width: 1199.98px) {
  /* Two columns: the tissues chart, the widest, takes the last row */
  body.ui-refined .wound-charts-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.ui-refined .wound-charts-grid > .wound-chart:last-child {
    grid-column: 1 / -1;
  }
}

body.ui-refined .wound-chart {
  min-width: 0;
  margin: 0;
}

body.ui-refined .wound-chart-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: start;
}

/* Fixed height: the chart no longer stretches to the height of a neighbouring column */
body.ui-refined .wound-chart-canvas {
  position: relative;
  height: 18rem;
}

body.ui-refined .wound-chart-canvas.d-none {
  display: none !important;
}

body.ui-refined .wound-chart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-height: 12rem;
  color: var(--bs-secondary-color);
  text-align: center;
}

body.ui-refined .wound-chart-empty.d-none {
  display: none !important;
}

body.ui-refined .charts-reset-range {
  min-height: 44px;
  color: var(--ui-accent-text);
  font-weight: 600;
}

body.ui-refined .wound-chart-data {
  margin-top: 0.75rem;
}

body.ui-refined .wound-chart-data.d-none {
  display: none !important;
}

body.ui-refined .wound-chart-data summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--ui-accent-text);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

body.ui-refined .wound-chart-data summary:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
}

body.ui-refined .wound-data-table {
  width: 100%;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  border-collapse: collapse;
}

body.ui-refined .wound-data-table th,
body.ui-refined .wound-data-table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--wound-edge);
  text-align: end;
  white-space: nowrap;
}

body.ui-refined .wound-data-table th:first-child {
  text-align: start;
  font-weight: 500;
}

body.ui-refined .wound-data-table thead th {
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
  font-weight: 600;
}

@media (max-width: 991.98px) {
  body.ui-refined .wound-charts-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 575.98px) {
  body.ui-refined .wound-chart-canvas {
    height: 14rem;
  }

  body.ui-refined .wound-segmented {
    width: 100%;
  }

  body.ui-refined .wound-segmented label {
    flex: 1 1 auto;
    padding-inline: 0.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.ui-refined .wound-segmented label {
    transition: none;
  }

  body.ui-refined .wound-segmented label:active {
    transform: none;
  }
}

@media (prefers-contrast: more) {
  body.ui-refined .wound-segmented,
  body.ui-refined .wound-segmented label {
    border-color: var(--bs-body-color);
  }
}

/* ===== Wound — evaluations: strip, reference bar, summary, panels and table ===== */
body.ui-refined .eval-workspace {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Strip of assessments: photo, date, area and tendency; newest first */
body.ui-refined .eval-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

body.ui-refined .timeline-nav-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

body.ui-refined .timeline-nav {
  display: flex;
  flex: 1 1 auto;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.375rem 0.25rem;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}

body.ui-refined .eval-chip {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  width: 6.5rem;
  background: transparent;
  border: 1px solid var(--ui-field-border);
  border-radius: 0.75rem;
  color: var(--bs-body-color);
  line-height: 1.2;
  scroll-snap-align: center;
  transition: background-color 0.12s ease-out;
}

body.ui-refined .eval-chip:hover:not(.active) {
  background: var(--ui-accent-tint);
}

/* Selected: solid accent. Reference: dashed accent, like its line in the charts */
body.ui-refined .eval-chip.active {
  background: var(--ui-accent-tint);
  border-color: var(--ui-accent);
  box-shadow: inset 0 0 0 1px var(--ui-accent);
}

body.ui-refined .eval-chip.is-reference {
  border-color: var(--ui-accent);
  border-style: dashed;
  border-width: 2px;
}

body.ui-refined .eval-chip-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.125rem;
  width: 100%;
  padding: 0.375rem 0.375rem 0.125rem;
  background: transparent;
  border: 0;
  border-radius: 0.65rem 0.65rem 0 0;
  color: inherit;
  font: inherit;
  line-height: inherit;
  text-align: center;
  cursor: pointer;
}

body.ui-refined .eval-chip-main:active {
  transform: scale(0.97);
}

body.ui-refined .eval-chip-role {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-height: 2rem;
  padding: 0 0.25rem 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
}

body.ui-refined .eval-chip-role .material-symbols-rounded {
  font-size: 0.95rem;
}

body.ui-refined .eval-chip-role--selected,
body.ui-refined .eval-chip-role--reference {
  color: var(--ui-accent-text);
}

body.ui-refined .eval-chip-compare {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  min-height: 2rem;
  padding: 0 0.6rem;
  background: transparent;
  border: 1px solid var(--ui-field-border);
  border-radius: 999px;
  color: var(--bs-body-color);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  transition: background-color 0.12s ease-out, transform 0.1s ease-out;
}

body.ui-refined .eval-chip-compare .material-symbols-rounded {
  font-size: 0.95rem;
}

body.ui-refined .eval-chip-compare:hover {
  background: var(--ui-accent-tint);
  border-color: var(--ui-accent);
}

body.ui-refined .eval-chip-compare:active {
  transform: scale(0.97);
}

/* Touch screens: the compare button is a full 44px target */
@media (pointer: coarse) {
  body.ui-refined .eval-chip-compare {
    min-height: 44px;
    padding: 0 0.85rem;
  }

  body.ui-refined .eval-chip-role {
    min-height: 44px;
  }
}

body.ui-refined .eval-chip-thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  margin-bottom: 0.2rem;
  overflow: hidden;
  background: var(--bs-tertiary-bg);
  border-radius: 0.5rem;
}

body.ui-refined .eval-chip-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

body.ui-refined .eval-chip-latest {
  position: absolute;
  inset-block-start: 0.25rem;
  inset-inline-start: 0.25rem;
  padding: 0.05rem 0.4rem;
  background: var(--ui-accent);
  border-radius: 999px;
  color: #ffffff;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.3;
}

body.ui-refined .timeline-chip-date {
  font-size: 0.875rem;
  font-weight: 600;
}

body.ui-refined .timeline-chip-time {
  color: var(--bs-secondary-color);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

body.ui-refined .eval-chip-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0 0.3rem;
  min-height: 1.1rem;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

body.ui-refined .eval-chip-area {
  font-weight: 600;
}

body.ui-refined .eval-chip-meta--busy {
  color: var(--bs-secondary-color);
}

body.ui-refined .eval-chip-meta--failed {
  color: #b02a37;
  font-weight: 600;
}

body.ui-refined .eval-chip-trend {
  display: inline-flex;
  align-items: center;
  font-weight: 600;
}

body.ui-refined .eval-chip-trend .material-symbols-rounded {
  font-size: 0.95rem;
}

body.ui-refined .eval-chip-trend--improve {
  color: #157347;
}

body.ui-refined .eval-chip-trend--worse {
  color: #b02a37;
}

body.ui-refined .eval-chip-trend--same {
  color: var(--bs-secondary-color);
}

body.ui-refined .timeline-nav-arrow {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--ui-field-border);
  border-radius: 50%;
  color: var(--bs-body-color);
  transition: background-color 0.12s ease-out, transform 0.1s ease-out;
}

body.ui-refined .timeline-nav-arrow:hover:not(:disabled) {
  background: var(--ui-accent-tint);
}

body.ui-refined .timeline-nav-arrow:active:not(:disabled) {
  transform: scale(0.97);
}

body.ui-refined .timeline-nav-arrow:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* The arrows point along the reading direction */
html[dir="rtl"] body.ui-refined .timeline-nav-arrow .material-symbols-rounded {
  transform: scaleX(-1);
}

/* Position counter and "compare with" */
body.ui-refined .eval-subbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
}

body.ui-refined .timeline-position {
  margin: 0;
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
}

body.ui-refined .eval-reference-bar {
  display: flex;
  flex: 0 1 32rem;
  align-items: flex-end;
  gap: 0.5rem;
  min-width: 0;
  margin-inline-start: auto;
}

body.ui-refined .eval-reference-bar.d-none {
  display: none !important;
}

body.ui-refined .eval-reference-field {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

body.ui-refined .eval-reference-field label {
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
  font-weight: 600;
}

body.ui-refined .eval-reference-swap {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--ui-field-border);
  border-radius: 50%;
  color: var(--bs-body-color);
  transition: background-color 0.12s ease-out, transform 0.1s ease-out;
}

body.ui-refined .eval-reference-swap:hover:not(:disabled) {
  background: var(--ui-accent-tint);
}

body.ui-refined .eval-reference-swap:active:not(:disabled) {
  transform: scale(0.97);
}

body.ui-refined .eval-reference-swap:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

body.ui-refined .eval-reference-field .form-select {
  min-height: 44px;
  border-color: var(--ui-field-border);
}

/* Summary of the change */
body.ui-refined .eval-summary {
  padding: 1rem 1.25rem;
  background: var(--bs-secondary-bg);
  border: 1px solid var(--wound-edge);
  border-radius: 0.875rem;
}

body.ui-refined .eval-summary:empty {
  display: none;
}

body.ui-refined .eval-summary-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  margin-bottom: 0.5rem;
}

body.ui-refined .eval-summary-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

body.ui-refined .eval-summary-range {
  margin: 0;
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
}

body.ui-refined .eval-summary-rate {
  margin: 0.5rem 0 0;
  color: var(--bs-secondary-color);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

body.ui-refined .eval-summary-note {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0;
  color: var(--bs-secondary-color);
}

body.ui-refined .eval-summary-note .material-symbols-rounded {
  flex: 0 0 auto;
  font-size: 1.25rem;
}

body.ui-refined .comparison-line {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  margin: 0 0 0.35rem;
  font-size: 0.9375rem;
}

body.ui-refined .comparison-line .material-symbols-rounded {
  flex: 0 0 auto;
  font-size: 1.1rem;
}

body.ui-refined .comparison-overall {
  margin: 0 0 0.6rem;
  padding-inline-start: 0.75rem;
  border-inline-start: 3px solid currentColor;
  font-size: 0.9375rem;
  font-weight: 600;
}

body.ui-refined .comparison-delta--improve,
body.ui-refined .comparison-line--improve,
body.ui-refined .comparison-overall--improve {
  color: #157347;
}

body.ui-refined .comparison-delta--worse,
body.ui-refined .comparison-line--worse,
body.ui-refined .comparison-overall--worse {
  color: #b02a37;
}

body.ui-refined .comparison-delta--same,
body.ui-refined .comparison-delta--na,
body.ui-refined .comparison-line--same,
body.ui-refined .comparison-overall--same,
body.ui-refined .comparison-overall--mixed {
  color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] body.ui-refined .comparison-delta--improve,
[data-bs-theme="dark"] body.ui-refined .comparison-line--improve,
[data-bs-theme="dark"] body.ui-refined .comparison-overall--improve,
[data-bs-theme="dark"] body.ui-refined .eval-chip-trend--improve,
body.ui-refined[data-bs-theme="dark"] .comparison-delta--improve,
body.ui-refined[data-bs-theme="dark"] .comparison-line--improve,
body.ui-refined[data-bs-theme="dark"] .comparison-overall--improve,
body.ui-refined[data-bs-theme="dark"] .eval-chip-trend--improve {
  color: #75b798;
}

[data-bs-theme="dark"] body.ui-refined .comparison-delta--worse,
[data-bs-theme="dark"] body.ui-refined .comparison-line--worse,
[data-bs-theme="dark"] body.ui-refined .comparison-overall--worse,
[data-bs-theme="dark"] body.ui-refined .eval-chip-trend--worse,
[data-bs-theme="dark"] body.ui-refined .eval-chip-meta--failed,
body.ui-refined[data-bs-theme="dark"] .comparison-delta--worse,
body.ui-refined[data-bs-theme="dark"] .comparison-line--worse,
body.ui-refined[data-bs-theme="dark"] .comparison-overall--worse,
body.ui-refined[data-bs-theme="dark"] .eval-chip-trend--worse,
body.ui-refined[data-bs-theme="dark"] .eval-chip-meta--failed {
  color: #ea868f;
}

/* Panels: reference | selected */
body.ui-refined .eval-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
  align-items: stretch;
}

body.ui-refined .eval-panels--single {
  grid-template-columns: minmax(0, 1fr);
  max-width: 40rem;
  margin-inline: auto;
}

body.ui-refined .eval-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
  padding: 1rem;
  background: var(--bs-body-bg);
  border: 1px solid var(--wound-edge);
  border-radius: 0.875rem;
}

body.ui-refined .eval-panel--selected {
  border-color: var(--ui-accent);
}

body.ui-refined .eval-panel-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

body.ui-refined .eval-panel-heading {
  flex: 1 1 auto;
  min-width: 0;
}

body.ui-refined .eval-panel-kicker {
  margin: 0;
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
  font-weight: 600;
}

body.ui-refined .evaluation-card-date {
  margin: 0;
  color: var(--bs-body-color) !important;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

body.ui-refined .evaluation-card-date * {
  color: inherit !important;
}

body.ui-refined .evaluation-card-latest {
  flex: 0 0 auto;
  padding: 0.2rem 0.6rem;
  background: var(--ui-accent-tint);
  border-radius: 999px;
  color: var(--ui-accent-text);
  font-size: 0.75rem;
  font-weight: 600;
}

body.ui-refined .eval-panel-menu {
  flex: 0 0 auto;
}

body.ui-refined .eval-menu-danger,
body.ui-refined .eval-menu-danger:hover,
body.ui-refined .eval-menu-danger:focus {
  color: #b42318;
}

[data-bs-theme="dark"] body.ui-refined .eval-menu-danger,
body.ui-refined[data-bs-theme="dark"] .eval-menu-danger {
  color: #ff8a80;
}

body.ui-refined .eval-panel-media {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

body.ui-refined .eval-panel-caption {
  margin: 0;
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
  text-align: center;
}

/* Original / AI segmentation toggle */
body.ui-refined .comparison-view-toggle {
  display: inline-flex;
  align-self: flex-start;
  border: 1px solid var(--ui-field-border);
  border-radius: 0.625rem;
  overflow: hidden;
}

body.ui-refined .comparison-view-toggle button {
  min-height: 44px;
  padding: 0.25rem 0.9rem;
  background: transparent;
  border: 0;
  border-inline-start: 1px solid var(--ui-field-border);
  color: var(--bs-body-color);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background-color 0.12s ease-out;
}

body.ui-refined .comparison-view-toggle button:first-child {
  border-inline-start: 0;
}

body.ui-refined .comparison-view-toggle button[aria-pressed="true"] {
  background: var(--ui-accent);
  color: #ffffff;
  font-weight: 600;
}

/* Photos: reserved square (no layout jump while loading), tap to open in the viewer */
body.ui-refined .eval-panel .evaluation-card-photo {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(32rem, 70vh);
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: var(--bs-tertiary-bg);
  border-radius: 0.75rem;
  box-shadow: none;
  cursor: zoom-in;
  transition: opacity 0.15s ease-out;
}

body.ui-refined .eval-panel .evaluation-photo-frame {
  min-height: 0;
}

/* Observations: clamped, expandable; they take the free room so both cards end together */
body.ui-refined .eval-panel-notes {
  flex: 1 1 auto;
}

body.ui-refined .eval-panel-notes .wound-subtitle {
  margin-bottom: 0.25rem;
}

body.ui-refined .evaluation-card-notes {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

body.ui-refined .evaluation-card-notes.is-clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}

body.ui-refined .evaluation-notes-toggle {
  min-height: 44px;
  padding: 0.25rem 0;
  color: var(--ui-accent-text);
  font-weight: 600;
  text-decoration: none;
}

body.ui-refined .evaluation-notes-toggle:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
}

body.ui-refined .evaluation-notes-toggle.d-none {
  display: none !important;
}

/* Photo viewer: pop-up with zoom and pan (built by openPhotoViewer) */
body.ui-refined .eval-viewer {
  width: min(96vw, 1280px);
  max-width: none;
  height: min(92vh, 920px);
  max-height: none;
  padding: 0;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 0.875rem;
  color: var(--bs-body-color);
  overflow: hidden;
}

body.ui-refined .eval-viewer[open] {
  display: flex;
  flex-direction: column;
}

body.ui-refined .eval-viewer::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

body.ui-refined .eval-viewer-bar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem 0.5rem 1rem;
  border-bottom: 1px solid var(--bs-border-color);
}

body.ui-refined .eval-viewer-title {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.ui-refined .eval-viewer-tools {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.25rem;
}

body.ui-refined .eval-viewer-tools button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--ui-field-border);
  border-radius: 0.625rem;
  color: var(--bs-body-color);
  transition: background-color 0.12s ease-out, transform 0.1s ease-out;
}

body.ui-refined .eval-viewer-tools button:hover:not(:disabled) {
  background: var(--ui-accent-tint);
}

body.ui-refined .eval-viewer-tools button:active:not(:disabled) {
  transform: scale(0.97);
}

body.ui-refined .eval-viewer-tools button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

body.ui-refined .eval-viewer-tools button:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
}

body.ui-refined .eval-viewer-level {
  min-width: 3.5rem;
  color: var(--bs-secondary-color);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

body.ui-refined .eval-viewer-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #111315;
  cursor: zoom-in;
  touch-action: none;
}

body.ui-refined .eval-viewer-stage.is-zoomed {
  cursor: grab;
}

body.ui-refined .eval-viewer-stage.is-dragging.is-zoomed {
  cursor: grabbing;
}

body.ui-refined .eval-viewer-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}

body.ui-refined .eval-viewer-hint {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.4rem 1rem;
  border-top: 1px solid var(--bs-border-color);
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
  text-align: center;
}

@media (max-width: 575.98px) {
  body.ui-refined .eval-viewer {
    width: 100vw;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  body.ui-refined .eval-viewer-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.ui-refined .eval-viewer-tools button {
    transition: none;
  }

  body.ui-refined .eval-viewer-tools button:active:not(:disabled) {
    transform: none;
  }
}

@media (prefers-contrast: more) {
  body.ui-refined .eval-viewer {
    border-color: var(--bs-body-color);
  }
}

/* Narrow screens: the two panels alternate in the same place, so the photo does not move */
body.ui-refined .eval-view-switch {
  display: none;
}

body.ui-refined .eval-view-switch button {
  min-height: 44px;
  padding: 0.25rem 1.1rem;
  background: transparent;
  border: 0;
  border-inline-start: 1px solid var(--ui-field-border);
  color: var(--bs-body-color);
  font-size: 0.9375rem;
  font-weight: 500;
}

body.ui-refined .eval-view-switch button:first-child {
  border-inline-start: 0;
}

body.ui-refined .eval-view-switch button[aria-pressed="true"] {
  background: var(--ui-accent);
  color: #ffffff;
  font-weight: 600;
}

@media (max-width: 991.98px) {
  body.ui-refined .eval-view-switch:not(.d-none) {
    display: inline-flex;
    align-self: flex-start;
    border: 1px solid var(--ui-field-border);
    border-radius: 0.625rem;
    overflow: hidden;
  }

  body.ui-refined .eval-panels {
    grid-template-columns: minmax(0, 1fr);
  }

  body.ui-refined .eval-panels[data-narrow-view="reference"] .eval-panel--selected,
  body.ui-refined .eval-panels[data-narrow-view="selected"] .eval-panel--reference {
    display: none;
  }

  body.ui-refined .eval-reference-bar {
    flex: 1 1 100%;
    margin-inline-start: 0;
  }

  body.ui-refined .eval-reference-field {
    flex: 1 1 12rem;
  }
}

/* Metrics table */
body.ui-refined .eval-table-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

body.ui-refined .evaluation-metrics {
  width: 100%;
}

body.ui-refined .evaluation-metrics thead th {
  padding: 0.5rem 0.75rem;
  color: var(--bs-secondary-color) !important;
  font-size: 0.8125rem !important;
  font-weight: 600 !important;
  letter-spacing: 0 !important;
  opacity: 1 !important;
  text-transform: none !important;
  vertical-align: bottom;
}

body.ui-refined .eval-th-date {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

body.ui-refined .evaluation-metrics tbody th,
body.ui-refined .evaluation-metrics tbody td {
  padding: 0.65rem 0.75rem;
  background: transparent;
  border-bottom: 1px solid var(--wound-edge);
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
}

body.ui-refined .eval-table-wrap {
  overflow-x: auto;
  overflow-y: hidden;
}

body.ui-refined .evaluation-metrics tbody th {
  letter-spacing: 0;
  text-align: start;
  text-transform: none;
}

body.ui-refined .evaluation-metrics tbody th,
body.ui-refined .evaluation-metrics tbody td {
  color: var(--bs-body-color) !important;
}

body.ui-refined .eval-metric-name {
  display: block;
  color: var(--bs-body-color) !important;
  font-weight: 600;
}

body.ui-refined .eval-metric-hint {
  display: block;
  color: var(--bs-secondary-color) !important;
  font-size: 0.75rem;
  font-weight: 400;
}

body.ui-refined .comparison-delta {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.15rem 0.35rem;
  font-weight: 600;
}

body.ui-refined .comparison-delta .material-symbols-rounded {
  align-self: center;
  font-size: 1.1rem;
}

body.ui-refined .comparison-delta-verdict {
  font-size: 0.8125rem;
  font-weight: 600;
}

body.ui-refined .eval-legend {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0;
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
}

body.ui-refined .eval-legend .material-symbols-rounded {
  flex: 0 0 auto;
  font-size: 1.1rem;
}

@media (max-width: 767.98px) {
  /* Stacked: each metric is a block, each value is labelled (data-label from the header) */
  body.ui-refined .evaluation-metrics thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  body.ui-refined .evaluation-metrics,
  body.ui-refined .evaluation-metrics tbody,
  body.ui-refined .evaluation-metrics tr,
  body.ui-refined .evaluation-metrics tbody th,
  body.ui-refined .evaluation-metrics tbody td {
    display: block;
    width: 100%;
  }

  body.ui-refined .evaluation-metrics tr {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--wound-edge);
  }

  body.ui-refined .evaluation-metrics tbody th,
  body.ui-refined .evaluation-metrics tbody td {
    padding: 0.1rem 0;
    border: 0;
    text-align: start;
  }

  body.ui-refined .evaluation-metrics tbody td[data-label] {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
  }

  body.ui-refined .evaluation-metrics tbody td[data-label]::before {
    content: attr(data-label);
    color: var(--bs-secondary-color);
    font-size: 0.8125rem;
    font-weight: 600;
  }
}

@media (max-width: 575.98px) {
  body.ui-refined .timeline-nav-container {
    gap: 0.25rem;
  }

  body.ui-refined .eval-chip {
    width: 5.75rem;
  }

  body.ui-refined .eval-panel {
    padding: 0.75rem;
  }

  body.ui-refined .eval-summary {
    padding: 0.75rem 1rem;
  }
}

/* Charts: which dates are marked, and what to do about it */
body.ui-refined .wound-chart-hint {
  margin: 0 0 0.75rem;
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
}

body.ui-refined .wound-chart-note {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--bs-warning-bg-subtle);
  border: 1px solid var(--bs-warning-border-subtle);
  border-radius: 0.5rem;
  color: var(--bs-warning-text-emphasis);
  font-size: 0.875rem;
}

body.ui-refined .wound-chart-note.d-none {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  body.ui-refined .eval-chip,
  body.ui-refined .eval-chip-compare,
  body.ui-refined .eval-reference-swap,
  body.ui-refined .timeline-nav-arrow,
  body.ui-refined .eval-panel .evaluation-card-photo,
  body.ui-refined .comparison-view-toggle button {
    transition: none;
  }

  body.ui-refined .eval-chip-main:active,
  body.ui-refined .eval-chip-compare:active,
  body.ui-refined .eval-reference-swap:active:not(:disabled),
  body.ui-refined .timeline-nav-arrow:active:not(:disabled) {
    transform: none;
  }
}

@media (prefers-contrast: more) {
  body.ui-refined .eval-chip,
  body.ui-refined .eval-panel,
  body.ui-refined .eval-summary {
    border-color: var(--bs-body-color);
  }
}

/* ===== Wound — dark theme: accent fill that carries white text at >= 4.5:1 =====
   In dark mode the shared --ui-accent resolves to #138496 (white on it: 4.4:1). On this view the
   filled accent uses the brand dark teal instead (white on it: 5.85:1). The shared tokens are untouched. */
[data-bs-theme="dark"] body.ui-refined[data-view="wound"] {
  --ui-accent: #0f6f7d;
  --ui-accent-hover: #0c5d6a;
  --ui-accent-active: #094b55;
}

body.ui-refined .wound-action-primary,
body.ui-refined .wound-action-primary:hover:not(:disabled) {
  color: #ffffff !important;
}

body.ui-refined .wound-action-primary:disabled {
  color: var(--bs-secondary-color) !important;
}

/* ===== Wound — RTL: rtl.css resets every .btn background (`[dir="rtl"] .btn { background-color:
   inherit !important }`); the filled accent buttons of this view restore theirs. The shared rule
   is left as is and reported in the playbook. ===== */
html[dir="rtl"] body.ui-refined .wound-action-primary,
html[dir="rtl"] body.ui-refined .wound-action-primary:hover:not(:disabled),
html[dir="rtl"] body.ui-refined .wound-action-primary:active:not(:disabled) {
  background-color: var(--ui-accent-active) !important;
}

html[dir="rtl"] body.ui-refined .wound-action-primary:disabled {
  background-color: var(--bs-secondary-bg) !important;
}

/* Long observations: clamped to 4 lines, expandable */
body.ui-refined .wound-observations {
  overflow-wrap: anywhere;
}

body.ui-refined .wound-observations.is-clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  overflow: hidden;
}

body.ui-refined .wound-observations-toggle {
  min-height: 44px;
  padding: 0.25rem 0;
  color: var(--ui-accent-text);
  font-weight: 600;
  text-decoration: none;
}

body.ui-refined .wound-observations-toggle:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
}

body.ui-refined .wound-observations-toggle.d-none {
  display: none !important;
}

/* ---------- View: profile ---------- */

/* Flat page: a summary of who I am, the editable data and the security row, each on a surface
   that uses the body background and the theme border (same language as the patient views).
   Every rule is scoped to .profile-view. Controls carry #main-content to win over the legacy
   globals of unified-styles.css. */
.profile-view {
  --pf-fill: var(--ui-accent);
  --pf-fill-hover: var(--ui-accent-hover);
  --pf-fill-active: var(--ui-accent-active);
  max-width: 62rem;
  margin-inline: auto;
}

/* White text needs 4.5:1: in dark mode the brand teal is lighter, so the fill steps one tone down */
[data-bs-theme="dark"] .profile-view {
  --pf-fill: var(--ui-accent-active);
  --pf-fill-hover: var(--ui-accent-hover);
  --pf-fill-active: var(--ui-accent);
}

#main-content .profile-view .pf-page-title {
  margin: 0.5rem 0 1rem;
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--bs-body-color);
}

#profileContent,
#profileSkeleton {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

#profileContent.d-none,
#profileSkeleton.d-none {
  display: none;
}

/* Room for the save bar so it never covers the last section */
.profile-view.has-savebar {
  padding-bottom: 6rem !important;
}

/* --- Identity summary (read-only) --- */
.pf-identity,
.pf-section {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius, 0.75rem);
  padding: 1.25rem 1.5rem;
}

.pf-identity {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.pf-photo {
  position: relative;
  flex: 0 0 auto;
  width: 112px;
  height: 112px;
}

.pf-photo-img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--bs-border-color);
  background: var(--bs-tertiary-bg);
}

/* The camera button sits on the corner of the photo with a 44px touch target */
#main-content .profile-view .pf-photo-btn {
  position: absolute;
  inset-block-end: -4px;
  inset-inline-end: -4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 3px solid var(--bs-body-bg);
  border-radius: 50%;
  background-color: var(--pf-fill);
  color: #fff;
  box-shadow: none;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

#main-content .profile-view .pf-photo-btn .material-symbols-rounded {
  font-size: 1.25rem;
  line-height: 1;
}

#main-content .profile-view .pf-photo-btn:hover {
  background-color: var(--pf-fill-hover);
  color: #fff;
}

#main-content .profile-view .pf-photo-btn:active {
  background-color: var(--pf-fill-active);
  transform: scale(0.95);
}

.pf-identity-text {
  flex: 1 1 auto;
  min-width: 0;
}

#main-content .profile-view .pf-name {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-weight: 700;
  color: var(--bs-body-color);
  overflow-wrap: anywhere;
}

.pf-name:focus {
  outline: none;
}

.pf-headline {
  margin: 0.125rem 0 0;
  color: var(--bs-secondary-color);
  overflow-wrap: anywhere;
}

.pf-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem 1.5rem;
  margin: 1rem 0 0;
}

.pf-fact {
  min-width: 0;
}

.pf-fact dt {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--bs-secondary-color);
}

.pf-fact dd {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--bs-body-color);
  overflow-wrap: anywhere;
}

/* --- Sections --- */
#main-content .profile-view .pf-section-title {
  margin: 0 0 1rem;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--bs-body-color);
}

.pf-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.25rem;
}

.pf-span-2 {
  grid-column: 1 / -1;
}

.pf-field {
  min-width: 0;
}

/* Fields: a visible edge in both themes and the brand focus ring */
#main-content .profile-view .form-label {
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--bs-body-color);
}

#main-content .profile-view .pf-optional {
  font-weight: 400;
  color: var(--bs-secondary-color);
}

#main-content .profile-view .form-control,
#main-content .profile-view .phone-input-group .phone-country-toggle {
  min-height: 42px;
  border: 1px solid var(--ui-field-border);
}

#main-content .profile-view .form-control:focus,
#main-content .profile-view .phone-input-group .phone-country-toggle:focus-visible {
  border-color: var(--ui-accent-text);
  box-shadow: 0 0 0 0.2rem var(--ui-accent-tint);
  outline: none;
}

/* The shared phone selector paints its toggle with fixed colors and !important: restore the
   field edge and the brand focus for this view only */
#main-content .profile-view .phone-input-group .phone-country-toggle.btn-outline-secondary {
  border-color: var(--ui-field-border) !important;
}

#main-content .profile-view .phone-input-group .phone-country-toggle.btn-outline-secondary:hover,
#main-content .profile-view .phone-input-group .phone-country-toggle.btn-outline-secondary:focus,
#main-content .profile-view .phone-input-group .phone-country-toggle.btn-outline-secondary.show {
  border-color: var(--ui-accent-text) !important;
}

#main-content .profile-view .phone-input-group .phone-country-toggle.btn-outline-secondary:focus {
  box-shadow: 0 0 0 0.2rem var(--ui-accent-tint);
}

/* The error message carries its own icon, so the Bootstrap icon inside the field is dropped
   (it crowded the date picker and the phone number) */
#main-content .profile-view .form-control.is-invalid {
  border-color: var(--bs-form-invalid-border-color);
  background-image: none;
  padding-inline-end: 0.75rem;
}

#main-content .profile-view .form-control.is-invalid:focus {
  box-shadow: 0 0 0 0.2rem rgba(var(--bs-danger-rgb), 0.25);
}

/* Inline errors: icon + text, never color alone */
#main-content .profile-view .invalid-feedback {
  display: flex;
  align-items: flex-start;
  gap: 0.25rem;
  margin-top: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--bs-danger-text-emphasis);
}

#main-content .profile-view .invalid-feedback::before {
  content: "error";
  flex: 0 0 auto;
  font-family: "Material Symbols Rounded";
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.2;
}

.pf-help {
  display: block;
  margin: 0.375rem 0 0;
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

.pf-field .invalid-feedback + .pf-help {
  margin-top: 0.25rem;
}

/* The phone number reads left to right in every language */
.profile-view .phone-input-group,
.profile-view .pf-field input[type="date"] {
  direction: ltr;
}

[dir="rtl"] #main-content .profile-view .form-label {
  color: var(--bs-body-color) !important; /* rtl.css paints form labels white */
}

[dir="rtl"] .profile-view .pf-field input[type="date"] {
  text-align: right;
}

/* --- Security row --- */
.pf-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  flex-wrap: wrap;
}

.pf-row-text {
  flex: 1 1 18rem;
  min-width: 0;
}

.pf-row-title {
  margin: 0;
  font-weight: 600;
  color: var(--bs-body-color);
}

.pf-row-text .pf-help {
  margin-top: 0.125rem;
}

/* --- Buttons: one primary (filled), one secondary (outline), one quiet (text) --- */
#main-content .profile-view .btn.pf-btn-primary,
#main-content .profile-view .btn.pf-btn-secondary,
#main-content .profile-view .btn.pf-btn-quiet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-height: 42px;
  padding: 0.4rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.25;
  box-shadow: none;
  transform: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

#main-content .profile-view .btn .material-symbols-rounded {
  font-size: 1.125rem;
  line-height: 1;
}

#main-content .profile-view .btn.pf-btn-primary {
  background-color: var(--pf-fill);
  border: 1px solid var(--pf-fill);
  color: #fff;
}

#main-content .profile-view .btn.pf-btn-primary:hover:not(:disabled) {
  background-color: var(--pf-fill-hover);
  border-color: var(--pf-fill-hover);
  color: #fff;
}

#main-content .profile-view .btn.pf-btn-primary:active:not(:disabled) {
  background-color: var(--pf-fill-active);
  border-color: var(--pf-fill-active);
  transform: scale(0.97);
}

#main-content .profile-view .btn.pf-btn-secondary {
  background-color: transparent;
  border: 1px solid var(--ui-field-border);
  color: var(--bs-body-color);
}

#main-content .profile-view .btn.pf-btn-secondary:hover:not(:disabled) {
  background-color: var(--ui-accent-tint);
  border-color: var(--ui-accent);
  color: var(--ui-accent-text);
}

#main-content .profile-view .btn.pf-btn-secondary:active:not(:disabled) {
  transform: scale(0.97);
}

#main-content .profile-view .btn.pf-btn-quiet {
  background-color: transparent;
  border: 1px solid transparent;
  color: var(--ui-accent-text);
}

#main-content .profile-view .btn.pf-btn-quiet:hover:not(:disabled) {
  background-color: var(--ui-accent-tint);
  color: var(--ui-accent-text);
}

#main-content .profile-view .btn.pf-btn-quiet:active:not(:disabled) {
  transform: scale(0.97);
}

#main-content .profile-view .btn:disabled {
  opacity: 0.55;
}

#main-content .profile-view .btn:focus-visible,
#main-content .profile-view .pf-photo-btn:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
  box-shadow: none;
}

/* --- Save bar: only while there are unsaved changes --- */
.profile-view .pf-savebar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 1030;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--bs-body-bg) 80%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--bs-border-color);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
  animation: pf-bar-in 0.2s ease-out;
}

@media (prefers-reduced-transparency: reduce) {
  .profile-view .pf-savebar {
    background: var(--bs-body-bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

.profile-view .pf-savebar[hidden] {
  display: none;
}

.pf-savebar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  max-width: 62rem;
  margin-inline: auto;
}

.pf-savebar-text {
  margin: 0;
  font-weight: 600;
  color: var(--bs-body-color);
}

.pf-savebar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

@keyframes pf-bar-in {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.pf-skel {
  background: linear-gradient(
    90deg,
    var(--bs-tertiary-bg) 25%,
    var(--bs-secondary-bg) 50%,
    var(--bs-tertiary-bg) 75%
  );
  background-size: 200% 100%;
  animation: pf-shimmer 1.5s infinite;
  border-radius: 6px;
}

@keyframes pf-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.pf-skel-stack {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  gap: 0.5rem;
}

.pf-skel-line {
  height: 16px;
  max-width: 100%;
}

.pf-skel-avatar {
  flex: 0 0 auto;
  width: 112px;
  height: 112px;
  border-radius: 50%;
}

.pf-skel-name {
  width: 14rem;
  height: 26px;
}

.pf-skel-w-40 {
  width: 40%;
  margin-bottom: 1rem;
}

.pf-skel-w-60 {
  width: 60%;
}

.pf-skel-w-80 {
  width: 80%;
}

.pf-skel-field {
  height: 42px;
  border-radius: 0.5rem;
}

/* --- Small screens: stacked identity, 44px controls, the save bar fills the width --- */
@media (max-width: 767.98px) {
  .pf-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  #main-content .profile-view .form-control,
  #main-content .profile-view .phone-input-group .phone-country-toggle,
  #main-content .profile-view .btn.pf-btn-primary,
  #main-content .profile-view .btn.pf-btn-secondary,
  #main-content .profile-view .btn.pf-btn-quiet {
    min-height: 44px;
  }

  .pf-identity,
  .pf-section {
    padding: 1rem;
  }
}

@media (max-width: 575.98px) {
  .pf-identity {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .pf-skel-avatar {
    width: 88px;
    height: 88px;
  }

  .pf-photo {
    width: 96px;
    height: 96px;
  }

  .pf-row .btn {
    width: 100%;
  }

  .pf-savebar-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .pf-savebar-actions {
    justify-content: flex-end;
  }

  .pf-savebar-actions .btn {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .profile-view .pf-savebar,
  .pf-skel {
    animation: none;
  }

  #main-content .profile-view .btn,
  #main-content .profile-view .pf-photo-btn {
    transition: none;
  }

  #main-content .profile-view .btn:active:not(:disabled),
  #main-content .profile-view .pf-photo-btn:active {
    transform: none;
  }
}

@media (prefers-contrast: more) {
  .pf-identity,
  .pf-section,
    .profile-view .pf-savebar {
    border-top: 2px solid var(--bs-body-color);
  }
}

/* ---------- View: admin-dashboard ---------- */

/* Launcher of the four admin modules: a flat list of link cards on the body surface.
   Every rule is scoped to .admin-dashboard-view; links carry #main-content to win over the
   legacy globals of unified-styles.css. */
.admin-dashboard-view {
  max-width: 80rem;
  margin-inline: auto;
}

#main-content .admin-dashboard-view .ad-title {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--bs-body-color);
}

#main-content .admin-dashboard-view .ad-subtitle {
  margin: 0 0 1.5rem;
  color: var(--bs-secondary-color);
}

.admin-dashboard-view .ad-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

@media (min-width: 992px) {
  .admin-dashboard-view .ad-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

#main-content .admin-dashboard-view .ad-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  height: 100%;
  min-height: 9rem;
  padding: 1.25rem;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius, 0.75rem);
  color: var(--bs-body-color);
  text-decoration: none;
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease;
}

#main-content .admin-dashboard-view .ad-card:hover {
  border-color: var(--ui-accent);
  background: var(--ui-accent-tint);
  color: var(--bs-body-color);
}

#main-content .admin-dashboard-view .ad-card:active {
  border-color: var(--ui-accent-active);
}

#main-content .admin-dashboard-view .ad-card:focus-visible {
  outline: 3px solid var(--ui-accent-text);
  outline-offset: 2px;
}

.admin-dashboard-view .ad-card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  margin-block-end: 0.35rem;
  border-radius: 0.75rem;
  background: var(--ui-accent-tint);
  color: var(--ui-accent-text);
}

.admin-dashboard-view .ad-card-icon .material-symbols-rounded {
  font-size: 1.6rem;
  line-height: 1;
}

.admin-dashboard-view .ad-card-label {
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.25;
}

.admin-dashboard-view .ad-card-caption {
  font-size: 0.875rem;
  line-height: 1.35;
  color: var(--bs-secondary-color);
}

@media (prefers-reduced-motion: reduce) {
  #main-content .admin-dashboard-view .ad-card {
    transition: none;
  }
}

@media (prefers-contrast: more) {
  #main-content .admin-dashboard-view .ad-card {
    border: 2px solid var(--ui-field-border);
  }
}

/* ---------- View: dashboard ---------- */

/* Launcher of the SUPER_ADMIN platform modules: same recipe as admin-dashboard with its own
   classes. Every rule is scoped to .superadmin-dashboard-view; links carry #main-content to
   win over the legacy globals of unified-styles.css. */
.superadmin-dashboard-view {
  max-width: 80rem;
  margin-inline: auto;
}

#main-content .superadmin-dashboard-view .sd-title {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--bs-body-color);
}

#main-content .superadmin-dashboard-view .sd-subtitle {
  margin: 0 0 1.5rem;
  color: var(--bs-secondary-color);
}

.superadmin-dashboard-view .sd-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

@media (min-width: 992px) {
  .superadmin-dashboard-view .sd-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

#main-content .superadmin-dashboard-view .sd-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  height: 100%;
  min-height: 9rem;
  padding: 1.25rem;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius, 0.75rem);
  color: var(--bs-body-color);
  text-decoration: none;
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease;
}

#main-content .superadmin-dashboard-view .sd-card:hover {
  border-color: var(--ui-accent);
  background: var(--ui-accent-tint);
  color: var(--bs-body-color);
}

#main-content .superadmin-dashboard-view .sd-card:active {
  border-color: var(--ui-accent-active);
}

#main-content .superadmin-dashboard-view .sd-card:focus-visible {
  outline: 3px solid var(--ui-accent-text);
  outline-offset: 2px;
}

.superadmin-dashboard-view .sd-card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  margin-block-end: 0.35rem;
  border-radius: 0.75rem;
  background: var(--ui-accent-tint);
  color: var(--ui-accent-text);
}

.superadmin-dashboard-view .sd-card-icon .material-symbols-rounded {
  font-size: 1.6rem;
  line-height: 1;
}

.superadmin-dashboard-view .sd-card-label {
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.25;
}

.superadmin-dashboard-view .sd-card-caption {
  font-size: 0.875rem;
  line-height: 1.35;
  color: var(--bs-secondary-color);
}

@media (prefers-reduced-motion: reduce) {
  #main-content .superadmin-dashboard-view .sd-card {
    transition: none;
  }
}

@media (prefers-contrast: more) {
  #main-content .superadmin-dashboard-view .sd-card {
    border: 2px solid var(--ui-field-border);
  }
}

/* ---------- View: admin-users ---------- */

/* User management: flat page header, one-row toolbar and the table as the only raised surface
   (same recipe as the patient list). Every rule hangs off .au-view, the class of
   this view; controls carry #main-content to win over the legacy globals of unified-styles.css.
   The fill of filled buttons is a local token because the dark-theme accent gives white text
   only 4.4:1; #0f6f7d gives 5.85:1 in both themes. */
.au-view {
  --au-fill: var(--ui-accent);
  --au-fill-hover: var(--ui-accent-hover);
  --au-fill-active: var(--ui-accent-active);
  --au-danger-fill: #b02a37; /* white text: 6.4:1 */
  --au-danger-fill-hover: #8c212c;
}

[data-bs-theme="dark"] .au-view {
  --au-fill: #0f6f7d;
  --au-fill-hover: #0c5d6a;
  --au-fill-active: #094b55;
}

/* --- Header --- */
.au-view .au-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
}

#main-content .au-view .au-title {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--bs-body-color);
}

#main-content .au-view .au-count {
  margin: 0.25rem 0 0;
  font-size: 0.9375rem;
  color: var(--bs-secondary-color);
}

/* --- Buttons --- */
#main-content .au-view .au-btn-primary {
  background-color: var(--au-fill);
  border-color: var(--au-fill);
  color: #ffffff;
  box-shadow: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease-out;
}

#main-content .au-view .au-btn-primary:hover {
  background-color: var(--au-fill-hover);
  border-color: var(--au-fill-hover);
  color: #ffffff;
}

#main-content .au-view .au-btn-primary:active {
  background-color: var(--au-fill-active);
  border-color: var(--au-fill-active);
  transform: scale(0.97);
}

#main-content .au-view .au-btn-primary:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
  box-shadow: none;
}

/* RTL strips the fill of every .btn: keep the filled buttons of this view */
[dir="rtl"] #main-content .au-view .au-btn-primary {
  background-color: var(--au-fill) !important;
  border-color: var(--au-fill) !important;
  color: #ffffff !important;
}

#main-content .au-view .au-btn-quiet,
#main-content .au-view .au-btn-secondary,
#main-content .au-view .au-btn-icon {
  color: var(--ui-accent-text);
  background-color: transparent;
  border: 1px solid var(--ui-field-border);
  box-shadow: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease-out;
}

#main-content .au-view .au-btn-quiet:hover,
#main-content .au-view .au-btn-secondary:hover,
#main-content .au-view .au-btn-icon:hover,
#main-content .au-view .au-btn-icon[aria-expanded="true"] {
  color: var(--ui-accent-text);
  background-color: var(--ui-accent-tint);
  border-color: var(--ui-accent-text);
}

#main-content .au-view .au-btn-quiet:active,
#main-content .au-view .au-btn-secondary:active,
#main-content .au-view .au-btn-icon:active {
  transform: scale(0.97);
}

#main-content .au-view .au-btn-quiet:focus-visible,
#main-content .au-view .au-btn-secondary:focus-visible,
#main-content .au-view .au-btn-icon:focus-visible,
#main-content .au-view .au-segmented .btn-check:focus-visible + label.btn {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
  box-shadow: none;
}

.au-view .au-btn-secondary .material-symbols-rounded,
.au-view .au-btn-quiet .material-symbols-rounded {
  font-size: 1.1rem;
  vertical-align: middle;
}

.au-view .au-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  padding-inline: 0.4rem;
}

/* --- Toolbar --- */
.au-view .au-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
  padding-bottom: 1rem;
}

.au-view .au-filter {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.au-view .au-filter-search {
  flex: 1 1 16rem;
  max-width: 30rem;
}

.au-view .au-filter-label {
  margin: 0;
  font-size: var(--fs-xs, 0.75rem);
  font-weight: 600;
  color: var(--bs-secondary-color);
}

.au-view .au-filters .form-control,
.au-view .au-filters .form-select,
.au-view .au-pagination .form-select {
  border-color: var(--ui-field-border);
}

.au-view .au-filters .form-control:focus,
.au-view .au-filters .form-select:focus,
.au-view .au-pagination .form-select:focus {
  border-color: var(--ui-accent-text);
  box-shadow: 0 0 0 0.2rem var(--ui-accent-tint);
}

/* Segmented Active | Inactive (the hidden radios make the first label a second child) */
.au-view .au-segmented > label.btn:first-of-type {
  border-top-left-radius: 0.375rem !important;
  border-bottom-left-radius: 0.375rem !important;
}

.au-view .au-segmented > label.btn:last-of-type {
  border-top-right-radius: 0.375rem !important;
  border-bottom-right-radius: 0.375rem !important;
}

[dir="rtl"] .au-view .au-segmented > label.btn:first-of-type {
  border-radius: 0 0.375rem 0.375rem 0 !important;
}

[dir="rtl"] .au-view .au-segmented > label.btn:last-of-type {
  border-radius: 0.375rem 0 0 0.375rem !important;
}

#main-content .au-view .au-segmented > label.btn {
  color: var(--bs-body-color) !important;
  background-color: transparent !important;
  border-color: var(--ui-field-border) !important;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease-out;
}

#main-content .au-view .au-segmented > label.btn:hover {
  background-color: var(--ui-accent-tint) !important;
  color: var(--ui-accent-text) !important;
  border-color: var(--ui-accent-text) !important;
}

#main-content .au-view .au-segmented > .btn-check:checked + label.btn,
#main-content .au-view .au-segmented > .btn-check:checked + label.btn:hover {
  background-color: var(--au-fill) !important;
  border-color: var(--au-fill) !important;
  color: #ffffff !important;
}

.au-view .au-segmented > label.btn:active {
  transform: scale(0.97);
}

/* --- Surface and table --- */
.au-view .au-surface {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius);
}

/* The table wraps its text instead of scrolling, so the wrapper never clips (needed by the
   sticky header and by the row menus, which open past the card edge) */
.au-view .table-responsive {
  overflow: visible;
}

.au-view .au-table {
  --bs-table-bg: transparent;
}

.au-view .au-table thead th {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--bs-secondary-color);
  white-space: nowrap;
  border-bottom: 1px solid var(--bs-border-color);
}

.au-view .au-table tbody td {
  padding-block: 0.75rem;
  vertical-align: middle;
}

.au-view .au-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.au-view .au-initials {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--ui-accent-tint);
  color: var(--ui-accent-text);
  font-size: 0.8125rem;
  font-weight: 700;
}

.au-view .au-user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  text-align: start;
}

.au-view .au-user-name {
  font-weight: 600;
  color: var(--bs-body-color);
}

.au-view .au-user-email {
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
  overflow-wrap: anywhere;
}

.au-view .au-status-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.au-view .au-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 500;
  color: var(--bs-body-color);
}

.au-view .au-status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--bs-success);
}

.au-view .au-status.is-inactive .au-status-dot {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--bs-secondary-color);
}

.au-view .au-invite {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--bs-secondary-color);
}

.au-view .au-invite .material-symbols-rounded {
  font-size: 1rem;
}

.au-view .au-date {
  font-size: 0.875rem;
  white-space: nowrap;
}

.au-view .au-muted {
  color: var(--bs-secondary-color);
  font-size: 0.875rem;
}

.au-view .au-actions {
  text-align: end;
}

.au-view .au-actions-inner {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}

/* Row menu */
.au-view .au-menu {
  --bs-dropdown-min-width: 13rem;
  border-color: var(--bs-border-color);
  padding-block: 0.25rem;
}

.au-view .au-menu .dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.25rem;
}

.au-view .au-menu .dropdown-item .material-symbols-rounded {
  font-size: 1.2rem;
}

.au-view .au-menu .dropdown-item.au-danger {
  color: var(--bs-danger-text-emphasis);
}

/* --- States: loading, empty, error --- */
.au-view .au-state-row:hover > * {
  --bs-table-bg-state: transparent;
}






.au-view .au-skel {
  display: block;
  background: var(--bs-secondary-bg);
  border-radius: 0.375rem;
  animation: au-skel-pulse 1.4s ease-in-out infinite;
}

.au-view .au-skel-line {
  height: 0.75rem;
  width: 8rem;
  max-width: 100%;
}

.au-view .au-skel-short {
  width: 5rem;
}

.au-view .au-skel-lines {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

@keyframes au-skel-pulse {
  50% {
    opacity: 0.55;
  }
}

/* --- Pagination --- */
.au-view .au-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--bs-border-color);
}

.au-view .au-pagination.d-none {
  display: none;
}

.au-view .au-pagination-info,
.au-view .au-pagination-label {
  margin: 0;
  font-size: 0.875rem;
  color: var(--bs-secondary-color);
}

.au-view .au-pagination-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.au-view .au-pagination .pagination .page-link {
  color: var(--ui-accent-text);
  background-color: transparent;
  border-color: var(--bs-border-color);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease,
    transform 0.1s ease-out;
}

.au-view .au-pagination .pagination .page-item:not(.active):not(.disabled) .page-link:hover {
  background-color: var(--ui-accent-tint);
  border-color: var(--ui-accent-text);
}

.au-view .au-pagination .pagination .page-link:active {
  transform: scale(0.97);
}

.au-view .au-pagination .pagination .page-item.active .page-link {
  background-color: var(--au-fill);
  border-color: var(--au-fill);
  color: #ffffff;
}

.au-view .au-pagination .pagination .page-item.disabled .page-link {
  background-color: transparent;
  color: var(--bs-secondary-color);
  opacity: 0.7;
}

.au-view .au-pagination .pagination .page-link:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
  box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  .au-view .au-skel {
    animation: none;
  }

  #main-content .au-view .au-btn-primary:active,
  #main-content .au-view .au-btn-quiet:active,
  #main-content .au-view .au-btn-secondary:active,
  #main-content .au-view .au-btn-icon:active,
  .au-view .au-segmented > label.btn:active,
  .au-view .au-pagination .pagination .page-link:active {
    transform: none;
  }

  #main-content .au-view .au-btn-primary,
  #main-content .au-view .au-btn-quiet,
  #main-content .au-view .au-btn-secondary,
  #main-content .au-view .au-btn-icon,
  #main-content .au-view .au-segmented > label.btn,
  .au-view .au-pagination .pagination .page-link {
    transition: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .au-view .au-table thead th,
  [data-bs-theme="dark"] .au-view .au-table thead th {
    background-color: var(--bs-body-bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  .au-view .au-surface,
  .au-view .au-table tbody tr {
    border-color: var(--ui-field-border);
  }

  .au-view .au-table thead th {
    border-bottom: 2px solid var(--bs-body-color);
    color: var(--bs-body-color);
  }
}

/* ---------- View: admin-audit ---------- */

/* Audit log: flat page header, always-visible toolbar, the table as the only raised surface and
   a side panel for the event detail (same recipe as admin-users). Every rule hangs off .aa-view
   or .aa-panel, the classes of this view; controls carry #main-content to win over the legacy
   globals of unified-styles.css. The fill of filled controls is a local token because the
   dark-theme accent gives white text only 4.4:1; #0f6f7d gives 5.85:1 in both themes. */
.aa-view,
.aa-panel {
  --aa-fill: var(--ui-accent);
  --aa-danger: #b02a37; /* text on the page background: 6.4:1 */
}

[data-bs-theme="dark"] .aa-view,
[data-bs-theme="dark"] .aa-panel {
  --aa-fill: #0f6f7d;
  --aa-danger: #f1999f;
}

/* --- Header --- */
.aa-view .aa-header {
  padding-bottom: 1rem;
}

#main-content .aa-view .aa-title {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--bs-body-color);
}

#main-content .aa-view .aa-count {
  margin: 0.25rem 0 0;
  min-height: 1.4em;
  font-size: 0.9375rem;
  color: var(--bs-secondary-color);
}

/* Global scope notice: one quiet line, not a full-width alert */
.aa-view .aa-scope {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0 0 1rem;
  padding: 0.5rem 0.75rem;
  border-inline-start: 3px solid var(--ui-accent-text);
  border-radius: 0.375rem;
  background: var(--ui-accent-tint);
  color: var(--bs-body-color);
  font-size: 0.875rem;
}

.aa-view .aa-scope.d-none {
  display: none;
}

.aa-view .aa-scope .material-symbols-rounded {
  flex: 0 0 auto;
  font-size: 1.2rem;
  color: var(--ui-accent-text);
}

/* --- Buttons --- */
#main-content .aa-view .aa-btn-quiet,
#main-content .aa-view .aa-btn-icon,
#main-content .aa-panel .aa-btn-quiet {
  color: var(--ui-accent-text);
  background-color: transparent;
  border: 1px solid var(--ui-field-border);
  box-shadow: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease-out;
}

#main-content .aa-view .aa-btn-quiet:hover,
#main-content .aa-view .aa-btn-icon:hover,
#main-content .aa-panel .aa-btn-quiet:hover:not(:disabled) {
  color: var(--ui-accent-text);
  background-color: var(--ui-accent-tint);
  border-color: var(--ui-accent-text);
}

#main-content .aa-view .aa-btn-quiet:active,
#main-content .aa-view .aa-btn-icon:active,
#main-content .aa-panel .aa-btn-quiet:active:not(:disabled) {
  transform: scale(0.97);
}

#main-content .aa-panel .aa-btn-quiet:disabled {
  color: var(--bs-secondary-color);
  opacity: 0.6;
}

#main-content .aa-view .aa-btn-quiet:focus-visible,
#main-content .aa-view .aa-btn-icon:focus-visible,
#main-content .aa-panel .aa-btn-quiet:focus-visible,
#main-content .aa-view .aa-segmented .btn-check:focus-visible + label.btn,
.aa-view .aa-advanced summary:focus-visible,
.aa-panel .aa-tech summary:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
  box-shadow: none;
}

.aa-view .aa-btn-quiet .material-symbols-rounded,
.aa-panel .aa-btn-quiet .material-symbols-rounded {
  font-size: 1.1rem;
  vertical-align: middle;
}

.aa-view .aa-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  padding-inline: 0.4rem;
}

[dir="rtl"] .aa-flip-rtl {
  transform: scaleX(-1);
}

/* --- Toolbar --- */
.aa-view .aa-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
  padding-bottom: 1rem;
}

.aa-view .aa-filters-advanced {
  padding-top: 0.75rem;
}

.aa-view .aa-filter {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.aa-view .aa-filter-search {
  flex: 1 1 14rem;
  max-width: 24rem;
}

.aa-view .aa-filter-date {
  flex: 0 1 12.5rem;
}

.aa-view .aa-filter-reset {
  margin-inline-start: auto;
}

.aa-view .aa-filter-label {
  margin: 0;
  font-size: var(--fs-xs, 0.75rem);
  font-weight: 600;
  color: var(--bs-secondary-color);
}

.aa-view .aa-filters .form-control,
.aa-view .aa-filters .form-select,
.aa-view .aa-pagination .form-select {
  border-color: var(--ui-field-border);
}

.aa-view .aa-filters .form-control:focus,
.aa-view .aa-filters .form-select:focus,
.aa-view .aa-pagination .form-select:focus {
  border-color: var(--ui-accent-text);
  box-shadow: 0 0 0 0.2rem var(--ui-accent-tint);
}

/* Segmented controls (the hidden radios make the first label a second child) */
.aa-view .aa-segmented > label.btn:first-of-type {
  border-top-left-radius: 0.375rem !important;
  border-bottom-left-radius: 0.375rem !important;
}

.aa-view .aa-segmented > label.btn:last-of-type {
  border-top-right-radius: 0.375rem !important;
  border-bottom-right-radius: 0.375rem !important;
}

[dir="rtl"] .aa-view .aa-segmented > label.btn:first-of-type {
  border-radius: 0 0.375rem 0.375rem 0 !important;
}

[dir="rtl"] .aa-view .aa-segmented > label.btn:last-of-type {
  border-radius: 0.375rem 0 0 0.375rem !important;
}

#main-content .aa-view .aa-segmented > label.btn {
  color: var(--bs-body-color) !important;
  background-color: transparent !important;
  border-color: var(--ui-field-border) !important;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease-out;
}

#main-content .aa-view .aa-segmented > label.btn:hover {
  background-color: var(--ui-accent-tint) !important;
  color: var(--ui-accent-text) !important;
  border-color: var(--ui-accent-text) !important;
}

#main-content .aa-view .aa-segmented > .btn-check:checked + label.btn,
#main-content .aa-view .aa-segmented > .btn-check:checked + label.btn:hover {
  background-color: var(--aa-fill) !important;
  border-color: var(--aa-fill) !important;
  color: #ffffff !important;
}

.aa-view .aa-segmented > label.btn:active {
  transform: scale(0.97);
}

/* --- Advanced filters (SUPER_ADMIN) --- */
.aa-view .aa-advanced {
  margin-bottom: 1rem;
}

.aa-view .aa-advanced.d-none {
  display: none;
}

.aa-view .aa-advanced summary,
.aa-panel .aa-tech summary {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  list-style: none;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ui-accent-text);
  border-radius: 0.25rem;
}

.aa-view .aa-advanced summary::-webkit-details-marker,
.aa-panel .aa-tech summary::-webkit-details-marker {
  display: none;
}

.aa-view .aa-advanced-icon,
.aa-panel .aa-advanced-icon {
  font-size: 1.25rem;
  transition: transform 0.15s ease-out;
}

.aa-view .aa-advanced:not([open]) .aa-advanced-icon,
.aa-panel .aa-tech:not([open]) .aa-advanced-icon {
  transform: rotate(-90deg);
}

[dir="rtl"] .aa-view .aa-advanced:not([open]) .aa-advanced-icon,
[dir="rtl"] .aa-panel .aa-tech:not([open]) .aa-advanced-icon {
  transform: rotate(90deg);
}

.aa-view .aa-advanced-count {
  min-width: 1.25rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--aa-fill);
  color: #ffffff;
  font-size: 0.75rem;
  line-height: 1.25rem;
  text-align: center;
}

.aa-view .aa-advanced-count.d-none {
  display: none;
}

/* --- Surface and table --- */
.aa-view .aa-surface {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius);
}

/* The table wraps its text instead of scrolling, so the wrapper never clips (needed by the
   sticky header) */
.aa-view .table-responsive {
  overflow: visible;
}

.aa-view .aa-table {
  --bs-table-bg: transparent;
}

.aa-view .aa-table thead th {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--bs-secondary-color);
  white-space: nowrap;
  border-bottom: 1px solid var(--bs-border-color);
}

.aa-view .aa-table tbody td {
  padding-block: 0.75rem;
  vertical-align: middle;
}

.aa-view .aa-row {
  cursor: pointer;
}

.aa-view .aa-row.is-failed > td:first-child {
  box-shadow: inset 3px 0 0 var(--aa-danger);
}

[dir="rtl"] .aa-view .aa-row.is-failed > td:first-child {
  box-shadow: inset -3px 0 0 var(--aa-danger);
}

.aa-view .aa-row.is-selected > * {
  --bs-table-bg-state: var(--ui-accent-tint);
}

.aa-view .aa-when {
  display: flex;
  flex-direction: column;
  white-space: nowrap;
}

.aa-view .aa-when-date {
  font-weight: 600;
  color: var(--bs-body-color);
}

.aa-view .aa-when-time {
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
  text-align: start;
}

.aa-view .aa-activity {
  display: flex;
  flex-direction: column;
  text-align: start;
}

.aa-view .aa-activity-title {
  font-weight: 600;
  color: var(--bs-body-color);
}

.aa-view .aa-sub {
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

.aa-view .aa-actor {
  overflow-wrap: anywhere;
}

.aa-view .aa-status-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.aa-view .aa-status,
.aa-panel .aa-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 500;
  color: var(--bs-body-color);
}

.aa-view .aa-status-dot,
.aa-panel .aa-status-dot {
  flex: 0 0 auto;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--bs-success);
}

.aa-view .aa-status.is-failed .aa-status-dot,
.aa-panel .aa-status.is-failed .aa-status-dot {
  background: var(--aa-danger);
}

.aa-view .aa-status.is-failed,
.aa-panel .aa-status.is-failed {
  color: var(--aa-danger);
}

.aa-view .aa-hint {
  max-width: 22rem;
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

.aa-view .aa-actions {
  text-align: end;
}

/* --- States: loading, empty, error --- */
.aa-view .aa-state-row {
  cursor: default;
}

.aa-view .aa-state-row:hover > * {
  --bs-table-bg-state: transparent;
}






.aa-view .aa-skel {
  display: block;
  background: var(--bs-secondary-bg);
  border-radius: 0.375rem;
  animation: aa-skel-pulse 1.4s ease-in-out infinite;
}

.aa-view .aa-skel-line {
  height: 0.75rem;
  width: 8rem;
  max-width: 100%;
}

.aa-view .aa-skel-short {
  width: 5rem;
}

@keyframes aa-skel-pulse {
  50% {
    opacity: 0.55;
  }
}

/* --- Pagination --- */
.aa-view .aa-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--bs-border-color);
}

.aa-view .aa-pagination.d-none {
  display: none;
}

.aa-view .aa-pagination-info,
.aa-view .aa-pagination-label {
  margin: 0;
  font-size: 0.875rem;
  color: var(--bs-secondary-color);
}

.aa-view .aa-pagination-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.aa-view .aa-pagination .pagination .page-link {
  color: var(--ui-accent-text);
  background-color: transparent;
  border-color: var(--bs-border-color);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease,
    transform 0.1s ease-out;
}

.aa-view .aa-pagination .pagination .page-item:not(.active):not(.disabled) .page-link:hover {
  background-color: var(--ui-accent-tint);
  border-color: var(--ui-accent-text);
}

.aa-view .aa-pagination .pagination .page-link:active {
  transform: scale(0.97);
}

.aa-view .aa-pagination .pagination .page-item.active .page-link {
  background-color: var(--aa-fill);
  border-color: var(--aa-fill);
  color: #ffffff;
}

.aa-view .aa-pagination .pagination .page-item.disabled .page-link {
  background-color: transparent;
  color: var(--bs-secondary-color);
  opacity: 0.7;
}

.aa-view .aa-pagination .pagination .page-link:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
  box-shadow: none;
}

/* --- Detail side panel: the container, header and close button come from .ui-panel --- */
.aa-panel .offcanvas-title {
  margin: 0;
}

.aa-panel .aa-panel-position {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

.aa-panel .aa-dl {
  margin: 0;
}

.aa-panel .aa-dl-row {
  padding-block: 0.6rem;
  border-bottom: 1px solid var(--bs-border-color);
}

.aa-panel .aa-dl-row dt {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--bs-secondary-color);
}

.aa-panel .aa-dl-row dd {
  margin: 0.15rem 0 0;
  overflow-wrap: anywhere;
  color: var(--bs-body-color);
}

.aa-panel .aa-mono {
  font-family: var(--bs-font-monospace);
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

.aa-panel .aa-muted {
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

.aa-panel .aa-panel-hint {
  margin: 1rem 0 0;
  color: var(--bs-secondary-color);
}

.aa-panel .aa-tech {
  margin-top: 1.25rem;
}

.aa-panel .aa-tech.d-none {
  display: none;
}

.aa-panel .aa-tech-pre {
  max-height: 50vh;
  margin: 0.75rem 0 0;
  padding: 0.75rem;
  overflow: auto;
  border: 1px solid var(--bs-border-color);
  border-radius: 0.375rem;
  background: var(--bs-tertiary-bg);
  color: var(--bs-body-color);
  font-size: 0.8125rem;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.aa-panel .aa-panel-footer {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--bs-border-color);
}

/* --- Wide screens: sticky translucent header, rounded first/last cells --- */
@media (min-width: 992px) {
  .aa-view .aa-table thead th {
    position: sticky;
    top: var(--ui-sticky-top);
    z-index: 5;
    box-shadow: none;
    background-color: color-mix(in srgb, var(--bs-body-bg) 78%, transparent);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
  }

  .aa-view .aa-table thead th:first-child {
    border-top-left-radius: var(--border-radius);
    padding-inline-start: 1rem;
  }

  .aa-view .aa-table thead th:last-child {
    border-top-right-radius: var(--border-radius);
    padding-inline-end: 1rem;
  }

  .aa-view .aa-table tbody td:first-child {
    padding-inline-start: 1rem;
  }

  .aa-view .aa-table tbody td:last-child {
    padding-inline-end: 1rem;
  }

  [dir="rtl"] .aa-view .aa-table thead th:first-child {
    border-radius: 0 var(--border-radius) 0 0;
  }

  [dir="rtl"] .aa-view .aa-table thead th:last-child {
    border-radius: var(--border-radius) 0 0 0;
  }

  [data-bs-theme="dark"] .aa-view .aa-table thead th {
    background-color: rgba(45, 48, 52, 0.78);
  }
}

/* --- Below lg: each event is its own card, the surface drops its frame --- */
@media (max-width: 991.98px) {
  .aa-view .aa-surface {
    background: transparent;
    border: 0;
    border-radius: 0;
  }

  .aa-view .aa-table tbody tr {
    background: var(--bs-body-bg);
  }

  .aa-view .aa-row.is-failed {
    border-inline-start: 3px solid var(--aa-danger);
  }

  .aa-view .aa-row.is-failed > td:first-child,
  [dir="rtl"] .aa-view .aa-row.is-failed > td:first-child {
    box-shadow: none;
  }

  .aa-view .aa-table tbody td.aa-actions {
    justify-content: flex-end;
    padding-top: 0.5rem;
  }

  .aa-view .aa-status-wrap {
    align-items: flex-end;
  }

  .aa-view .aa-hint {
    max-width: none;
  }

  .aa-view .aa-pagination {
    border: 0;
    padding-inline: 0.25rem;
  }

  .aa-view .aa-filter-reset {
    margin-inline-start: 0;
  }
}

@media (max-width: 575.98px) {
  .aa-view .aa-filter,
  .aa-view .aa-filter-search,
  .aa-view .aa-filter-date {
    flex: 1 1 100%;
    max-width: none;
  }

  /* Five periods do not fit one row: the group wraps into separate pills */
  .aa-view .aa-segmented {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  #main-content .aa-view .aa-segmented > label.btn {
    border-radius: 0.375rem !important;
  }

}

/* --- Touch targets: 44px on touch screens --- */
@media (pointer: coarse), (max-width: 991.98px) {
  .aa-view .aa-filters .form-control,
  .aa-view .aa-filters .form-select,
  .aa-view .aa-filters .btn,
  .aa-view .aa-table .btn,
  .aa-view .aa-pagination .form-select,
  .aa-view .aa-pagination .page-link,
  .aa-view .aa-advanced summary,
  .aa-panel .aa-btn-quiet,
  .aa-panel .aa-tech summary {
    min-height: 44px;
  }

  .aa-view .aa-btn-icon,
  .aa-view .aa-pagination .page-link {
    min-width: 44px;
  }
}

/* --- Reduced motion / transparency / contrast --- */
@media (prefers-reduced-motion: reduce) {
  .aa-view .aa-skel {
    animation: none;
  }

  #main-content .aa-view .aa-btn-quiet:active,
  #main-content .aa-view .aa-btn-icon:active,
  #main-content .aa-panel .aa-btn-quiet:active,
  .aa-view .aa-segmented > label.btn:active,
  .aa-view .aa-pagination .pagination .page-link:active {
    transform: none;
  }

  #main-content .aa-view .aa-btn-quiet,
  #main-content .aa-view .aa-btn-icon,
  #main-content .aa-panel .aa-btn-quiet,
  #main-content .aa-view .aa-segmented > label.btn,
  .aa-view .aa-pagination .pagination .page-link,
  .aa-view .aa-advanced-icon,
  .aa-panel .aa-advanced-icon {
    transition: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .aa-view .aa-table thead th,
  [data-bs-theme="dark"] .aa-view .aa-table thead th {
    background-color: var(--bs-body-bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  .aa-view .aa-surface,
  .aa-view .aa-table tbody tr,
  .aa-view .aa-scope {
    border-color: var(--ui-field-border);
  }

  .aa-view .aa-table thead th {
    border-bottom: 2px solid var(--bs-body-color);
    color: var(--bs-body-color);
  }

  .aa-view .aa-sub,
  .aa-view .aa-when-time,
  .aa-view .aa-hint {
    color: var(--bs-body-color);
  }
}

/* ===== Wound progress chip (verdict + % of area closed), shared by list, patient, wound, report ===== */
.progress-chip {
  --chip-fg: var(--ui-text-muted, #475569);
  --chip-bg: rgba(71, 85, 105, 0.1);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: var(--fs-xs, 0.75rem);
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  color: var(--chip-fg);
  background: var(--chip-bg);
  direction: ltr;
  unicode-bidi: isolate;
}

[dir='rtl'] .progress-chip {
  direction: rtl;
}

.progress-chip .material-symbols-rounded {
  font-size: 1rem;
}

.progress-chip__alert {
  display: inline-flex;
  align-items: center;
  margin: -0.15rem -0.2rem -0.15rem 0;
  padding: 0.15rem;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--ui-warning, #9a5b00);
  cursor: pointer;
}

.progress-chip__alert:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 1px;
}

.info-popover {
  max-width: 18rem;
  font-size: 0.8125rem;
}

.progress-chip--improving,
.progress-chip--healed {
  --chip-fg: var(--ui-success, #1b7a3a);
  --chip-bg: var(--ui-success-tint, rgba(27, 122, 58, 0.1));
}

.progress-chip--worsening {
  --chip-fg: var(--ui-danger, #b42335);
  --chip-bg: var(--ui-danger-tint, rgba(180, 35, 53, 0.1));
}

.progress-chip--none {
  font-weight: 500;
}

.progress-chip--compact .progress-chip__text {
  font-size: var(--fs-xs, 0.75rem);
}

[data-bs-theme='dark'] .progress-chip {
  --chip-fg: #cbd5e1;
  --chip-bg: rgba(203, 213, 225, 0.12);
}

[data-bs-theme='dark'] .progress-chip--improving,
[data-bs-theme='dark'] .progress-chip--healed {
  --chip-fg: #6fdc8c;
  --chip-bg: rgba(111, 220, 140, 0.14);
}

[data-bs-theme='dark'] .progress-chip--worsening {
  --chip-fg: #ff8a95;
  --chip-bg: rgba(255, 138, 149, 0.14);
}

[data-bs-theme='dark'] .progress-chip__alert {
  color: #f5b04c;
}

/* Patient card: label | chip grid, so both verdicts start in the same column */
.pt-progress {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 0.35rem 0.75rem;
  align-items: center;
}

.pt-progress__item {
  display: contents;
}

.pt-progress__label {
  font-size: var(--fs-xs, 0.75rem);
  color: var(--bs-secondary-color);
}

.pt-progress .progress-chip {
  justify-self: start;
}

/* Comparison: verdict, necrosis alert, wound-bed bars and table groups */
body.ui-refined .comparison-overall {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

body.ui-refined .comparison-overall .progress-chip {
  font-size: 0.9375rem;
  padding: 0.25rem 0.75rem;
}

body.ui-refined .comparison-overall__text {
  font-size: 1.125rem;
  font-weight: 700;
}

body.ui-refined .comparison-alert {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.6rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ui-warning);
}

body.ui-refined .bed-bars {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

body.ui-refined .bed-bar {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.15rem 0.75rem;
  align-items: center;
  font-size: 0.8125rem;
}

body.ui-refined .bed-bar__label {
  font-weight: 600;
}

body.ui-refined .bed-bar__track {
  display: flex;
  height: 0.75rem;
  overflow: hidden;
  border-radius: 999px;
  background: var(--ui-field-border);
}

body.ui-refined .bed-bar__text {
  grid-column: 2;
  color: var(--bs-secondary-color);
}

body.ui-refined .bed-bar__seg--granulation {
  background: #cc6677;
}

body.ui-refined .bed-bar__seg--fibrin {
  background: #ddcc77;
}

body.ui-refined .bed-bar__seg--necrosis {
  background: #332288;
}

body.ui-refined .eval-group th {
  padding-top: 0.9rem;
  font-size: var(--fs-xs, 0.75rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
}

/* "pp" (percentage points): a dotted underline hints that it can be clicked for an explanation */
body.ui-refined .pp-abbr {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
  cursor: pointer;
}

body.ui-refined .pp-abbr:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* ---------- View: admin-health-providers ---------- */

/* Health providers catalog: flat page header, always-visible toolbar and the table as the only
   raised surface (same recipe as admin-users). Every rule hangs off .hp-view, the class of this
   view; controls carry #main-content to win over the legacy globals of unified-styles.css.
   The fill of filled controls is a local token because the dark-theme accent gives white text
   only 4.4:1; #0f6f7d gives 5.85:1 in both themes. */
.hp-view {
  --hp-fill: var(--ui-accent);
  --hp-fill-hover: var(--ui-accent-hover);
  --hp-fill-active: var(--ui-accent-active);
}

[data-bs-theme="dark"] .hp-view {
  --hp-fill: #0f6f7d;
  --hp-fill-hover: #0c5d6a;
  --hp-fill-active: #094b55;
}

/* --- Header --- */
.hp-view .hp-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
}

#main-content .hp-view .hp-title {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--bs-body-color);
}

#main-content .hp-view .hp-count {
  margin: 0.25rem 0 0;
  min-height: 1.4em;
  font-size: 0.9375rem;
  color: var(--bs-secondary-color);
}

/* --- Buttons --- */
#main-content .hp-view .hp-btn-primary {
  background-color: var(--hp-fill);
  border-color: var(--hp-fill);
  color: #ffffff;
  box-shadow: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease-out;
}

#main-content .hp-view .hp-btn-primary:hover {
  background-color: var(--hp-fill-hover);
  border-color: var(--hp-fill-hover);
  color: #ffffff;
}

#main-content .hp-view .hp-btn-primary:active {
  background-color: var(--hp-fill-active);
  border-color: var(--hp-fill-active);
  transform: scale(0.97);
}

#main-content .hp-view .hp-btn-primary:disabled {
  opacity: 0.6;
  transform: none;
}

/* RTL strips the fill of every .btn: keep the filled buttons of this view */
[dir="rtl"] #main-content .hp-view .hp-btn-primary {
  background-color: var(--hp-fill) !important;
  border-color: var(--hp-fill) !important;
  color: #ffffff !important;
}

/* Quiet: neutral outline (Deactivate, Clear filters). Secondary: accent outline (Activate) */
#main-content .hp-view .hp-btn-quiet,
#main-content .hp-view .hp-btn-secondary {
  background-color: transparent;
  box-shadow: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease-out;
}

#main-content .hp-view .hp-btn-quiet {
  color: var(--bs-body-color);
  border: 1px solid var(--ui-field-border);
}

#main-content .hp-view .hp-btn-secondary {
  color: var(--ui-accent-text);
  border: 1px solid var(--ui-accent-text);
}

#main-content .hp-view .hp-btn-quiet:hover,
#main-content .hp-view .hp-btn-secondary:hover {
  color: var(--ui-accent-text);
  background-color: var(--ui-accent-tint);
  border-color: var(--ui-accent-text);
}

#main-content .hp-view .hp-btn-quiet:active,
#main-content .hp-view .hp-btn-secondary:active {
  transform: scale(0.97);
}

#main-content .hp-view .hp-btn-primary:focus-visible,
#main-content .hp-view .hp-btn-quiet:focus-visible,
#main-content .hp-view .hp-btn-secondary:focus-visible,
#main-content .hp-view .hp-segmented .btn-check:focus-visible + label.btn {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
  box-shadow: none;
}

.hp-view .hp-btn-quiet .material-symbols-rounded {
  font-size: 1.1rem;
  vertical-align: middle;
}

/* --- Toolbar --- */
.hp-view .hp-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
  padding-bottom: 1rem;
}

.hp-view .hp-filter {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.hp-view .hp-filter-search {
  flex: 1 1 16rem;
  max-width: 30rem;
}

.hp-view .hp-filter-label {
  margin: 0;
  font-size: var(--fs-xs, 0.75rem);
  font-weight: 600;
  color: var(--bs-secondary-color);
}

.hp-view .hp-filters .form-control,
.hp-view .hp-filters .form-select {
  border-color: var(--ui-field-border);
}

.hp-view .hp-filters .form-control:focus,
.hp-view .hp-filters .form-select:focus {
  border-color: var(--ui-accent-text);
  box-shadow: 0 0 0 0.2rem var(--ui-accent-tint);
}

/* Segmented All | Active | Inactive (the hidden radios shift the label positions) */
.hp-view .hp-segmented > label.btn {
  border-radius: 0 !important;
}

.hp-view .hp-segmented > label.btn:first-of-type {
  border-start-start-radius: 0.375rem !important;
  border-end-start-radius: 0.375rem !important;
}

.hp-view .hp-segmented > label.btn:last-of-type {
  border-start-end-radius: 0.375rem !important;
  border-end-end-radius: 0.375rem !important;
}

#main-content .hp-view .hp-segmented > label.btn {
  color: var(--bs-body-color) !important;
  background-color: transparent !important;
  border-color: var(--ui-field-border) !important;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease-out;
}

#main-content .hp-view .hp-segmented > label.btn:hover {
  background-color: var(--ui-accent-tint) !important;
  color: var(--ui-accent-text) !important;
  border-color: var(--ui-accent-text) !important;
}

#main-content .hp-view .hp-segmented > .btn-check:checked + label.btn,
#main-content .hp-view .hp-segmented > .btn-check:checked + label.btn:hover {
  background-color: var(--hp-fill) !important;
  border-color: var(--hp-fill) !important;
  color: #ffffff !important;
}

.hp-view .hp-segmented > label.btn:active {
  transform: scale(0.97);
}

/* --- Surface and table --- */
.hp-view .hp-surface {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius);
}

/* The table wraps its text instead of scrolling, so the wrapper never clips (needed by the
   sticky header) */
.hp-view .table-responsive {
  overflow: visible;
}

.hp-view .hp-table {
  --bs-table-bg: transparent;
}

#main-content .hp-view .hp-table thead th {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  opacity: 1;
  color: var(--bs-secondary-color);
  white-space: nowrap;
  border-bottom: 1px solid var(--bs-border-color);
}

.hp-view .hp-table tbody td {
  padding-block: 0.75rem;
  vertical-align: middle;
}

.hp-view .hp-name-block {
  display: flex;
  flex-direction: column;
  min-width: 0;
  text-align: start;
}

.hp-view .hp-name {
  font-weight: 600;
  color: var(--bs-body-color);
  overflow-wrap: anywhere;
}

/* The creation date sits under the name only where the Created column is hidden (cards) */
.hp-view .hp-name-date {
  display: none;
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
}

.hp-view .hp-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 500;
  color: var(--bs-body-color);
}

.hp-view .hp-status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--bs-success);
}

.hp-view .hp-status.is-inactive .hp-status-dot {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--bs-secondary-color);
}

.hp-view .hp-date {
  font-size: 0.875rem;
  white-space: nowrap;
  color: var(--bs-secondary-color);
}

.hp-view .hp-actions {
  text-align: end;
}

/* --- Sticky, translucent table header (only where the table is a table) --- */
@media (min-width: 992px) {
  .hp-view .hp-surface {
    overflow: visible; /* an overflow container would stop the header from sticking */
  }

  #main-content .hp-view .hp-table thead th {
    position: sticky;
    top: var(--ui-sticky-top);
    z-index: 5;
    --bs-table-bg: transparent;
    box-shadow: none;
    background-color: color-mix(in srgb, var(--bs-body-bg) 78%, transparent) !important;
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
  }

  .hp-view .hp-table thead th:first-child {
    border-start-start-radius: var(--border-radius);
  }

  .hp-view .hp-table thead th:last-child {
    border-start-end-radius: var(--border-radius);
  }

  /* Narrow, right-aligned action column */
  .hp-view .hp-table th:last-child,
  .hp-view .hp-table td.hp-actions {
    width: 9rem;
  }
}

/* --- Cards below 992 px (shared .table-cards): name first, status, one action --- */
@media (max-width: 991.98px) {
  .hp-view .hp-name-date {
    display: block;
  }

  .hp-view .hp-table tbody td.hp-actions {
    justify-content: flex-end;
  }

  .hp-view .hp-table tbody td.hp-actions .btn,
  .hp-view .hp-filters .form-control,
  .hp-view .hp-filters .form-select,
  .hp-view .hp-filters .btn,
  .hp-view .hp-btn-primary {
    min-height: 44px;
  }

  .hp-view .hp-filter-search,
  .hp-view .hp-filter:has(.form-select) {
    flex: 1 1 100%;
    max-width: none;
  }
}

@media (pointer: coarse) {
  .hp-view .hp-table tbody td.hp-actions .btn,
  .hp-view .hp-filters .form-control,
  .hp-view .hp-filters .form-select,
  .hp-view .hp-filters .btn,
  .hp-view .hp-btn-primary {
    min-height: 44px;
  }
}

/* --- States: loading, empty, error --- */
.hp-view .hp-state-row:hover > * {
  --bs-table-bg-state: transparent;
}

.hp-view .hp-skel {
  display: block;
  background: var(--bs-secondary-bg);
  border-radius: 0.375rem;
  animation: hp-skel-pulse 1.4s ease-in-out infinite;
}

.hp-view .hp-skel-line {
  height: 0.75rem;
  width: 10rem;
  max-width: 100%;
}

.hp-view .hp-skel-short {
  width: 5rem;
}

@keyframes hp-skel-pulse {
  50% {
    opacity: 0.55;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hp-view .hp-skel {
    animation: none;
  }

  #main-content .hp-view .hp-btn-primary:active,
  #main-content .hp-view .hp-btn-quiet:active,
  #main-content .hp-view .hp-btn-secondary:active,
  .hp-view .hp-segmented > label.btn:active {
    transform: none;
  }

  #main-content .hp-view .hp-btn-primary,
  #main-content .hp-view .hp-btn-quiet,
  #main-content .hp-view .hp-btn-secondary,
  #main-content .hp-view .hp-segmented > label.btn {
    transition: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  #main-content .hp-view .hp-table thead th {
    background-color: var(--bs-body-bg) !important;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  .hp-view .hp-surface,
  .hp-view .hp-table tbody tr {
    border-color: var(--ui-field-border);
  }

  #main-content .hp-view .hp-table thead th {
    border-bottom: 2px solid var(--bs-body-color);
    color: var(--bs-body-color);
  }

  .hp-view .hp-date,
  .hp-view .hp-name-date {
    color: var(--bs-body-color);
  }
}

/* ---------- View: admin-entity ---------- */

/* Organization settings: flat header, a logo section and two form sections on the body surface,
   plus a save bar that only appears with unsaved changes (same pattern as profile).
   Every rule is scoped to .ae-view; controls carry #main-content to win over unified-styles.css.
   Modals of this view (tutorial, crop, delete) keep the shared modal system. */
.ae-view {
  --ae-fill: var(--ui-accent);
  --ae-fill-hover: var(--ui-accent-hover);
  --ae-fill-active: var(--ui-accent-active);
  max-width: 62rem;
  margin-inline: auto;
}

[data-bs-theme="dark"] .ae-view {
  --ae-fill: var(--ui-accent-active);
  --ae-fill-hover: var(--ui-accent-hover);
  --ae-fill-active: var(--ui-accent);
}

.ae-view.has-savebar {
  padding-bottom: 6rem !important;
}

.ae-header {
  margin: 0.5rem 0 1rem;
}

#main-content .ae-view .ae-title {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--bs-body-color);
}

.ae-subtitle {
  margin: 0.25rem 0 0;
  min-height: 1.25rem;
  color: var(--bs-secondary-color);
}

.ae-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-width: 24rem;
  margin-bottom: 1rem;
}

.ae-toolbar.d-none {
  display: none;
}

.ae-field-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--bs-secondary-color);
}

.ae-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.ae-stack.d-none {
  display: none;
}

.ae-section {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--border-radius, 0.75rem);
  padding: 1.25rem 1.5rem;
}

#main-content .ae-view .ae-section-title {
  margin: 0 0 1rem;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--bs-body-color);
}

.ae-hint {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--bs-secondary-color);
}

.ae-hint-top {
  margin: 0.75rem 0 0;
}

.ae-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.ae-span-all {
  grid-column: 1 / -1;
}

.ae-switch {
  margin-top: 1rem;
}

/* --- Logo --- */
.ae-logo-row {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.admin-entity-logo-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 112px;
  height: 112px;
  overflow: hidden;
  border: 1px dashed var(--ui-field-border);
  border-radius: 0.75rem;
  background: var(--bs-tertiary-bg);
}

.admin-entity-logo-preview {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.admin-entity-logo-preview.d-none,
.admin-entity-logo-placeholder.d-none {
  display: none;
}

.admin-entity-logo-placeholder {
  padding: 0.5rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--bs-secondary-color);
}

.ae-logo-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.ae-btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.ae-btn-row .invalid-feedback {
  flex-basis: 100%;
}

/* --- Emails and phones --- */
.ae-list-block {
  margin-top: 1.25rem;
}

.ae-list-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.ae-counter {
  font-size: 0.8125rem;
  color: var(--bs-secondary-color);
  direction: ltr;
  unicode-bidi: isolate;
}

.ae-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 34rem;
}

/* --- Buttons --- */
#main-content .ae-view .btn.ae-btn-primary,
#main-content .ae-view .btn.ae-btn-secondary,
#main-content .ae-view .btn.ae-btn-quiet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-height: 42px;
  padding: 0.4rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.25;
  box-shadow: none;
  transform: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

#main-content .ae-view .btn .material-symbols-rounded {
  font-size: 1.125rem;
  line-height: 1;
}

#main-content .ae-view .btn.ae-btn-primary {
  background-color: var(--ae-fill);
  border: 1px solid var(--ae-fill);
  color: #fff;
}

#main-content .ae-view .btn.ae-btn-primary:hover:not(:disabled) {
  background-color: var(--ae-fill-hover);
  border-color: var(--ae-fill-hover);
  color: #fff;
}

#main-content .ae-view .btn.ae-btn-primary:active:not(:disabled) {
  background-color: var(--ae-fill-active);
  border-color: var(--ae-fill-active);
  transform: scale(0.97);
}

#main-content .ae-view .btn.ae-btn-secondary {
  background-color: transparent;
  border: 1px solid var(--ui-field-border);
  color: var(--bs-body-color);
}

#main-content .ae-view .btn.ae-btn-secondary:hover:not(:disabled) {
  background-color: var(--ui-accent-tint);
  border-color: var(--ui-accent);
  color: var(--ui-accent-text);
}

#main-content .ae-view .btn.ae-btn-quiet {
  background-color: transparent;
  border: 1px solid transparent;
  color: var(--ui-accent-text);
}

#main-content .ae-view .btn.ae-btn-quiet:hover:not(:disabled) {
  background-color: var(--ui-accent-tint);
  color: var(--ui-accent-text);
}

#main-content .ae-view .btn.ae-btn-secondary:active:not(:disabled),
#main-content .ae-view .btn.ae-btn-quiet:active:not(:disabled) {
  transform: scale(0.97);
}

#main-content .ae-view .btn:disabled {
  opacity: 0.55;
}

#main-content .ae-view .btn:focus-visible {
  outline: 2px solid var(--ui-accent-text);
  outline-offset: 2px;
  box-shadow: none;
}

#main-content .ae-view .form-control,
#main-content .ae-view .form-select {
  border-color: var(--ui-field-border);
}

#main-content .ae-view .ae-rows .btn-outline-secondary {
  min-width: 42px;
  min-height: 42px;
  border-color: var(--ui-field-border);
  color: var(--bs-body-color);
}

/* --- Save bar --- */
.ae-view .ae-savebar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 1030;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--bs-body-bg) 80%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--bs-border-color);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
  animation: ae-bar-in 0.2s ease-out;
}

.ae-view .ae-savebar[hidden] {
  display: none;
}

@media (prefers-reduced-transparency: reduce) {
  .ae-view .ae-savebar {
    background: var(--bs-body-bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

.ae-savebar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  max-width: 62rem;
  margin-inline: auto;
}

.ae-savebar-text {
  margin: 0;
  font-weight: 600;
  color: var(--bs-body-color);
}

.ae-savebar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

@keyframes ae-bar-in {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* --- Skeleton --- */
.ae-skel {
  background: linear-gradient(
    90deg,
    var(--bs-tertiary-bg) 25%,
    var(--bs-secondary-bg) 50%,
    var(--bs-tertiary-bg) 75%
  );
  background-size: 200% 100%;
  animation: ae-shimmer 1.5s infinite;
  border-radius: 6px;
}

@keyframes ae-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.ae-skel-line {
  height: 16px;
}

.ae-skel-w-40 {
  width: 40%;
  margin-bottom: 1rem;
}

.ae-skel-logo {
  width: 112px;
  height: 112px;
  border-radius: 0.75rem;
}

.ae-skel-field {
  height: 42px;
  border-radius: 0.5rem;
}

/* --- Small screens --- */
@media (max-width: 991.98px) {
  .ae-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 767.98px) {
  .ae-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .ae-section {
    padding: 1rem;
  }

  #main-content .ae-view .form-control,
  #main-content .ae-view .form-select,
  #main-content .ae-view .phone-input-group .phone-country-toggle,
  #main-content .ae-view .btn.ae-btn-primary,
  #main-content .ae-view .btn.ae-btn-secondary,
  #main-content .ae-view .btn.ae-btn-quiet {
    min-height: 44px;
  }
}

@media (max-width: 575.98px) {
  .ae-logo-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .ae-savebar-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .ae-savebar-actions {
    justify-content: flex-end;
  }

  .ae-savebar-actions .btn {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ae-view .ae-savebar,
  .ae-skel {
    animation: none;
  }

  #main-content .ae-view .btn {
    transition: none;
  }

  #main-content .ae-view .btn:active:not(:disabled) {
    transform: none;
  }
}

@media (prefers-contrast: more) {
  .ae-section,
  .ae-view .ae-savebar {
    border-color: var(--bs-body-color);
  }
}

/* rtl.css resets the background of every .btn in RTL; the filled button gets it back */
[dir="rtl"] #main-content .ae-view .btn.ae-btn-primary {
  background-color: var(--ae-fill) !important;
}
