/* QoinPay AI support chat widget — self-contained, navy+gold, theme-agnostic.
   Loaded on both the marketing site and the dashboard. */
#qpy-support {
  --qsc-navy: #16233f;
  --qsc-navy-2: #1f3057;
  --qsc-gold: #c9a227;
  --qsc-gold-deep: #a97e12;
  --qsc-ink: #17233b;
  --qsc-muted: #6b7488;
  --qsc-surface: #ffffff;
  --qsc-surface-2: #f4f6fa;
  --qsc-line: rgba(20, 27, 46, 0.10);
  --qsc-radius: 16px;
  --qsc-font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 2147483000;
  font-family: var(--qsc-font);
}

/* Launcher */
.qsc-fab {
  width: 60px; height: 60px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--qsc-navy-2), var(--qsc-navy));
  color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 30px rgba(22, 35, 63, 0.35), 0 2px 8px rgba(22, 35, 63, 0.25);
  position: relative; transition: transform .18s ease, box-shadow .18s ease;
}
.qsc-fab:hover { transform: translateY(-2px); box-shadow: 0 16px 40px rgba(22, 35, 63, 0.42); }
.qsc-fab::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--qsc-gold); opacity: .0; }
.qsc-fab:hover::after { opacity: .55; }
.qsc-fab__close { display: none; }
#qpy-support.is-open .qsc-fab__open { display: none; }
#qpy-support.is-open .qsc-fab__close { display: block; }
.qsc-fab__badge {
  position: absolute; top: -3px; right: -3px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: var(--qsc-gold); color: #201700; font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 6px rgba(0,0,0,.2);
}

/* Panel — hidden until the widget is opened. A class selector beats the [hidden]
   UA rule, so visibility is driven by .is-open, not the hidden attribute. */
.qsc-panel { display: none; }
#qpy-support.is-open .qsc-panel {
  position: absolute; right: 0; bottom: 74px; width: 380px; max-width: calc(100vw - 32px);
  height: 560px; max-height: calc(100vh - 120px);
  background: var(--qsc-surface); border: 1px solid var(--qsc-line); border-radius: var(--qsc-radius);
  box-shadow: 0 24px 60px rgba(16, 23, 38, 0.28), 0 8px 20px rgba(16, 23, 38, 0.14);
  display: flex; flex-direction: column; overflow: hidden;
  animation: qsc-in .22s cubic-bezier(.22,1,.36,1);
}
@keyframes qsc-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

.qsc-head {
  display: flex; align-items: center; gap: 11px; padding: 14px 16px;
  background: linear-gradient(135deg, var(--qsc-navy-2), var(--qsc-navy)); color: #fff;
}
.qsc-head__avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255,255,255,0.12); display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--qsc-gold); color: var(--qsc-gold);
}
.qsc-head__meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.qsc-head__meta strong { font-size: 14.5px; font-weight: 700; }
.qsc-head__status { font-size: 11.5px; color: rgba(255,255,255,0.72); display: flex; align-items: center; gap: 6px; }
.qsc-head__status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #37d67a; box-shadow: 0 0 0 3px rgba(55,214,122,.2); }
.qsc-head__min { background: none; border: none; color: rgba(255,255,255,0.7); cursor: pointer; padding: 4px; border-radius: 6px; }
.qsc-head__min:hover { background: rgba(255,255,255,0.12); color: #fff; }

.qsc-log { flex: 1; overflow-y: auto; padding: 16px; background: var(--qsc-surface-2); display: flex; flex-direction: column; gap: 10px; }
.qsc-msg { display: flex; flex-direction: column; max-width: 84%; }
.qsc-msg--you { align-self: flex-end; align-items: flex-end; }
.qsc-msg--bot, .qsc-msg--staff { align-self: flex-start; }
.qsc-msg__who { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--qsc-muted); margin: 0 4px 3px; }
.qsc-bubble {
  padding: 10px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.5; color: var(--qsc-ink);
  background: var(--qsc-surface); border: 1px solid var(--qsc-line); word-wrap: break-word;
}
.qsc-msg--you .qsc-bubble {
  background: linear-gradient(135deg, var(--qsc-navy-2), var(--qsc-navy)); color: #fff; border-color: transparent;
  border-bottom-right-radius: 4px;
}
.qsc-msg--bot .qsc-bubble { border-bottom-left-radius: 4px; }
.qsc-msg--staff .qsc-bubble { border-left: 3px solid var(--qsc-gold); border-bottom-left-radius: 4px; }

.qsc-typing { display: flex; gap: 4px; padding: 4px 20px 8px; background: var(--qsc-surface-2); }
.qsc-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--qsc-muted); opacity: .5; animation: qsc-blink 1.2s infinite; }
.qsc-typing span:nth-child(2) { animation-delay: .2s; }
.qsc-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes qsc-blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.qsc-actions { padding: 0 14px; background: var(--qsc-surface-2); }
.qsc-human {
  width: 100%; padding: 8px; margin-bottom: 6px; border-radius: 9px; cursor: pointer; font-family: var(--qsc-font);
  font-size: 12.5px; font-weight: 600; color: var(--qsc-navy); background: #fff; border: 1px solid var(--qsc-line);
}
.qsc-human:hover { border-color: var(--qsc-gold); color: var(--qsc-gold-deep); }

.qsc-composer { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--qsc-line); background: var(--qsc-surface); }
.qsc-input {
  flex: 1; min-width: 0; height: 40px; padding: 0 13px; border: 1px solid var(--qsc-line); border-radius: 10px;
  font-size: 13.5px; font-family: var(--qsc-font); color: var(--qsc-ink); background: var(--qsc-surface-2);
}
.qsc-input:focus { outline: none; border-color: var(--qsc-gold); box-shadow: 0 0 0 3px rgba(201,162,39,.15); background: #fff; }
.qsc-send {
  width: 40px; height: 40px; flex-shrink: 0; border: none; border-radius: 10px; cursor: pointer; color: #201700;
  background: linear-gradient(135deg, var(--qsc-gold), var(--qsc-gold-deep));
  display: flex; align-items: center; justify-content: center; transition: transform .15s ease;
}
.qsc-send:hover { transform: scale(1.05); }
.qsc-legal { font-size: 10.5px; color: var(--qsc-muted); text-align: center; padding: 0 14px 12px; background: var(--qsc-surface); line-height: 1.4; }

/* Lift the launcher clear of the mobile bottom tab bar. --mobile-nav-h is
   measured at runtime (app.js); the 66px constant this replaced was smaller
   than the real bar on notched phones, so the launcher sat on top of it. */
@media (max-width: 1024px) {
  #qpy-support {
    bottom: calc(var(--mobile-nav-h, 57px) + env(safe-area-inset-bottom, 0px) + 14px);
  }
}
@media (max-width: 480px) {
  #qpy-support { right: 14px; }
  .qsc-panel { width: calc(100vw - 28px); height: calc(100vh - 160px); bottom: 70px; }
}
@media (prefers-reduced-motion: reduce) {
  .qsc-panel, .qsc-fab, .qsc-send { animation: none; transition: none; }
  .qsc-typing span { animation: none; }
}
