/* Micipi Chat Widget — minimal, modern, themable.
 *
 * Variables drive both the fullscreen (index.html) and the embed-iframe
 * (widget.html) views. Override via inline <style> from the embed snippet
 * to brand-match the host site.
 */

:root {
  --m-bg: #ffffff;
  --m-bg-elev: #f7f7fa;
  --m-fg: #14151a;
  --m-fg-muted: #6b6f7a;
  --m-border: rgba(20, 21, 26, 0.08);
  --m-bubble-bot-bg: #f1f1f4;
  --m-bubble-bot-fg: #14151a;
  --m-bubble-user-bg: #14151a;
  --m-bubble-user-fg: #ffffff;
  --m-accent: #6366f1;
  --m-accent-soft: rgba(99, 102, 241, 0.12);
  --m-system: #94959c;
  --m-radius: 18px;
  --m-radius-sm: 12px;
  --m-shadow: 0 12px 40px rgba(20, 21, 26, 0.08);
  --m-font:
    ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Inter', 'Helvetica Neue',
    sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --m-bg: #0b0b0f;
    --m-bg-elev: #14151a;
    --m-fg: #f6f6f9;
    --m-fg-muted: #9a9ba5;
    --m-border: rgba(255, 255, 255, 0.08);
    --m-bubble-bot-bg: #1c1d22;
    --m-bubble-bot-fg: #f6f6f9;
    --m-bubble-user-bg: #f6f6f9;
    --m-bubble-user-fg: #0b0b0f;
    --m-accent: #818cf8;
    --m-accent-soft: rgba(129, 140, 248, 0.18);
    --m-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--m-bg);
  color: var(--m-fg);
  font-family: var(--m-font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.m-chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--m-bg);
}

/* Embedded mode (inside iframe) — no extra max-width. */
.m-chat--embed {
  max-width: none;
}

/* ── Header ───────────────────────────────────────────────────────────── */

.m-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--m-border);
  background: var(--m-bg);
  position: sticky;
  top: 0;
  z-index: 2;
}

.m-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--m-accent-soft);
  color: var(--m-accent);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  flex-shrink: 0;
}

.m-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.m-header__meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.m-header__name {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-header__status {
  font-size: 12px;
  color: var(--m-fg-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.m-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
}

.m-header__close,
.m-header__action {
  background: none;
  border: 0;
  color: var(--m-fg-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease;
}
.m-header__close:hover,
.m-header__action:hover {
  background: var(--m-bg-elev);
  color: var(--m-fg);
}
.m-header__action:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ── Conversation pane ────────────────────────────────────────────────── */

.m-thread {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.m-thread::-webkit-scrollbar {
  width: 6px;
}
.m-thread::-webkit-scrollbar-thumb {
  background: var(--m-border);
  border-radius: 3px;
}

.m-msg {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--m-radius);
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: m-pop 180ms cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.m-msg--bot {
  align-self: flex-start;
  background: var(--m-bubble-bot-bg);
  color: var(--m-bubble-bot-fg);
  border-bottom-left-radius: 6px;
}

.m-msg--user {
  align-self: flex-end;
  background: var(--m-bubble-user-bg);
  color: var(--m-bubble-user-fg);
  border-bottom-right-radius: 6px;
}

.m-msg--system {
  align-self: center;
  background: transparent;
  color: var(--m-system);
  font-size: 12.5px;
  font-style: italic;
  max-width: 90%;
  text-align: center;
}

@keyframes m-pop {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Typing indicator */
.m-typing {
  align-self: flex-start;
  background: var(--m-bubble-bot-bg);
  border-radius: var(--m-radius);
  border-bottom-left-radius: 6px;
  padding: 12px 16px;
  display: inline-flex;
  gap: 4px;
}
.m-typing__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--m-fg-muted);
  opacity: 0.45;
  animation: m-blink 1.2s infinite ease-in-out both;
}
.m-typing__dot:nth-child(2) {
  animation-delay: 0.15s;
}
.m-typing__dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes m-blink {
  0%,
  80%,
  100% {
    transform: scale(0.7);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ── Composer ─────────────────────────────────────────────────────────── */

.m-composer {
  padding: 12px 16px max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--m-border);
  background: var(--m-bg);
  position: sticky;
  bottom: 0;
}

.m-composer__row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--m-bg-elev);
  border-radius: 24px;
  padding: 8px 8px 8px 16px;
  border: 1px solid var(--m-border);
  transition: border-color 0.15s ease;
}

.m-composer__row:focus-within {
  border-color: var(--m-accent);
}

.m-composer__input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--m-fg);
  font: inherit;
  font-size: 15px;
  resize: none;
  max-height: 140px;
  line-height: 1.4;
  padding: 6px 0;
  font-family: inherit;
}

.m-composer__input::placeholder {
  color: var(--m-fg-muted);
}

.m-send {
  border: 0;
  background: var(--m-accent);
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition:
    transform 0.1s ease,
    opacity 0.15s ease;
  flex-shrink: 0;
}
.m-send:hover {
  transform: scale(1.06);
}
.m-send:active {
  transform: scale(0.96);
}
.m-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.m-footer {
  text-align: center;
  font-size: 11px;
  color: var(--m-fg-muted);
  padding: 6px 0 0;
}

.m-footer a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

/* ── Error banner ─────────────────────────────────────────────────────── */

.m-error {
  margin: 12px 16px 0;
  padding: 10px 14px;
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border-radius: var(--m-radius-sm);
  font-size: 13px;
}

/* ── Launcher (embed) ─────────────────────────────────────────────────── */

.m-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483646;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--m-accent);
  border: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: white;
  box-shadow: var(--m-shadow);
  transition: transform 0.15s ease;
}
.m-launcher:hover {
  transform: translateY(-2px);
}
.m-launcher:active {
  transform: translateY(0);
}

.m-launcher svg {
  width: 26px;
  height: 26px;
}

.m-frame {
  position: fixed;
  right: 20px;
  bottom: 96px;
  z-index: 2147483645;
  width: 380px;
  height: min(640px, calc(100dvh - 120px));
  border-radius: 20px;
  border: 1px solid var(--m-border);
  background: var(--m-bg);
  box-shadow: var(--m-shadow);
  overflow: hidden;
  transform-origin: bottom right;
  animation: m-frame-in 180ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.m-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

@keyframes m-frame-in {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (max-width: 480px) {
  .m-frame {
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    border: 0;
  }
}
