/* ==========================================================================
   TimpaGym — Consulta Auditiva Interactiva
   Estética clínica moderna, Maletín Desplegable, Seguridad Clínica y Cero Recortes
   ========================================================================== */

:root {
  --bg-page: #f3f8fc;
  --bg-surface: #ffffff;
  --bg-soft: #eaf3fa;
  --border-light: #dbe8f4;
  --border-strong: #bfd6ea;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;

  --blue-primary: #0284c7;
  --blue-deep: #1d4ed8;
  --blue-soft: #e0f2fe;

  --teal-primary: #0d9488;
  --teal-bright: #14b8a6;
  --teal-soft: #ccfbf1;

  --amber-warm: #f59e0b;
  --amber-deep: #b45309;
  --amber-soft: #fef3c7;

  --green-success: #10b981;
  --green-deep: #047857;
  --green-soft: #d1fae5;

  --red-danger: #ef4444;
  --red-deep: #b91c1c;
  --red-soft: #fee2e2;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 28px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 18px 46px rgba(15, 23, 42, 0.2);

  --font-sans: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  height: 100%;
  font-family: var(--font-sans);
  color: var(--text-main);
  background: radial-gradient(circle at 12% 8%, #e6f4fe 0%, #f3f8fc 45%, #eef7f6 100%);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--blue-primary);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app-shell,
.screen {
  width: 100%;
  max-width: 100vw;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: clip;
}

/* ==========================================================================
   COMPONENTES REUTILIZABLES
   ========================================================================== */

.brand-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  padding: 6px 14px 6px 8px;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand-name {
  font-weight: 800;
  font-size: 1.02rem;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.badge-access,
.badge-success {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}

.badge-access {
  background: var(--teal-soft);
  color: #0f766e;
}

.badge-success {
  background: var(--green-soft);
  color: var(--green-deep);
}

.btn-audio-circle {
  position: relative;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-strong);
  color: var(--blue-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: transform 0.14s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.btn-audio-circle:hover {
  border-color: var(--blue-primary);
  background: #f0f9ff;
}

.btn-audio-circle:active {
  transform: scale(0.94);
}

.btn-audio-circle .audio-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
}

.audio-status-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green-success);
  border: 2px solid #ffffff;
}

.btn-audio-circle[aria-pressed="false"] {
  background: #f1f5f9;
  color: #64748b;
  border-color: #cbd5e1;
}

.btn-audio-circle[aria-pressed="false"] .audio-status-dot {
  background: #94a3b8;
}

/* Medidor de Seguridad Clínica (3 vidas) */
.safety-meter {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #fff5f5;
  border: 1.5px solid #fecaca;
  flex-shrink: 0;
}

.safety-meter.is-shake {
  animation: safetyShake 0.36s ease;
}

@keyframes safetyShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-3px); }
}

.safety-heart {
  width: 14px;
  height: 14px;
  display: inline-block;
  background: #e2e8f0;
  clip-path: path('M7 12.8 L6.1 12 C2.6 8.9 0.5 6.9 0.5 4.3 C0.5 2.3 2.1 0.8 4 0.8 C5.2 0.8 6.3 1.4 7 2.3 C7.7 1.4 8.8 0.8 10 0.8 C11.9 0.8 13.5 2.3 13.5 4.3 C13.5 6.9 11.4 8.9 7.9 12 Z');
  transition: transform 0.2s ease, background-color 0.25s ease;
}

.safety-heart.is-full {
  background: #ef4444;
  transform: scale(1);
}

.safety-heart:not(.is-full) {
  transform: scale(0.84);
}

/* Anillo Circular de Claridad Auditiva */
.clarity-ring-widget {
  position: relative;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.clarity-ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.clarity-ring-bg {
  fill: #f8fbfe;
  stroke: #dbe8f4;
  stroke-width: 4.5;
}

.clarity-ring-arc {
  fill: none;
  stroke: var(--blue-primary);
  stroke-width: 4.5;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.22s ease, stroke 0.25s ease;
}

.clarity-ring-widget.is-low .clarity-ring-arc { stroke: var(--amber-warm); }
.clarity-ring-widget.is-mid .clarity-ring-arc { stroke: #0ea5e9; }
.clarity-ring-widget.is-high .clarity-ring-arc { stroke: var(--green-success); }

.clarity-ring-text {
  position: absolute;
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 12px 24px;
  border-radius: 14px;
  background: linear-gradient(135deg, #0284c7 0%, #0d9488 100%);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.96rem;
  box-shadow: 0 8px 22px rgba(2, 132, 199, 0.26);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(2, 132, 199, 0.34);
  filter: brightness(1.04);
}

.btn-primary:active { transform: translateY(0); }

.btn-hero {
  padding: 15px 36px;
  font-size: 1.08rem;
  border-radius: 16px;
}

/* Botón circular grande solo ícono Play con pulso llamativo para niños pequeños */
.btn-play-orb {
  position: relative;
  width: 104px;
  height: 104px;
  margin: 14px auto 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0ea5e9 0%, #0d9488 100%);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 14px 34px rgba(2, 132, 199, 0.38), inset 0 2px 6px rgba(255, 255, 255, 0.35);
  animation: playOrbBreathe 2.1s ease-in-out infinite;
  transition: transform 0.16s ease, filter 0.18s ease;
}

.btn-play-orb:hover {
  filter: brightness(1.07);
  transform: scale(1.06);
}

.btn-play-orb:active {
  transform: scale(0.95);
}

.play-orb-icon {
  position: relative;
  z-index: 2;
  margin-left: 4px;
  filter: drop-shadow(0 3px 6px rgba(15, 23, 42, 0.22));
}

.play-orb-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 3px solid rgba(14, 165, 233, 0.55);
  pointer-events: none;
  animation: playOrbRipple 2.2s cubic-bezier(0.2, 0.7, 0.3, 1) infinite;
}

.play-orb-ring.ring-2 {
  border-color: rgba(20, 184, 166, 0.45);
  animation-delay: 1.1s;
}

@keyframes playOrbBreathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.055); }
}

@keyframes playOrbRipple {
  0% { transform: scale(0.96); opacity: 0.85; }
  100% { transform: scale(1.52); opacity: 0; }
}

.btn-danger-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 14px;
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: 0 8px 20px rgba(239, 68, 68, 0.28);
}

.btn-ghost-modal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 12px;
  background: #f1f5f9;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.88rem;
  border: 1px solid var(--border-light);
}

.btn-ghost-modal:hover {
  background: #e2e8f0;
  color: var(--text-main);
}

.btn-icon-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 10px;
  border-radius: 11px;
  background: #f8fbfe;
  border: 1.5px solid var(--border-light);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
  flex-shrink: 0;
}

.btn-icon-back:hover {
  border-color: var(--blue-primary);
  color: var(--blue-primary);
}

/* ==========================================================================
   PANTALLA 1: INICIO (ENFOCADA EN UN SOLO BOTÓN DE CONSULTA CONTINUA)
   ========================================================================== */

.screen-start {
  justify-content: space-between;
  padding: 18px clamp(14px, 4vw, 42px) 16px;
  gap: 18px;
}

.start-topbar {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.start-main {
  width: 100%;
  max-width: 960px;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.hero-block {
  text-align: center;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(240, 249, 255, 0.92) 100%);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: clamp(26px, 4.5vw, 44px) clamp(18px, 3vw, 36px);
  box-shadow: var(--shadow-md);
}

.hero-kicker {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal-primary);
  background: var(--teal-soft);
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 12px;
}

.hero-title {
  margin: 0;
  font-size: clamp(1.55rem, 3.2vw, 2.5rem);
  line-height: 1.15;
  letter-spacing: -0.025em;
}

.hero-subtitle {
  margin: 12px auto 20px;
  max-width: 600px;
  font-size: clamp(0.96rem, 1.45vw, 1.1rem);
  color: var(--text-muted);
  line-height: 1.5;
}

.session-stats-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-deep);
  font-size: 0.84rem;
  font-weight: 800;
}

.specialties-strip {
  background: var(--bg-surface);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}

.specialties-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.specialties-header h2 {
  margin: 0;
  font-size: 0.98rem;
}

.specialties-header span {
  font-size: 0.8rem;
  color: var(--text-subtle);
}

.specialty-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.spec-tag {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 999px;
  background: #f1f7fc;
  color: #334155;
  border: 1px solid var(--border-light);
}

.spec-tag.is-featured {
  background: linear-gradient(135deg, #e0f2fe 0%, #ccfbf1 100%);
  color: #0369a1;
  border-color: #7dd3fc;
}

.start-footer {
  text-align: center;
}

.start-footer p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-subtle);
}

/* ==========================================================================
   PANTALLA 2: CONSULTA (SOLO BARRA SUPERIOR + VISOR COMPLETO + BOTÓN MALETÍN)
   ========================================================================== */

.screen-consult {
  width: 100%;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  background: #edf5fb;
}

.consult-top {
  width: 100%;
  max-width: 100%;
  background: var(--bg-surface);
  border-bottom: 1.5px solid var(--border-light);
  padding: 7px clamp(10px, 2vw, 18px);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
  z-index: 12;
  overflow: hidden;
}

.top-row-main {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.3fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 100%;
}

.top-left-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.patient-meta {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1;
}

.patient-portrait {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--blue-soft);
  background: var(--bg-soft);
  transition: border-color 0.3s ease;
}

.patient-portrait.is-happy { border-color: var(--green-success); }
.patient-portrait.is-hurt { border-color: var(--red-danger); }

.patient-portrait img,
.patient-portrait svg {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.patient-details {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.patient-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.patient-name {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
  white-space: nowrap;
  flex-shrink: 0;
}

.symptom-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber-deep);
  font-size: 0.69rem;
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.symptom-pill.is-resolved {
  background: var(--green-soft);
  color: var(--green-deep);
}

.symptom-dot {
  width: 6px;
  height: 6px;
  flex-shrink: 0;
  border-radius: 50%;
  background: currentColor;
}

.patient-speech {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clinical-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  background: #f4fafe;
  border: 1.5px solid var(--border-strong);
  padding: 5px 9px 5px 11px;
  border-radius: 12px;
  font-size: 0.79rem;
  font-weight: 700;
  color: var(--text-main);
}

.clinical-banner.is-alert {
  border-color: var(--amber-warm);
  background: #fffbeb;
  color: var(--amber-deep);
}

.clinical-banner.is-danger {
  border-color: var(--red-danger);
  background: var(--red-soft);
  color: var(--red-deep);
}

.clinical-banner.is-success {
  border-color: var(--green-success);
  background: #ecfdf5;
  color: var(--green-deep);
}

.banner-dot {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--teal-primary);
}

#clinical-banner-text {
  flex: 1;
  min-width: 0;
  line-height: 1.24;
}

.step-pill {
  background: #0f172a;
  color: #ffffff;
  font-size: 0.67rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.top-right-gauges {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

/* VISOR CLÍNICO A PANTALLA CASI COMPLETA */
.consult-viewer {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.canvas-stage {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000000;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

#clinical-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}

.wave-source-badge {
  position: absolute;
  left: 10px;
  top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  color: #e0f2fe;
  font-size: 0.7rem;
  font-weight: 700;
  pointer-events: none;
}

.wave-source-badge.is-top {
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
}

.wave-pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #38bdf8;
  animation: pulseRing 1.5s infinite;
}

@keyframes pulseRing {
  0% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7); }
  70% { box-shadow: 0 0 0 7px rgba(56, 189, 248, 0); }
  100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}

/* ==========================================================================
   BOTÓN FLOTANTE DE MALETÍN CLÍNICO + PANEL DESPLEGABLE ESCALABLE
   ========================================================================== */

.tool-dock-floating {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 16;
  max-width: calc(100% - 20px);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Flecha animada apuntando al maletín cuando toca elegir herramienta */
.tool-guide-arrow {
  color: #f59e0b;
  margin-bottom: 4px;
  filter: drop-shadow(0 3px 8px rgba(245, 158, 11, 0.55));
  pointer-events: none;
  animation: guideArrowBounce 0.85s ease-in-out infinite;
}

@keyframes guideArrowBounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-9px) scale(1.08); }
}

.btn-tool-launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px 7px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border: 2px solid var(--border-strong);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
  transition: transform 0.15s ease, border-color 0.2s ease, background-color 0.25s ease, box-shadow 0.2s ease;
}

.btn-tool-launcher:hover {
  transform: translateY(-2px);
  border-color: var(--blue-primary);
}

/* Cambio de color llamativo + vibración juguetona cuando toca abrir el maletín */
.btn-tool-launcher.needs-switch {
  border-color: #f59e0b;
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  animation: suitcaseWiggle 1.45s ease-in-out infinite;
}

.btn-tool-launcher.needs-switch .launcher-action-pill {
  background: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.45);
}

@keyframes suitcaseWiggle {
  0%, 58%, 100% {
    transform: translateY(0) rotate(0deg) scale(1);
    box-shadow: 0 10px 26px rgba(245, 158, 11, 0.28), 0 0 0 0 rgba(245, 158, 11, 0.55);
  }
  65% { transform: translateY(-4px) rotate(-3deg) scale(1.04); }
  72% { transform: translateY(-4px) rotate(3deg) scale(1.04); }
  79% { transform: translateY(-2px) rotate(-2.5deg) scale(1.03); }
  86% {
    transform: translateY(-2px) rotate(2deg) scale(1.02);
    box-shadow: 0 10px 26px rgba(245, 158, 11, 0.35), 0 0 0 12px rgba(245, 158, 11, 0);
  }
}

.launcher-tool-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #f0f9ff;
  border: 1.5px solid #bae6fd;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  flex-shrink: 0;
}

.launcher-tool-icon img,
.launcher-tool-icon svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.launcher-text {
  display: flex;
  flex-direction: column;
  text-align: left;
  line-height: 1.15;
}

.launcher-kicker {
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-subtle);
}

.launcher-name {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text-main);
}

.launcher-action-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, #0284c7 0%, #0d9488 100%);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 800;
}

.tool-count-badge {
  background: rgba(255, 255, 255, 0.24);
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.72rem;
}

/* Panel desplegable del maletín */
.tool-drawer-sheet {
  width: min(680px, calc(100vw - 24px));
  max-height: calc(100dvh - 28px);
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  animation: sheetPop 0.18s ease;
}

@keyframes sheetPop {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.tool-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tool-drawer-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.tool-drawer-header p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.btn-close-sheet {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f1f5f9;
  color: var(--text-muted);
  font-weight: 800;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-close-sheet:hover {
  background: #e2e8f0;
  color: var(--text-main);
}

.drawer-tools-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 2px;
}

.tool-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 13px;
  background: #f8fbfe;
  border: 2px solid var(--border-light);
  text-align: left;
  min-width: 0;
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.tool-btn:hover {
  border-color: var(--blue-primary);
  background: #f0f9ff;
}

.tool-btn.is-active {
  border-color: var(--blue-primary);
  background: linear-gradient(135deg, #e0f2fe 0%, #ecfeff 100%);
  box-shadow: inset 0 0 0 1px rgba(2, 132, 199, 0.18);
}

/* Animación solo por color/borde (sin cambiar tamaño para nunca generar scroll horizontal) */
.tool-btn.is-recommended {
  border-color: #f59e0b;
  background-color: #fffbeb;
  animation: recToolColorPulse 1.35s ease-in-out infinite;
}

.tool-btn.is-recommended::after {
  content: '★';
  position: absolute;
  top: 5px;
  right: 20px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #f59e0b;
  color: #ffffff;
  font-size: 0.68rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes recToolColorPulse {
  0%, 100% {
    background-color: #fffbeb;
    border-color: #f59e0b;
    box-shadow: inset 0 0 0 0 rgba(245, 158, 11, 0);
  }
  50% {
    background-color: #fde68a;
    border-color: #ea580c;
    box-shadow: inset 0 0 0 2px rgba(234, 88, 12, 0.22);
  }
}

.tool-icon-wrap {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 10px;
  background: #ffffff;
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
}

.tool-icon-wrap img,
.tool-icon-wrap svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.tool-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.tool-name {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.15;
}

.tool-sub {
  font-size: 0.69rem;
  color: var(--text-subtle);
  line-height: 1.2;
}

.tool-key {
  position: absolute;
  top: 4px;
  right: 7px;
  font-size: 0.62rem;
  font-weight: 700;
  color: #94a3b8;
}

/* ==========================================================================
   SUB-PANELES DE MINIJUEGOS (EQ, IMPLANTE COCLEAR, BAROTRAUMA)
   ========================================================================== */

.sub-panel {
  position: absolute;
  inset: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  pointer-events: none;
}

.eq-card,
.cochlear-card,
.baro-card {
  pointer-events: auto;
  width: min(740px, 100%);
  max-height: 100%;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(12px);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 13px 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

/* --- EQ 3 BANDAS --- */
.eq-speech-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.eq-speech-bubble {
  flex: 1;
  min-width: 0;
  background: linear-gradient(135deg, #f0f9ff 0%, #ecfdf5 100%);
  border: 1.5px solid #bae6fd;
  border-radius: 12px;
  padding: 8px 12px;
}

.eq-speech-bubble.is-clear {
  border-color: var(--green-success);
  background: #ecfdf5;
}

.eq-speech-tag,
.cochlear-kicker {
  display: block;
  font-size: 0.67rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--blue-primary);
  margin-bottom: 2px;
}

.eq-speech-text {
  margin: 0;
  font-size: clamp(0.95rem, 2.2vw, 1.28rem);
  font-weight: 800;
  transition: filter 0.12s ease;
  user-select: none;
}

.eq-side-metrics {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.eq-clarity-chip,
.eq-timer-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  padding: 6px 8px;
  border-radius: 11px;
  background: var(--bg-soft);
  border: 1px solid var(--border-light);
  font-size: 0.68rem;
  color: var(--text-muted);
}

.eq-clarity-chip strong { font-size: 1rem; color: var(--blue-primary); }
.eq-timer-chip strong { font-size: 1rem; color: var(--text-main); font-variant-numeric: tabular-nums; }
.eq-timer-chip.is-urgent { background: var(--red-soft); border-color: var(--red-danger); }
.eq-timer-chip.is-urgent strong { color: var(--red-deep); }

.eq-osc-wrap {
  background: #0f172a;
  border-radius: 12px;
  padding: 6px 10px;
}

.eq-osc-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: #cbd5e1;
  margin-bottom: 3px;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 4px;
  border-radius: 99px;
  margin-right: 4px;
  vertical-align: middle;
}

.legend-dot.target { background: #94a3b8; border-bottom: 2px dashed #e2e8f0; }
.legend-dot.active { background: #38bdf8; }
.legend-dot.active.is-matched { background: #10b981; }

.eq-oscilloscope {
  display: block;
  width: 100%;
  height: 74px;
}

.eq-sliders-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.eq-band-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  background: #f8fbfe;
  border: 1.5px solid var(--border-light);
  border-radius: 12px;
  padding: 8px 6px;
}

.eq-band-col.is-aligned {
  border-color: var(--green-success);
  background: #f0fdf8;
}

.eq-band-header {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 800;
}

.eq-band-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cbd5e1;
}

.eq-band-col.is-aligned .eq-band-status-dot { background: var(--green-success); }

.eq-slider-track {
  position: relative;
  width: 44px;
  height: 108px;
  border-radius: 999px;
  background: #e2ecf5;
  border: 1px solid #cbd5e1;
  touch-action: none;
  cursor: ns-resize;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 6px;
}

.eq-slider-fill {
  width: 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #0ea5e9 0%, #0d9488 100%);
  pointer-events: none;
}

.eq-band-col.is-aligned .eq-slider-fill {
  background: linear-gradient(180deg, #34d399 0%, #059669 100%);
}

.eq-slider-thumb {
  position: absolute;
  left: 50%;
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: #ffffff;
  border: 2.5px solid #0284c7;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.18);
  transform: translate(-50%, 50%);
  pointer-events: none;
}

.eq-band-col.is-aligned .eq-slider-thumb { border-color: var(--green-success); }

.eq-band-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  color: var(--text-subtle);
  font-weight: 700;
}

.eq-band-val { color: var(--blue-primary); font-variant-numeric: tabular-nums; }
.eq-band-col.is-aligned .eq-band-val { color: var(--green-deep); }

/* --- IMPLANTE COCLEAR (MAPEO DE 5 ELECTRODOS) --- */
.cochlear-card {
  width: min(640px, 100%);
}

.cochlear-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.cochlear-title {
  margin: 0;
  font-size: 1.05rem;
}

.cochlear-feedback {
  font-size: 0.78rem;
  font-weight: 800;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: #0369a1;
}

.cochlear-feedback.is-good { background: var(--green-soft); color: var(--green-deep); }
.cochlear-feedback.is-bad { background: var(--red-soft); color: var(--red-deep); }

.cochlear-body {
  display: grid;
  grid-template-columns: 0.9fr 1.2fr;
  gap: 14px;
  align-items: center;
}

.cochlear-spiral-box {
  background: #0f172a;
  border-radius: 14px;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cochlear-canvas {
  width: 100%;
  max-width: 210px;
  height: 155px;
  display: block;
}

.cochlear-meter-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cochlear-meter-labels,
.baro-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-subtle);
}

.label-green { color: var(--green-deep); }
.label-red { color: var(--red-deep); }

.cochlear-bar-track,
.baro-bar-track {
  position: relative;
  height: 28px;
  border-radius: 999px;
  background: #e2ecf5;
  border: 1.5px solid #cbd5e1;
  overflow: hidden;
}

.cochlear-zone-green,
.baro-zone-green {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(16, 185, 129, 0.34);
  border-left: 2px solid #10b981;
  border-right: 2px solid #10b981;
}

.cochlear-zone-red,
.baro-zone-red {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  background: rgba(239, 68, 68, 0.28);
  border-left: 2px dashed #ef4444;
}

.cochlear-needle {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 10px;
  border-radius: 99px;
  background: #0f172a;
  box-shadow: 0 0 0 2px #ffffff;
  transform: translateX(-50%);
}

.btn-pulse-action {
  width: 100%;
  padding: 13px 18px;
  font-size: 0.98rem;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* --- COMPENSADOR BAROMÉTRICO (BAROTRAUMA) --- */
.baro-card {
  width: min(520px, 100%);
  text-align: center;
}

.baro-header h3 {
  margin: 0;
  font-size: 1rem;
}

.baro-meter-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.baro-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 10%;
  background: linear-gradient(90deg, #38bdf8 0%, #8b5cf6 100%);
  border-radius: 999px;
}

.baro-fill.is-safe {
  background: linear-gradient(90deg, #34d399 0%, #059669 100%);
}

.baro-fill.is-danger {
  background: linear-gradient(90deg, #f97316 0%, #ef4444 100%);
}

.baro-hold-progress {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.baro-hold-track {
  height: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.baro-hold-fill {
  height: 100%;
  width: 0%;
  background: var(--green-success);
  transition: width 0.08s linear;
}

/* ==========================================================================
   MODALES FIJOS AL VIEWPORT (CERO ZOOM, CERO RECORTES)
   ========================================================================== */

.viewer-modal {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(4px);
  z-index: 50;
  overflow: hidden;
  animation: fadeIn 0.16s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(440px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  padding: 18px 20px;
  border: 1.5px solid var(--border-light);
}

.warning-card {
  border-color: var(--amber-warm);
  background: linear-gradient(180deg, #ffffff 0%, #fffbeb 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
}

.warning-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--amber-soft);
  color: #d97706;
  display: flex;
  align-items: center;
  justify-content: center;
}

.warning-card h3 { margin: 0 0 4px; font-size: 1rem; color: var(--amber-deep); }
.warning-card p { margin: 0; font-size: 0.88rem; line-height: 1.45; }

.btn-warning-ok {
  padding: 9px 24px;
  border-radius: 12px;
  background: var(--amber-warm);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.9rem;
}

.victory-card,
.fail-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.victory-card { border-color: var(--green-success); }
.fail-card { border-color: var(--red-danger); }

.victory-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.victory-portrait {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--green-success);
}

.victory-portrait.is-fail {
  border-color: var(--red-danger);
}

.victory-portrait img,
.victory-portrait svg {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.victory-badge,
.fail-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}

.victory-badge { background: var(--green-soft); color: var(--green-deep); }
.fail-badge { background: var(--red-soft); color: var(--red-deep); }

.victory-title { margin: 0; font-size: 1.12rem; }
.victory-text { margin: 0; font-size: 0.87rem; line-height: 1.45; color: var(--text-muted); }

.victory-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
}

/* ==========================================================================
   PANTALLA 3: RESUMEN DE JORNADA
   ========================================================================== */

.screen-summary {
  padding: 16px clamp(14px, 4vw, 40px) 28px;
  gap: 18px;
}

.summary-main {
  width: 100%;
  max-width: 1020px;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.summary-hero {
  text-align: center;
  background: var(--bg-surface);
  border: 1.5px solid #a7f3d0;
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  box-shadow: var(--shadow-md);
}

.summary-title { margin: 0; font-size: clamp(1.2rem, 2.5vw, 1.85rem); }
.summary-subtitle { margin: 8px auto 0; max-width: 600px; font-size: 0.92rem; color: var(--text-muted); }

.summary-recap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.recap-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}

.recap-card.is-failed {
  border-color: #fecaca;
  background: #fffafa;
}

.recap-avatar {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--green-success);
}

.recap-card.is-failed .recap-avatar { border-color: var(--red-danger); }

.recap-avatar img,
.recap-avatar svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.recap-card h3 { margin: 0 0 2px; font-size: 0.9rem; }
.recap-card p { margin: 0; font-size: 0.78rem; color: var(--text-muted); line-height: 1.35; }

.summary-bottom-row {
  display: grid;
  grid-template-columns: 1.4fr 0.9fr;
  gap: 14px;
}

.sponsor-box {
  background: var(--bg-surface);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sponsor-tag { font-size: 0.7rem; font-weight: 800; text-transform: uppercase; color: var(--teal-primary); }
.sponsor-box h3 { margin: 0; font-size: 0.94rem; }
.sponsor-box p { margin: 0; font-size: 0.82rem; color: var(--text-muted); }
.sponsor-contact-line { display: flex; gap: 8px; font-size: 0.8rem; font-weight: 700; color: var(--blue-primary); }

.summary-cta-box {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 14px;
}

.mini-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}

/* ==========================================================================
   RESPONSIVO: MÓVIL HORIZONTAL (ULTRA-LIMPIO)
   ========================================================================== */
@media (max-height: 540px) and (orientation: landscape) {
  .consult-top { padding: 4px 10px; }
  .top-row-main { grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; }
  .back-label, .patient-speech, .symptom-pill { display: none; }
  .btn-icon-back { padding: 6px; }
  .patient-portrait { width: 34px; height: 34px; }
  .patient-name { font-size: 0.82rem; }
  .clinical-banner { padding: 4px 8px; font-size: 0.73rem; }
  .clarity-ring-widget { width: 36px; height: 36px; }
  .btn-audio-circle { width: 34px; height: 34px; }
  .safety-meter { padding: 4px 6px; }
  .safety-heart { width: 12px; height: 12px; }

  /* En horizontal, ubicar el botón de maletín en la esquina inferior derecha sin tapar el canal */
  .tool-dock-floating {
    left: auto;
    right: 12px;
    bottom: 10px;
    transform: none;
  }

  .btn-tool-launcher { padding: 5px 8px 5px 6px; gap: 7px; }
  .launcher-tool-icon { width: 32px; height: 32px; }
  .launcher-kicker { display: none; }
  .launcher-name { font-size: 0.78rem; }
  .launcher-action-pill { padding: 5px 9px; font-size: 0.74rem; }

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

  .eq-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    gap: 6px 10px;
    padding: 8px 10px;
    align-items: center;
  }
  .eq-speech-wrap { grid-column: 1 / 2; grid-row: 1 / 2; }
  .eq-osc-wrap { grid-column: 1 / 2; grid-row: 2 / 3; }
  .eq-sliders-row { grid-column: 2 / 3; grid-row: 1 / 3; gap: 6px; }
  .eq-oscilloscope { height: 58px; }
  .eq-slider-track { height: 100px; width: 36px; }

  .cochlear-canvas { height: 118px; }
  .victory-portrait { width: 52px; height: 52px; }
  .modal-card { padding: 12px 16px; gap: 6px; }
}

/* ==========================================================================
   RESPONSIVO: MÓVIL VERTICAL (BARRA ELEVADA + MALETÍN DE 2 COLUMNAS)
   ========================================================================== */
@media (max-width: 820px) and (orientation: portrait), (max-width: 640px) {
  .summary-bottom-row { grid-template-columns: 1fr; }

  .consult-top { padding: 6px 10px; }
  .top-row-main {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    gap: 6px 8px;
  }
  .top-left-group { grid-column: 1 / 2; grid-row: 1 / 2; }
  .top-right-gauges { grid-column: 2 / 3; grid-row: 1 / 2; }
  .clinical-banner {
    grid-column: 1 / 3;
    grid-row: 2 / 3;
    padding: 5px 9px;
    font-size: 0.75rem;
  }

  .back-label, .badge-access { display: none; }
  .btn-icon-back { padding: 6px; }
  .patient-portrait { width: 36px; height: 36px; }
  .patient-name { font-size: 0.84rem; }
  .patient-speech { font-size: 0.71rem; }
  .clarity-ring-widget { width: 38px; height: 38px; }
  .btn-audio-circle { width: 36px; height: 36px; }
  .safety-meter { padding: 4px 6px; }
  .safety-heart { width: 12px; height: 12px; }

  /* Botón flotante de maletín elevado con margen seguro para Android */
  .tool-dock-floating {
    bottom: calc(26px + env(safe-area-inset-bottom, 12px));
  }

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

  .cochlear-body {
    grid-template-columns: 1fr;
  }

  .cochlear-canvas {
    height: 120px;
  }

  .eq-slider-track {
    height: 98px;
    width: 40px;
  }
}
