/* ===========================================================================
   English Coach — estilo "pizarra de salón de clases"
   Paleta:
     --pizarra      #14352C  fondo, verde pizarra profundo
     --pizarra-2    #0E2820  sombras y paneles
     --tiza         #F6F3E8  texto principal (tiza blanca)
     --tiza-tenue   rgba(246,243,232,.55)
     --amarillo     #F8CE5B  tiza amarilla → el estudiante
     --menta        #8FD6B4  tiza menta   → el profe
   Tipografía:
     Display: Bricolage Grotesque · Cuerpo: Instrument Sans · Acentos: Caveat
   =========================================================================== */

:root {
  --pizarra: #14352c;
  --pizarra-2: #0e2820;
  --tiza: #f6f3e8;
  --tiza-tenue: rgba(246, 243, 232, 0.55);
  --linea: rgba(246, 243, 232, 0.18);
  --amarillo: #f8ce5b;
  --menta: #8fd6b4;
  --rojo: #f08a7e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Instrument Sans', system-ui, sans-serif;
  color: var(--tiza);
  background:
    radial-gradient(1200px 600px at 70% -10%, rgba(143, 214, 180, 0.07), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(248, 206, 91, 0.06), transparent 60%),
    var(--pizarra);
  min-height: 100vh;
  line-height: 1.55;
}

.board {
  max-width: 1060px;
  margin: 0 auto;
  padding: 48px 24px 32px;
}

/* ----- Encabezado ----- */
.board-header { text-align: center; margin-bottom: 36px; }

.eyebrow {
  font-family: 'Caveat', cursive;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}
.eyebrow .es { color: var(--amarillo); }
.eyebrow .en { color: var(--menta); }
.eyebrow .arrow { color: var(--tiza-tenue); padding: 0 0.35em; }

h1 {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 800;
  font-size: clamp(2.6rem, 6vw, 4rem);
  letter-spacing: -0.02em;
  margin: 4px 0 10px;
}

/* Subrayado de tiza: el trazo imperfecto del salón de clases */
.chalk-underline { position: relative; white-space: nowrap; }
.chalk-underline::after {
  content: '';
  position: absolute;
  left: -2%;
  bottom: 0.04em;
  width: 104%;
  height: 0.16em;
  background: var(--amarillo);
  border-radius: 999px 2px 999px 3px;
  transform: rotate(-1.2deg);
  opacity: 0.9;
}

.subtitle {
  max-width: 560px;
  margin: 0 auto;
  color: var(--tiza-tenue);
  font-size: 1.02rem;
}

/* ----- Disposición principal ----- */
.layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
  transition: grid-template-columns 0.45s cubic-bezier(0.4, 0, 0.2, 1),
              gap 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

.panel {
  background: var(--pizarra-2);
  border: 1.5px solid var(--linea);
  border-radius: 14px;
  padding: 26px 24px;
}

/* ----- Panel de control ----- */
.control-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  overflow: hidden;
  min-width: 0;
  opacity: 1;
  transition: opacity 0.3s ease, padding 0.45s cubic-bezier(0.4, 0, 0.2, 1),
              border-width 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ----- Código de acceso ----- */
.access { display: flex; flex-direction: column; gap: 8px; }
.access-label { font-weight: 600; }
.access-field { position: relative; display: flex; align-items: center; }
.access-field input {
  width: 100%;
  min-height: 44px;
  padding: 11px 44px 11px 13px;
  border-radius: 10px;
  border: 1.5px solid var(--linea);
  background: var(--pizarra);
  color: var(--tiza);
  font-family: 'Instrument Sans', sans-serif;
  font-size: 0.98rem;
  letter-spacing: 0.12em;
}
.access-field input:focus-visible { outline: 2px solid var(--amarillo); outline-offset: 1px; }
.eye-btn {
  position: absolute;
  right: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--tiza-tenue);
  cursor: pointer;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.eye-btn:hover { color: var(--tiza); background: rgba(246, 243, 232, 0.06); }
.eye-btn:focus-visible { outline: 2px solid var(--amarillo); outline-offset: 1px; }

/* ----- Sesión (temporizador) ----- */
.session { display: flex; flex-direction: column; gap: 10px; }
.session-label { font-weight: 600; }
.session-row { display: flex; align-items: center; gap: 8px; }
.session-row input {
  width: 70px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1.5px solid var(--linea);
  background: transparent;
  color: var(--tiza);
  font-family: 'Instrument Sans', sans-serif;
  font-size: 0.95rem;
}
.session-row input:focus-visible { outline: 2px solid var(--amarillo); outline-offset: 1px; }
.session-unit { color: var(--tiza-tenue); font-size: 0.9rem; }
.btn.small { flex: 0 0 auto; font-size: 0.92rem; padding: 9px 16px; }
.session-note { color: var(--tiza-tenue); font-size: 0.82rem; line-height: 1.4; }

.orb-wrap { text-align: center; padding-top: 8px; }

/* El orbe de tiza: círculo central con anillos de sonido */
.orb {
  position: relative;
  width: 130px;
  height: 130px;
  margin: 0 auto 14px;
}
.orb-core {
  position: absolute;
  inset: 32px;
  border-radius: 50%;
  border: 2.5px dashed var(--tiza-tenue);
  background: rgba(246, 243, 232, 0.04);
  transition: border-color 0.3s, background 0.3s;
}
.ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  opacity: 0;
}
.r2 { inset: 11px; }
.r3 { inset: 22px; }

/* Escuchando: anillos amarillos (turno del estudiante) */
.orb.listening .orb-core { border-color: var(--amarillo); }
.orb.listening .ring {
  border-color: var(--amarillo);
  animation: pulse 1.8s ease-out infinite;
}
/* Hablando: anillos menta (turno del profe) */
.orb.speaking .orb-core { border-color: var(--menta); background: rgba(143, 214, 180, 0.08); }
.orb.speaking .ring {
  border-color: var(--menta);
  animation: pulse 1.1s ease-out infinite;
}
.r2 { animation-delay: 0.25s !important; }
.r3 { animation-delay: 0.5s !important; }

/* En pausa: orbe atenuado y quieto (la sesión sigue viva, solo en espera) */
.orb.paused .orb-core {
  border-color: var(--tiza-tenue);
  border-style: dotted;
  background: rgba(246, 243, 232, 0.02);
}
.orb.paused .ring { animation: none; opacity: 0; }

@keyframes pulse {
  0%   { transform: scale(0.82); opacity: 0.85; }
  100% { transform: scale(1.12); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ring { animation: none !important; }
  .orb.listening .r1, .orb.speaking .r1 { opacity: 0.6; }
}

.status { color: var(--tiza-tenue); font-size: 0.95rem; min-height: 1.5em; }

/* ----- Botones ----- */
.actions { display: flex; gap: 10px; }

.btn {
  flex: 1;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  padding: 13px 16px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.2s;
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--amarillo); outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.primary { background: var(--amarillo); color: #1c1607; }
.btn.ghost { background: transparent; color: var(--tiza); border-color: var(--linea); }
.btn.ghost.resume { color: var(--menta); border-color: var(--menta); }
.btn.danger { background: transparent; color: var(--rojo); border-color: rgba(240, 138, 126, 0.5); }
.btn.danger:hover { background: rgba(240, 138, 126, 0.08); }

/* Hint de minutos máximos junto al campo */
.session-max-hint {
  font-size: 0.8rem;
  color: var(--tiza-tenue);
  white-space: nowrap;
  align-self: center;
}

/* ----- Modos ----- */
.modes-label { font-weight: 600; margin-bottom: 10px; }

.mode-row { display: flex; gap: 10px; }

.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  padding: 12px 14px;
  background: transparent;
  color: var(--tiza);
  border: 1.5px solid var(--linea);
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  text-align: left;
  transition: border-color 0.2s, background 0.2s;
}
.mode-btn:focus-visible { outline: 2px solid var(--amarillo); outline-offset: 2px; }
.mode-btn .hand {
  font-family: 'Caveat', cursive;
  font-size: 1.05rem;
  color: var(--tiza-tenue);
}
.mode-btn.active {
  border-color: var(--menta);
  background: rgba(143, 214, 180, 0.08);
}
.mode-btn.active strong { color: var(--menta); }

.modes-tip { margin-top: 10px; font-size: 0.85rem; color: var(--tiza-tenue); }

/* ----- Dispositivos de audio ----- */
.device-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.92rem;
}
.device-row span { width: 84px; color: var(--tiza-tenue); flex-shrink: 0; }
.device-row select {
  flex: 1;
  min-width: 0;
  min-height: 44px;                 /* objetivo táctil cómodo */
  background: var(--pizarra);
  color: var(--tiza);
  border: 1.5px solid var(--linea);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.95rem;
  -webkit-appearance: none;
  appearance: none;
  /* flecha propia para verse igual en iOS/Android */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%23cfcab8' stroke-width='1.6' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.device-row select:focus-visible { outline: 2px solid var(--amarillo); outline-offset: 2px; }

/* ----- Errores ----- */
.error {
  display: none;
  background: rgba(240, 138, 126, 0.12);
  border: 1.5px solid var(--rojo);
  color: var(--rojo);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.92rem;
}
.error.visible { display: block; }

/* ----- Panel de conversación ----- */
.conversation-panel { display: flex; flex-direction: column; min-height: 480px; }

.conv-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1.5px solid var(--linea);
  padding-bottom: 12px;
  margin-bottom: 14px;
}
.conv-header-right { display: flex; align-items: center; gap: 10px; }

/* Chip del temporizador (visible también en modo enfoque) */
.session-chip {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  background: rgba(246, 243, 232, 0.06);
  border: 1.5px solid var(--linea);
  border-radius: 999px;
  padding: 4px 13px;
  color: var(--tiza-tenue);
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease, border-color 0.3s ease, font-size 0.3s ease;
}
.session-chip.warning {
  color: var(--rojo);
  border-color: rgba(240, 138, 126, 0.6);
  animation: chipPulse 1.4s ease-in-out infinite;
}
@keyframes chipPulse { 50% { opacity: 0.55; } }
.layout.focus-mode .session-chip { font-size: 1.15rem; padding: 6px 16px; }

/* Nota del sistema dentro del chat: centrada, roja y en negrita */
.system-note {
  align-self: center;
  max-width: 90%;
  text-align: center;
  color: var(--rojo);
  font-weight: 700;
  font-size: 0.92rem;
  padding: 7px 16px;
  margin: 3px 0;
  background: rgba(240, 138, 126, 0.12);
  border: 1px solid rgba(240, 138, 126, 0.45);
  border-radius: 999px;
  animation: msgIn 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.conv-header h2 {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700;
  font-size: 1.25rem;
}

/* Botón para ampliar/restaurar la conversación */
.conv-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'Instrument Sans', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--tiza-tenue);
  background: transparent;
  border: 1.5px solid var(--linea);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.conv-toggle:hover { color: var(--tiza); border-color: var(--tiza-tenue); background: rgba(246,243,232,0.05); }
.conv-toggle:focus-visible { outline: 2px solid var(--amarillo); outline-offset: 2px; }
.conv-toggle[aria-pressed="true"] { color: var(--amarillo); border-color: var(--amarillo); }
.toggle-icon { flex-shrink: 0; }
.layout.focus-mode .expand-icon  { display: none; }
.layout.focus-mode .collapse-icon { display: inline; }
.collapse-icon { display: none; }

/* ----- Modo enfoque: solo la conversación, en grande (transición suave) ----- */
.layout.focus-mode { grid-template-columns: 0 minmax(0, 1fr); gap: 0; }
.layout.focus-mode .control-panel {
  opacity: 0;
  padding-left: 0;
  padding-right: 0;
  border-width: 0;
  pointer-events: none;
}
.layout.focus-mode .conversation-panel { min-height: 76vh; }
.layout.focus-mode .conversation { max-height: 72vh; }
.layout.focus-mode .message { max-width: 70%; }
.layout.focus-mode .conv-header h2 { font-size: 1.5rem; }
.layout.focus-mode .message .who { font-size: 1.25rem; }
.layout.focus-mode .message p { font-size: 1.15rem; }
.layout.focus-mode .empty-hint { font-size: 1.1rem; }

/* Transiciones de tamaño para que el texto crezca/encoja con suavidad */
.conversation-panel { transition: min-height 0.45s cubic-bezier(0.4, 0, 0.2, 1); }
.conv-header h2,
.message .who,
.message p,
.empty-hint { transition: font-size 0.3s ease; }

@media (prefers-reduced-motion: reduce) {
  .layout,
  .control-panel,
  .conversation-panel,
  .conv-header h2,
  .message .who,
  .message p,
  .empty-hint { transition: none; }
}
.legend { color: var(--tiza-tenue); font-size: 1.05rem; }

.conversation {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-height: 560px;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--linea) transparent;
}

.empty-hint { color: var(--tiza-tenue); font-size: 0.95rem; padding-top: 8px; }

/* ----- Burbujas estilo WhatsApp ----- */
.message {
  position: relative;
  max-width: 78%;
  padding: 8px 13px 7px;
  border-radius: 16px;
  border: 1px solid var(--linea);
  background: rgba(246, 243, 232, 0.04);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  animation: msgIn 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.message .who {
  display: block;
  font-family: 'Caveat', cursive;
  font-size: 1.05rem;
  margin-bottom: 1px;
}
.message p { font-size: 0.97rem; line-height: 1.42; word-wrap: break-word; }
.message .time {
  display: block;
  text-align: right;
  font-size: 0.68rem;
  color: var(--tiza-tenue);
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.message.user {
  align-self: flex-end;
  background: rgba(248, 206, 91, 0.13);
  border-color: rgba(248, 206, 91, 0.45);
  border-bottom-right-radius: 5px;   /* "pico" de la burbuja a la derecha */
}
.message.user .who { color: var(--amarillo); }

.message.assistant {
  align-self: flex-start;
  background: rgba(143, 214, 180, 0.12);
  border-color: rgba(143, 214, 180, 0.45);
  border-bottom-left-radius: 5px;    /* "pico" de la burbuja a la izquierda */
}
.message.assistant .who { color: var(--menta); }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

/* Indicador "escribiendo..." con tres puntos (estilo WhatsApp) */
.message.typing { padding: 9px 14px 10px; }
.message.typing.leaving { opacity: 0; transform: translateY(4px); transition: opacity 0.16s ease, transform 0.16s ease; }
.typing-dots { display: inline-flex; gap: 5px; align-items: center; height: 12px; }
.typing-dots .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--tiza-tenue);
  animation: typingBounce 1.3s infinite ease-in-out;
}
.typing-dots .dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dots .dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .message { animation: none; }
  .typing-dots .dot { animation: none; opacity: 0.6; }
  .session-chip.warning { animation: none; }
}

/* ----- Pie ----- */
.board-footer {
  margin-top: 22px;
  text-align: center;
  color: var(--tiza-tenue);
  font-size: 0.88rem;
}

/* ----- Responsive ----- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .conversation-panel { min-height: 320px; }
  .board { padding-top: 32px; }

  /* Selección de audio cómoda al tacto: etiqueta arriba, selector ancho */
  .device-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .device-row span { width: auto; font-size: 0.95rem; }
  .device-row select {
    min-height: 48px;
    font-size: 16px;            /* 16px evita que iOS haga zoom al enfocar */
    padding: 12px 14px;
    padding-right: 36px;
  }
  .session-row input { font-size: 16px; min-height: 48px; }
  .access-field input { font-size: 16px; min-height: 48px; }
}

/* ----- Panel de clases por Zoom (modo meeting bot) ----- */
.plain-link { color: var(--menta); text-decoration: none; }
.plain-link:hover { text-decoration: underline; }

.send-panel { margin-bottom: 20px; }
.send-row { display: flex; gap: 10px; flex-wrap: wrap; }
.send-row input {
  flex: 1;
  min-width: 240px;
  background: var(--pizarra);
  color: var(--tiza);
  border: 1.5px solid var(--linea);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 0.95rem;
}
.send-row input:focus-visible { outline: 2px solid var(--amarillo); outline-offset: 2px; }
.send-row .btn { flex: 0 0 auto; }

.class-list { display: flex; flex-direction: column; gap: 16px; }
.class-card .conversation { max-height: 280px; min-height: 120px; margin-top: 10px; }
.meeting-link {
  color: var(--tiza-tenue);
  font-size: 0.85rem;
  word-break: break-all;
  margin-top: 8px;
}
.badge {
  font-size: 0.82rem;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--linea);
  color: var(--tiza-tenue);
  white-space: nowrap;
}
.badge[data-status="en_clase"] { border-color: var(--menta); color: var(--menta); }
.badge[data-status="sala_de_espera"] { border-color: var(--amarillo); color: var(--amarillo); }
.badge[data-status="error_agente"] { border-color: var(--rojo); color: var(--rojo); }
.class-card .end-btn { flex: 0 0 auto; padding: 8px 14px; font-size: 0.88rem; }

/* ----- Registro de costo oculto (atajo Alt+Shift+C) ----- */
.cost-panel {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 60;
  min-width: 190px;
  background: rgba(14, 40, 32, 0.96);
  border: 1.5px solid var(--linea);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  animation: msgIn 0.25s ease;
}
.cost-title {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--tiza-tenue);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}
.cost-row { display: flex; justify-content: space-between; gap: 18px; font-size: 0.95rem; }
.cost-row + .cost-row { margin-top: 5px; }
.cost-row strong { font-variant-numeric: tabular-nums; }
.cost-row:last-of-type strong { color: var(--menta); }
.cost-hint { margin-top: 11px; font-size: 0.7rem; color: var(--tiza-tenue); text-align: right; }
