/**
 * Support Chat Widget — SSLWebsites — τAI / h-conductor
 * Pattern: bandsaas.com support-chat.css + impeccable.style
 *
 * Themable via CSS custom properties (--sc-*)
 * Tinted neutrals, ease-out-quart motion, focus-visible, 44px touch targets
 */

/* ─── Chat Bubble ────────────────────────────────────────────────── */

.sc-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--sc-accent, #1c1a18);
  color: #faf9f7;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(12, 14, 20, 0.2);
  z-index: 9990;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 150ms cubic-bezier(0.25, 1, 0.5, 1),
              box-shadow 250ms cubic-bezier(0.25, 1, 0.5, 1);
}

.sc-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(12, 14, 20, 0.3);
}

.sc-bubble:active {
  transform: scale(0.97);
}

.sc-bubble:focus-visible {
  outline: 2px solid var(--sc-accent, #1c1a18);
  outline-offset: 3px;
}

.sc-bubble svg { width: 28px; height: 28px; fill: currentColor; }
.sc-bubble .sc-close { display: none; }
.sc-bubble.open .sc-chat-icon { display: none; }
.sc-bubble.open .sc-close { display: block; }

/* ─── Chat Panel ─────────────────────────────────────────────────── */

.sc-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  border-radius: 16px;
  background: var(--sc-bg, #faf9f7);
  border: 1px solid var(--sc-border, #e2dfda);
  box-shadow: 0 12px 40px rgba(12, 14, 20, 0.15);
  z-index: 9989;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  transition: all 400ms cubic-bezier(0.25, 1, 0.5, 1);
  color: var(--sc-text, #1c1a18);
}

.sc-panel.open { display: flex; }

.sc-panel.maximized {
  width: 560px;
  height: 80vh;
  max-height: calc(100vh - 48px);
  bottom: 50%;
  right: 50%;
  transform: translate(50%, 50%);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(12, 14, 20, 0.25);
}

/* ─── Backdrop ───────────────────────────────────────────────────── */

.sc-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 14, 20, 0.3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9988;
  opacity: 0;
  pointer-events: none;
  transition: opacity 400ms cubic-bezier(0.25, 1, 0.5, 1);
}

.sc-backdrop.show { opacity: 1; pointer-events: auto; }

/* ─── Header (dark bg compensation) ──────────────────────────────── */

.sc-header {
  padding: 16px 20px;
  background: var(--sc-header, var(--sc-accent, #1c1a18));
  color: #faf9f7;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  letter-spacing: 0.01em;
}

.sc-header .sc-logo { height: 24px; width: auto; flex-shrink: 0; }

.sc-maximize {
  background: none;
  border: none;
  color: #faf9f7;
  cursor: pointer;
  margin-left: auto;
  padding: 4px;
  opacity: 0.8;
  transition: opacity 150ms cubic-bezier(0.25, 1, 0.5, 1);
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sc-maximize:hover { opacity: 1; }
.sc-maximize:focus-visible { outline: 2px solid #faf9f7; outline-offset: 2px; border-radius: 4px; }
.sc-maximize svg { width: 16px; height: 16px; fill: currentColor; }

/* ─── Messages ───────────────────────────────────────────────────── */

.sc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sc-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

/* User messages */
.sc-msg.user {
  align-self: flex-end;
  background: var(--sc-accent, #1c1a18);
  color: #faf9f7;
  border-bottom-right-radius: 4px;
  letter-spacing: 0.01em;
}

/* Assistant messages */
.sc-msg.assistant {
  align-self: flex-start;
  background: var(--sc-card, #f1efe9);
  color: var(--sc-text, #1c1a18);
  border-bottom-left-radius: 4px;
}

.sc-msg.assistant strong { color: var(--sc-accent, #1c1a18); }

.sc-msg.assistant code {
  background: rgba(12, 14, 20, 0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Menlo', 'Consolas', monospace;
}

.sc-msg.assistant .sc-heading {
  font-weight: 700;
  font-size: 15px;
  margin: 12px 0 6px;
  color: var(--sc-accent, #1c1a18);
  line-height: 1.1;
}

.sc-msg.assistant .sc-heading:first-child { margin-top: 0; }

/* List items */
.sc-msg.assistant .sc-list-item {
  padding-left: 12px;
  position: relative;
  margin: 3px 0;
}

.sc-msg.assistant .sc-list-item::before {
  content: '\2022';
  position: absolute;
  left: 0;
  color: var(--sc-accent, #1c1a18);
}

.sc-msg.assistant .sc-list-ordered::before {
  content: counter(sc-list) '.';
  counter-increment: sc-list;
}

/* Links */
.sc-msg.assistant .sc-link {
  color: var(--sc-accent, #38BDF8);
  text-decoration: none;
  font-weight: 500;
  transition: opacity 150ms cubic-bezier(0.25, 1, 0.5, 1);
}

.sc-msg.assistant .sc-link:hover { opacity: 0.7; }
.sc-msg.assistant .sc-link:focus-visible { outline: 2px solid var(--sc-accent, #38BDF8); outline-offset: 2px; border-radius: 2px; }

/* Tables */
.sc-msg.assistant .sc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
}

.sc-msg.assistant .sc-table th {
  text-align: left;
  padding: 6px 10px;
  background: rgba(12, 14, 20, 0.04);
  border-bottom: 1px solid var(--sc-border, #e2dfda);
  font-weight: 600;
}

.sc-msg.assistant .sc-table td {
  padding: 5px 10px;
  border-bottom: 1px solid rgba(12, 14, 20, 0.04);
}

.sc-msg.assistant .sc-table tr:last-child td { border-bottom: none; }

/* Code blocks */
.sc-code-block {
  margin: 8px 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--sc-accent, #1c1a18);
}

.sc-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: rgba(250, 249, 247, 0.05);
  font-size: 11px;
  letter-spacing: 0.01em;
}

.sc-code-lang { color: rgba(250, 249, 247, 0.5); }

.sc-code-copy {
  background: none;
  border: none;
  color: rgba(250, 249, 247, 0.5);
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 150ms cubic-bezier(0.25, 1, 0.5, 1);
  min-height: auto;
}

.sc-code-copy:hover { color: #faf9f7; }

.sc-code-block pre {
  padding: 12px;
  margin: 0;
  overflow-x: auto;
}

.sc-code-block code {
  color: rgba(250, 249, 247, 0.85);
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Menlo', 'Consolas', monospace;
  font-size: 13px;
  background: none;
  padding: 0;
  line-height: 1.6;
  letter-spacing: 0.015em;
}

/* System messages */
.sc-msg.system {
  align-self: center;
  font-size: 12px;
  color: var(--sc-muted, #6b6862);
  padding: 4px 12px;
}

/* ─── Typing Indicator ───────────────────────────────────────────── */

.sc-typing {
  align-self: flex-start;
  padding: 10px 14px;
  background: var(--sc-card, #f1efe9);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  display: none;
}

.sc-typing.show { display: flex; gap: 4px; align-items: center; }

.sc-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sc-muted, #6b6862);
  animation: sc-bounce 0.6s infinite alternate;
  animation-timing-function: cubic-bezier(0.25, 1, 0.5, 1);
}

.sc-typing span:nth-child(2) { animation-delay: 0.15s; }
.sc-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes sc-bounce { to { opacity: 0.3; transform: translateY(-4px); } }

/* ─── Escalation Badge ───────────────────────────────────────────── */

.sc-escalation {
  background: rgba(217, 119, 6, 0.08);
  border: 1px solid rgba(217, 119, 6, 0.2);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  color: #92400e;
  margin-top: 4px;
}

.sc-escalation-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.sc-escalation-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(217, 119, 6, 0.15);
  color: #b45309;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.sc-escalation-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(217, 119, 6, 0.12);
  color: #b45309;
  margin-left: auto;
}

.sc-escalation p { margin: 0 0 4px; line-height: 1.5; }
.sc-escalation small { color: #a16207; font-size: 11px; }

/* ─── Quick Reply Buttons ────────────────────────────────────────── */

.sc-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
}

.sc-quick-btn {
  background: transparent;
  border: 1px solid var(--sc-accent, #1c1a18);
  color: var(--sc-accent, #1c1a18);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 150ms cubic-bezier(0.25, 1, 0.5, 1),
              color 150ms cubic-bezier(0.25, 1, 0.5, 1);
  font-family: inherit;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.sc-quick-btn:hover {
  background: var(--sc-accent, #1c1a18);
  color: #faf9f7;
}

.sc-quick-btn:focus-visible {
  outline: 2px solid var(--sc-accent, #1c1a18);
  outline-offset: 2px;
}

.sc-quick-btn:active {
  transform: scale(0.97);
}

/* ─── Input Area ─────────────────────────────────────────────────── */

.sc-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--sc-border, #e2dfda);
  display: flex;
  gap: 8px;
  background: var(--sc-bg, #faf9f7);
}

.sc-input {
  flex: 1;
  border: 1px solid var(--sc-border, #e2dfda);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  background: var(--sc-bg, #faf9f7);
  color: var(--sc-text, #1c1a18);
  font-family: inherit;
  resize: none;
  max-height: 80px;
  transition: border-color 250ms cubic-bezier(0.25, 1, 0.5, 1);
}

.sc-input::placeholder { color: var(--sc-muted, #6b6862); }
.sc-input:focus { border-color: var(--sc-accent, #1c1a18); }
.sc-input:focus-visible { outline: 2px solid var(--sc-accent, #1c1a18); outline-offset: -2px; border-radius: 24px; }

.sc-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--sc-accent, #1c1a18);
  color: #faf9f7;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 150ms cubic-bezier(0.25, 1, 0.5, 1);
  min-height: 44px;
  min-width: 44px;
}

.sc-send:disabled { opacity: 0.4; cursor: default; }
.sc-send:focus-visible { outline: 2px solid var(--sc-accent, #1c1a18); outline-offset: 3px; }
.sc-send:active:not(:disabled) { transform: scale(0.97); }
.sc-send svg { width: 18px; height: 18px; fill: currentColor; }

/* ─── Responsive (mobile-first) ──────────────────────────────────── */

@media (max-width: 480px) {
  .sc-panel,
  .sc-panel.maximized {
    bottom: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    transform: none;
  }
  .sc-bubble { bottom: 16px; right: 16px; }
}

/* Touch device: enlarge targets */
@media (pointer: coarse) {
  .sc-quick-btn { min-height: 48px; padding: 8px 16px; }
  .sc-send { min-height: 48px; min-width: 48px; }
  .sc-maximize { min-height: 48px; min-width: 48px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .sc-bubble,
  .sc-panel,
  .sc-backdrop,
  .sc-quick-btn,
  .sc-send,
  .sc-input,
  .sc-maximize { transition: none; }
  .sc-typing span { animation: none; }
}
