/* API2Trade live chat widget.
   Ink/paper/sodium palette, matching the marketing site. Self-contained:
   the widget is injected into a page whose CSS it can't rely on, so no
   custom properties from the host are used. */

.a2t-chat-root {
  --a2t-paper: #FAF8F4;
  --a2t-surface: #FFFFFF;
  --a2t-surface-2: #F2EFE9;
  --a2t-ink: #1A1A18;
  --a2t-ink-dim: #5C5A54;
  --a2t-ink-faint: #8A8579;
  --a2t-rule: #E3DFD5;
  --a2t-rule-strong: #C9C4B6;
  --a2t-accent: #D96A16;
  --a2t-accent-hover: #B85610;
  font-family: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ── Launcher ── */
.a2t-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  /* One above .a2t-chat-panel, NOT equal to it. Equal z-index means DOM order
     decides, and the panel is emitted after this button, so it painted over
     the close affordance. */
  z-index: 2147483001;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(135deg, rgba(48, 48, 52, 0.92) 0%, rgba(12, 12, 14, 0.96) 100%);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(217, 106, 22, 0.2);
  color: #fff;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.a2t-chat-toggle:hover { transform: scale(1.06); }
.a2t-chat-toggle .a2t-icon-close { display: none; }
.a2t-chat-root.a2t-open .a2t-chat-toggle .a2t-icon-open { display: none; }
.a2t-chat-root.a2t-open .a2t-chat-toggle .a2t-icon-close { display: block; }

.a2t-unread {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--a2t-accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  box-sizing: border-box;
}
.a2t-unread.a2t-show { display: flex; }

/* ── Panel ── */
.a2t-chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 2147483000;
  width: 360px;
  max-height: 520px;
  display: none;
  flex-direction: column;
  overflow: hidden;
  background: var(--a2t-surface);
  border: 1px solid var(--a2t-rule);
  border-radius: 4px;
  box-shadow: 0 24px 60px rgba(26, 26, 24, 0.18);
}
.a2t-chat-root.a2t-open .a2t-chat-panel { display: flex; }

.a2t-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--a2t-rule);
  background: var(--a2t-surface-2);
}
.a2t-avatar {
  width: 34px;
  height: 34px;
  border-radius: 2px;
  background: var(--a2t-accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}
/* Telegram shortcut -- icon only, sits at the far right of the header.
   For people who would rather talk there than in the widget. */
.a2t-tg {
  margin-left: auto;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 2px;
  color: var(--a2t-ink-faint);
  text-decoration: none;
  transition: color 0.2s, background 0.2s;
}
.a2t-tg:hover { color: #229ED9; background: rgba(34,158,217,0.10); }

.a2t-chat-title { font-size: 14px; font-weight: 600; color: var(--a2t-ink); }
.a2t-chat-sub {
  font-size: 12px;
  color: var(--a2t-ink-dim);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}
.a2t-status-led {
  width: 6px;
  height: 6px;
  border-radius: 1px;
  background: #16A34A;
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.16);
}

/* ── Messages ── */
.a2t-chat-messages {
  flex: 1;
  min-height: 180px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--a2t-paper);
}
.a2t-msg { max-width: 82%; display: flex; flex-direction: column; gap: 3px; }
.a2t-msg-visitor { align-self: flex-end; align-items: flex-end; }
.a2t-msg-admin { align-self: flex-start; align-items: flex-start; }
.a2t-bubble {
  padding: 9px 12px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.a2t-msg-visitor .a2t-bubble { background: var(--a2t-accent); color: #fff; }
.a2t-msg-admin .a2t-bubble {
  background: var(--a2t-surface);
  color: var(--a2t-ink);
  border: 1px solid var(--a2t-rule);
}
.a2t-time { font-size: 10.5px; color: var(--a2t-ink-faint); font-variant-numeric: tabular-nums; }

.a2t-waiting {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 11px 13px;
  background: var(--a2t-surface);
  border: 1px solid var(--a2t-rule);
  border-radius: 4px;
}
.a2t-waiting span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--a2t-ink-faint);
  animation: a2tBounce 1.3s infinite ease-in-out;
}
.a2t-waiting span:nth-child(2) { animation-delay: 0.16s; }
.a2t-waiting span:nth-child(3) { animation-delay: 0.32s; }
@keyframes a2tBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .a2t-waiting span { animation: none; }
  .a2t-chat-toggle { transition: none; }
}

/* ── Email gate + composer ── */
.a2t-gate, .a2t-input-row {
  padding: 12px;
  border-top: 1px solid var(--a2t-rule);
  background: var(--a2t-surface);
}
.a2t-gate-label {
  font-size: 12.5px;
  color: var(--a2t-ink-dim);
  margin-bottom: 8px;
  line-height: 1.45;
}
.a2t-gate-row, .a2t-input-row { display: flex; gap: 8px; }
.a2t-gate-row { align-items: stretch; }

.a2t-chat-panel input[type="email"],
.a2t-chat-panel input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--a2t-rule-strong);
  border-radius: 2px;
  font-family: inherit;
  font-size: 14px;
  color: var(--a2t-ink);
  background: var(--a2t-paper);
  box-sizing: border-box;
}
.a2t-chat-panel input:focus { outline: 2px solid var(--a2t-accent); outline-offset: -1px; }

.a2t-btn {
  padding: 9px 14px;
  border: 1px solid var(--a2t-accent);
  border-radius: 2px;
  background: var(--a2t-accent);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}
.a2t-btn:hover { background: var(--a2t-accent-hover); border-color: var(--a2t-accent-hover); }
.a2t-btn[disabled] { opacity: 0.55; cursor: default; }

.a2t-error {
  font-size: 12px;
  color: #B91C1C;
  margin-top: 7px;
  display: none;
}
.a2t-error.a2t-show { display: block; }

.a2t-privacy {
  font-size: 10.5px;
  color: var(--a2t-ink-faint);
  margin-top: 8px;
  line-height: 1.4;
}
.a2t-privacy a { color: var(--a2t-ink-dim); }

@media (max-width: 480px) {
  .a2t-chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 84px;
    max-height: 70vh;
  }
  .a2t-chat-toggle { bottom: 16px; right: 16px; }
}


/* ══════════════════════════════════════════════════════════════════════════
   Touch targets
   ══════════════════════════════════════════════════════════════════════════
   The launcher doubles as the close button -- it swaps to an X while the panel
   is open -- so on a phone it is the only way out of the chat. At 56px with a
   20px glyph that is already a tight target for a thumb; two situations make it
   worse and are handled separately below.
   ══════════════════════════════════════════════════════════════════════════ */

/* 1. Ordinary phone layout. Coarse pointer plus a narrow viewport: give the
      button and especially the X real thumb size. Gated on pointer:coarse so a
      narrow desktop window is left alone. */
@media (pointer: coarse) and (max-width: 767px) {
  .a2t-chat-toggle {
    width: 64px;
    height: 64px;
    bottom: 20px;
    right: 20px;
  }
  .a2t-chat-root.a2t-open .a2t-chat-toggle {
    /* Bigger again while open: this is the close affordance, and it sits over
       the panel where a mis-tap costs the user their place. */
    width: 68px;
    height: 68px;
  }
  .a2t-chat-toggle .a2t-icon-close { width: 30px; height: 30px; }
  .a2t-chat-toggle .a2t-icon-open  { width: 26px; height: 26px; }
}

/* 2. The host site's mini-desktop mode, where a phone renders the 1024px
      desktop layout scaled to fit -- roughly 0.38x on a 390px device. Every
      fixed size in this file is multiplied by that, so the 56px launcher lands
      at ~21px physical and its 20px X at ~8px: effectively untappable, and
      no width-based media query can detect it because the viewport reports
      1024px. html.mini-desktop is set on the host page by its own script, and
      is the only honest signal here.

      Sizes are chosen so the RESULT is a sane target rather than the source:
      at 0.38x, 116px -> ~44px physical, which is the usual minimum, and the
      52px X -> ~20px. Deliberately not applied at pointer:fine, so a desktop
      browser that somehow carries the class is unaffected. */
@media (pointer: coarse) {
  html.mini-desktop .a2t-chat-toggle {
    width: 116px;
    height: 116px;
    bottom: 40px;
    right: 40px;
    border-width: 3px;
  }
  /* Clear the enlarged launcher: 40px offset + 116px tall = 156px, plus a
     16px gap. Without this the panel's lower edge lands on top of the button. */
  html.mini-desktop .a2t-chat-panel {
    bottom: 172px;
    max-height: calc(100vh - 220px);
  }
  html.mini-desktop .a2t-chat-toggle .a2t-icon-close { width: 52px; height: 52px; }
  html.mini-desktop .a2t-chat-toggle .a2t-icon-open  { width: 46px; height: 46px; }
  html.mini-desktop .a2t-chat-toggle .a2t-icon-close path,
  html.mini-desktop .a2t-chat-toggle .a2t-icon-open path {
    stroke-width: 2;
  }
  /* The unread pill hangs off the launcher corner; keep it in proportion. */
  html.mini-desktop .a2t-unread {
    min-width: 40px;
    height: 40px;
    border-radius: 20px;
    font-size: 22px;
    border-width: 4px;
  }
}
