/* AISupportChat.pro — inline AI support chat widget */

.ascw {
  --brand: #2457e6;
  --ink: #0f172a;
  --line: #e2e8f0;
  --muted: #64748b;
  --bg: #f8fafc;
  /* Theme-aware surfaces (overridden below for dark mode) */
  --panel-bg: #ffffff;
  --bubble-ai-bg: #ffffff;
  --bubble-ai-ink: #334155;
  --form-bg: #ffffff;
  --foot-bg: #ffffff;
  --avatar-ai-bg: #e8efff;
  --input-bg: #f8fafc;
  position: fixed;
  bottom: 20px;
  z-index: 2147483000;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
}
.ascw-left  { left: 20px; }
.ascw-right { right: 20px; }

/* ---------- Launcher ---------- */
.ascw-launcher {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 52px;
  padding: 0 20px 0 14px;
  border: 0;
  border-radius: 16px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 14px 30px -10px rgba(15, 23, 42, .35);
  transition: transform .15s ease, box-shadow .15s ease;
}
.ascw-launcher:hover { transform: translateY(-2px); box-shadow: 0 18px 36px -10px rgba(15, 23, 42, .4); }
.ascw-launcher-icon { display: inline-flex; }
.ascw-launcher svg { width: 20px; height: 20px; }
.ascw-icon-close { display: none; }

.ascw-open .ascw-icon-chat { display: none; }
.ascw-open .ascw-icon-close { display: block; }

/* ---------- Panel ---------- */
.ascw-panel {
  display: none;
  flex-direction: column;
  width: min(370px, calc(100vw - 32px));
  max-height: min(620px, calc(100vh - 130px));
  margin-bottom: 12px;
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 60px -18px rgba(15, 23, 42, .35);
  overflow: hidden;
}
.ascw-open .ascw-panel { display: flex; }

/* ---------- Header ---------- */
.ascw-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  color: #fff;
}
.ascw-head-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 11px;
  background: rgba(255, 255, 255, .18);
  overflow: hidden;
}
.ascw-head-logo svg { width: 17px; height: 17px; }
.ascw-head-logo img { width: 100%; height: 100%; object-fit: cover; }
.ascw-head-text { min-width: 0; }
.ascw-head-text strong { display: block; font-size: 13px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ascw-head-text span { display: block; font-size: 10px; color: rgba(255, 255, 255, .78); }
.ascw-close {
  margin-left: auto;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: rgba(255, 255, 255, .75);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.ascw-close:hover { background: rgba(255, 255, 255, .16); color: #fff; }
.ascw-close svg { width: 15px; height: 15px; }

/* ---------- Body / messages ---------- */
.ascw-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
}
.ascw-msg { display: flex; align-items: flex-start; gap: 8px; }
.ascw-user { flex-direction: row-reverse; }
.ascw-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 9px;
  font-size: 9px;
  font-weight: 800;
}
.ascw-avatar svg { width: 14px; height: 14px; }
.ascw-avatar-ai  { background: var(--avatar-ai-bg); color: var(--brand); }
.ascw-avatar-user { background: #0f172a; color: #fff; }
.ascw-bubble {
  max-width: 86%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.ascw-bubble-ai   { background: var(--bubble-ai-bg); border: 1px solid var(--line); color: var(--bubble-ai-ink); border-top-left-radius: 4px; }
.ascw-bubble-user { background: #0f172a; color: #fff; border-top-right-radius: 4px; }

.ascw-thinking { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.ascw-thinking-text { display: inline-flex; align-items: center; gap: 4px; }
.ascw-dots i {
  display: inline-block;
  width: 4px;
  height: 4px;
  margin: 0 1px;
  border-radius: 50%;
  background: var(--brand);
  animation: ascw-blink 1.2s infinite ease-in-out;
}
.ascw-dots i:nth-child(2) { animation-delay: .18s; }
.ascw-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes ascw-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* The hidden attribute must win over display:flex/block so the
   "Thinking…" and error rows only appear when actually active. */
.ascw-thinking[hidden],
.ascw-error[hidden],
.ascw-connect[hidden],
.ascw-connecting[hidden],
.ascw-ticket-form[hidden],
.ascw-ticket-done[hidden],
.ascw-ticket-known[hidden],
.ascw-ticket-fields[hidden],
.ascw-form[hidden],
.ascw-handoff[hidden] { display: none !important; }

.ascw-error {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #991b1b;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 12px;
  line-height: 1.5;
}

/* ---------- Input ---------- */
.ascw-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--form-bg);
}
.ascw-form input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input-bg);
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.ascw-form input::placeholder { color: var(--muted); }
.ascw-form input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(36, 87, 230, .14); }
.ascw-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: 0;
  border-radius: 12px;
  color: #fff;
  cursor: pointer;
  transition: opacity .15s ease;
}
.ascw-send:hover { opacity: .88; }
.ascw-send:disabled { opacity: .45; cursor: not-allowed; }
.ascw-send svg { width: 15px; height: 15px; }

/* ---------- Foot ---------- */
.ascw-foot { padding: 0 14px 13px; background: var(--foot-bg); border-top: 1px solid var(--line); }
.ascw-handoff {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: 12px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-bg);
  color: var(--bubble-ai-ink);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.ascw-handoff:hover { background: var(--bg); }
.ascw-handoff svg { width: 14px; height: 14px; }
.ascw-handoff-primary { border-color: var(--brand); background: var(--brand); color: #fff; }
.ascw-handoff-primary:hover { background: var(--brand); opacity: .9; }
.ascw-branding { margin: 10px 0 0; display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center; font-size: 10px; color: var(--muted); }
.ascw-branding-link { color: var(--muted); text-decoration: none; transition: color .15s ease; }
.ascw-branding-link:hover { color: var(--brand); text-decoration: underline; }

/* ---------- Dark mode (matches the site's data-theme toggle) ---------- */
html[data-theme="dark"] .ascw {
  --ink: #e2e8f0;
  --line: #2b3a54;
  --muted: #94a3b8;
  --bg: #0b1220;
  --panel-bg: #0f172a;
  --bubble-ai-bg: #1e293b;
  --bubble-ai-ink: #e2e8f0;
  --form-bg: #0f172a;
  --foot-bg: #0f172a;
  --avatar-ai-bg: rgba(36, 87, 230, .22);
  --input-bg: #141f38;
}
html[data-theme="dark"] .ascw-bubble-user { background: var(--brand); }

@media (max-width: 520px) {
  .ascw { bottom: 14px; }
  .ascw-left, .ascw-right { left: 14px; right: 14px; }
  .ascw-panel { width: calc(100vw - 28px); max-height: calc(100vh - 90px); margin-bottom: 10px; }
  .ascw-launcher { height: 50px; }
}

/* ---------- Standalone preview page (widget.php opened directly) ---------- */
body.ascw-standalone-mode {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 100%);
}
.ascw-standalone {
  width: 100%;
  max-width: 460px;
  padding: 24px;
  box-sizing: border-box;
}
.ascw-standalone-card {
  background: #ffffff;
  border-radius: 18px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 24px 60px -20px rgba(15, 23, 42, .5);
}
.ascw-standalone-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
  margin-bottom: 14px;
  overflow: hidden;
}
.ascw-standalone-logo svg { width: 24px; height: 24px; }
.ascw-standalone-logo img { width: 100%; height: 100%; object-fit: cover; }
.ascw-standalone-title { display: block; font-size: 17px; font-weight: 800; color: #0f172a; }
.ascw-standalone-text { font-size: 13px; line-height: 1.6; color: #475569; margin: 8px 0 0; }

/* ---------- AI assistant off: connect-to-human flow ---------- */
.ascw-connect,
.ascw-ticket-form { display: block; }
.ascw-form-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bubble-ai-bg);
}
.ascw-form-title {
  display: flex;
  align-items: flex-start;
  gap: 9px;
}
.ascw-form-title-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 10px;
  background: var(--avatar-ai-bg);
  color: var(--brand);
}
.ascw-form-title-icon svg { width: 15px; height: 15px; }
.ascw-form-title-ok .ascw-form-title-icon { background: rgba(34, 197, 94, .16); color: #16a34a; }
.ascw-form-title-warn .ascw-form-title-icon { background: rgba(245, 158, 11, .16); color: #d97706; }
.ascw-form-title-text { min-width: 0; }
.ascw-form-title-text strong { display: block; font-size: 13px; font-weight: 800; color: var(--bubble-ai-ink); }
.ascw-form-title-text span { display: block; font-size: 11px; line-height: 1.45; color: var(--muted); }
.ascw-field { display: flex; flex-direction: column; gap: 5px; }
.ascw-field-label { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .01em; }
.ascw-field-wrap { position: relative; display: block; }
.ascw-field-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 14px;
  height: 14px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  transition: color .15s ease;
}
.ascw-field-wrap-area .ascw-field-icon { top: 15px; transform: none; }
.ascw-field-wrap:focus-within .ascw-field-icon { color: var(--brand); }
.ascw-connect input,
.ascw-ticket-form input,
.ascw-ticket-form textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px 10px 35px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input-bg);
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.ascw-ticket-form textarea { padding-top: 11px; resize: vertical; min-height: 64px; }
.ascw-connect input::placeholder,
.ascw-ticket-form input::placeholder,
.ascw-ticket-form textarea::placeholder { color: var(--muted); }
.ascw-connect input:focus,
.ascw-ticket-form input:focus,
.ascw-ticket-form textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(36, 87, 230, .14); }
.ascw-connect-btn,
.ascw-ticket-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  background: var(--brand);
  box-shadow: 0 10px 22px -8px rgba(36, 87, 230, .55);
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.ascw-connect-btn:hover,
.ascw-ticket-btn:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 14px 26px -9px rgba(36, 87, 230, .6); }
.ascw-connect-btn:active,
.ascw-ticket-btn:active { transform: translateY(0); }
.ascw-connect-btn:disabled,
.ascw-ticket-btn:disabled { opacity: .55; cursor: not-allowed; }
.ascw-connect-btn svg,
.ascw-ticket-btn svg { width: 14px; height: 14px; }
.ascw-field-note { margin: 0; text-align: center; font-size: 10.5px; line-height: 1.5; color: var(--muted); }

.ascw-connecting { display: flex; }
.ascw-connecting-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px 14px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: var(--bubble-ai-bg);
}
.ascw-connecting-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--avatar-ai-bg);
  color: var(--brand);
  margin-bottom: 8px;
  animation: ascw-pulse 1.6s infinite ease-in-out;
}
.ascw-connecting-icon svg { width: 17px; height: 17px; }
@keyframes ascw-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(36, 87, 230, .28); } 55% { box-shadow: 0 0 0 8px rgba(36, 87, 230, 0); } }
.ascw-connecting-text { font-size: 13px; font-weight: 700; color: var(--bubble-ai-ink); display: inline-flex; align-items: center; }
.ascw-connect-dots { display: inline-flex; gap: 2px; margin-left: 7px; vertical-align: middle; }
.ascw-connect-dots i {
  font-style: normal;
  font-size: 12px;
  font-weight: 800;
  color: var(--brand);
  opacity: 0;
  animation: ascw-count 2.4s infinite;
}
.ascw-connect-dots i:nth-child(1) { animation-delay: 0s; }
.ascw-connect-dots i:nth-child(2) { animation-delay: .8s; }
.ascw-connect-dots i:nth-child(3) { animation-delay: 1.6s; }
@keyframes ascw-count { 0%, 18% { opacity: 0; } 28%, 62% { opacity: 1; } 72%, 100% { opacity: 0; } }

.ascw-ticket-known {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--input-bg);
}
.ascw-ticket-known-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}
.ascw-ticket-known-text { min-width: 0; display: flex; flex-direction: column; }
.ascw-ticket-known-text strong {
  font-size: 12px;
  font-weight: 700;
  color: var(--bubble-ai-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ascw-ticket-known-text span {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ascw-ticket-done { padding: 0 2px; }
.ascw-ticket-open {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 10px 22px -8px rgba(36, 87, 230, .55);
  transition: transform .15s ease, filter .15s ease;
}
.ascw-ticket-open:hover { filter: brightness(1.08); transform: translateY(-1px); text-decoration: none; color: #fff; }
