/* ==========================================================================
   Accuracy Accounting Suite — marketing chat widget
   Self-contained, brand-matched (navy #0C2340 + teal #37D9C8).
   Everything is scoped under .acc-chat so it cannot clash with the site CSS.
   Brand tokens fall back to literals so the widget is correct even if
   styles.css hasn't loaded / changes.
   ========================================================================== */

.acc-chat {
  /* Local tokens (mirror the site, with hard fallbacks) */
  --acc-navy:      var(--navy, #0C2340);
  --acc-navy-2:    var(--navy-2, #15365C);
  --acc-teal:      #37D9C8;
  --acc-teal-deep: #0fae9f;
  --acc-ink:       #14233a;
  --acc-muted:     #5b6b80;
  --acc-surface:   #ffffff;
  --acc-bot-bg:    #eef2f7;
  --acc-bot-ink:   #1c2c44;
  --acc-border:    #e1e4e8;
  --acc-ring:      0 0 0 3px rgba(55, 217, 200, .5);
  --acc-shadow:    0 18px 50px rgba(12, 35, 64, .28), 0 6px 18px rgba(12, 35, 64, .16);
  --acc-radius:    18px;
  --acc-font:      "Sora", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --acc-body:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --acc-panel-w:   370px;
  --acc-panel-h:   544px;

  position: fixed;
  right: clamp(14px, 2.4vw, 26px);
  bottom: clamp(14px, 2.4vw, 26px);
  z-index: 2147483000;            /* above sticky header + mobile menu */
  font-family: var(--acc-body);
  line-height: 1.5;
}

.acc-chat *,
.acc-chat *::before,
.acc-chat *::after { box-sizing: border-box; }

/* ----------------------------------------------------------- Launcher ---- */
.acc-chat__launcher {
  position: relative;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: var(--acc-teal);
  color: #06231f;
  box-shadow: 0 10px 26px rgba(55, 217, 200, .42), 0 3px 10px rgba(12, 35, 64, .25);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .2s cubic-bezier(.34, 1.56, .64, 1), box-shadow .2s ease, background .2s ease;
  -webkit-tap-highlight-color: transparent;
}
.acc-chat__launcher:hover { background: #54e6d6; transform: translateY(-2px); }
.acc-chat__launcher:active { transform: translateY(0); }
.acc-chat__launcher:focus-visible { outline: none; box-shadow: var(--acc-ring), 0 10px 26px rgba(55, 217, 200, .42); }
.acc-chat__launcher svg { width: 28px; height: 28px; display: block; pointer-events: none; }
.acc-chat__launcher .acc-i-chat { width: 36px; height: 36px; }   /* Wingman bubble — fill the button more (X stays 28px) */
.acc-chat__launcher .acc-i-chat,
.acc-chat__launcher .acc-i-x { grid-area: 1 / 1; transition: opacity .18s ease, transform .18s ease; }
.acc-chat__launcher .acc-i-x { opacity: 0; transform: rotate(-45deg) scale(.7); }

/* Unread dot on the launcher (welcome / new reply while closed) */
.acc-chat__launcher::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #ff5d5d;
  border: 2px solid var(--acc-navy);
  opacity: 0;
  transform: scale(.4);
  transition: opacity .2s ease, transform .2s ease;
}
.acc-chat.has-unread .acc-chat__launcher::after { opacity: 1; transform: scale(1); }

/* Open state: launcher morphs to a close affordance */
.acc-chat.is-open .acc-chat__launcher { background: var(--acc-navy); color: #fff; }
.acc-chat.is-open .acc-chat__launcher:hover { background: var(--acc-navy-2); }
.acc-chat.is-open .acc-chat__launcher .acc-i-chat { opacity: 0; transform: rotate(45deg) scale(.7); }
.acc-chat.is-open .acc-chat__launcher .acc-i-x { opacity: 1; transform: rotate(0) scale(1); }
.acc-chat.is-open .acc-chat__launcher::after { display: none; }

/* ------------------------------------------------------------ Teaser ----- */
/* Nudge bubble sitting to the left of the closed launcher. */
.acc-chat__teaser {
  position: absolute;
  bottom: 7px;
  right: 74px;
  width: min(248px, calc(100vw - 96px));   /* fixed width so the nudge wraps to ~2 tidy lines, not a narrow column */
  display: flex;
  align-items: flex-start;
  gap: .35rem;
  padding: .55rem .45rem .55rem .8rem;
  background: var(--acc-surface);
  border: 1px solid var(--acc-border);
  border-radius: 14px;
  box-shadow: var(--acc-shadow);
  animation: acc-teaser-in .35s ease .9s both;
}
.acc-chat__teaser::after {                 /* little tail toward the launcher */
  content: "";
  position: absolute;
  right: -7px;
  bottom: 15px;
  width: 0; height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 7px solid var(--acc-surface);
}
.acc-chat__teaser-msg {
  border: 0;
  background: transparent;
  color: var(--acc-navy);
  font-family: var(--acc-font);
  font-weight: 600;
  font-size: .82rem;
  line-height: 1.32;
  text-align: left;
  padding: 0;
  cursor: pointer;
}
.acc-chat__teaser-msg b { color: var(--acc-teal-deep); }
.acc-chat__teaser-x {
  flex: none;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: var(--acc-bot-bg);
  color: var(--acc-muted);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color .15s ease, background .15s ease;
}
.acc-chat__teaser-x:hover { color: var(--acc-navy); background: #dfe6ee; }
.acc-chat__teaser-msg:focus-visible,
.acc-chat__teaser-x:focus-visible { outline: none; box-shadow: var(--acc-ring); border-radius: 8px; }
.acc-chat.is-open .acc-chat__teaser,
.acc-chat__teaser.is-dismissed { display: none; }

/* ------------------------------------------------------------- Panel ----- */
.acc-chat__panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: var(--acc-panel-w);
  height: min(var(--acc-panel-h), calc(100vh - 104px));
  background: var(--acc-surface);
  border: 1px solid var(--acc-border);
  border-radius: var(--acc-radius);
  box-shadow: var(--acc-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(12px) scale(.96);
  pointer-events: none;
  transition: opacity .22s ease, transform .22s cubic-bezier(.34, 1.4, .64, 1);
}
.acc-chat.is-open .acc-chat__panel {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* Header */
.acc-chat__header {
  flex: none;
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .85rem 1rem;
  background: linear-gradient(135deg, var(--acc-navy-2), var(--acc-navy));
  color: #fff;
}
.acc-chat__avatar {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--acc-teal);
  border: 1px solid var(--acc-teal);
  color: #06231f;
}
.acc-chat__avatar svg { width: 24px; height: 24px; }
.acc-chat__titles { flex: 1; min-width: 0; }
.acc-chat__title {
  font-family: var(--acc-font);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -.01em;
  margin: 0;
  color: #fff;
}
.acc-chat__status {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .76rem;
  color: #bcd0e6;
}
.acc-chat__status .acc-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--acc-teal);
  box-shadow: 0 0 0 3px rgba(55, 217, 200, .25);
}
.acc-chat__close {
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, .1);
  color: #dbe6f3;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.acc-chat__close:hover { background: rgba(255, 255, 255, .2); color: #fff; }
.acc-chat__close:focus-visible { outline: none; box-shadow: var(--acc-ring); }
.acc-chat__close svg { width: 18px; height: 18px; }

/* Message list */
.acc-chat__messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem .9rem .4rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  background:
    radial-gradient(600px 240px at 100% 0%, rgba(55, 217, 200, .06), transparent 70%),
    #f6f8fa;
  /* instant, not smooth: programmatic pin/scroll must land deterministically
     (smooth animates the jump and makes scrollTop read back mid-animation). */
  scroll-behavior: auto;
  overscroll-behavior: contain;
}
.acc-chat__messages::-webkit-scrollbar { width: 8px; }
.acc-chat__messages::-webkit-scrollbar-thumb { background: #cdd6e0; border-radius: 8px; }
.acc-chat__messages { scrollbar-width: thin; scrollbar-color: #cdd6e0 transparent; }

/* Bubbles */
.acc-msg {
  max-width: 86%;
  padding: .6rem .8rem;
  border-radius: 14px;
  font-size: .92rem;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
  animation: acc-pop .2s ease;
}
.acc-msg--user {
  align-self: flex-end;
  background: var(--acc-navy);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.acc-msg--assistant {
  align-self: flex-start;
  background: var(--acc-bot-bg);
  color: var(--acc-bot-ink);
  border-bottom-left-radius: 5px;
  border: 1px solid var(--acc-border);
}
.acc-msg p { margin: 0; }
.acc-msg p + p { margin-top: .5rem; }
.acc-msg ul { margin: .4rem 0 .1rem; padding-left: 1.15rem; list-style: disc; }
.acc-msg li { margin: .12rem 0; }
.acc-msg strong { font-weight: 700; }
.acc-msg a {
  color: var(--acc-teal-deep);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-word;
}
.acc-msg--user a { color: #aef1e8; }
.acc-msg a:focus-visible { outline: none; box-shadow: var(--acc-ring); border-radius: 4px; }

/* Typing indicator */
.acc-typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: .7rem .85rem;
  background: var(--acc-bot-bg);
  border: 1px solid var(--acc-border);
  border-radius: 14px;
  border-bottom-left-radius: 5px;
}
.acc-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9fb0c4;
  animation: acc-bounce 1.3s infinite ease-in-out;
}
.acc-typing span:nth-child(2) { animation-delay: .18s; }
.acc-typing span:nth-child(3) { animation-delay: .36s; }

/* Footer / input */
.acc-chat__footer {
  flex: none;
  border-top: 1px solid var(--acc-border);
  background: var(--acc-surface);
  padding: .6rem .6rem .65rem;
}
.acc-chat__inputrow {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  background: #fff;
  border: 1.5px solid var(--acc-border);
  border-radius: 14px;
  padding: .35rem .4rem .35rem .7rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.acc-chat__inputrow:focus-within {
  border-color: var(--acc-teal-deep);
  box-shadow: 0 0 0 3px rgba(15, 174, 159, .15);
}
.acc-chat__input {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--acc-ink);
  font-family: var(--acc-body);
  font-size: .92rem;
  line-height: 1.45;
  max-height: 120px;
  min-height: 22px;
  padding: .3rem 0;
}
.acc-chat__input::placeholder { color: #9aa8ba; }
.acc-chat__send {
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 11px;
  background: var(--acc-teal);
  color: #06231f;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease, opacity .15s ease;
}
.acc-chat__send:hover:not(:disabled) { background: #54e6d6; }
.acc-chat__send:active:not(:disabled) { transform: scale(.94); }
.acc-chat__send:disabled { opacity: .45; cursor: not-allowed; }
.acc-chat__send:focus-visible { outline: none; box-shadow: var(--acc-ring); }
.acc-chat__send svg { width: 19px; height: 19px; }
.acc-chat__legal {
  margin: .45rem .3rem 0;
  text-align: center;
  font-size: .68rem;
  color: #92a1b4;
}
.acc-chat__legal a { color: var(--acc-teal-deep); text-decoration: none; font-weight: 600; }
.acc-chat__legal a:hover { text-decoration: underline; }

/* visually-hidden (for the live region / SR labels) */
.acc-chat__sr {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

/* --------------------------------------------------------- Animations ---- */
@keyframes acc-pop {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@keyframes acc-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .55; }
  30%           { transform: translateY(-5px); opacity: 1; }
}
@keyframes acc-teaser-in {
  from { opacity: 0; transform: translateY(6px) scale(.96); }
  to   { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------- Mobile ---- */
@media (max-width: 480px) {
  .acc-chat {
    right: 14px;
    bottom: 14px;
  }
  .acc-chat__panel {
    position: fixed;
    right: 8px;
    left: 8px;
    bottom: 8px;
    top: 8px;
    width: auto;
    height: auto;
    border-radius: 16px;
  }
}

/* --------------------------------------------- Reduced motion / a11y ----- */
@media (prefers-reduced-motion: reduce) {
  .acc-chat__launcher,
  .acc-chat__panel,
  .acc-chat__launcher .acc-i-chat,
  .acc-chat__launcher .acc-i-x,
  .acc-chat__launcher::after,
  .acc-chat__close,
  .acc-chat__send,
  .acc-chat__inputrow { transition: none; }
  .acc-chat__messages { scroll-behavior: auto; }
  .acc-msg { animation: none; }
  .acc-chat__teaser { animation: none; }
  .acc-typing span { animation-duration: 0s; }
}

/* --------------------------------------------------------- Dark scheme --- */
@media (prefers-color-scheme: dark) {
  .acc-chat {
    --acc-surface:  #0f2138;
    --acc-bot-bg:   #142641;
    --acc-bot-ink:  #d9e3ef;
    --acc-border:   #24384f;
    --acc-ink:      #d9e3ef;
    --acc-teal-deep:#37D9C8;
  }
  .acc-chat__messages {
    background:
      radial-gradient(600px 240px at 100% 0%, rgba(55, 217, 200, .08), transparent 70%),
      #0a1626;
  }
  .acc-chat__messages::-webkit-scrollbar-thumb { background: #2c4159; }
  .acc-chat__inputrow { background: #0c1c30; }
  .acc-chat__input { color: #d9e3ef; }
  .acc-chat__input::placeholder { color: #6f8197; }
  .acc-msg--user { background: #18406b; }
  .acc-msg--user a { color: #aef1e8; }
  .acc-chat__teaser-msg { color: #eaf1f9; }
  .acc-chat__teaser-x:hover { background: #1d3149; color: #fff; }
}
