/* ─── Kaspi POS Automation — support widget (anon / marketing) ──────────────
 * Loaded on every marketing page via <link rel="stylesheet"> in <head>.
 * Vanilla CSS, no preprocessor, no build step. Reuses palette from style.css.
 *
 * Layout:
 *   .sw-fab       — round floating button, bottom-right, above everything
 *   .sw-badge     — red dot on the FAB when unread messages exist
 *   .sw-panel     — modal-style chat panel (bottom-right on desktop,
 *                   full-screen on narrow phones)
 *   .sw-thread    — scrolling message list
 *   .sw-msg       — one message bubble; two variants (client / admin)
 *   .sw-compose   — textarea + Send button footer
 *
 * All colors reuse the CSS variables defined in /site/style.css
 * (--brand, --bg, --text, --muted, --border, --radius, --shadow-md).
 * ────────────────────────────────────────────────────────────────────────── */

/* ─── Floating action button (FAB) ───────────────────────────────────────── */
.sw-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--brand, #E2261D);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.12s ease;
  padding: 0;
}
.sw-fab:hover {
  background: var(--brand-dark, #B91C13);
  transform: translateY(-1px);
}
.sw-fab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(226, 38, 29, 0.35), 0 6px 18px rgba(0, 0, 0, 0.18);
}
.sw-fab__icon {
  width: 26px;
  height: 26px;
  fill: #fff;
  pointer-events: none;
}
.sw-fab__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #F59E0B;
  color: #0F172A;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}
.sw-fab[hidden] { display: none; }

/* ─── Panel container (modal-ish, bottom-right) ──────────────────────────── */
.sw-panel {
  position: fixed;
  bottom: 90px;
  right: 20px;
  z-index: 1001;
  width: 380px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 14px;
  border: 1px solid #E5E7EB;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  color: #1A1A1A;
  animation: sw-pop 0.16s ease-out;
}
@keyframes sw-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.sw-panel[hidden] { display: none; }

/* On narrow phones: fill the viewport (nowhere to scroll to otherwise). */
@media (max-width: 480px) {
  .sw-panel {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    max-width: none;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  .sw-fab {
    bottom: 12px;
    right: 12px;
  }
}

/* ─── Panel header ───────────────────────────────────────────────────────── */
.sw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(180deg, #F8FAFC 0%, #F1F5F9 100%);
  border-bottom: 1px solid #E5E7EB;
}
.sw-header__title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}
.sw-header__subtitle {
  font-size: 0.78rem;
  color: #6B7280;
  margin: 2px 0 0;
}
.sw-header__close {
  background: none;
  border: none;
  color: #6B7280;
  cursor: pointer;
  padding: 4px 8px;
  font-size: 1.4rem;
  line-height: 1;
  border-radius: 6px;
}
.sw-header__close:hover { color: #1A1A1A; background: #E5E7EB; }
.sw-header__close:focus-visible {
  outline: none;
  color: #1A1A1A;
  background: #E5E7EB;
  box-shadow: 0 0 0 2px rgba(226, 38, 29, 0.35);
}

/* ─── Thread (scrolling messages list) ───────────────────────────────────── */
.sw-thread {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #FAFAFA;
  min-height: 240px;
  max-height: 60vh;
}
.sw-thread__intro {
  color: #6B7280;
  font-size: 0.9rem;
  text-align: center;
  padding: 16px 8px;
  line-height: 1.4;
}
.sw-thread__loading, .sw-thread__error {
  color: #6B7280;
  font-size: 0.88rem;
  text-align: center;
  padding: 12px 8px;
}
.sw-thread__error { color: #991B1B; }

/* ─── Message bubbles ────────────────────────────────────────────────────── */
.sw-msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 82%;
}
.sw-msg--client {
  align-self: flex-end;
}
.sw-msg--admin, .sw-msg--system {
  align-self: flex-start;
}
.sw-msg__bubble {
  padding: 8px 12px;
  border-radius: 12px;
  line-height: 1.4;
  font-size: 0.92rem;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.sw-msg--client .sw-msg__bubble {
  background: var(--brand, #E2261D);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.sw-msg--admin .sw-msg__bubble {
  background: #fff;
  color: #1A1A1A;
  border: 1px solid #E5E7EB;
  border-bottom-left-radius: 4px;
}
.sw-msg--system .sw-msg__bubble {
  background: #F1F5F9;
  color: #475569;
  font-style: italic;
  border-bottom-left-radius: 4px;
}
.sw-msg__meta {
  font-size: 0.72rem;
  color: #94A3B8;
  padding: 0 6px;
}
.sw-msg--client .sw-msg__meta { text-align: right; }

/* ─── Compose (textarea + Send) ──────────────────────────────────────────── */
.sw-compose {
  border-top: 1px solid #E5E7EB;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fff;
}
.sw-compose__row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.sw-compose__textarea {
  flex: 1;
  min-height: 40px;
  max-height: 160px;
  resize: none;
  padding: 10px 12px;
  border: 1px solid #E5E7EB;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.4;
  color: #1A1A1A;
  background: #fff;
}
.sw-compose__textarea:focus {
  outline: none;
  border-color: var(--brand, #E2261D);
  box-shadow: 0 0 0 3px rgba(226, 38, 29, 0.12);
}
.sw-compose__textarea[disabled] { opacity: 0.6; cursor: not-allowed; }
.sw-compose__send {
  background: var(--brand, #E2261D);
  color: #fff;
  border: none;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  min-width: 82px;
  transition: background 0.12s;
}
.sw-compose__send:hover:not(:disabled) { background: var(--brand-dark, #B91C13); }
.sw-compose__send:disabled { opacity: 0.5; cursor: not-allowed; }
.sw-compose__send:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(226, 38, 29, 0.35);
}

/* Optional email input on first message */
.sw-compose__email {
  padding: 8px 12px;
  border: 1px solid #E5E7EB;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.88rem;
  color: #1A1A1A;
  background: #fff;
  width: 100%;
}
.sw-compose__email:focus {
  outline: none;
  border-color: var(--brand, #E2261D);
  box-shadow: 0 0 0 3px rgba(226, 38, 29, 0.12);
}
.sw-compose__hint {
  color: #6B7280;
  font-size: 0.78rem;
  margin: 0 4px;
}
.sw-compose__error {
  color: #991B1B;
  font-size: 0.82rem;
  margin: 0 4px;
  min-height: 1em;
}

/* ─── Status footer for resolved threads / fallback ─────────────────────── */
.sw-status {
  padding: 10px 14px;
  background: #FEF3C7;
  color: #92400E;
  border-top: 1px solid #FCD34D;
  font-size: 0.85rem;
  text-align: center;
}
.sw-status--info {
  background: #EFF6FF;
  color: #1E40AF;
  border-top-color: #BFDBFE;
}
.sw-status--err {
  background: #FEE2E2;
  color: #991B1B;
  border-top-color: #FCA5A5;
}
.sw-status a { color: inherit; text-decoration: underline; }
