html:has(body.epicrisis-page) {
  scroll-behavior: smooth;
}

@layer organisms {
  .epicrisis-shell {
    background:
      radial-gradient(circle at top left, rgb(255 255 255 / 0.3), transparent 18rem),
      radial-gradient(circle at bottom right, rgb(81 131 196 / 0.18), transparent 24rem),
      var(--color-brand-gradient-soft),
      var(--color-surface-muted);
    color: var(--color-text);
  }

  .epicrisis-content {
    width: min(100% - 2rem, 94rem);
    margin: 0 auto;
    padding: clamp(var(--space-4), 2vw, var(--space-7));
  }

  .epicrisis-top-sentinel {
    inline-size: 100%;
    block-size: 1px;
    margin-block-start: -1px;
    pointer-events: none;
  }

  .epicrisis-sections {
    gap: clamp(var(--space-4), 2vw, var(--space-6));
  }

  .epicrisis-header-actions {
    justify-content: center;
  }

  .epicrisis-header-actions .ui-button--ghost {
    border-color: transparent;
    background: transparent;
    color: var(--cidti-white);
    box-shadow: none;
  }

  .epicrisis-header-actions .ui-button--ghost:hover,
  .epicrisis-header-actions .ui-button--ghost:focus-visible {
    border-color: rgb(255 255 255 / 0.9);
    background: rgb(255 255 255 / 0.96);
    color: #16324e;
  }

  .epicrisis-hero {
    overflow: hidden;
    margin-top: var(--space-12);
    padding: clamp(var(--space-4), 2vw, var(--space-6));
  }

  .epicrisis-hero__copy {
    display: grid;
    gap: var(--space-4);
  }

  .epicrisis-hero__heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
  }

  .epicrisis-hero__heading h1 {
    margin: 0;
  }

  .epicrisis-hero__summary {
    margin-bottom: 0;
  }

  .epicrisis-kv-grid {
    display: grid;
    gap: var(--space-3);
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .epicrisis-kv {
    display: grid;
    gap: var(--space-1);
  }

  .epicrisis-kv span {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .epicrisis-kv strong {
    font-size: var(--font-size-sm);
  }

  .epicrisis-kv small {
    color: var(--color-text-subtle);
    font-size: var(--font-size-xs);
  }

  .epicrisis-hero__stats {
    align-content: start;
  }

  .epicrisis-quality {
    display: grid;
    gap: var(--space-4);
    border-left: 0.35rem solid var(--color-success, #16794b);
    padding: clamp(var(--space-4), 2vw, var(--space-5));
  }

  .epicrisis-quality--warning {
    border-left-color: var(--color-warning, #b86b00);
  }

  .epicrisis-quality__header {
    display: flex;
    flex-wrap: wrap;
    align-items: start;
    justify-content: space-between;
    gap: var(--space-3);
  }

  .epicrisis-quality__header h2 {
    margin: var(--space-1) 0 0;
    color: var(--color-brand-support);
    font-size: clamp(1.15rem, 1.5vw, 1.4rem);
  }

  .epicrisis-quality__status {
    border: 1px solid color-mix(in srgb, var(--color-success, #16794b) 35%, white);
    border-radius: 999px;
    background: color-mix(in srgb, var(--color-success, #16794b) 9%, white);
    color: var(--color-success, #16794b);
    padding: var(--space-1) var(--space-3);
    font-size: var(--font-size-xs);
    font-weight: 800;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  .epicrisis-quality--warning .epicrisis-quality__status {
    border-color: color-mix(in srgb, var(--color-warning, #b86b00) 35%, white);
    background: color-mix(in srgb, var(--color-warning, #b86b00) 9%, white);
    color: var(--color-warning, #925500);
  }

  .epicrisis-quality__grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-3);
    margin: 0;
  }

  .epicrisis-quality__grid > div {
    display: grid;
    gap: var(--space-1);
    border-top: 1px solid color-mix(in srgb, var(--color-brand-support) 16%, white);
    padding-top: var(--space-2);
  }

  .epicrisis-quality__grid dt {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .epicrisis-quality__grid dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: var(--font-size-sm);
    font-weight: 700;
  }

  .epicrisis-quality__warnings {
    border-radius: var(--radius-md, 0.5rem);
    background: color-mix(in srgb, var(--color-warning, #b86b00) 8%, white);
    padding: var(--space-3);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
  }

  .epicrisis-quality__warnings ul {
    margin: var(--space-2) 0 0;
    padding-left: var(--space-5);
  }

  .epicrisis-status {
    max-width: 44rem;
    margin: var(--space-12) auto 0;
  }

  .epicrisis-status__heading {
    display: grid;
    gap: var(--space-2);
  }

  .epicrisis-status__heading h1 {
    margin: 0;
  }

  .epicrisis-status__meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    color: var(--color-text-subtle);
    font-size: var(--font-size-sm);
  }

  .epicrisis-status__message {
    color: var(--color-text-muted);
    line-height: var(--line-height-relaxed);
  }

  .epicrisis-status__actions {
    margin-top: var(--space-2);
  }

  .epicrisis-page .container {
    display: grid;
    gap: clamp(var(--space-4), 2vw, var(--space-6));
  }

  .epicrisis-page .card {
    border: var(--border-width) solid color-mix(in srgb, var(--color-brand-support) 14%, white);
    border-radius: 1rem;
    background:
      radial-gradient(circle at top right, rgb(255 255 255 / 0.48), transparent 18rem),
      linear-gradient(180deg, rgb(255 255 255 / 0.96), rgb(255 255 255 / 0.9));
    box-shadow: var(--shadow-sm);
    padding: clamp(var(--space-4), 2vw, var(--space-6));
  }

  .epicrisis-page .card h2 {
    margin-bottom: var(--space-4);
    border-bottom: 2px solid color-mix(in srgb, var(--color-brand-primary) 32%, white);
    color: var(--color-brand-support);
    padding-bottom: var(--space-3);
    font-size: clamp(1.45rem, 2vw, 1.85rem);
  }

  .epicrisis-page .card h3 {
    margin: var(--space-5) 0 var(--space-3);
    border-left: 4px solid var(--color-brand-primary);
    color: var(--color-brand-support);
    font-size: clamp(1.1rem, 1.8vw, 1.35rem);
    padding-left: var(--space-3);
  }

  .epicrisis-page .card h4,
  .epicrisis-page .card h5 {
    color: var(--color-brand-support);
  }

  .epicrisis-page .section-header {
    margin: calc(-1 * clamp(var(--space-4), 2vw, var(--space-6))) calc(-1 * clamp(var(--space-4), 2vw, var(--space-6)))
      var(--space-5);
    border-radius: 1rem 1rem 0 0;
    background: linear-gradient(
      135deg,
      color-mix(in srgb, var(--color-brand-support) 90%, black) 0%,
      color-mix(in srgb, var(--color-brand-support) 70%, var(--color-brand-primary)) 100%
    );
    color: var(--cidti-white);
    font-size: clamp(1.1rem, 1.7vw, 1.3rem);
    font-weight: 700;
    padding: var(--space-4) clamp(var(--space-4), 2vw, var(--space-6));
  }

  .epicrisis-page .documento-info,
  .epicrisis-page .resumen-texto,
  .epicrisis-page .hallazgos-section {
    border-radius: 1rem;
    background: color-mix(in srgb, white 84%, var(--color-brand-support-soft) 16%);
    color: var(--color-text);
    padding: var(--space-4);
  }

  .epicrisis-page .documento-info {
    border-left: 4px solid var(--color-brand-support);
  }

  .epicrisis-page .resumen-texto {
    border-left: 4px solid var(--color-brand-primary);
    line-height: var(--line-height-loose);
  }

  .epicrisis-page .hallazgos-section {
    border-left: 4px solid var(--color-brand-support);
    line-height: var(--line-height-loose);
  }

  .epicrisis-page .hallazgos-section h4 {
    margin-top: 0;
  }

  .epicrisis-page table {
    width: 100%;
    margin: var(--space-4) 0;
    border-collapse: collapse;
    overflow: hidden;
    border-radius: var(--radius-lg);
  }

  .epicrisis-page th,
  .epicrisis-page td {
    border: 1px solid var(--color-border);
    padding: 0.85rem 0.9rem;
    text-align: left;
    vertical-align: top;
  }

  .epicrisis-page th {
    background: color-mix(in srgb, var(--color-brand-support) 90%, white);
    color: var(--cidti-white);
    font-size: var(--font-size-sm);
    font-weight: 700;
  }

  .epicrisis-page tr:nth-child(even) {
    background: color-mix(in srgb, var(--color-brand-support-soft) 36%, white);
  }

  .epicrisis-page .muted {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
  }

  .epicrisis-page .badge {
    display: inline-flex;
    align-items: center;
    min-height: 1.75rem;
    border-radius: var(--radius-pill);
    font-size: var(--font-size-xs);
    font-weight: 700;
    margin-left: var(--space-2);
    padding-inline: var(--space-3);
  }

  .epicrisis-page .badge-pre {
    background: color-mix(in srgb, var(--color-info-bg) 78%, white);
    color: var(--color-info);
  }

  .epicrisis-page .badge-post {
    background: color-mix(in srgb, var(--color-success-bg) 84%, white);
    color: var(--color-success);
  }

  .epicrisis-page .badge-post--warning {
    background: color-mix(in srgb, var(--color-warning-bg) 90%, white);
    color: var(--color-warning);
  }

  .epicrisis-page .btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-4);
  }

  .epicrisis-page .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    border: var(--border-width) solid transparent;
    border-radius: var(--radius-md);
    background: var(--color-brand-support);
    color: var(--cidti-white);
    cursor: pointer;
    font-size: var(--font-size-sm);
    font-weight: 700;
    padding: 0.7rem 1rem;
    text-decoration: none;
    transition:
      background var(--transition-fast),
      transform var(--transition-fast);
  }

  .epicrisis-page .btn:hover {
    background: color-mix(in srgb, var(--color-brand-support) 80%, black);
    transform: translateY(-1px);
  }

  .epicrisis-page .btn-secondary {
    background: var(--color-text-muted);
  }

  .epicrisis-page .btn-success {
    background: var(--color-success);
  }

  .epicrisis-selection-note {
    margin-bottom: var(--space-3);
  }

  .epicrisis-inline-status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
  }

  .selection-grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .selection-grid--supporting {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: var(--space-4);
  }

  .selection-box {
    display: grid;
    gap: var(--space-3);
    align-content: start;
    border: var(--border-width) solid color-mix(in srgb, var(--color-brand-primary) 16%, white);
    border-radius: 1rem;
    background: color-mix(in srgb, white 90%, var(--color-brand-primary-soft) 10%);
    padding: var(--space-4);
  }

  .selection-box--stacked {
    margin-top: var(--space-4);
  }

  .selection-box h4 {
    margin: 0;
  }

  .selection-list {
    min-height: 16rem;
    max-height: 20rem;
    overflow-y: auto;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface-raised);
    padding: var(--space-3);
  }

  .selection-list--medications {
    max-height: min(32rem, 60vh);
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-gutter: stable;
  }

.selection-item {
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
    font-size: var(--font-size-sm);
  }

  .selection-item + .selection-item {
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid color-mix(in srgb, var(--color-border) 80%, white);
  }

  .selection-item--stacked {
    display: grid;
    gap: var(--space-1);
  }

  .selection-item input[type="checkbox"] {
    margin-top: 0.12rem;
  }

  .selection-item-content {
    display: grid;
    gap: var(--space-1);
    min-width: 0;
  }

  .selection-extra,
  .aid-filter,
  .epicrisis-page input[type="text"] {
    width: 100%;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-raised);
    color: var(--color-text);
    font: inherit;
    padding: 0.75rem 0.85rem;
  }

  .selection-extra {
    min-height: 6.75rem;
    resize: vertical;
  }

  .selection-extra:focus,
  .aid-filter:focus,
  .epicrisis-page input[type="text"]:focus,
  .epicrisis-page textarea:focus,
  .epicrisis-page select:focus {
    border-color: var(--color-brand-primary);
    box-shadow: var(--focus-ring);
    outline: none;
  }

  .aid-badges {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
  }

  .aid-badge {
    display: inline-flex;
    align-items: center;
    min-height: 1.6rem;
    border: var(--border-width) solid color-mix(in srgb, var(--color-border-strong) 75%, white);
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, white 78%, var(--color-brand-support-soft) 22%);
    color: var(--color-text-muted);
    font-size: 0.7rem;
    line-height: 1;
    padding-inline: 0.45rem;
    white-space: nowrap;
  }

  .aid-badge.alert {
    border-color: var(--color-warning-border);
    background: var(--color-warning-bg);
    color: var(--color-warning);
  }

  .aid-badge.blocked {
    border-color: var(--color-error-border);
    background: var(--color-error-bg);
    color: var(--color-error);
  }

  .epicrisis-page pre {
    font-family: var(--font-secondary);
  }

  .epicrisis-scroll-top {
    position: fixed;
    inset-inline-end: clamp(var(--space-3), 2vw, var(--space-5));
    inset-block-end: clamp(var(--space-4), 3vw, var(--space-6));
    z-index: var(--z-header);
    border-color: rgb(255 255 255 / 0.7);
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, white 72%, var(--color-brand-primary) 28%);
    box-shadow:
      0 18px 42px rgb(38 50 56 / 0.22),
      0 6px 18px rgb(38 50 56 / 0.12);
    color: var(--color-brand-support);
    backdrop-filter: blur(16px);
    transition:
      opacity var(--transition-fast),
      transform var(--transition-fast),
      visibility var(--transition-fast),
      background var(--transition-fast),
      color var(--transition-fast),
      border-color var(--transition-fast);
  }

  .epicrisis-scroll-top svg {
    inline-size: 1rem;
    block-size: 1rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
  }

  .epicrisis-scroll-top:hover {
    border-color: color-mix(in srgb, var(--color-brand-support) 42%, white);
    background: var(--color-brand-support);
    color: var(--cidti-white);
  }

  body.epicrisis-scroll-top-managed .epicrisis-scroll-top {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(0.75rem) scale(0.96);
  }

  body.epicrisis-scroll-top-managed .epicrisis-scroll-top.epicrisis-scroll-top--visible {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
  }

  .epicrisis-print-frame {
    position: fixed;
    right: 0;
    bottom: 0;
    width: 0;
    height: 0;
    border: 0;
    visibility: hidden;
  }

  .agente-qx-status--error {
    color: #b91c1c;
  }

  .agente-qx-status--idle {
    color: #4b5563;
  }

  .is-hidden {
    display: none !important;
  }

  .epicrisis-stack-lg {
    display: grid;
    gap: var(--space-4);
  }

  .epicrisis-mt-lg {
    margin-top: var(--space-5);
  }

  .epicrisis-panel {
    border-left: 5px solid var(--color-brand-primary);
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, white 86%, var(--color-brand-support-soft) 14%);
    padding: var(--space-5);
  }

  .epicrisis-panel--patient {
    background: #e8f4fd;
    border-left-color: #0d6efd;
  }

  .epicrisis-panel--summary {
    background: #f8f9fa;
    border-left-color: #007bff;
  }

  .epicrisis-panel--recommendations {
    background: color-mix(in srgb, var(--color-surface) 90%, var(--color-success) 10%);
    border-left-color: var(--color-success);
  }

  .epicrisis-panel--procedures {
    background: #e7f3ff;
    border-left-color: #0066cc;
  }

  .epicrisis-panel--medications {
    background: color-mix(in srgb, var(--color-surface) 90%, var(--color-brand-primary) 10%);
    border-left-color: var(--color-brand-primary-dark);
  }

  .epicrisis-panel--antecedents {
    background: color-mix(
      in srgb,
      var(--color-surface) 92%,
      var(--color-brand-support) 8%
    );
    border-left-color: var(--color-brand-support);
  }

  .epicrisis-panel--success {
    background: #f0f8f0;
    border-left-color: #28a745;
  }

  .epicrisis-panel--neutral {
    border-left-width: 4px;
    background: #f8f9fa;
    border-left-color: #6c757d;
    padding: var(--space-4);
  }

  .epicrisis-panel--info {
    background: #f3f4f6;
    border-left-color: #8b5cf6;
    padding: var(--space-4);
  }

  .epicrisis-panel--warning {
    background: #fef3c7;
    border-left-color: #f59e0b;
  }

  .epicrisis-panel--glosa {
    background: color-mix(in srgb, var(--color-surface) 84%, var(--color-warning) 16%);
    border-left-color: var(--color-warning);
  }

  .epicrisis-panel__title {
    margin: 0 0 var(--space-3);
    color: var(--color-brand-support);
    font-size: 1.1em;
  }

  .epicrisis-panel__title--underlined {
    border-bottom: 2px solid currentColor;
    font-size: 1.2em;
    padding-bottom: var(--space-2);
  }

  .epicrisis-panel--patient .epicrisis-panel__title,
  .epicrisis-panel--patient .epicrisis-key-value__value--accent {
    color: #0d6efd;
  }

  .epicrisis-panel--summary .epicrisis-panel__title {
    color: #2a5298;
  }

  .epicrisis-panel--procedures .epicrisis-panel__title {
    color: #0066cc;
  }

  .epicrisis-panel--medications .epicrisis-panel__title {
    color: color-mix(in srgb, var(--color-text) 38%, var(--color-brand-primary-dark) 62%);
  }

  .medication-matrix-wrap {
    overflow-x: auto;
    border: 1px solid color-mix(in srgb, var(--color-border) 76%, var(--color-brand-primary) 24%);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
  }

  .medication-matrix {
    width: 100%;
    min-width: 52rem;
    border-collapse: collapse;
  }

  .medication-matrix :is(th, td) {
    padding: var(--space-3);
    border-bottom: 1px solid color-mix(in srgb, var(--color-border) 86%, transparent);
    text-align: left;
    vertical-align: top;
  }

  .medication-matrix th {
    background: color-mix(in srgb, var(--color-surface) 91%, var(--color-brand-primary) 9%);
    color: color-mix(in srgb, var(--color-text) 74%, var(--color-brand-support) 26%);
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .medication-matrix td small {
    display: block;
    margin-top: var(--space-1);
    color: var(--color-text-muted);
    font-size: 0.72rem;
  }

  .medication-matrix__quantity {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
  }

  .medication-matrix__reconciliation {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin-top: var(--space-2);
    color: var(--color-text-muted);
    font-size: 0.68rem;
    line-height: 1.4;
    text-transform: capitalize;
  }

  .medication-statuses {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
  }

  .medication-status {
    border: 1px solid color-mix(in srgb, var(--color-border) 72%, var(--color-text-muted) 28%);
    border-radius: var(--radius-pill);
    background: var(--color-surface-muted);
    padding: 0.16rem 0.45rem;
    color: var(--color-text-muted);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: capitalize;
  }

  .medication-status--administrado {
    border-color: color-mix(in srgb, var(--color-success) 34%, var(--color-border));
    background: color-mix(in srgb, var(--color-surface) 88%, var(--color-success) 12%);
    color: var(--color-success);
  }

  .medication-status--formulado,
  .medication-status--ordenado {
    border-color: color-mix(in srgb, var(--color-info) 32%, var(--color-border));
    background: color-mix(in srgb, var(--color-surface) 89%, var(--color-info) 11%);
    color: var(--color-info);
  }

  .medication-status--facturado {
    border-color: color-mix(in srgb, var(--color-brand-accent) 32%, var(--color-border));
    background: color-mix(in srgb, var(--color-surface) 90%, var(--color-brand-accent) 10%);
    color: var(--color-brand-accent);
  }

  .medication-pertinence-wrap {
    display: flex;
    flex-wrap: wrap;
    margin-top: var(--space-2);
  }

  .medication-pertinence {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    padding: 0.18rem 0.5rem;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.2;
    text-transform: capitalize;
  }

  .medication-pertinence--pertinente {
    border-color: color-mix(in srgb, var(--color-success) 34%, var(--color-border));
    background: color-mix(in srgb, var(--color-surface) 88%, var(--color-success) 12%);
    color: color-mix(in srgb, var(--color-success) 82%, var(--color-text) 18%);
  }

  .medication-pertinence--revisar {
    border-color: color-mix(in srgb, var(--color-warning) 34%, var(--color-border));
    background: color-mix(in srgb, var(--color-surface) 88%, var(--color-warning) 12%);
    color: color-mix(in srgb, var(--color-warning) 82%, var(--color-text) 18%);
  }

  .medication-pertinence--posible_glosa {
    border-color: color-mix(in srgb, var(--color-error) 34%, var(--color-border));
    background: color-mix(in srgb, var(--color-surface) 88%, var(--color-error) 12%);
    color: color-mix(in srgb, var(--color-error) 84%, var(--color-text) 16%);
  }

  .medication-glosa {
    margin-top: var(--space-5);
    border-top: 1px solid color-mix(in srgb, var(--color-warning) 32%, var(--color-border));
    padding-top: var(--space-4);
  }

  .medication-glosa__heading,
  .medication-glosa__item header,
  .medication-glosa__summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  .medication-glosa__heading,
  .medication-glosa__item header {
    justify-content: space-between;
  }

  .medication-glosa__item header > span:first-child {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 0;
  }

  .medication-glosa__heading h4,
  .medication-glosa__eyebrow {
    margin: 0;
  }

  .medication-glosa__eyebrow {
    color: var(--color-text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .medication-glosa__list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
    gap: var(--space-3);
    margin-top: var(--space-3);
  }

  .medication-glosa__item {
    border: 1px solid color-mix(in srgb, var(--color-warning) 28%, var(--color-border));
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--color-surface) 94%, var(--color-warning) 6%);
    padding: var(--space-3);
  }

  .medication-glosa__item--posible_glosa {
    border-color: color-mix(in srgb, var(--color-error) 30%, var(--color-border));
    background: color-mix(in srgb, var(--color-surface) 95%, var(--color-error) 5%);
  }

  .medication-glosa__item :is(ul, p, details) {
    margin: var(--space-2) 0 0;
  }

  .medication-glosa__presentation {
    color: var(--color-text-muted);
    font-size: 0.72rem;
    font-weight: 500;
  }

  .medication-glosa__scheme,
  .medication-glosa__quantities,
  .medication-glosa__chain {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .medication-glosa__scheme span:not(:last-child)::after,
  .medication-glosa__quantities span:not(:last-child)::after {
    margin-left: var(--space-2);
    color: var(--color-text-muted);
    content: "•";
  }

  .medication-support {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    padding: 0.16rem 0.45rem;
    background: color-mix(in srgb, var(--color-surface) 94%, var(--color-text-muted) 6%);
    color: var(--color-text-muted);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: capitalize;
  }

  .medication-support--presente {
    border-color: color-mix(in srgb, var(--color-success) 34%, var(--color-border));
    background: color-mix(in srgb, var(--color-surface) 90%, var(--color-success) 10%);
    color: color-mix(in srgb, var(--color-success) 82%, var(--color-text) 18%);
  }

  .medication-support--ausente {
    border-color: color-mix(in srgb, var(--color-error) 34%, var(--color-border));
    background: color-mix(in srgb, var(--color-surface) 92%, var(--color-error) 8%);
    color: color-mix(in srgb, var(--color-error) 84%, var(--color-text) 16%);
  }

  .medication-glosa__association {
    text-transform: capitalize;
  }

  .medication-glosa__item ul {
    padding-left: var(--space-5);
  }

  .medication-glosa__item :is(p, li, summary) {
    color: color-mix(in srgb, var(--color-text) 78%, var(--color-text-muted) 22%);
    font-size: 0.82rem;
    line-height: 1.5;
  }

  .medication-glosa__item summary {
    cursor: pointer;
    font-weight: 700;
  }

  .epicrisis-panel--antecedents .epicrisis-panel__title {
    color: color-mix(in srgb, var(--color-text) 35%, var(--color-brand-support) 65%);
  }

  .antecedents-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
  }

  .antecedents-heading .epicrisis-panel__title {
    margin: 0;
    font-size: 1.2rem;
    letter-spacing: -0.01em;
  }

  .antecedents-heading__eyebrow {
    margin: 0 0 0.2rem;
    color: var(--color-text-muted);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.11em;
    text-transform: uppercase;
  }

  .antecedents-status {
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-brand-support);
    font-size: 0.72rem;
    font-weight: 800;
    padding: 0.35rem 0.65rem;
    white-space: nowrap;
  }

  .antecedents-status--review {
    border-color: var(--color-warning-border);
    background: var(--color-warning-bg);
    color: var(--color-warning);
  }

  .antecedents-alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    border: 1px solid var(--color-warning-border);
    border-radius: var(--radius-md);
    background: var(--color-warning-bg);
    margin-bottom: var(--space-4);
    color: var(--color-warning);
    padding: var(--space-3);
  }

  .antecedents-alert svg {
    flex: 0 0 1.1rem;
    width: 1.1rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
  }

  .antecedents-alert p {
    margin: 0;
    font-size: 0.86rem;
    line-height: 1.45;
  }

  .antecedents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr));
    gap: var(--space-3);
  }

  .antecedent-card {
    min-width: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--color-surface) 82%, transparent);
    padding: var(--space-3);
  }

  .antecedent-card--alergico {
    border-color: var(--color-error-border);
    background: color-mix(in srgb, var(--color-surface) 45%, var(--color-error-bg) 55%);
    box-shadow: inset 3px 0 0 var(--color-error);
  }

  .antecedent-card--discordant {
    border-color: var(--color-warning-border);
  }

  .antecedent-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
  }

  .antecedent-card__header h5 {
    margin: 0;
    color: color-mix(in srgb, var(--color-text) 50%, var(--color-brand-support) 50%);
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .antecedent-card--alergico .antecedent-card__header h5 {
    color: var(--color-error);
  }

  .antecedent-card__header > span {
    display: grid;
    min-width: 1.35rem;
    min-height: 1.35rem;
    place-items: center;
    border-radius: 50%;
    background: color-mix(
      in srgb,
      var(--color-surface) 84%,
      var(--color-brand-support) 16%
    );
    color: var(--color-brand-support);
    font-size: 0.68rem;
    font-weight: 800;
  }

  .antecedent-card__values,
  .antecedents-negatives__values {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .antecedent-chip,
  .antecedents-negatives__values span {
    max-width: 100%;
    border: 1px solid var(--color-border);
    border-radius: 0.45rem;
    background: var(--color-surface-muted);
    color: var(--color-text);
    font-size: 0.82rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
    padding: 0.28rem 0.5rem;
  }

  .antecedent-chip--discordant,
  .antecedents-negatives__values .is-discordant {
    border-color: var(--color-warning-border);
    background: var(--color-warning-bg);
  }

  .antecedent-evidence {
    margin-top: var(--space-2);
    border-top: 1px dashed var(--color-warning-border);
    padding-top: var(--space-2);
  }

  .antecedent-evidence summary,
  .antecedents-negatives summary {
    color: color-mix(in srgb, var(--color-text) 70%, var(--color-warning) 30%);
    cursor: pointer;
    font-size: 0.76rem;
    font-weight: 800;
  }

  .antecedent-evidence p {
    display: grid;
    gap: 0.2rem;
    margin: var(--space-2) 0 0;
    color: var(--color-text-muted);
    font-size: 0.74rem;
    line-height: 1.4;
  }

  .antecedent-evidence q {
    overflow-wrap: anywhere;
  }

  .antecedents-negatives {
    margin-top: var(--space-3);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--color-surface) 55%, transparent);
    padding: var(--space-3);
  }

  .antecedents-negatives summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    color: var(--color-text);
  }

  .antecedents-negatives summary small {
    color: var(--color-text-subtle);
    font-weight: 600;
  }

  .antecedents-negatives__values {
    margin-top: var(--space-3);
  }

  .antecedents-negatives__values span {
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
  }

  .epicrisis-panel--success .epicrisis-panel__title {
    color: #28a745;
  }

  .epicrisis-panel--info .epicrisis-panel__title {
    color: #4b5563;
  }

  .epicrisis-panel--warning .epicrisis-panel__title,
  .epicrisis-panel--warning .epicrisis-callout,
  .epicrisis-panel--warning .epicrisis-note {
    color: #78350f;
  }

  .epicrisis-panel--glosa .epicrisis-note {
    color: color-mix(in srgb, var(--color-warning) 72%, var(--color-text) 28%);
  }

  .epicrisis-callout {
    margin: 0;
    color: var(--color-text);
    font-size: 0.95em;
    line-height: var(--line-height-relaxed);
  }

  .epicrisis-callout + .epicrisis-callout {
    margin-top: var(--space-3);
  }

  .epicrisis-note {
    margin: 0 0 var(--space-3);
    font-size: 0.95em;
    line-height: var(--line-height-relaxed);
  }

  .epicrisis-text-justified {
    margin: 0;
    color: #333;
    line-height: 1.8;
    text-align: justify;
  }

  .epicrisis-list {
    margin: 0;
    padding-left: 1.6rem;
    line-height: 2;
  }

  .epicrisis-list li {
    color: #333;
  }

  .epicrisis-list li + li {
    margin-top: var(--space-2);
  }

  .epicrisis-recommendation-group + .epicrisis-recommendation-group {
    margin-top: var(--space-4);
  }

  .epicrisis-recommendation-group h5 {
    margin: 0 0 var(--space-2);
  }

  .epicrisis-recommendation-group li > span {
    display: block;
  }

  .epicrisis-list--mono li {
    font-family: "Courier New", monospace;
    font-size: 0.95em;
  }

  .epicrisis-patient-table {
    margin: 0;
    background: white;
  }

  .epicrisis-patient-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }

  .epicrisis-kv-cell {
    display: grid;
    gap: var(--space-1);
    min-width: 0;
    border: 1px solid color-mix(in srgb, #0d6efd 16%, white);
    border-radius: var(--radius-md);
    background: white;
    padding: var(--space-3);
  }

  .epicrisis-kv-cell--wide {
    grid-column: span 2;
  }

  .epicrisis-kv-cell span {
    color: #315f94;
    font-size: var(--font-size-xs);
    font-weight: 700;
    text-transform: uppercase;
  }

  .epicrisis-kv-cell strong {
    min-width: 0;
    overflow-wrap: anywhere;
    color: #1f2937;
    font-size: var(--font-size-sm);
    line-height: var(--line-height-snug);
  }

  .epicrisis-key-value {
    width: 35%;
    background: #f1f8ff;
    font-weight: 600;
  }

  .epicrisis-key-value__value--accent {
    color: #0d6efd;
    font-size: 1.05em;
    font-weight: 600;
  }

  .epicrisis-text-center {
    text-align: center;
  }

  .epicrisis-text-sm {
    font-size: 0.9em;
  }

  .epicrisis-col-35 {
    width: 35%;
  }

  .epicrisis-col-50 {
    width: 50%;
  }

  .epicrisis-col-65 {
    width: 65%;
  }

  .epicrisis-col-25 {
    width: 25%;
  }

  .epicrisis-col-15 {
    width: 15%;
  }

  .epicrisis-col-10 {
    width: 10%;
  }

  .section-header--violet {
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
  }

  @media (max-width: 720px) {
    .epicrisis-patient-grid {
      grid-template-columns: 1fr;
    }

    .epicrisis-kv-cell--wide {
      grid-column: auto;
    }

    .antecedents-grid {
      grid-template-columns: 1fr;
    }

    .antecedents-heading,
    .antecedents-negatives summary {
      align-items: flex-start;
      flex-direction: column;
    }
  }

  .soat-form-controls {
    display: flex;
    gap: var(--space-3);
  }

  .codigo-input-group {
    display: flex;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
  }

  .codigo-input-group input[name="codigo_soat"] {
    flex: 0 0 120px;
  }

  .codigo-input-group input[name="descripcion"] {
    flex: 1;
  }

  .codigo-input-remove {
    min-width: 2.5rem;
    padding-inline: 0.75rem;
  }

  .soat-results-list {
    display: grid;
    gap: var(--space-5);
  }

  .soat-summary {
    border: 2px solid #d1d5db;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
    margin-top: var(--space-5);
    padding: var(--space-5);
  }

  .soat-summary__title,
  .soat-block__title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0 0 var(--space-3);
  }

  .soat-summary__icon {
    font-size: 1.3em;
  }

  .soat-summary__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
  }

  .soat-summary__card {
    border-left: 4px solid #8b5cf6;
    border-radius: var(--radius-md);
    background: white;
    padding: var(--space-4);
    text-align: center;
  }

  .soat-summary__card--cie10 {
    border-left-color: #3b82f6;
  }

  .soat-summary__card--cups {
    border-left-color: #10b981;
  }

  .soat-summary__value {
    font-size: 2em;
    font-weight: 700;
    color: #8b5cf6;
  }

  .soat-summary__card--cie10 .soat-summary__value {
    color: #3b82f6;
  }

  .soat-summary__card--cups .soat-summary__value {
    color: #10b981;
  }

  .soat-summary__label {
    margin-top: var(--space-1);
    color: #6b7280;
    font-size: 0.9em;
  }

  .soat-result-card {
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    background: white;
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.05);
    margin-bottom: var(--space-5);
    padding: var(--space-5);
  }

  .soat-result-card__header {
    margin: calc(-1 * var(--space-5)) calc(-1 * var(--space-5)) var(--space-5);
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    padding: var(--space-4);
  }

  .soat-result-card__heading {
    margin: 0;
    color: white;
    font-size: 1.15em;
  }

  .soat-result-card__code {
    font-size: 1.1em;
    font-weight: 700;
  }

  .soat-result-card__description {
    margin: var(--space-2) 0 0;
    font-size: 0.95em;
    opacity: 0.95;
  }

  .soat-block {
    border-left: 5px solid #3b82f6;
    border-radius: var(--radius-lg);
    background: #dbeafe;
    margin-bottom: var(--space-4);
    padding: 18px;
  }

  .soat-block--cie10-secondary {
    border-left-color: #6366f1;
    background: #e0e7ff;
  }

  .soat-block--cups-primary {
    border-left-color: #10b981;
    background: #d1fae5;
  }

  .soat-block--cups-secondary {
    border-left-color: #34d399;
    background: #d1fae5;
  }

  .soat-block--analysis {
    border-left-color: #f59e0b;
    background: #fef3c7;
    margin-bottom: 0;
  }

  .soat-block__title {
    color: #1e40af;
    font-size: 1.1em;
  }

  .soat-block--cie10-secondary .soat-block__title {
    color: #4338ca;
    font-size: 1em;
  }

  .soat-block--cups-primary .soat-block__title {
    color: #065f46;
  }

  .soat-block--cups-secondary .soat-block__title {
    color: #047857;
    font-size: 1em;
  }

  .soat-block--analysis .soat-block__title {
    color: #92400e;
    font-size: 1em;
  }

  .soat-block__icon {
    font-size: 1.2em;
  }

  .soat-block__icon--lg {
    font-size: 1.3em;
  }

  .soat-entry {
    border: 1px solid #93c5fd;
    border-radius: var(--radius-md);
    background: white;
    padding: var(--space-4);
  }

  .soat-entry--secondary {
    border-color: #c7d2fe;
    margin-bottom: var(--space-3);
    padding: 12px;
  }

  .soat-entry--cups {
    border-color: #6ee7b7;
  }

  .soat-entry--cups-alt {
    border-color: #a7f3d0;
    margin-bottom: var(--space-3);
    padding: 12px;
  }

  .soat-entry--analysis {
    border-color: #fcd34d;
    max-height: 400px;
    overflow-y: auto;
  }

  .soat-entry__row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
  }

  .soat-entry__row--compact {
    gap: var(--space-2);
    margin-bottom: var(--space-2);
  }

  .soat-token {
    border-radius: var(--radius-md);
    background: #3b82f6;
    color: white;
    font-size: 1.05em;
    font-weight: 700;
    padding: 6px 14px;
  }

  .soat-token--secondary {
    border-radius: 4px;
    background: #6366f1;
    font-size: 0.9em;
    font-weight: 600;
    padding: 4px 10px;
  }

  .soat-token--cups {
    background: #10b981;
    letter-spacing: 1px;
  }

  .soat-token--cups-alt {
    border-radius: 4px;
    background: #34d399;
    font-size: 0.9em;
    font-weight: 600;
    letter-spacing: 0.5px;
    padding: 4px 10px;
  }

  .soat-entry__description {
    flex: 1;
    color: #1e40af;
    font-weight: 600;
  }

  .soat-entry__description--secondary {
    color: #4338ca;
    font-size: 0.9em;
    font-weight: 500;
  }

  .soat-entry__description--cups {
    color: #065f46;
    font-size: 0.95em;
  }

  .soat-entry__description--cups-alt {
    color: #047857;
    font-size: 0.9em;
    font-weight: 500;
  }

  .soat-justification {
    margin: var(--space-3) 0 0;
    border-radius: 4px;
    background: #f0f9ff;
    color: #374151;
    font-size: 0.9em;
    line-height: 1.6;
    padding: var(--space-3);
  }

  .soat-justification strong {
    color: #1e40af;
  }

  .soat-justification--secondary {
    margin: 6px 0 0;
    color: #6b7280;
    font-size: 0.85em;
    line-height: 1.5;
    padding-left: 12px;
  }

  .soat-justification--secondary em {
    font-style: italic;
  }

  .soat-justification--cups {
    background: #ecfdf5;
  }

  .soat-justification--cups strong {
    color: #065f46;
  }

  .soat-analysis-pre {
    margin: 0;
    color: #374151;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    font-size: 0.9em;
    line-height: 1.7;
    white-space: pre-wrap;
  }
}

.selection-item--procedure {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-3);
  overflow-wrap: anywhere;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--color-surface) 94%, var(--color-brand-primary) 6%);
  padding: var(--space-3);
  box-shadow: var(--shadow-sm);
}

.selection-list--procedures {
  overflow-x: hidden;
}

.selection-item--procedure + .selection-item--procedure {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: var(--border-width) solid var(--color-border);
}

.procedure-inclusion {
  align-self: flex-start;
}

.procedure-content {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: var(--space-1);
}

.procedure-code {
  color: var(--color-brand-support);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
}

.procedure-description,
.procedure-manual-input {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  color: var(--color-text);
  line-height: var(--line-height-base);
}

.procedure-manual-label {
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: 600;
}

.pdf-procedure-classification {
  width: 100%;
  min-width: 0;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  padding: var(--space-2);
  font: inherit;
  font-size: var(--font-size-xs);
}

.pdf-procedure-classification:focus-visible,
.procedure-inclusion input:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.procedure-remove {
  align-self: flex-start;
  color: var(--color-error);
}

.selection-item--medication {
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  overflow-wrap: anywhere;
}

.selection-medication-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  min-width: 0;
}

.selection-medication-name {
  color: var(--color-text);
  font-size: var(--font-size-sm);
  line-height: 1.45;
}

.selection-medication-presentation,
.selection-medication-codes {
  color: var(--color-text-muted);
  font-size: 0.7rem;
  line-height: 1.45;
}

.selection-medication-presentation {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.selection-medication-posology {
  margin-top: var(--space-1);
  color: var(--color-text);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.45;
}

.selection-medication-measurements {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2);
  color: var(--color-text);
  font-size: 0.75rem;
  line-height: 1.45;
}

.selection-medication-dose,
.selection-medication-quantity {
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}

.selection-medication-separator {
  color: var(--color-text-muted);
}

.selection-medication-quantity {
  color: color-mix(in srgb, var(--color-text) 72%, var(--color-brand-support) 28%);
}

.selection-medication-warning {
  display: block;
  margin-top: var(--space-1);
  color: var(--color-warning);
  font-size: 0.7rem;
  font-weight: 400;
}

.selection-medication-content .medication-statuses {
  margin-top: var(--space-2);
}

.selection-medication-reconciliation {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: 0.68rem;
  line-height: 1.4;
  text-transform: capitalize;
}

.selection-medication-supports {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.procedure-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.procedure-badge {
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
}

.procedure-badge--quirurgico { color: var(--color-error); background: var(--color-error-bg); }
.procedure-badge--no_quirurgico { color: var(--color-success); background: var(--color-success-bg); }
.procedure-badge--sin_clasificar { color: var(--color-warning); background: var(--color-warning-bg); }
.procedure-support-warning { color: var(--color-error); font-weight: 700; }

@media (max-width: 80rem) {
  .selection-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 64rem) {
  .epicrisis-header-actions {
    gap: var(--space-2);
  }

  .epicrisis-kv-grid {
    grid-template-columns: 1fr;
  }

  .epicrisis-quality__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Clinical reconciliation ledger: compact, evidence-first and status legible. */
@layer organisms {
.curation-ledger {
  margin-block: var(--space-5);
  border-top: 0.3rem solid var(--color-brand-primary);
}

.curation-ledger__header,
.curation-item__codes {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.curation-ledger__header {
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-4);
}

.curation-ledger__header h2,
.curation-ledger__sections h3 {
  margin: 0;
}

.curation-ledger__sections {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.curation-ledger__sections h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.curation-ledger__sections h3 > span {
  display: inline-grid;
  min-width: var(--space-8);
  min-height: var(--space-8);
  place-items: center;
  border: var(--border-width) solid color-mix(in srgb, var(--color-brand-support) 24%, var(--color-border));
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--color-surface) 88%, var(--color-brand-support) 12%);
  color: var(--color-brand-support);
  font: 700 var(--font-size-sm) var(--font-primary);
}

.curation-list {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.curation-item__main {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--space-3);
}

.curation-item {
  padding: var(--space-3);
  border: var(--border-width) solid var(--color-border);
  border-inline-start: var(--space-1) solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-surface) 96%, var(--color-brand-primary) 4%);
}

.curation-item[data-status="conflicto"] {
  border-inline-start-color: var(--color-error);
}

.curation-item[data-status^="pendiente"] {
  border-inline-start-color: var(--color-warning);
}

.curation-item[data-status="validado_automaticamente"],
.curation-item[data-status="aprobado"],
.curation-item[data-status="corregido"] {
  border-inline-start-color: var(--color-success);
}

.curation-item__main strong {
  min-width: 0;
  font-size: var(--font-size-sm);
  line-height: var(--line-height-base);
  overflow-wrap: anywhere;
}

.curation-item__codes {
  align-items: flex-start;
}

.code-chip,
.curation-status,
.curation-state-grid span {
  min-height: 1.65rem;
  padding: 0.2rem 0.55rem;
  font-size: var(--font-size-xs);
  font-weight: 700;
  letter-spacing: 0.025em;
  text-transform: uppercase;
}

.code-chip--cie10 {
  border-color: var(--color-info-border);
  background: var(--color-info-bg);
  color: var(--color-info);
}

.code-chip--cups {
  border-color: var(--color-success-border);
  background: var(--color-success-bg);
  color: var(--color-success);
}

.code-chip--soat {
  border-color: var(--color-warning-border);
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.code-chip--billing {
  border-color: var(--color-border-strong);
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
}

.curation-status {
  border-color: var(--color-border);
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
}

.curation-status--pending {
  border-color: var(--color-warning-border);
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.curation-status--ready {
  border-color: var(--color-success-border);
  background: var(--color-success-bg);
  color: var(--color-success);
}

.curation-alert {
  margin-bottom: var(--space-4);
}

.curation-state-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.curation-state-grid span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  color: var(--color-text-muted);
  background: var(--color-surface-muted);
  opacity: 0.58;
}

.curation-state-grid .is-active {
  color: var(--color-success);
  background: var(--color-success-bg);
  opacity: 1;
}

.curation-evidence {
  margin-top: var(--space-3);
}

.curation-evidence summary,
.curation-catalogs summary {
  cursor: pointer;
  font-weight: 700;
}

.curation-evidence blockquote {
  margin: var(--space-2) 0 0;
  padding-inline-start: var(--space-3);
  border-inline-start: 2px solid var(--color-border);
  color: var(--color-text-muted);
}

.curation-actions {
  display: grid;
  grid-template-columns: minmax(7rem, 0.7fr) minmax(12rem, 1.3fr) repeat(3, max-content);
  align-items: end;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--color-border);
}

.curation-actions label {
  display: grid;
  align-items: stretch;
  gap: var(--space-1);
}

.curation-actions input {
  width: 100%;
  min-height: var(--space-10);
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-sm);
}

.curation-actions__label {
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: 700;
}

.curation-reference {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-surface) 94%, var(--color-brand-primary) 6%);
}

.curation-reference legend {
  padding-inline: var(--space-2);
  font-weight: 600;
}

.curation-reference__components {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}

.curation-reference input:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.curation-conflicts,
.curation-catalogs {
  margin-top: var(--space-4);
}

.curation-feedback {
  min-height: 1.5rem;
  margin-bottom: 0;
  color: var(--color-success);
}

.curation-feedback.is-error {
  color: var(--color-error);
}
}

@media (max-width: 48rem) {
  .epicrisis-content {
    width: min(100% - 1rem, 94rem);
    padding: var(--space-3) 0 var(--space-5);
  }

  .epicrisis-header-actions {
    justify-content: center;
  }

  .selection-grid,
  .selection-grid--supporting {
    grid-template-columns: 1fr;
  }

  .selection-list--medications {
    max-height: min(28rem, 58vh);
  }

  .epicrisis-quality__grid {
    grid-template-columns: 1fr;
  }

  .curation-ledger__sections {
    grid-template-columns: 1fr;
  }

  .medication-matrix-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .medication-matrix {
    min-width: 0;
  }

  .medication-matrix thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .medication-matrix :is(tbody, tr, td) {
    display: block;
    width: 100%;
  }

  .medication-matrix tr {
    margin-bottom: var(--space-3);
    border: 1px solid color-mix(in srgb, var(--color-border) 80%, var(--color-brand-primary) 20%);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    padding: var(--space-3);
  }

  .medication-matrix td {
    display: grid;
    grid-template-columns: minmax(6.5rem, 0.38fr) minmax(0, 1fr);
    gap: var(--space-3);
    padding: var(--space-2) 0;
  }

  .medication-matrix td::before {
    content: attr(data-label);
    color: var(--color-text-muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .epicrisis-scroll-top {
    inset-inline-end: var(--space-3);
    inset-block-end: var(--space-4);
    min-height: 2.5rem;
    padding-inline: 0.9rem;
  }
}

/* Auditoría: una cola clínica compacta con revisión progresiva en panel lateral. */
@layer organisms {
  .audit-workspace {
    display: grid;
    gap: var(--space-5);
    min-width: 0;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    padding: clamp(var(--space-4), 2vw, var(--space-6));
  }

  .audit-workspace__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
  }

  .audit-workspace__header h2,
  .audit-workspace__header p {
    margin-block: 0 var(--space-1);
  }

  .audit-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-3);
    margin: 0;
  }

  .audit-metrics > div {
    display: grid;
    gap: var(--space-1);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-muted);
    padding: var(--space-3) var(--space-4);
  }

  .audit-metrics dt {
    color: var(--color-text-subtle);
    font-size: var(--font-size-xs);
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .audit-metrics dd {
    margin: 0;
    color: var(--color-brand-support);
    font-size: var(--font-size-xl);
    font-weight: 800;
  }

  .audit-tabs {
    margin-bottom: var(--space-4);
  }

  .audit-list {
    display: grid;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
  }

  .audit-row {
    display: grid;
    grid-template-columns: minmax(10rem, 0.75fr) minmax(15rem, 1.5fr) minmax(9rem, 0.65fr) auto;
    align-items: center;
    gap: var(--space-4);
    min-width: 0;
    border-bottom: var(--border-width) solid var(--color-border);
    background: var(--color-surface);
    padding: var(--space-3) var(--space-4);
  }

  .audit-row:last-of-type {
    border-bottom: 0;
  }

  .audit-row:hover {
    background: color-mix(in srgb, var(--color-surface) 94%, var(--color-brand-primary) 6%);
  }

  .audit-row__type,
  .audit-row__content,
  .audit-row__meta {
    display: grid;
    gap: var(--space-1);
    min-width: 0;
  }

  .audit-row__type > span:first-child,
  .audit-severity {
    color: var(--color-text-subtle);
    font-size: var(--font-size-xs);
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .audit-row__content strong,
  .audit-row__content p {
    margin: 0;
    overflow-wrap: anywhere;
  }

  .audit-row__content p,
  .audit-row__meta span:last-child {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
  }

  .audit-panel__empty {
    display: grid;
    gap: var(--space-1);
    border: var(--border-width) dashed var(--color-border-strong);
    border-radius: var(--radius-lg);
    background: var(--color-surface-muted);
    padding: var(--space-6);
    color: var(--color-text-muted);
    text-align: center;
  }

  .audit-history {
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface-muted);
    padding: var(--space-3);
  }

  .audit-history > summary,
  .audit-history > summary span {
    color: var(--color-brand-support);
    cursor: pointer;
    font-weight: 800;
  }

  .audit-history__list {
    display: grid;
    gap: var(--space-2);
    margin-top: var(--space-3);
  }

  .audit-history__list > button {
    display: grid;
    grid-template-columns: minmax(8rem, auto) minmax(0, 1fr) auto;
    gap: var(--space-3);
    align-items: center;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    padding: var(--space-3);
    color: var(--color-text);
    cursor: pointer;
    text-align: left;
  }

  .audit-history__list > button:hover {
    border-color: var(--color-border-strong);
  }

  .audit-history__list small,
  .audit-evidence-list li > span {
    color: var(--color-text-subtle);
  }

  .audit-sheet__summary,
  .audit-warning-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  .audit-sheet__section {
    display: grid;
    gap: var(--space-2);
  }

  .audit-sheet__section h4,
  .audit-sheet__section p {
    margin: 0;
  }

  .audit-sheet__section h4 span {
    color: var(--color-text-subtle);
    font-size: var(--font-size-sm);
  }

  .audit-warning-list span {
    border: var(--border-width) solid var(--color-warning-border);
    border-radius: var(--radius-pill);
    background: var(--color-warning-bg);
    padding: var(--space-1) var(--space-2);
    color: var(--color-warning);
    font-size: var(--font-size-xs);
    font-weight: 700;
  }

  .audit-evidence-list {
    display: grid;
    gap: var(--space-3);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .audit-evidence-list li {
    display: grid;
    gap: var(--space-1);
    border-inline-start: var(--space-1) solid var(--color-border-strong);
    background: var(--color-surface-muted);
    padding: var(--space-3);
  }

  .audit-evidence-list blockquote {
    margin: var(--space-1) 0 0;
    color: var(--color-text-muted);
  }

  .audit-edit-form,
  .audit-reason {
    display: grid;
    gap: var(--space-3);
  }

  .audit-edit-form[hidden] {
    display: none;
  }

  .audit-edit-form > label,
  .audit-reason {
    gap: var(--space-1);
    font-weight: 700;
  }

  .audit-edit-form :is(input, select),
  .audit-reason textarea {
    width: 100%;
  }

  .audit-sheet__error {
    margin: 0;
    border: var(--border-width) solid var(--color-error-border);
    border-radius: var(--radius-md);
    background: var(--color-error-bg);
    padding: var(--space-3);
    color: var(--color-error);
    font-weight: 700;
  }

  .audit-sheet__error[hidden],
  .audit-sheet__actions[hidden] {
    display: none;
  }

  .audit-workspace :is(button, input, select, textarea, summary):focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
  }
}

@media (max-width: 64rem) {
  .audit-row {
    grid-template-columns: minmax(9rem, 0.7fr) minmax(0, 1.3fr) auto;
  }

  .audit-row__meta {
    grid-column: 2;
  }

  .audit-row > .ui-button {
    grid-column: 3;
    grid-row: 1 / span 2;
  }
}

@media (max-width: 48rem) {
  .audit-workspace__header,
  .audit-history__list > button {
    grid-template-columns: 1fr;
  }

  .audit-workspace__header {
    display: grid;
  }

  .audit-metrics {
    gap: var(--space-2);
  }

  .audit-metrics > div {
    padding: var(--space-2);
  }

  .audit-row {
    grid-template-columns: 1fr;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
  }

  .audit-list {
    border: 0;
    overflow: visible;
  }

  .audit-row__meta,
  .audit-row > .ui-button {
    grid-column: 1;
    grid-row: auto;
  }

  .audit-row > .ui-button {
    width: 100%;
    min-height: var(--space-10);
  }

  .audit-sheet .pdf-sheet__surface {
    width: 100%;
  }
}

@layer organisms {
  .pdf-workspace {
    display: grid;
    gap: var(--space-5);
    min-width: 0;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    padding: clamp(var(--space-4), 2vw, var(--space-6));
  }

  .pdf-workspace__header,
  .pdf-workspace__header > div,
  .pdf-tab-panel,
  .pdf-supporting ul,
  .pdf-expansions,
  .pdf-sheet__fields {
    display: grid;
    gap: var(--space-3);
  }

  .pdf-tab-panel[hidden] {
    display: none;
  }

  .pdf-workspace__header {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    border-bottom: var(--border-width) solid var(--color-border);
    padding-bottom: var(--space-5);
  }

  .pdf-workspace__header > .pdf-workspace__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2) var(--space-3);
    font-size: var(--font-size-xs);
  }

  .pdf-workspace__selection-meta {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    border: var(--border-width) solid color-mix(in srgb, var(--color-brand-support) 22%, var(--color-border));
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--color-surface) 92%, var(--color-brand-support-soft) 8%);
    padding: var(--space-1) var(--space-2);
  }

  .pdf-workspace :is(h2, h3, p),
  .pdf-supporting ul {
    margin: 0;
  }

  .pdf-workspace__header h2 {
    border: 0;
    padding: 0;
  }

  .pdf-workspace__eyebrow {
    color: var(--color-brand-primary-dark);
    font-size: var(--font-size-xs);
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .pdf-tabs {
    display: flex;
    overflow-x: auto;
    border-bottom: var(--border-width) solid var(--color-border);
    scrollbar-width: thin;
  }

  .pdf-tabs__tab {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--space-10);
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    font: inherit;
    font-size: var(--font-size-sm);
    font-weight: 700;
    padding-inline: var(--space-4);
  }

  .pdf-tabs__tab[aria-selected="true"] {
    border-bottom-color: var(--color-brand-primary-dark);
    color: var(--color-brand-support);
  }

  .pdf-tabs__tab:focus-visible,
  .pdf-row-detail:focus-visible,
  .pdf-sheet__close:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
  }

  .pdf-tabs__count {
    border-radius: var(--radius-pill);
    background: var(--color-surface-muted);
    color: var(--color-text-subtle);
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
    font-variant-numeric: tabular-nums;
  }

  .pdf-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: var(--space-3);
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--color-surface) 82%, var(--color-brand-support-soft) 18%);
    padding: var(--space-3);
  }

  .pdf-search,
  .pdf-filter,
  .pdf-sheet__fields label,
  .pdf-sheet__body > label,
  .pdf-expansions label {
    display: grid;
    gap: var(--space-1);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: 700;
  }

  .pdf-search {
    flex: 1 1 18rem;
  }

  .pdf-filter {
    flex: 0 1 14rem;
  }

  .pdf-toolbar__actions,
  .pdf-sheet__actions,
  .pdf-detail-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .pdf-toolbar__actions {
    margin-left: auto;
  }

  .pdf-list {
    min-width: 0;
    overflow-x: auto;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
  }

  .pdf-list__head,
  .pdf-list__row {
    display: grid;
    align-items: center;
    gap: var(--space-3);
    min-width: 54rem;
    border-bottom: var(--border-width) solid var(--color-border);
    padding: var(--space-3);
  }

  .pdf-list__head {
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .pdf-list__row:last-child {
    border-bottom: 0;
  }

  .pdf-list__row:hover {
    background: color-mix(in srgb, var(--color-surface) 94%, var(--color-brand-primary) 6%);
  }

  .pdf-list__row > :is(span, strong) {
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: var(--font-size-sm);
  }

  .pdf-list__row small {
    display: block;
    margin-top: var(--space-1);
    color: var(--color-text-subtle);
    font-size: var(--font-size-xs);
  }

  .pdf-list__row--diagnosis,
  .pdf-list__row--diagnosticos {
    grid-template-columns: 3.5rem 7rem minmax(10rem, 1fr) minmax(12rem, 1.4fr) 4rem;
  }

  .pdf-list__row--procedure,
  .pdf-list__row--procedimientos {
    grid-template-columns: 3.5rem 7rem minmax(14rem, 1fr) 8rem 10rem 4rem;
  }

  .pdf-list__row--medication,
  .pdf-list__row--medicamentos {
    grid-template-columns: 3.5rem minmax(12rem, 1.3fr) minmax(10rem, 1fr) 7rem 7rem 8rem 4rem;
  }

  .pdf-list__row--aid,
  .pdf-list__row--ayudas_diagnosticas {
    grid-template-columns: 3.5rem 9rem minmax(11rem, 1fr) minmax(12rem, 1.2fr) 9rem 4rem;
  }

  .pdf-list input[type="checkbox"] {
    width: var(--space-5);
    height: var(--space-5);
    accent-color: var(--color-brand-primary-dark);
  }

  .pdf-row-detail {
    min-width: var(--space-10);
    min-height: var(--space-8);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-brand-support);
    cursor: pointer;
    font-weight: 700;
  }

  .pdf-classification,
  .pdf-type-label {
    text-transform: capitalize;
  }

  .pdf-procedure-classification {
    text-transform: none;
  }

  .pdf-group-badge {
    display: inline-flex;
    width: fit-content;
    border: var(--border-width) solid color-mix(in srgb, var(--color-brand-support) 26%, var(--color-border));
    border-radius: var(--radius-pill);
    background: var(--color-brand-support-soft);
    color: var(--color-brand-support);
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
    font-weight: 800;
  }

  .pdf-list__empty {
    padding: var(--space-8);
    color: var(--color-text-muted);
    text-align: center;
  }

  .pdf-workspace__note {
    border-left: 3px solid var(--color-warning);
    background: var(--color-warning-bg);
    color: var(--color-warning);
    padding: var(--space-3);
    font-size: var(--font-size-sm);
  }

  .pdf-supporting {
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface-muted);
    padding: var(--space-3);
  }

  .pdf-supporting summary {
    color: var(--color-brand-support);
    cursor: pointer;
    font-weight: 800;
  }

  .pdf-supporting > :not(summary) {
    margin-top: var(--space-3);
  }

  .pdf-supporting li small {
    display: block;
    color: var(--color-text-subtle);
  }

  .pdf-expansions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pdf-expansions textarea {
    min-height: 7rem;
  }

  #pdf_autosave_status {
    color: var(--color-text-subtle);
    font-size: var(--font-size-xs);
  }

  #pdf_autosave_status[data-status="error"] {
    color: var(--color-error);
  }

  .pdf-sheet {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    border: 0;
    background: transparent;
    padding: 0;
  }

  .pdf-sheet::backdrop {
    background: var(--color-overlay);
  }

  .pdf-sheet__surface {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: min(100%, 34rem);
    height: 100%;
    margin-left: auto;
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
  }

  .pdf-sheet__surface > :is(header, footer) {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    border-bottom: var(--border-width) solid var(--color-border);
    padding: var(--space-4);
  }

  .pdf-sheet__surface > footer {
    justify-content: flex-end;
    border-top: var(--border-width) solid var(--color-border);
    border-bottom: 0;
  }

  .pdf-sheet__close {
    min-width: var(--space-10);
    min-height: var(--space-10);
    border: 0;
    border-radius: var(--radius-md);
    background: var(--color-surface-muted);
    color: var(--color-text);
    cursor: pointer;
    font-size: var(--font-size-xl);
  }

  .pdf-sheet__body {
    display: grid;
    align-content: start;
    gap: var(--space-4);
    overflow-y: auto;
    padding: var(--space-5);
  }

  .pdf-detail-list {
    display: grid;
    gap: var(--space-3);
    margin: 0;
  }

  .pdf-detail-list > div {
    display: grid;
    gap: var(--space-1);
    border-bottom: var(--border-width) solid var(--color-border);
    padding-bottom: var(--space-3);
  }

  .pdf-detail-list dt {
    color: var(--color-text-subtle);
    font-size: var(--font-size-xs);
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .pdf-detail-list dd {
    margin: 0;
    overflow-wrap: anywhere;
  }

  .pdf-detail-links a {
    color: var(--color-brand-support);
    font-weight: 700;
  }
}

@media (max-width: 48rem) {
  .pdf-workspace {
    border-inline: 0;
    border-radius: 0;
    padding-inline: var(--space-3);
  }

  .pdf-workspace__header,
  .pdf-expansions {
    grid-template-columns: 1fr;
  }

  .pdf-workspace__header > .pdf-workspace__meta {
    justify-content: flex-start;
  }

  .pdf-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .pdf-toolbar__actions {
    margin-left: 0;
  }

  .pdf-toolbar__actions .ui-button {
    flex: 1 1 auto;
  }

  .pdf-list {
    overflow: visible;
    border: 0;
  }

  .pdf-list__head {
    display: none;
  }

  .pdf-list__row {
    min-width: 0;
    margin-bottom: var(--space-3);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
  }

  .pdf-list__row--diagnosticos,
  .pdf-list__row--procedimientos,
  .pdf-list__row--medicamentos,
  .pdf-list__row--ayudas_diagnosticas {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .pdf-list__row > :is(span, strong):not(:first-child) {
    grid-column: 2;
  }

  .pdf-list__row > span:first-child {
    grid-column: 1;
    grid-row: 1 / span 3;
  }

  .pdf-sheet__surface {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pdf-workspace *,
  .pdf-sheet * {
    scroll-behavior: auto;
    transition-duration: 0.01ms;
  }
}

@layer organisms {
  .invoice-workspace {
    display: grid;
    gap: var(--space-5);
    min-width: 0;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    padding: clamp(var(--space-4), 2vw, var(--space-6));
  }

  .invoice-workspace__header,
  .invoice-section-card__header {
    display: flex;
    flex-wrap: wrap;
    align-items: start;
    justify-content: space-between;
    gap: var(--space-3);
  }

  .invoice-workspace__header {
    border-bottom: var(--border-width) solid var(--color-border);
    padding-bottom: var(--space-5);
  }

  .invoice-workspace__header h2,
  .invoice-panel-intro h3,
  .invoice-section-card h3,
  .invoice-identity-card h3 {
    margin: 0;
    color: var(--color-brand-support);
  }

  .invoice-workspace__header p,
  .invoice-panel-intro p,
  .invoice-section-card__kicker {
    margin: 0;
  }

  .invoice-workspace__header > div:first-child,
  .invoice-panel-intro {
    display: grid;
    gap: var(--space-2);
  }

  .invoice-workspace__header > div:first-child > p:last-child,
  .invoice-panel-intro > p:last-child {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
  }

  .invoice-workspace__eyebrow,
  .invoice-section-card__kicker {
    color: var(--color-brand-primary-dark);
    font-size: var(--font-size-xs);
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .invoice-workspace__meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: end;
    gap: var(--space-2);
  }

  .invoice-tabs {
    display: flex;
    overflow-x: auto;
    border-bottom: var(--border-width) solid var(--color-border);
    scrollbar-width: thin;
  }

  .invoice-tabs__tab {
    display: inline-flex;
    flex: 0 0 auto;
    min-height: var(--space-10);
    align-items: center;
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    font: inherit;
    font-size: var(--font-size-sm);
    font-weight: 700;
    padding: 0 var(--space-4);
    transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
  }

  .invoice-tabs__tab[aria-selected="true"] {
    border-bottom-color: var(--color-brand-primary-dark);
    color: var(--color-brand-support);
  }

  .invoice-tabs__tab:hover {
    background: color-mix(in srgb, var(--color-brand-primary-soft) 58%, transparent);
    color: var(--color-brand-support);
  }

  .invoice-tabs__tab:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
  }

  .invoice-tab-panel {
    display: grid;
    gap: var(--space-5);
    min-width: 0;
  }

  .invoice-tab-panel[hidden] {
    display: none;
  }

  .invoice-surface {
    min-width: 0;
    border: var(--border-width) solid color-mix(in srgb, var(--color-brand-support) 14%, var(--color-border));
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--color-surface) 96%, var(--color-brand-support-soft) 4%);
    box-shadow: var(--shadow-sm);
    padding: var(--space-4);
  }

  .invoice-identity-grid,
  .invoice-summary-grid,
  .invoice-service-sections {
    display: grid;
    gap: var(--space-4);
  }

  .invoice-identity-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .invoice-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .invoice-key-values,
  .invoice-financial-grid,
  .invoice-soat-summary {
    display: grid;
    gap: var(--space-3);
    margin: var(--space-4) 0 0;
  }

  .invoice-key-values > div,
  .invoice-financial-grid > div,
  .invoice-soat-summary > div {
    display: grid;
    gap: var(--space-1);
    min-width: 0;
  }

  .invoice-key-values dt,
  .invoice-financial-grid dt,
  .invoice-soat-summary dt {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .invoice-key-values dd,
  .invoice-financial-grid dd,
  .invoice-soat-summary dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: var(--font-size-sm);
    font-weight: 700;
  }

  .invoice-key-values time {
    font: inherit;
    font-variant-numeric: tabular-nums;
  }

  .invoice-financial-grid,
  .invoice-soat-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .invoice-financial-grid > div,
  .invoice-soat-summary > div {
    border-top: var(--border-width) solid color-mix(in srgb, var(--color-brand-support) 16%, var(--color-border));
    padding-top: var(--space-2);
  }

  .invoice-count {
    display: inline-flex;
    min-width: var(--space-8);
    justify-content: center;
    border-radius: var(--radius-pill);
    background: var(--color-brand-support-soft);
    color: var(--color-brand-support);
    font-size: var(--font-size-xs);
    font-weight: 800;
    padding: var(--space-1) var(--space-2);
  }

  .invoice-section-card__header {
    align-items: center;
    margin-bottom: var(--space-4);
  }

  .invoice-table-wrap {
    margin-top: var(--space-3);
  }

  .invoice-table-wrap table {
    min-width: 58rem;
  }

  .invoice-table-wrap th {
    white-space: nowrap;
  }

  .invoice-empty,
  .invoice-empty-state {
    margin: 0;
    border-radius: var(--radius-md);
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
    padding: var(--space-4);
  }

  .invoice-empty-state {
    display: grid;
    gap: var(--space-2);
    border-left: 3px solid var(--color-warning);
  }

  .invoice-empty-state h3,
  .invoice-empty-state p {
    margin: 0;
  }

  .invoice-observations {
    margin: var(--space-4) 0 0;
    padding-left: var(--space-5);
  }

  .invoice-note {
    margin: var(--space-4) 0 0;
    border-left: 3px solid var(--color-info);
    background: var(--color-info-bg);
    color: var(--color-text-muted);
    padding: var(--space-3);
    font-size: var(--font-size-sm);
  }

  .invoice-status {
    display: inline-flex;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-pill);
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: 800;
    padding: var(--space-1) var(--space-2);
    white-space: nowrap;
  }

  .invoice-status--liquidada {
    border-color: var(--color-success-border);
    background: var(--color-success-bg);
    color: var(--color-success);
  }

  .invoice-status--conflicto,
  .invoice-status--pendiente_revision {
    border-color: var(--color-warning-border);
    background: var(--color-warning-bg);
    color: var(--color-warning);
  }

  .invoice-table-wrap small {
    display: block;
    color: var(--color-text-subtle);
    font-size: var(--font-size-xs);
  }

  .invoice-details-row td {
    padding: 0;
    background: color-mix(in srgb, var(--color-surface-muted) 56%, var(--color-surface) 44%);
  }

  .invoice-details {
    padding: var(--space-3) var(--space-4);
  }

  .invoice-details summary {
    color: var(--color-brand-support);
    cursor: pointer;
    font-size: var(--font-size-sm);
    font-weight: 800;
  }

  .invoice-details__grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-4);
  }

  .invoice-details__grid h4,
  .invoice-details__grid p,
  .invoice-details__grid ul {
    margin: 0;
  }

  .invoice-details__grid h4 {
    color: var(--color-brand-support);
    font-size: var(--font-size-sm);
  }

  .invoice-details__grid ul {
    padding-left: var(--space-4);
  }

  @media (max-width: 64rem) {
    .invoice-identity-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  @media (max-width: 48rem) {
    .invoice-workspace {
      border-inline: 0;
      border-radius: 0;
      padding-inline: var(--space-3);
    }

    .invoice-tabs__tab {
      padding-inline: var(--space-3);
    }

    .invoice-workspace__meta {
      justify-content: start;
    }

    .invoice-identity-grid,
    .invoice-summary-grid,
    .invoice-details__grid {
      grid-template-columns: 1fr;
    }

    .invoice-financial-grid,
    .invoice-soat-summary {
      grid-template-columns: 1fr 1fr;
    }

    .invoice-table-wrap {
      overflow-x: auto;
    }

    .invoice-table-wrap table {
      min-width: 58rem;
    }
  }
}

@layer organisms {
  .epicrisis-hero {
    margin-top: var(--space-4);
    padding: var(--space-5) var(--space-6);
  }

  .epicrisis-hero__heading h1 {
    font-size: clamp(var(--font-size-2xl), 3vw, var(--font-size-3xl));
    line-height: var(--line-height-tight);
  }

  .epicrisis-hero__heading .ui-pill {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .epicrisis-hero__availability {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .epicrisis-subview-nav {
    width: min(100% - var(--space-8), 94rem);
    margin-inline: auto;

    position: sticky;
    top: var(--epicrisis-header-height, 0px);
    z-index: calc(var(--z-header) - 1);
    border-block: var(--border-width) solid var(--color-border);
    background: color-mix(in srgb, var(--color-surface) 88%, var(--color-brand-support-soft) 12%);
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow-sm);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
  }

  .epicrisis-subview-nav__scroller {
    width: min(100% - var(--space-8), 94rem);
    margin-inline: auto;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }

  .epicrisis-subview-tabs {
    display: flex;
    width: max-content;
    min-width: 100%;
    gap: var(--space-1);
    padding: var(--space-2) 0;
  }

  .epicrisis-subview-tab {
    display: inline-flex;
    position: relative;
    align-items: center;
    gap: var(--space-2);
    min-height: calc(var(--space-10) + var(--space-1));
    border: var(--border-width) solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text-muted);
    padding: var(--space-2) var(--space-3);
    font: 700 var(--font-size-sm) var(--font-primary);
    text-decoration: none;
    white-space: nowrap;
    transition:
      background var(--transition-fast),
      border-color var(--transition-fast),
      color var(--transition-fast);
  }

  .epicrisis-subview-tab::after {
    inline-size: var(--space-2);
    block-size: var(--space-2);
    flex: 0 0 auto;
    border-radius: var(--radius-pill);
    background: var(--color-border-strong);
    content: "";
  }

  .epicrisis-subview-tab--alert::after {
    background: var(--color-warning);
  }

  .epicrisis-subview-tab--success::after {
    background: var(--color-success);
  }

  .epicrisis-subview-tab:is(:hover, [aria-selected="true"]) {
    border-color: color-mix(in srgb, var(--color-brand-support) 28%, var(--color-border));
    background: color-mix(in srgb, var(--color-surface) 90%, var(--color-brand-support) 10%);
    color: var(--color-brand-support);
  }

  .epicrisis-subview-tab[aria-selected="true"] {
    border-color: color-mix(in srgb, var(--color-brand-support) 36%, var(--color-border));
    background: color-mix(in srgb, var(--color-surface) 84%, var(--color-brand-support) 16%);
    box-shadow: inset 0 calc(var(--space-1) * -1) 0 var(--color-brand-primary);
  }

  .epicrisis-subview-tab:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
  }

  .epicrisis-subview-content {
    padding-top: clamp(var(--space-4), 2vw, var(--space-6));
  }

  .epicrisis-subview-panel .curation-ledger {
    margin-block: 0;
  }

  .epicrisis-subview-panel {
    display: grid;
    gap: clamp(var(--space-4), 2vw, var(--space-6));
    min-width: 0;
  }

  .epicrisis-subviews-ready .epicrisis-subview-panel[hidden] {
    display: none;
  }

  .epicrisis-empty-state {
    border: var(--border-width) dashed var(--color-border-strong);
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--color-surface) 82%, var(--color-surface-muted) 18%);
    padding: clamp(var(--space-5), 3vw, var(--space-8));
    color: var(--color-text-muted);
    text-align: center;
  }

  .epicrisis-empty-state h2 {
    margin: var(--space-2) 0;
    color: var(--color-brand-support);
    font-size: var(--font-size-xl);
  }

  .epicrisis-empty-state p:last-child {
    max-width: 44rem;
    margin: 0 auto;
  }

  .epicrisis-metadata-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
    gap: var(--space-3);
    margin: 0;
  }

  .epicrisis-metadata-grid > div {
    display: grid;
    gap: var(--space-1);
    min-width: 0;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-muted);
    padding: var(--space-3);
  }

  .epicrisis-metadata-grid dt {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .epicrisis-metadata-grid dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-weight: 700;
  }

  .epicrisis-metadata-grid small {
    color: var(--color-text-subtle);
  }
}

@media (max-width: 80rem) {
  .curation-ledger__sections {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 48rem) {
  .epicrisis-subview-nav__scroller {
    width: calc(100% - var(--space-4));
  }

  .epicrisis-subview-tab {
    min-height: var(--space-10);
    padding-inline: var(--space-3);
  }

  .epicrisis-hero {
    padding: var(--space-4);
  }

  .curation-item__main {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .curation-item__main strong {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .curation-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .curation-actions label {
    grid-column: 1 / -1;
  }

  .curation-actions .ui-button {
    width: 100%;
    padding-inline: var(--space-2);
  }
}

/* El panel de auditoría prioriza la decisión; el detalle queda disponible sin competir por atención. */
@layer organisms {
  .audit-sheet .pdf-sheet__surface {
    width: min(100%, 31rem);
  }

  .audit-sheet .pdf-sheet__surface > :is(header, footer) {
    padding: var(--space-3);
  }

  .audit-sheet .pdf-sheet__surface > header {
    align-items: flex-start;
  }

  .audit-sheet .pdf-sheet__surface > header h3 {
    max-width: 22rem;
    font-size: var(--font-size-lg);
    line-height: var(--line-height-tight);
  }

  .audit-sheet .pdf-workspace__eyebrow {
    font-size: var(--font-size-xs);
  }

  .audit-sheet .pdf-sheet__body {
    gap: var(--space-3);
    padding: var(--space-3);
  }

  .audit-sheet__summary {
    gap: var(--space-1);
    padding-bottom: var(--space-2);
    border-bottom: var(--border-width) solid var(--color-border);
  }

  .audit-sheet__summary .curation-item__codes {
    flex-basis: 100%;
  }

  .audit-sheet__section {
    gap: var(--space-1);
  }

  .audit-sheet__section h4 {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-tight);
  }

  .audit-sheet__section p {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-base);
  }

  .audit-sheet .curation-state-grid {
    gap: var(--space-1);
    margin-top: var(--space-1);
  }

  .audit-sheet .curation-state-grid span {
    min-height: 1.5rem;
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
  }

  .audit-warning-list {
    gap: var(--space-1);
  }

  .audit-warning-list span {
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
  }

  .audit-evidence-list {
    gap: var(--space-1);
  }

  .audit-evidence-list li {
    gap: 0;
    padding: var(--space-2);
  }

  .audit-evidence-list li > strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--font-size-sm);
  }

  .audit-evidence-list__meta {
    color: var(--color-text-subtle);
    font-size: var(--font-size-xs);
  }

  .audit-evidence__excerpt {
    margin-top: var(--space-1);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
  }

  .audit-evidence__excerpt summary {
    width: fit-content;
    color: var(--color-brand-support);
    cursor: pointer;
    font-weight: 700;
  }

  .audit-evidence-list blockquote {
    max-height: 4.5rem;
    overflow: auto;
    margin-top: var(--space-1);
    font-size: var(--font-size-xs);
    line-height: var(--line-height-base);
  }

  .audit-sheet [data-audit-edit] {
    justify-self: start;
    min-height: 2rem;
    padding-block: var(--space-1);
  }

  .audit-edit-form {
    gap: var(--space-2);
    padding: var(--space-2);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-muted);
  }

  .audit-edit-form > label,
  .audit-reason {
    gap: var(--space-1);
    font-size: var(--font-size-xs);
  }

  .audit-edit-form :is(input, select),
  .audit-reason textarea {
    min-height: 2.25rem;
    padding: var(--space-2);
    font-size: var(--font-size-sm);
  }

  .audit-reason textarea {
    min-height: 5rem;
  }

  .audit-sheet .curation-reference {
    gap: var(--space-2);
    padding: var(--space-2);
  }

  .audit-sheet .curation-reference legend {
    font-size: var(--font-size-xs);
  }

  .audit-sheet .curation-reference__components {
    gap: var(--space-1) var(--space-3);
  }

  .audit-sheet .curation-reference label {
    font-size: var(--font-size-xs);
  }

  .audit-sheet .pdf-sheet__actions {
    gap: var(--space-2);
  }

  .audit-sheet .pdf-sheet__actions .ui-button {
    min-height: 2.25rem;
    padding-block: var(--space-2);
  }
}
