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,
.procedure-classification legend {
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: 600;
}

.procedure-classification {
  display: flex;
  width: 100%;
  min-width: 0;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}

.procedure-classification legend {
  width: 100%;
  margin-bottom: var(--space-1);
}

.procedure-classification label {
  min-width: 0;
  font-size: var(--font-size-xs);
}

.procedure-classification input: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-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;
  }
}

@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);
  }
}
