/* Qok chat widget — dual-mode.
   Mode A (default): floating bubble bottom-right → click expands to overlay panel.
   Mode B (embedded, desktop with data-mount-desktop): panel fills its container, always visible, no bubble.
   Mode switch is done by qok.js via the `.is-embedded` class on .qok-root. */

.qok-root {
  --qok-accent: var(--accent, #EA580C);
  --qok-accent-hover: var(--accent-hover, #C2410C);
  --qok-card: var(--card, #FFFFFF);
  --qok-text: var(--text, #0F172A);
  --qok-muted: var(--text-muted, #475569);
  --qok-border: var(--border, #E2E8F0);
  --qok-bg-soft: var(--bg-soft, #F1F5F9);
  --qok-shadow-bubble: 0 14px 40px -10px rgba(15, 23, 42, 0.25), 0 4px 10px -4px rgba(15, 23, 42, 0.12);
  font-family: 'Cabinet Grotesk', 'Instrument Sans', sans-serif;
  color: var(--qok-text);
}

/* ═══════════════════════════════════════════════════════════════════
   MODE A — Floating bubble (tablet, mobile, or any host without mount)
   ═══════════════════════════════════════════════════════════════════ */
.qok-root:not(.is-embedded) {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9998;
}

.qok-root:not(.is-embedded) .qok-bubble {
  display: inline-flex;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--qok-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: var(--qok-shadow-bubble);
  transition: transform 180ms ease, background 180ms ease;
  position: relative;
}
.qok-root:not(.is-embedded) .qok-bubble:hover { background: var(--qok-accent-hover); transform: translateY(-2px); }
.qok-root:not(.is-embedded) .qok-bubble:focus-visible { outline: 3px solid rgba(234,88,12,0.4); outline-offset: 3px; }
.qok-root:not(.is-embedded) .qok-bubble svg { width: 26px; height: 26px; }
.qok-root:not(.is-embedded) .qok-bubble .qok-bubble-icon-close { display: none; }
.qok-root:not(.is-embedded).is-open .qok-bubble .qok-bubble-icon-open { display: none; }
.qok-root:not(.is-embedded).is-open .qok-bubble .qok-bubble-icon-close { display: inline-block; }

@keyframes qok-pulse {
  0%   { box-shadow: var(--qok-shadow-bubble), 0 0 0 0 rgba(234,88,12,0.5); }
  70%  { box-shadow: var(--qok-shadow-bubble), 0 0 0 18px rgba(234,88,12,0); }
  100% { box-shadow: var(--qok-shadow-bubble), 0 0 0 0 rgba(234,88,12,0); }
}
.qok-root:not(.is-embedded) .qok-bubble.pulse-once { animation: qok-pulse 1.4s ease-out; }

/* Floating panel: shown when bubble clicked */
.qok-root:not(.is-embedded) .qok-panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--qok-card);
  border: 1px solid var(--qok-border);
  border-radius: 16px;
  box-shadow: var(--qok-shadow-bubble);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.qok-root:not(.is-embedded).is-open .qok-panel {
  display: flex;
  animation: qok-panel-in 220ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes qok-panel-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 640px) {
  .qok-root:not(.is-embedded) .qok-panel {
    position: fixed;
    left: 0; right: 0; top: 0; bottom: 0;
    width: 100%;
    height: 100dvh;
    height: 100vh;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }
  .qok-root:not(.is-embedded).is-open { z-index: 9999; }
  .qok-root:not(.is-embedded) .qok-bubble { width: 56px; height: 56px; }
}

/* ═══════════════════════════════════════════════════════════════════
   MODE B — Embedded (desktop inside .trade-sidebar container)
   ═══════════════════════════════════════════════════════════════════ */
.qok-root.is-embedded {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: 100%;
}
.qok-root.is-embedded .qok-bubble { display: none; }
.qok-root.is-embedded .qok-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--qok-card);
  width: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════════
   PANEL CHROME — shared between modes
   ═══════════════════════════════════════════════════════════════════ */
.qok-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px;
  background: var(--qok-card);
  border-bottom: 1px solid var(--qok-border);
  flex-shrink: 0;
}
.qok-head-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--qok-accent), #FB923C);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.qok-head-avatar svg { width: 18px; height: 18px; }
.qok-head-text { flex: 1; min-width: 0; }
.qok-head-title { font-weight: 800; font-size: 14px; color: var(--qok-text); line-height: 1.2; letter-spacing: -0.2px; }
.qok-head-sub { font-size: 11.5px; color: var(--qok-muted); line-height: 1.35; margin-top: 2px; display: flex; align-items: center; gap: 5px; }
.qok-head-sub .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok, #16A34A); box-shadow: 0 0 0 3px rgba(22,163,74,0.15); }

.qok-head-lang {
  display: inline-flex;
  gap: 2px;
  background: var(--qok-bg-soft);
  border-radius: 8px;
  padding: 2px;
  border: 1px solid var(--qok-border);
  flex-shrink: 0;
}
.qok-head-lang button {
  background: transparent;
  border: none;
  color: var(--qok-muted);
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.3px;
}
.qok-head-lang button.is-active { background: var(--qok-card); color: var(--qok-text); box-shadow: 0 1px 2px rgba(15,23,42,0.06); }

/* In embedded mode, language is owned by the host page — hide widget toggle to avoid two sources of truth */
.qok-root.is-embedded .qok-head-lang { display: none; }

/* Close button visible only in floating mode */
.qok-head-close {
  display: none;
  background: transparent;
  border: none;
  color: var(--qok-muted);
  width: 32px; height: 32px;
  border-radius: 8px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.qok-head-close:hover { background: var(--qok-bg-soft); color: var(--qok-text); }
.qok-head-close svg { width: 18px; height: 18px; }
.qok-root:not(.is-embedded).is-open .qok-head-close { display: inline-flex; }

.qok-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  background: var(--qok-bg-soft);
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 13.5px;
}
.qok-msg {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: qok-msg-in 220ms ease;
}
@keyframes qok-msg-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.qok-msg.bot  { background: var(--qok-card); color: var(--qok-text); border-bottom-left-radius: 4px; align-self: flex-start; box-shadow: 0 1px 2px rgba(15,23,42,0.05); }
.qok-msg.user { background: var(--qok-accent); color: #fff; border-bottom-right-radius: 4px; align-self: flex-end; }

.qok-typing { display: inline-flex; gap: 3px; padding: 4px 0; }
.qok-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--qok-muted); animation: qok-typing 1s infinite ease-in-out; }
.qok-typing span:nth-child(2) { animation-delay: 0.15s; }
.qok-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes qok-typing { 0%,80%,100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.qok-wa {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  background: #25D366;
  color: #fff;
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 700;
  border-top: 1px solid var(--qok-border);
  transition: background 160ms ease;
  flex-shrink: 0;
}
.qok-wa:hover { background: #1EBE57; }
.qok-wa svg { width: 14px; height: 14px; }

.qok-foot {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--qok-border);
  background: var(--qok-card);
  align-items: flex-end;
  flex-shrink: 0;
}
.qok-input {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  background: var(--qok-bg-soft);
  border: 1px solid var(--qok-border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--qok-text);
  resize: none;
  line-height: 1.4;
  max-height: 90px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.qok-input:focus { border-color: var(--qok-accent); box-shadow: 0 0 0 3px rgba(234,88,12,0.15); }
.qok-input::placeholder { color: var(--qok-muted); }

.qok-send {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--qok-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 160ms ease;
}
.qok-send:hover:not(:disabled) { background: var(--qok-accent-hover); }
.qok-send:disabled { opacity: 0.4; cursor: not-allowed; }
.qok-send svg { width: 15px; height: 15px; }

@media (prefers-reduced-motion: reduce) {
  .qok-root, .qok-msg, .qok-send { transition: none !important; animation: none !important; }
  .qok-typing span { animation: none !important; opacity: 0.6; }
}

@media print {
  .qok-root { display: none !important; }
}
