/* Chat flotante: burbuja arrastrable + panel. Todo cuelga de #mkpi-chat (no afecta al resto de la página). */

#mkpi-chat {
  --mkc-bg: var(--colorBg, #2f2f2f);
  --mkc-fg: var(--txt1, #fff);
  --mkc-muted: var(--txt2, #c9c9c9);
  --mkc-accent: var(--color1, #106e85);
  --mkc-link: var(--colorlink, #4fc3f7);
  --mkc-size: 54px;
  position: fixed;
  inset: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  z-index: 9000;                      /* por debajo del visor AR (9999), diálogos y avisos */
  pointer-events: none;               /* solo la burbuja y el panel reciben toques */
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#mkpi-chat * { box-sizing: border-box; }
#mkpi-chat button, #mkpi-chat input { font: inherit; }

/* Burbuja ------------------------------------------------------------- */
.mkc-bubble {
  position: absolute; left: 0; top: 0;
  width: var(--mkc-size); height: var(--mkc-size);
  display: grid; place-items: center;
  padding: 0; border: 0; border-radius: 50%;
  color: #fff; background: var(--mkc-accent);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .45);
  cursor: grab; pointer-events: auto;
  touch-action: none;                 /* el dedo arrastra la burbuja, no la página */
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  will-change: transform;
}
.mkc-bubble:focus-visible { outline: 3px solid var(--mkc-link); outline-offset: 3px; }
.mkc-bubble.is-dragging { cursor: grabbing; box-shadow: 0 8px 24px rgba(0, 0, 0, .55); }
.mkc-bubble.is-ready:not(.is-dragging) { transition: transform .22s cubic-bezier(.2, .8, .2, 1); }   /* se pega al borde al soltar */
.mkc-bubble svg { width: 26px; height: 26px; fill: currentColor; pointer-events: none; }
.mkc-online, .mkc-unread {
  position: absolute; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; font-size: 11px; font-weight: 700; line-height: 20px; text-align: center;
  pointer-events: none;
}
.mkc-online { right: -2px; bottom: -2px; color: #06260f; background: #4ade80; border: 2px solid var(--mkc-bg); line-height: 16px; height: 20px; }
.mkc-unread { left: -2px; top: -2px; color: #fff; background: #ef4444; border: 2px solid var(--mkc-bg); line-height: 16px; }
.mkc-unread[hidden] { display: none; }

/* Panel --------------------------------------------------------------- */
.mkc-panel {
  position: absolute; left: 0; top: 0;
  width: 340px; height: min(460px, calc(100% - 16px));
  display: flex; flex-direction: column;
  color: var(--mkc-fg); background: var(--mkc-bg);
  border: 1px solid rgba(255, 255, 255, .14); border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .55);
  overflow: hidden; pointer-events: auto;
  animation: mkc-pop .16s ease-out;
}
.mkc-panel[hidden] { display: none; }
@keyframes mkc-pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.mkc-head { display: flex; align-items: center; gap: .6rem; padding: .65rem .8rem; background: rgba(255, 255, 255, .06); }
.mkc-head strong { font-size: 15px; }
.mkc-count { flex: 1; font-size: 12px; color: var(--mkc-muted); }
.mkc-count::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: #4ade80; }
.mkc-close {
  width: 32px; height: 32px; border: 0; border-radius: 8px; cursor: pointer;
  color: var(--mkc-fg); background: transparent; font-size: 20px; line-height: 1;
}
.mkc-close:hover { background: rgba(255, 255, 255, .1); }

.mkc-log {
  flex: 1; margin: 0; padding: .6rem .8rem; list-style: none; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: .45rem;
}
.mkc-empty { margin: auto; color: var(--mkc-muted); text-align: center; font-size: 13px; }
.mkc-msg { max-width: 92%; align-self: flex-start; word-break: break-word; }
.mkc-msg__meta { display: flex; gap: .4rem; font-size: 11px; color: var(--mkc-muted); }
.mkc-msg__nick { font-weight: 700; color: var(--mkc-link); }
.mkc-msg__body { margin: 2px 0 0; padding: .4rem .65rem; border-radius: 12px 12px 12px 4px; background: rgba(255, 255, 255, .09); white-space: pre-wrap; }
.mkc-msg.is-mine { align-self: flex-end; }
.mkc-msg.is-mine .mkc-msg__meta { justify-content: flex-end; }
.mkc-msg.is-mine .mkc-msg__nick { color: var(--mkc-muted); }
.mkc-msg.is-mine .mkc-msg__body { border-radius: 12px 12px 4px 12px; background: var(--mkc-accent); }

.mkc-status { min-height: 1.3em; margin: 0; padding: 0 .8rem; font-size: 12px; color: #fbbf24; }
.mkc-form { display: grid; grid-template-columns: 1fr auto; gap: .45rem; padding: .5rem .8rem .35rem; }
.mkc-form input[name="nick"] { grid-column: 1 / -1; }
.mkc-form input:not([name="website"]) {
  min-width: 0; min-height: 40px; padding: 0 .7rem; border-radius: 10px;
  color: var(--mkc-fg); background: rgba(255, 255, 255, .09); border: 1px solid rgba(255, 255, 255, .15);
  font-size: 16px;                    /* 16px evita el zoom automático de iOS al enfocar */
}
.mkc-form input[name="nick"] { min-height: 34px; font-size: 14px; }
.mkc-form input:focus-visible { outline: 2px solid var(--mkc-link); outline-offset: 1px; }
.mkc-form input[name="website"] { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }   /* trampa anti-bots */
.mkc-send {
  min-width: 64px; min-height: 40px; border: 0; border-radius: 10px; cursor: pointer;
  font-weight: 600; color: #fff; background: var(--mkc-accent);
}
.mkc-send:disabled { opacity: .5; cursor: default; }
.mkc-note { margin: 0; padding: 0 .8rem .6rem; font-size: 11px; color: var(--mkc-muted); }

/* Móvil: el panel es una hoja inferior para que el teclado y el dedo no choquen con la burbuja */
@media (max-width: 600px) {
  .mkc-panel { left: 8px !important; right: 8px; top: auto !important; bottom: 8px; width: auto; height: min(70dvh, 480px); }
}
@media (prefers-reduced-motion: reduce) {
  .mkc-panel { animation: none; }
  .mkc-bubble.is-ready:not(.is-dragging) { transition: none; }
}
