/* Fuentes de la marca (OFL), alojadas en el propio servidor */
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 900; font-display: swap; src: url(fonts/nunito-latin.woff2) format('woff2'); }
@font-face { font-family: 'Varela Round'; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/varela-round-latin.woff2) format('woff2'); }

/* Paleta imegle: azul + naranja. Tema oscuro por defecto; claro solo si el usuario lo elige. */
:root {
  --blue: #1d6ff2;
  --blue-2: #3b82f6;
  --orange: #ff7a1a;
  --orange-2: #ff9a4a;
  --on-orange: #241000;
  --accent: var(--blue);
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 16px;

  --bg: #0b1220;
  --panel: #111a2c;
  --panel-2: #18233a;
  --border: #25324d;
  --text: #e8eef8;
  --muted: #8e9cb6;
  --slogan: #7cb7ff;
  --divider: #ffffff24;
  --glow-1: #15305e;
  --glow-2: #35200c;
  --video-bg: #05070b;
  --overlay-1: #0f1728;
  --overlay-2: #0a0e16;
  --warn-bg: #7f1d1d66;
  --warn-border: #ef444488;
  --warn-text: #fecaca;
  --warn-strong: #ffffff;
  --shadow: 0 20px 60px #000a;
  --backdrop: #0008;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f6fb; --panel: #ffffff; --panel-2: #eef2f8; --border: #d8e0ec; --text: #152036; --muted: #5d6b83;
  --slogan: #1d5fd1; --divider: #0000001f; --glow-1: #dbe8ff; --glow-2: #ffe8d4;
  --overlay-1: #eaf0fa; --overlay-2: #dfe7f4;
  --warn-bg: #fee2e2; --warn-border: #fca5a5; --warn-text: #991b1b; --warn-strong: #7f1d1d;
  --shadow: 0 20px 60px #0f172a33; --backdrop: #0f172a55;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 600px at 10% -10%, var(--glow-1) 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 110%, var(--glow-2) 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px;
}
/* Logo: burbuja azul con la "i" + "megle" en naranja; eslogan a la derecha (debajo en móvil) */
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; color: inherit; text-decoration: none; }
.wordmark { display: flex; align-items: center; gap: 5px; font: 900 31px/1 'Nunito', system-ui, sans-serif; color: var(--orange); letter-spacing: -.2px; }
.wordmark .mark { width: 28px; height: 31px; flex: none; }
.wordmark .megle { margin-bottom: 5px; }
.slogan { font: 15px/1.2 'Varela Round', system-ui, sans-serif; color: var(--slogan); padding-left: 14px; border-left: 1.5px solid var(--divider); white-space: nowrap; }
.top-right { display: flex; align-items: center; gap: 8px; }
.seg {
  display: flex; padding: 3px; gap: 2px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
}
.seg button {
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-family: inherit; font-size: 12px; font-weight: 600; line-height: 1; letter-spacing: .5px;
  /* Mismo tamaño en el selector de tema (iconos) y en el de idioma (texto) */
  height: 25px; width: 31px; padding: 0; border-radius: 999px; transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--blue); color: #fff; }
.online {
  display: flex; align-items: center; gap: 4px;
  background: var(--panel); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px; font-size: 14px; color: var(--muted);
}
.online #onlineCount { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 4px; box-shadow: 0 0 0 0 #22c55e88; animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px #22c55e00; } 100% { box-shadow: 0 0 0 0 #22c55e00; } }

/*
 * Escritorio: la columna de vídeo crece como máximo hasta que cada recuadro (hay dos apilados)
 * alcanza 4:3. A partir de ahí todo el ancho sobrante se lo queda el chat (mínimo 360px).
 * 100cqh = alto del área de contenido de .layout (contenedor de consulta).
 */
.layout {
  --gap: 16px;
  flex: 1; min-height: 0;
  container-type: size;
  display: flex; gap: var(--gap);
  padding: 0 20px 20px;
}
.videos {
  display: grid; grid-template-rows: 1fr 1fr; gap: var(--gap); min-height: 0; min-width: 0;
  flex: 0 1 auto;
  width: calc((100cqh - var(--gap)) / 2 * 4 / 3); /* recuadros 4:3, la proporción preferida de la cámara */
}
.video-box {
  position: relative; overflow: hidden; border-radius: var(--radius);
  background: var(--video-bg); border: 1px solid var(--border); min-height: 0;
}
/* El vídeo ocupa el máximo espacio disponible sin recortarse y manteniendo su proporción */
.video-box video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; object-position: center; display: block; background: var(--video-bg);
}
.video-box.local video { transform: scaleX(-1); }
/* Sin vídeo (se ve el aviso): nada oscuro debajo, o en tema claro asoma por el borde redondeado
   y las esquinas parecen más gruesas. El fondo oscuro solo cuando hay vídeo. */
.video-box:has(> .overlay:not(.gone)) { background: var(--overlay-2); }
.video-box:has(> .overlay:not(.gone)) video { visibility: hidden; }
.label {
  position: absolute; left: 12px; bottom: 12px; font-size: 12px;
  background: #000a; padding: 3px 10px; border-radius: 999px; color: #fff; backdrop-filter: blur(6px);
}
.badge {
  position: absolute; right: 12px; top: 12px; font-size: 12px;
  padding: 3px 10px; border-radius: 999px; backdrop-filter: blur(6px);
  background: #000a; border: 1px solid #ffffff22;
}
.badge.p2p { color: #86efac; }
.badge.relay { color: #fcd34d; }
.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; text-align: center; padding: 20px;
  color: var(--muted); background: linear-gradient(160deg, var(--overlay-1), var(--overlay-2));
  transition: opacity .25s;
}
.overlay.small { font-size: 13px; }
.overlay.gone { opacity: 0; pointer-events: none; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--orange); animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chat {
  flex: 1 0 360px; min-width: 360px;
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 14px; word-wrap: break-word; white-space: pre-wrap; }
.msg.me { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.sys { align-self: center; font-size: 12.5px; color: var(--muted); text-align: center; padding: 2px 8px; }
/* Aviso disuasorio a quien acumula reportes */
.sys.warn { align-self: stretch; color: var(--warn-text); background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 10px; padding: 8px 12px; font-size: 13px; line-height: 1.4; }
.sys.warn b { color: var(--warn-strong); letter-spacing: .03em; }
.typing { font-size: 12px; color: var(--muted); padding: 0 14px 6px; }

.composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.composer input {
  flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font: inherit; outline: none;
}
.composer input:focus { border-color: var(--blue); }
.composer button {
  width: 42px; border: 0; border-radius: 10px; background: var(--blue); color: #fff; cursor: pointer;
  display: grid; place-items: center;
}
.composer :disabled { opacity: .45; cursor: not-allowed; }

/* Botones de tamaño fijo (el que tienen con el chat a su ancho mínimo de 360px), alineados a la izquierda */
.controls { display: grid; grid-template-columns: repeat(2, 165px); justify-content: start; gap: 10px; padding: 0 10px 10px; }
.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 13px 10px; border-radius: 12px; font: 600 15px/1 inherit; font-family: inherit; cursor: pointer;
  transition: transform .08s, filter .15s, background .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
/* Iniciar: azul. Siguiente/Skip (en llamada): naranja, la acción más usada. */
.btn.primary { background: var(--blue); border: 0; color: #fff; }
#nextBtn:not(:disabled) { background: var(--orange); border-color: var(--orange); color: var(--on-orange); }
.btn.danger { background: var(--danger); border: 0; color: #fff; }
kbd { font: 11px/1 ui-monospace, monospace; border: 1px solid currentColor; border-radius: 4px; padding: 2px 4px; margin-left: 4px; opacity: .6; }
/* Botón de reportar (bandera roja) en el vídeo remoto */
.icon-btn.report-btn { position: absolute; left: 12px; top: 12px; z-index: 3; color: #ef4444; border-color: #ef444466; }
.icon-btn.report-btn:hover:not(:disabled) { background: #ef4444; color: #fff; }
.icon-btn.report-btn:hover svg { transform: none; }
.icon-btn.report-btn.done, .icon-btn.report-btn:disabled { background: #ef4444; color: #fff; cursor: default; opacity: .85; }
.notice { margin: 0; padding: 0 12px 10px; font-size: 11.5px; line-height: 1.35; color: var(--muted); opacity: .8; }
.hidden { display: none !important; }

/* Botón de dispositivos sobre la cámara propia: visible al pasar el ratón */
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0;
  border: 1px solid #ffffff22; border-radius: 50%; cursor: pointer;
  background: #000a; color: #fff; backdrop-filter: blur(6px);
  transition: opacity .2s, transform .2s, background .15s;
}
.icon-btn:hover { background: #000d; }
.icon-btn:hover svg { transform: rotate(45deg); }
.icon-btn svg { transition: transform .3s; }
.device-btn { position: absolute; top: 10px; right: 10px; z-index: 3; opacity: 0; transform: scale(.9); }
.video-box.local:hover .device-btn,
.device-btn:focus-visible { opacity: 1; transform: none; }
@media (hover: none) { .device-btn { opacity: 1; transform: none; width: 32px; height: 32px; } }

/* Silenciar micrófono propio / audio remoto: visibles al pasar el ratón (como el de ajustes).
   Si están silenciados se quedan siempre visibles, con una raya roja en diagonal. */
.hover-btn { position: absolute; z-index: 3; opacity: 0; transform: scale(.9); }
.video-box:hover .hover-btn, .hover-btn:focus-visible, .mute-btn.muted { opacity: 1; transform: none; }
/* Esquina inferior derecha de cada vídeo */
.mic-mute { right: 10px; bottom: 10px; }
.remote-mute { right: 12px; bottom: 12px; }
.video-box.remote:not(.in-call) .remote-mute:not(.muted) { display: none; }
.icon-btn.mute-btn:hover svg { transform: none; }
.mute-btn .slash { stroke: #ef4444; stroke-width: 2.6; stroke-linecap: round; opacity: 0; }
.mute-btn.muted .slash { opacity: 1; }
.mute-btn.muted { border-color: #ef444499; }
@media (hover: none) {
  .hover-btn { opacity: 1; transform: none; width: 32px; height: 32px; }
  .mic-mute { right: 8px; bottom: 8px; }
}

/* Diálogo de dispositivos */
.devices {
  width: min(400px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--panel); color: var(--text);
  box-shadow: var(--shadow);
}
.devices::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
.devices form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.devices h2 { margin: 0 0 2px; font-size: 17px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field select {
  width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 14px; outline: none;
}
.field select:focus { border-color: var(--blue); }
.hint { margin: 0; font-size: 12.5px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; }
.dialog-actions .btn { padding: 10px 22px; }

@media (max-width: 860px) {
  .topbar { padding: 10px 16px; }
  .brand { flex-direction: column; align-items: flex-start; gap: 2px; flex: none; }
  .wordmark { font-size: 25px; gap: 4px; }
  .wordmark .mark { width: 22px; height: 25px; }
  .wordmark .megle { margin-bottom: 4px; }
  .slogan { border: 0; padding: 0 0 0 1px; font-size: 12px; }
  .top-right { gap: 6px; }
  .seg button { width: 28px; }
  .online { padding: 5px 10px; font-size: 13px; }
  .layout { container-type: normal; display: grid; grid-template-columns: 1fr; grid-template-rows: auto minmax(260px, 1fr); padding: 0 16px 16px; --gap: 12px; }
  /* Vídeo casi cuadrado (15:16); el resto del alto es para el chat. En pantallas bajas el vídeo cede
     para que el chat conserve al menos ~340px (mensajes + escribir + botones). */
  .videos { width: 100%; grid-template-rows: none; grid-template-columns: 1fr; position: relative; aspect-ratio: 15 / 16; max-height: calc(100dvh - 340px); container-type: size;
    /* Alto de la miniatura propia: 34% del recuadro, o menos si con la proporción de la cámara superaría el 40% del ancho */
    --local-h: min(34cqh, calc(40cqw / var(--local-ratio, 0.75))); }
  .chat { min-width: 0; }
  .controls { grid-template-columns: 1fr 1fr; }
  /* Miniatura propia: siempre con la proporción exacta de la cámara (sin bandas negras) */
  .video-box.local { position: absolute; right: 10px; bottom: 10px; height: var(--local-h); width: auto; aspect-ratio: var(--local-ar, 3 / 4); z-index: 2; border-radius: 12px; }
  .video-box.local .label { display: none; }
  .remote-mute { right: 10px; bottom: calc(var(--local-h) + 18px); }
  /* La miniatura propia es baja: engranaje y micrófono en la misma fila inferior, el micro en la esquina */
  .video-box.local .device-btn { top: auto; bottom: 8px; right: 46px; }
  .video-box.local .mic-mute { right: 8px; bottom: 8px; }
  kbd { display: none; }
}
/* Móvil estrecho: el contador muestra solo el número (el texto sigue en el tooltip) */
@media (max-width: 480px) {
  .topbar { padding: 10px 12px; gap: 8px; }
  .top-right { gap: 5px; }
  .online [data-i18n="online"] { display: none; }
  .online { padding: 5px 9px; }
}
