/* ============================================================================
   EcuTunerx — the public chat widget.

   Self-contained: every token it needs is declared on .ecux-w with a fallback,
   so the widget looks right on a page that has NOT loaded site.css, and adopts
   the page's own palette where it has. A support widget that only renders
   correctly on some pages is a support widget nobody trusts.

   The visual direction is the site's, not a chat vendor's: cream paper, ink
   type, thin burgundy rules, Fraunces for anything that carries weight. It
   should read as part of EcuTunerx rather than a bolted-on third-party box —
   no rounded-blue-bubble house style, no gradient launcher.
   ========================================================================= */

/* An element this widget marks hidden must actually be hidden. The UA rule
   `[hidden] { display: none }` loses to any class that sets a display value,
   and `.ecux-transfer`/`.ecux-ident` both do — so without this the transfer bar
   and the email capture rendered before there was a conversation to transfer
   or an address to attach. admin.css carries the same guard for the same
   reason; widget.css needs its own because it never loads alongside it. */
.ecux-w [hidden] { display: none !important; }

.ecux-w {
  --w-paper: var(--paper-white, #FFFDF8);
  --w-paper-2: var(--paper-2, #F1EBE0);
  --w-ink: var(--ink, #1B1712);
  --w-soft: var(--ink-soft, #5C5346);
  --w-faint: var(--ink-faint, #8A7F6E);
  --w-accent: var(--burgundy, #7A1F2B);
  --w-rule: var(--rule-soft, #DDD5C7);
  --w-amber: #9A6B14;
  --w-ok: #2F6B44;
  --w-serif: var(--serif, "Fraunces", Georgia, serif);
  --w-sans: var(--sans, "Inter", system-ui, sans-serif);
  --w-mono: var(--mono, "IBM Plex Mono", ui-monospace, monospace);
  --w-ease: var(--ease, cubic-bezier(0.16, 1, 0.3, 1));

  position: fixed;
  right: clamp(0.9rem, 3vw, 1.6rem);
  bottom: clamp(0.9rem, 3vw, 1.6rem);
  z-index: 2147483000;          /* above the site, below a browser dialog */
  font-family: var(--w-sans);
  color: var(--w-ink);
}

/* ---- the launcher ------------------------------------------------------- */
.ecux-fab {
  position: relative;
  width: 58px; height: 58px;
  display: grid; place-items: center;
  cursor: pointer;
  background: var(--w-accent);
  color: #FFFDF8;
  border: 1px solid var(--burgundy-deep, #5E1620);
  border-radius: 50%;
  box-shadow: 0 14px 28px -12px rgba(27, 23, 18, 0.55);
  transition: transform 0.24s var(--w-ease), box-shadow 0.24s var(--w-ease);
}
.ecux-fab:hover { transform: translateY(-2px); box-shadow: 0 20px 34px -14px rgba(27, 23, 18, 0.6); }
.ecux-fab:active { transform: translateY(0); }
.ecux-fab:focus-visible { outline: 3px solid var(--w-accent); outline-offset: 3px; }
.ecux-fab svg { width: 24px; height: 24px; }
.ecux-fab .x { display: none; }
.ecux-w.is-open .ecux-fab .b { display: none; }
.ecux-w.is-open .ecux-fab .x { display: block; }

.ecux-badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 20px; height: 20px; padding: 0 5px;
  display: none; place-items: center;
  background: var(--w-ink); color: #FFFDF8;
  border-radius: 10px;
  font-family: var(--w-mono); font-size: 0.66rem; font-weight: 700;
}
.ecux-badge.show { display: grid; }

/* A single ring, once, when a proactive greeting lands. Anything more
   insistent than this is the kind of widget people close and never reopen. */
.ecux-fab.is-calling::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  border: 2px solid var(--w-accent); animation: ecux-ring 1.6s var(--w-ease) 3;
}
@keyframes ecux-ring {
  0% { opacity: 0.8; transform: scale(0.92); }
  100% { opacity: 0; transform: scale(1.22); }
}

/* ---- the teaser (a proactive greeting, before the panel is opened) ------- */
.ecux-teaser {
  position: absolute; right: 0; bottom: 70px; width: min(310px, calc(100vw - 2.4rem));
  background: var(--w-paper); border: 1px solid var(--w-rule);
  border-left: 3px solid var(--w-accent);
  padding: 0.85rem 2rem 0.85rem 0.95rem;
  box-shadow: 0 18px 36px -18px rgba(27, 23, 18, 0.45);
  font-size: 0.88rem; line-height: 1.55; color: var(--w-soft);
  cursor: pointer;
  animation: ecux-rise 0.4s var(--w-ease);
}
.ecux-teaser b { display: block; font-family: var(--w-serif); font-size: 0.95rem;
                 font-weight: 600; color: var(--w-ink); margin-bottom: 0.2rem; }
.ecux-teaser .close {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px;
  background: none; border: 0; color: var(--w-faint); cursor: pointer; font-size: 1rem; line-height: 1;
}
.ecux-teaser .close:hover { color: var(--w-ink); }

@keyframes ecux-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---- the panel ---------------------------------------------------------- */
.ecux-panel {
  position: absolute; right: 0; bottom: 70px;
  width: min(378px, calc(100vw - 1.8rem));
  height: min(576px, calc(100vh - 7rem));
  display: none; flex-direction: column;
  background: var(--w-paper);
  border: 1px solid var(--w-rule);
  box-shadow: 0 30px 60px -28px rgba(27, 23, 18, 0.5);
  overflow: hidden;
}
.ecux-w.is-open .ecux-panel { display: flex; animation: ecux-rise 0.28s var(--w-ease); }

.ecux-top {
  flex: 0 0 auto; padding: 0.95rem 1rem;
  background: var(--w-ink); color: var(--paper-hi, #FBF8F2);
  display: flex; align-items: center; gap: 0.7rem;
}
.ecux-top h3 { margin: 0; font-family: var(--w-serif); font-size: 1.02rem; font-weight: 600; }
.ecux-top .sub {
  display: flex; align-items: center; gap: 0.35rem; margin-top: 0.15rem;
  font-family: var(--w-mono); font-size: 0.58rem; letter-spacing: 0.1em;
  text-transform: uppercase; opacity: 0.72;
}
.ecux-led { width: 6px; height: 6px; border-radius: 50%; background: #6FBF8B; }
.ecux-led--off { background: #8A7F6E; }

.ecux-close {
  flex: none; margin-left: auto; width: 30px; height: 30px;
  display: grid; place-items: center;
  background: none; border: 1px solid rgba(243, 237, 226, 0.22); border-radius: 2px;
  color: inherit; cursor: pointer; opacity: 0.7;
  transition: opacity 0.16s var(--w-ease), border-color 0.16s var(--w-ease);
}
.ecux-close:hover { opacity: 1; border-color: rgba(243, 237, 226, 0.5); }
.ecux-close svg { width: 15px; height: 15px; }

.ecux-faces { display: flex; margin-left: auto; }
.ecux-faces + .ecux-close { margin-left: 0.6rem; }
.ecux-faces img, .ecux-faces span {
  width: 26px; height: 26px; border-radius: 50%; object-fit: cover;
  border: 1.5px solid var(--w-ink); margin-left: -8px;
  background: var(--w-accent); color: #FFFDF8;
  display: grid; place-items: center; font-size: 0.66rem; font-weight: 600;
}

.ecux-log {
  flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
  padding: 1rem 0.95rem 0.5rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  background: var(--w-paper);
}
.ecux-log::-webkit-scrollbar { width: 8px; }
.ecux-log::-webkit-scrollbar-thumb { background: var(--w-rule); border-radius: 8px; }

.ecux-m { max-width: 84%; display: flex; flex-direction: column; gap: 0.2rem; }
.ecux-m--them { align-self: flex-start; }
.ecux-m--me { align-self: flex-end; align-items: flex-end; }

.ecux-who {
  font-family: var(--w-mono); font-size: 0.54rem; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--w-faint);
}
.ecux-b {
  padding: 0.55rem 0.75rem; font-size: 0.875rem; line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--w-paper-2); border: 1px solid var(--w-rule);
  border-radius: 2px 10px 10px 10px;
  animation: ecux-pop 0.2s var(--w-ease);
}
.ecux-m--me .ecux-b {
  background: var(--w-ink); color: var(--paper-hi, #FBF8F2); border-color: var(--w-ink);
  border-radius: 10px 2px 10px 10px;
}
/* The assistant never wears a tuner's face or name. */
.ecux-m--ai .ecux-b { background: #FBF6EA; border-color: #E4D3AE; }
.ecux-m--ai .ecux-who { color: var(--w-amber); }
.ecux-b img { display: block; max-width: 100%; margin-top: 0.4rem; border: 1px solid var(--w-rule); }
.ecux-b a { color: var(--w-accent); }

.ecux-sys {
  align-self: center; text-align: center; max-width: 92%;
  font-size: 0.73rem; font-style: italic; color: var(--w-faint);
  padding: 0.3rem 0;
}
.ecux-time { font-family: var(--w-mono); font-size: 0.54rem; color: var(--w-faint); }

@keyframes ecux-pop {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

.ecux-typing { display: flex; gap: 4px; padding: 0.6rem 0.8rem; }
.ecux-typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--w-faint);
                 animation: ecux-blink 1.25s infinite; }
.ecux-typing i:nth-child(2) { animation-delay: 0.18s; }
.ecux-typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes ecux-blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* ---- the transfer bar --------------------------------------------------- */
/* Always visible while the assistant has the thread. Hiding the way out behind
   a menu is the single most resented pattern in automated support. */
.ecux-transfer {
  flex: 0 0 auto; display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.9rem;
  background: #FBF6EA; border-top: 1px solid #E4D3AE;
  font-size: 0.76rem; color: var(--w-soft);
}
.ecux-transfer button {
  margin-left: auto; flex: none; cursor: pointer;
  background: var(--w-accent); color: #FFFDF8; border: 1px solid var(--burgundy-deep, #5E1620);
  font-family: var(--w-mono); font-size: 0.6rem; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  padding: 0.4rem 0.6rem; border-radius: 2px;
  transition: background 0.16s var(--w-ease);
}
.ecux-transfer button:hover { background: var(--burgundy-deep, #5E1620); }
.ecux-transfer button:disabled { opacity: 0.5; cursor: wait; }

/* ---- the email capture -------------------------------------------------- */
.ecux-ident {
  flex: 0 0 auto; padding: 0.6rem 0.9rem; border-top: 1px solid var(--w-rule);
  background: var(--w-paper-2); display: flex; gap: 0.4rem; align-items: center;
}
.ecux-ident input {
  flex: 1 1 auto; min-width: 0; background: var(--w-paper); color: var(--w-ink);
  border: 1px solid var(--w-rule); border-radius: 2px;
  font-family: var(--w-sans); font-size: 0.8rem; padding: 0.4rem 0.5rem;
}
.ecux-ident input:focus { outline: none; border-color: var(--w-accent); }
.ecux-ident button {
  flex: none; cursor: pointer; background: none; border: 1px solid var(--w-rule);
  color: var(--w-soft); font-family: var(--w-mono); font-size: 0.6rem;
  letter-spacing: 0.08em; text-transform: uppercase; padding: 0.4rem 0.5rem; border-radius: 2px;
}
.ecux-ident button:hover { border-color: var(--w-accent); color: var(--w-accent); }

/* ---- the composer ------------------------------------------------------- */
.ecux-c {
  flex: 0 0 auto; border-top: 1px solid var(--w-rule);
  background: var(--w-paper); padding: 0.6rem 0.7rem 0.7rem;
}
.ecux-c.is-drop { background: var(--w-paper-2); box-shadow: inset 0 0 0 2px var(--w-accent); }
.ecux-crow { display: flex; gap: 0.45rem; align-items: flex-end; }
.ecux-ta {
  flex: 1 1 auto; resize: none; min-height: 38px; max-height: 120px;
  background: var(--w-paper); color: var(--w-ink);
  border: 1px solid var(--w-rule); border-radius: 2px;
  font-family: var(--w-sans); font-size: 0.87rem; line-height: 1.5;
  padding: 0.5rem 0.6rem;
}
.ecux-ta:focus { outline: none; border-color: var(--w-accent); }
.ecux-ta::placeholder { color: var(--w-faint); }

.ecux-icon {
  flex: none; width: 34px; height: 34px; display: grid; place-items: center;
  background: none; border: 1px solid var(--w-rule); border-radius: 2px;
  color: var(--w-soft); cursor: pointer;
  transition: color 0.16s var(--w-ease), border-color 0.16s var(--w-ease);
}
.ecux-icon:hover { color: var(--w-accent); border-color: var(--w-accent); }
.ecux-icon svg { width: 16px; height: 16px; }

.ecux-go {
  flex: none; width: 38px; height: 38px; display: grid; place-items: center;
  background: var(--w-accent); color: #FFFDF8; cursor: pointer;
  border: 1px solid var(--burgundy-deep, #5E1620); border-radius: 2px;
  transition: background 0.16s var(--w-ease);
}
.ecux-go:hover { background: var(--burgundy-deep, #5E1620); }
.ecux-go:disabled { opacity: 0.45; cursor: not-allowed; }
.ecux-go svg { width: 17px; height: 17px; }

.ecux-files { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.4rem; }
.ecux-file {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.4rem; border: 1px solid var(--w-rule); border-radius: 2px;
  background: var(--w-paper-2); font-size: 0.72rem; color: var(--w-soft);
}
.ecux-file button { background: none; border: 0; cursor: pointer; color: var(--w-faint); font-size: 0.85rem; }

.ecux-foot {
  padding: 0.35rem 0.7rem 0.5rem; text-align: center;
  font-family: var(--w-mono); font-size: 0.52rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--w-faint);
}

/* ---- small screens ------------------------------------------------------ */
@media (max-width: 460px) {
  .ecux-panel {
    position: fixed; inset: 0; width: 100vw; height: 100dvh;
    border: 0; bottom: 0; right: 0;
  }
  .ecux-w.is-open .ecux-fab { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ecux-fab, .ecux-panel, .ecux-b, .ecux-teaser { animation: none; transition: none; }
  .ecux-typing i, .ecux-fab.is-calling::after { animation: none; }
}
