/* ============================================
   DESIGN SYSTEM — Componentes ("Clinical Precision")
   ============================================
   Primitivos CSS puros. Usan los tokens de design-system.css
   (prefijo --ds-). Todas las clases usan el prefijo .ds- para
   convivir sin conflicto con las clases de producción existentes
   (.btn-primary, .modal, .toast, .badge, etc. en styles.css).

   Nada aquí se auto-aplica: una página adopta un componente
   agregando la clase .ds-* en su HTML cuando decida migrar.
   ============================================ */

/* ---- Base tipográfica reutilizable ---- */
.ds-headline-lg { font-family: var(--ds-font-family); font-size: var(--ds-headline-lg-size); font-weight: var(--ds-headline-lg-weight); line-height: var(--ds-headline-lg-line); letter-spacing: var(--ds-headline-lg-tracking); }
.ds-headline-md { font-family: var(--ds-font-family); font-size: var(--ds-headline-md-size); font-weight: var(--ds-headline-md-weight); line-height: var(--ds-headline-md-line); letter-spacing: var(--ds-headline-md-tracking); }
.ds-headline-sm { font-family: var(--ds-font-family); font-size: var(--ds-headline-sm-size); font-weight: var(--ds-headline-sm-weight); line-height: var(--ds-headline-sm-line); }
.ds-body-lg      { font-family: var(--ds-font-family); font-size: var(--ds-body-lg-size); font-weight: var(--ds-body-lg-weight); line-height: var(--ds-body-lg-line); }
.ds-body-md      { font-family: var(--ds-font-family); font-size: var(--ds-body-md-size); font-weight: var(--ds-body-md-weight); line-height: var(--ds-body-md-line); }
.ds-body-sm-dense{ font-family: var(--ds-font-family); font-size: var(--ds-body-sm-dense-size); font-weight: var(--ds-body-sm-dense-weight); line-height: var(--ds-body-sm-dense-line); }
.ds-label-uppercase {
  font-family: var(--ds-font-family);
  font-size: var(--ds-label-uppercase-size);
  font-weight: var(--ds-label-uppercase-weight);
  line-height: var(--ds-label-uppercase-line);
  letter-spacing: var(--ds-label-uppercase-tracking);
  text-transform: uppercase;
}

/* ---- Iconos ----
   El sistema actual usa emoji inline; el design system no exige
   una librería de iconos concreta, solo un tamaño/alineación
   consistente. Esta clase normaliza cualquier icono (emoji, SVG,
   <span> de fuente de iconos) a un box cuadrado alineado al texto. */
.ds-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25em;
  height: 1.25em;
  line-height: 1;
  flex-shrink: 0;
}
.ds-icon-sm { width: 1em; height: 1em; font-size: 0.85em; }
.ds-icon-lg { width: 1.75em; height: 1.75em; font-size: 1.4em; }

/* ---- Botones ---- */
.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ds-space-base);
  font-family: var(--ds-font-family);
  font-size: var(--ds-body-md-size);
  font-weight: 600;
  border-radius: var(--ds-radius);
  padding: var(--ds-space-sm) var(--ds-space-md);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
  border: 1px solid transparent;
}
.ds-btn:active { transform: translateY(1px); }
.ds-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.ds-btn-primary {
  background: var(--ds-primary);
  color: var(--ds-on-primary);
}
.ds-btn-primary:hover:not(:disabled) { background: var(--ds-primary-container); }

.ds-btn-secondary {
  background: transparent;
  color: var(--ds-secondary);
  border-color: var(--ds-secondary);
}
.ds-btn-secondary:hover:not(:disabled) { background: var(--ds-secondary-container); }

.ds-btn-tertiary {
  background: transparent;
  color: var(--ds-on-surface-variant);
  border-color: transparent;
}
.ds-btn-tertiary:hover:not(:disabled) { background: var(--ds-surface-container-low); color: var(--ds-primary); }

.ds-btn-danger {
  background: var(--ds-danger);
  color: #ffffff;
}
.ds-btn-danger:hover:not(:disabled) { opacity: 0.88; }

/* ---- Inputs (floating label) ---- */
.ds-field {
  position: relative;
  margin-bottom: var(--ds-space-md);
}
.ds-field input,
.ds-field select,
.ds-field textarea {
  width: 100%;
  font-family: var(--ds-font-family);
  font-size: var(--ds-body-md-size);
  color: var(--ds-on-surface);
  background: var(--ds-surface-base);
  border: 1px solid var(--ds-border-low-contrast);
  border-radius: var(--ds-radius);
  padding: var(--ds-space-sm) var(--ds-space-md);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.ds-field input:focus,
.ds-field select:focus,
.ds-field textarea:focus {
  outline: none;
  border-color: var(--ds-primary);
  border-width: 2px;
  box-shadow: 0 0 0 3px rgba(0, 104, 95, 0.12);
}
.ds-field label {
  display: block;
  font-family: var(--ds-font-family);
  font-size: var(--ds-label-uppercase-size);
  font-weight: var(--ds-label-uppercase-weight);
  letter-spacing: var(--ds-label-uppercase-tracking);
  text-transform: uppercase;
  color: var(--ds-on-surface-variant);
  margin-bottom: var(--ds-space-base);
}
.ds-field-error input,
.ds-field-error select,
.ds-field-error textarea {
  border-color: var(--ds-danger);
}
.ds-field-error-text {
  font-family: var(--ds-font-family);
  font-size: var(--ds-body-sm-dense-size);
  color: var(--ds-danger);
  margin-top: var(--ds-space-base);
}

/* ---- Cards ---- */
.ds-card {
  background: var(--ds-surface-base);
  border: 1px solid var(--ds-border-low-contrast);
  border-radius: var(--ds-radius);
  padding: var(--ds-space-md);
}
.ds-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--ds-space-sm);
  margin-bottom: var(--ds-space-sm);
  border-bottom: 1px solid var(--ds-border-low-contrast);
}

/* ---- Tablas densas ---- */
.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--ds-font-family);
  font-size: var(--ds-body-sm-dense-size);
}
.ds-table th {
  text-align: left;
  padding: var(--ds-space-sm) var(--ds-space-md);
  font-size: var(--ds-label-uppercase-size);
  font-weight: var(--ds-label-uppercase-weight);
  letter-spacing: var(--ds-label-uppercase-tracking);
  text-transform: uppercase;
  color: var(--ds-on-surface-variant);
  border-bottom: 1px solid var(--ds-border-low-contrast);
  position: sticky;
  top: 0;
  background: var(--ds-surface-base);
}
.ds-table td {
  padding: var(--ds-space-sm) var(--ds-space-md);
  border-bottom: 1px solid var(--ds-border-low-contrast);
  vertical-align: middle;
}
.ds-table tr:last-child td { border-bottom: none; }
.ds-table tbody tr:nth-child(even) { background: rgba(248, 250, 252, 0.5); } /* zebra striping, surface-subtle 50% */

/* ---- Dialogs (modales) ---- */
.ds-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 29, 28, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.ds-dialog-overlay.active { opacity: 1; pointer-events: auto; }
.ds-dialog {
  background: var(--ds-surface-base);
  border-radius: var(--ds-radius-md);
  box-shadow: var(--ds-elevation-2);
  max-width: 480px;
  width: 92%;
  max-height: 90vh;
  overflow-y: auto;
}
.ds-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--ds-space-md) var(--ds-space-lg);
  border-bottom: 1px solid var(--ds-border-low-contrast);
}
.ds-dialog-body { padding: var(--ds-space-lg); }

/* ---- Badges / Status Pills ---- */
.ds-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-base);
  padding: 0.2rem var(--ds-space-sm);
  border-radius: var(--ds-radius-full);
  font-family: var(--ds-font-family);
  font-size: var(--ds-status-pill-size);
  font-weight: var(--ds-status-pill-weight);
  line-height: var(--ds-status-pill-line);
}
.ds-badge-success { background: rgba(16, 185, 129, 0.1); color: var(--ds-success); }
.ds-badge-warning { background: rgba(245, 158, 11, 0.1); color: var(--ds-warning); }
.ds-badge-danger  { background: rgba(225, 29, 72, 0.1);  color: var(--ds-danger); }
.ds-badge-neutral { background: var(--ds-surface-container); color: var(--ds-on-surface-variant); }

/* ---- Chips ---- */
.ds-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-base);
  padding: 0.3rem var(--ds-space-sm);
  border-radius: var(--ds-radius-full);
  border: 1px solid var(--ds-border-low-contrast);
  background: var(--ds-surface-base);
  font-family: var(--ds-font-family);
  font-size: var(--ds-body-sm-dense-size);
  color: var(--ds-on-surface-variant);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.ds-chip:hover { border-color: var(--ds-primary); color: var(--ds-primary); }
.ds-chip-active {
  background: var(--ds-primary-container);
  border-color: var(--ds-primary);
  color: var(--ds-on-primary-container);
}

/* ---- Form controls (checkbox / radio / switch) ---- */
.ds-checkbox,
.ds-radio {
  width: 18px;
  height: 18px;
  accent-color: var(--ds-primary);
  cursor: pointer;
}
.ds-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}
.ds-switch input { opacity: 0; width: 0; height: 0; }
.ds-switch-track {
  position: absolute;
  inset: 0;
  background: var(--ds-outline-variant);
  border-radius: var(--ds-radius-full);
  transition: background 0.15s ease;
  cursor: pointer;
}
.ds-switch-track::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s ease;
}
.ds-switch input:checked + .ds-switch-track { background: var(--ds-primary); }
.ds-switch input:checked + .ds-switch-track::before { transform: translateX(18px); }

/* ---- Calendar primitives ---- */
.ds-cal-day {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-family: var(--ds-font-family);
  font-size: var(--ds-body-md-size);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.ds-cal-day:hover { background: var(--ds-surface-container-low); }
.ds-cal-day-today { background: var(--ds-primary); color: var(--ds-on-primary); font-weight: 700; }
.ds-cal-day-selected { background: var(--ds-inverse-surface); color: var(--ds-inverse-on-surface); font-weight: 700; }

.ds-cal-event {
  border-radius: var(--ds-radius-sm);
  padding: 2px 5px;
  font-size: var(--ds-body-sm-dense-size);
  font-weight: 600;
  color: #fff;
  background: var(--ds-primary);
  overflow: hidden;
  cursor: pointer;
}
.ds-cal-event-confirmed { background: var(--ds-secondary); }
.ds-cal-event-completed { background: var(--ds-on-surface-variant); }
.ds-cal-event-cancelled { background: var(--ds-danger); opacity: 0.75; }
.ds-cal-event-pending   { background: var(--ds-warning); color: var(--ds-on-surface); }

/* ---- Toasts ---- */
.ds-toast {
  position: fixed;
  bottom: var(--ds-space-lg);
  right: var(--ds-space-lg);
  background: var(--ds-inverse-surface);
  color: var(--ds-inverse-on-surface);
  border-left: 4px solid var(--ds-success);
  border-radius: var(--ds-radius-sm);
  padding: var(--ds-space-sm) var(--ds-space-md);
  font-family: var(--ds-font-family);
  font-size: var(--ds-body-md-size);
  box-shadow: var(--ds-elevation-2);
  z-index: 2000;
  animation: ds-toast-in 0.25s ease;
}
.ds-toast-error   { border-left-color: var(--ds-danger); }
.ds-toast-warning { border-left-color: var(--ds-warning); }
@keyframes ds-toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Loading Skeletons ---- */
.ds-skeleton {
  background: linear-gradient(
    90deg,
    var(--ds-surface-container-low) 25%,
    var(--ds-surface-container) 37%,
    var(--ds-surface-container-low) 63%
  );
  background-size: 400% 100%;
  animation: ds-skeleton-shimmer 1.4s ease infinite;
  border-radius: var(--ds-radius-sm);
}
.ds-skeleton-text  { height: 0.9em; width: 100%; margin-bottom: var(--ds-space-base); }
.ds-skeleton-title { height: 1.4em; width: 60%; margin-bottom: var(--ds-space-sm); }
.ds-skeleton-avatar{ width: 40px; height: 40px; border-radius: 50%; }
.ds-skeleton-card   { height: 120px; width: 100%; border-radius: var(--ds-radius); }
@keyframes ds-skeleton-shimmer {
  0%   { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ---- Consentimiento y firma digital (nuevo-paciente.html + modal
   "Completar firma" en expediente.html — mismo componente, dos lugares) ---- */
.consentimiento-texto {
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg, #f8f9fa);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.1rem 1.35rem;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 1.25rem;
}
.consentimiento-texto h4 {
  font-size: 0.86rem; font-weight: 700; margin: 0 0 0.85rem;
  padding-bottom: 0.6rem; border-bottom: 1px solid var(--border);
  color: var(--text);
}
.consentimiento-texto h5 {
  font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  margin: 1.1rem 0 0.4rem; color: var(--accent);
}
.consentimiento-texto h5:first-of-type { margin-top: 0; }
.consentimiento-texto p { margin: 0 0 0.55rem; font-size: 0.8rem; }
.consentimiento-texto strong { font-weight: 600; }

.consentimiento-seccion-titulo {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 1rem; font-weight: 700; color: var(--text);
  margin-bottom: 0.35rem;
}
.consentimiento-seccion-sub {
  font-size: 0.82rem; color: var(--text-muted); margin-bottom: 1rem;
}

/* ---- Tarjeta de firma: encabezado + estado + contenido ---- */
.firma-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 1.25rem; background: var(--surface);
}
.firma-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.85rem 1.1rem; background: var(--bg, #f8f9fa);
  border-bottom: 1px solid var(--border);
}
.firma-card-head-title { font-size: 0.85rem; font-weight: 700; color: var(--text); }
.firma-status-pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.72rem; font-weight: 700; padding: 0.25rem 0.65rem;
  border-radius: 999px; background: #F3F4F6; color: var(--text-muted);
}
.firma-status-pill.lista { background: rgba(15,122,133,0.12); color: var(--accent); }
.firma-card-body { padding: 1.1rem; }

.firma-tabs { display: flex; gap: 0.5rem; margin-bottom: 0.85rem; }
.firma-tab {
  flex: 1; text-align: center; padding: 0.6rem 0.75rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; font-size: 0.85rem; font-weight: 600;
  color: var(--text-muted); transition: var(--transition, all 0.15s);
}
.firma-tab.active { border-color: var(--accent); background: rgba(15,122,133,0.08); color: var(--accent); }

.firma-panel { display: none; }
.firma-panel.active { display: block; }

.firma-canvas-wrap { position: relative; }
.firma-canvas-el {
  width: 100%; height: 170px;
  border: 1.5px dashed var(--border); border-radius: var(--radius-sm);
  background: #fff; touch-action: none; cursor: crosshair;
  display: block;
}
.firma-canvas-el.tiene-trazo { border-style: solid; border-color: var(--accent); }
.firma-canvas-placeholder {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; color: var(--text-light, #B0BABA); pointer-events: none;
}
.firma-canvas-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 0.6rem; }
.firma-canvas-hint { font-size: 0.75rem; color: var(--text-muted); }

.firma-texto-input {
  width: 100%; padding: 0.75rem 1rem; font-size: 1.05rem; font-family: var(--font-display, inherit);
  font-style: italic; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: #fff;
}
.firma-texto-input:focus { outline: none; border-color: var(--accent); }

.consentimiento-checkbox-row {
  display: flex; align-items: flex-start; gap: 0.75rem;
  margin-top: 0; padding: 1rem 1.1rem;
  background: rgba(15,122,133,0.06); border: 1.5px solid rgba(15,122,133,0.25); border-radius: var(--radius-sm);
}
.consentimiento-checkbox-row input[type="checkbox"] { margin-top: 0.15rem; flex-shrink: 0; width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }
.consentimiento-checkbox-row label { font-size: 0.85rem; font-weight: 600; color: var(--text); margin: 0; line-height: 1.45; cursor: pointer; }
.consentimiento-checkbox-row .req-marca { color: var(--accent); }

.consentimiento-pendiente-link {
  display: inline-block; margin-top: 0.85rem; font-size: 0.78rem;
  color: var(--text-muted); cursor: pointer; text-decoration: underline;
}
.consentimiento-pendiente-panel {
  display: none; margin-top: 0.75rem; padding: 0.85rem 1rem;
  background: #FEF3C7; border: 1px solid #F59E0B; border-radius: var(--radius-sm);
}
.consentimiento-pendiente-panel.active { display: block; }
.consentimiento-pendiente-panel textarea {
  width: 100%; min-height: 60px; margin-top: 0.5rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem; font-family: var(--font-body); font-size: 0.85rem;
  resize: vertical;
}
