/* ─────────────────────────────────────────────────────────────
   Registro Anestésico Digital — Historias clínicas
   Estilos del listado y del formulario de historia clínica
   ───────────────────────────────────────────────────────────── */

/* Ancho de lectura cómodo para el formulario */
#view-historias {
  max-width: 1180px;
  margin: 0 auto;
}

/* ── Listado ──────────────────────────────────────────────── */
.hc-link {
  font-weight: 600;
  color: var(--primary);
  text-align: left;
}

.hc-link:hover { text-decoration: underline; }

.hc-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 44px 16px;
  color: var(--foreground);
}

/* ── Barra de acciones del formulario ─────────────────────── */
.hc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.hc-header { margin-bottom: 16px; }

/* ── Índice de secciones ──────────────────────────────────── */
.hc-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.hc-nav-item {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  color: var(--muted-foreground);
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.hc-nav-item:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(28, 80, 163, 0.05);
  text-decoration: none;
}

/* ── Secciones y campos ───────────────────────────────────── */
.hc-section { scroll-margin-top: 16px; }

.hc-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
}

.hc-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.hc-field.wide { grid-column: 1 / -1; }

.hc-help {
  font-size: 11px;
  color: var(--muted-foreground);
  line-height: 1.4;
}

/* ── Grupos de opciones ───────────────────────────────────── */
.opt-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
  padding-top: 2px;
}

.opt-grid {
  display: grid;
  grid-template-columns: repeat(var(--opt-cols, 2), minmax(0, 1fr));
  gap: 4px 14px;
  padding-top: 2px;
}

.opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.opt label {
  font-size: 13px;
  line-height: 1.3;
  cursor: pointer;
  user-select: none;
}

.opt-clear {
  display: inline-flex;
  align-items: center;
  color: var(--muted-foreground);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.opt-clear:hover { color: var(--destructive); background: rgba(207, 53, 39, 0.08); }

/* ── Mapa de dermatomas ───────────────────────────────────── */
.derm-map { display: flex; flex-direction: column; gap: 14px; }

.derm-figures {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px;
}

.derm-figure {
  flex: 1 1 260px;
  max-width: 320px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  padding: 10px 10px 6px;
}

.derm-figure svg {
  width: 100%;
  height: auto;
  display: block;
  touch-action: manipulation;
}

.derm-figure figcaption {
  margin-top: 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--foreground);
}

.derm-figure figcaption span {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--muted-foreground);
}

.derm-region {
  fill: #eef2f7;
  stroke: #b9c3d1;
  stroke-width: 0.6;
  cursor: pointer;
  transition: fill 0.12s;
}

.derm-region:hover { fill: #cfe0f7; }

.derm-region.on { fill: #ef4444; fill-opacity: 0.72; stroke: #b91c1c; }
.derm-region.on:hover { fill-opacity: 0.85; }

.derm-region:focus-visible {
  outline: none;
  stroke: var(--primary);
  stroke-width: 1.6;
}

.derm-label {
  font-size: 6.5px;
  font-weight: 600;
  fill: #334155;
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.85);
  stroke-width: 1.6px;
  stroke-linejoin: round;
}

.derm-label.small { font-size: 5.5px; }

.derm-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #991b1b;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
}

.derm-chip strong { font-weight: 700; }
.derm-chip button { display: inline-flex; color: #b91c1c; }
.derm-chip button:hover { color: #7f1d1d; }

/* ── Cuestionario de Oswestry ─────────────────────────────── */
.owe-wrap { display: flex; flex-direction: column; gap: 12px; }

.owe-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.owe-result-slot { flex: 1 1 260px; }

.owe-result {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted-foreground);
  border-radius: var(--radius-lg);
  background: rgba(233, 237, 243, 0.4);
  padding: 10px 14px;
}

.owe-score { min-width: 74px; text-align: center; }

.owe-percent {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.owe-detail { min-width: 0; }
.owe-detail .hc-help { margin-top: 2px; }

.owe-ok { border-left-color: #16a34a; background: #f0fdf4; }
.owe-ok .owe-percent { color: #15803d; }
.owe-warn { border-left-color: #eab308; background: #fefce8; }
.owe-warn .owe-percent { color: #a16207; }
.owe-high { border-left-color: #f97316; background: #fff7ed; }
.owe-high .owe-percent { color: #c2410c; }
.owe-severe { border-left-color: #dc2626; background: #fef2f2; }
.owe-severe .owe-percent { color: #b91c1c; }

.owe-sections { display: flex; flex-direction: column; gap: 10px; }

.owe-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 12px 10px;
  min-width: 0;
}

.owe-section.pending { border-style: dashed; }

.owe-section legend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 0 4px;
}

.owe-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  font-size: 11px;
  font-weight: 700;
}

.owe-options { display: flex; flex-direction: column; gap: 1px; margin-top: 4px; }

.owe-opt {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 6px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.12s;
}

.owe-opt:hover { background: rgba(233, 237, 243, 0.7); }
.owe-opt.on { background: rgba(28, 80, 163, 0.08); }

.owe-opt input { margin-top: 2px; flex-shrink: 0; }

.owe-points {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--muted);
  color: var(--muted-foreground);
  font-size: 10px;
  font-weight: 700;
  margin-top: 1px;
}

.owe-opt.on .owe-points { background: var(--primary); color: var(--primary-foreground); }

.owe-text { font-size: 13px; line-height: 1.35; }
.owe-opt.on .owe-text { font-weight: 500; }

/* ── Campo de firma ───────────────────────────────────────── */
.signature-field { max-width: 520px; }

.signature-field .signature-box canvas { height: 130px; }

.signature-saved {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #fff;
  padding: 8px;
  min-height: 90px;
}

.signature-saved img {
  max-height: 110px;
  max-width: 100%;
  object-fit: contain;
}

/* ── Foto adjunta (ECG) ───────────────────────────────────── */
.photo-field { max-width: 640px; }

.photo-preview {
  position: relative;
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #fff;
  padding: 0;
  cursor: zoom-in;
}

.photo-preview img { width: 100%; display: block; }

.photo-zoom {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  font-size: 11px;
  padding: 3px 9px;
}

.photo-viewer { padding-top: 8px; }
.photo-viewer img { width: 100%; border-radius: var(--radius-md); }

/* Adjunto que no es imagen (PDF) */
.attach-file {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  padding: 12px 14px;
}

.attach-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Evaluación automática del ECG ────────────────────────── */
.ecg-eval { display: flex; flex-direction: column; gap: 8px; }

.ecg-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  border: 1px solid;
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  font-size: 13px;
}

.ecg-ok { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }
.ecg-warn { background: #fffbeb; border-color: #fde68a; color: #a16207; }
.ecg-alert { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }

.ecg-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }

.ecg-item { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }

.ecg-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  flex-shrink: 0;
  margin-top: 6px;
}

.ecg-item.ecg-normal .ecg-dot { background: #16a34a; }
.ecg-item.ecg-warn .ecg-dot { background: #eab308; }
.ecg-item.ecg-alert .ecg-dot { background: #dc2626; }

.ecg-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ecg-line { line-height: 1.35; }
.ecg-note { font-size: 11px; color: var(--muted-foreground); line-height: 1.35; }

.ecg-disclaimer {
  border-top: 1px dashed var(--border);
  padding-top: 6px;
}

.ecg-disclaimer svg { display: inline; vertical-align: -1px; }

/* ── Tablas editables ─────────────────────────────────────── */
.hc-table-wrap { overflow-x: auto; }

.hc-table { min-width: 460px; }
.hc-table thead th { position: static; }
.hc-table tbody td { padding: 4px 4px; vertical-align: middle; }
.hc-table tbody tr:hover { background: transparent; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .hc-grid { grid-template-columns: 1fr; }
  .opt-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .opt-grid { grid-template-columns: 1fr; }
  .hc-toolbar { align-items: stretch; }
}

/* ── Impresión de la historia clínica ─────────────────────── */
@media print {
  .hc-toolbar,
  .hc-nav { display: none !important; }

  .hc-header { margin-bottom: 4px !important; }

  .hc-section {
    break-inside: avoid;
    page-break-inside: avoid;
    border: 1px solid #cbd5e1 !important;
    margin-bottom: 4px !important;
  }

  .hc-section .card-header { padding: 3px 5px 2px !important; }
  .hc-section .card-title { font-size: 9px !important; }
  .hc-section .card-content { padding: 0 5px 4px !important; }
  /* Al imprimir se muestran todas las secciones, incluso las ocultas en pantalla */
  .hc-section .card-content.hidden { display: block !important; }

  /* En papel siempre a dos columnas, sin importar el ancho de página */
  .hc-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 3px 8px !important;
  }

  .hc-field label { font-size: 6.5px !important; }
  .hc-help { font-size: 6px !important; }

  .opt-grid {
    grid-template-columns: repeat(var(--opt-cols, 2), minmax(0, 1fr)) !important;
    gap: 1px 6px !important;
  }

  /* Los campos de fecha se imprimen como texto */
  input[type="date"]::-webkit-calendar-picker-indicator { display: none !important; }
  input[type="date"] { min-width: 0 !important; }
  .opt label { font-size: 7px !important; }
  .opt input { width: 7px !important; height: 7px !important; }

  .hc-table { min-width: 0 !important; }
  .hc-table-wrap { overflow: visible !important; }

  /* ── Mapa de dermatomas ── */
  .derm-map { gap: 4px !important; }
  .derm-figures { gap: 8px !important; }

  .derm-figure {
    flex: 0 0 auto !important;
    width: 170px !important;
    padding: 2px !important;
    border-color: #cbd5e1 !important;
  }

  .derm-figure figcaption { font-size: 6.5px !important; margin-top: 1px !important; }
  .derm-figure figcaption span { font-size: 5.5px !important; }

  /* Las áreas marcadas deben salir sí o sí en papel */
  .derm-region.on {
    fill: #ef4444 !important;
    fill-opacity: 0.75 !important;
  }

  .derm-chip { font-size: 6.5px !important; padding: 0 4px !important; }

  /* ── Cuestionario de Oswestry ──
     En papel se imprime sólo la respuesta elegida de cada sección:
     las 60 opciones completas ocuparían casi dos hojas. */
  .owe-opt:not(.on) { display: none !important; }

  .owe-wrap { gap: 4px !important; }
  .owe-sections { gap: 2px !important; }

  .owe-section {
    padding: 2px 5px 3px !important;
    border-radius: 3px !important;
    break-inside: avoid;
  }

  .owe-section legend { font-size: 7px !important; gap: 3px !important; }
  .owe-number { width: 10px !important; height: 10px !important; font-size: 6px !important; }
  .owe-section.pending .owe-options::after {
    content: 'Sin responder';
    font-size: 7px;
    color: #64748b;
    font-style: italic;
  }

  .owe-opt { padding: 0 !important; background: transparent !important; }
  .owe-opt input { display: none !important; }
  .owe-points {
    width: 10px !important;
    height: 10px !important;
    font-size: 6.5px !important;
    background: #1c50a3 !important;
    color: #fff !important;
  }
  .owe-text { font-size: 7.5px !important; }

  .owe-result {
    padding: 3px 6px !important;
    gap: 8px !important;
    border-radius: 3px !important;
  }
  .owe-percent { font-size: 14px !important; }
  .owe-score { min-width: 42px !important; }

  /* ── Firma ──
     En papel sale la firma guardada; si no hay, una línea para
     firmar a mano sobre la hoja impresa. */
  .signature-field { max-width: 300px !important; }
  .signature-field .tabs-list,
  .signature-field .upload-drop,
  .signature-field .hc-help { display: none !important; }

  .signature-saved {
    border: none !important;
    padding: 0 !important;
    min-height: 0 !important;
    justify-content: flex-start !important;
  }

  .signature-saved img { max-height: 52px !important; }

  .signature-field .signature-box {
    border: none !important;
    border-bottom: 1px solid #94a3b8 !important;
    border-radius: 0 !important;
    height: 46px !important;
    background: transparent !important;
  }

  .signature-field .signature-box canvas { height: 44px !important; }
  .signature-hint { display: none !important; }

  /* ── Archivos adjuntos (laboratorio, informe cardiológico) ── */
  .photo-field { max-width: 100% !important; }

  /* La miniatura es un botón: la impresión oculta los botones,
     así que hay que volver a mostrarla explícitamente. */
  .photo-preview {
    display: block !important;
    border-color: #cbd5e1 !important;
    cursor: default !important;
    break-inside: avoid;
  }
  .photo-preview img { max-height: 260px !important; object-fit: contain !important; }
  .photo-zoom { display: none !important; }

  .ecg-eval { gap: 3px !important; }
  .ecg-summary { padding: 2px 5px !important; font-size: 7.5px !important; border-radius: 3px !important; }
  .ecg-item { font-size: 7px !important; gap: 4px !important; }
  .ecg-dot { width: 5px !important; height: 5px !important; margin-top: 3px !important; }
  .ecg-note { font-size: 6.5px !important; }
  .ecg-disclaimer { font-size: 6.5px !important; padding-top: 2px !important; }
}
