/* ── Suimas Chatbot Widget ── v1.0.0 ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

/* ── CSS Custom Properties (overridden by JS) ─────────────────────────────── */
:root {
  --sc-primary:       #158c48;
  --sc-primary-dark:  #0f6b35;
  --sc-primary-light: #e8f7ee;
  --sc-bg:            #ffffff;
  --sc-surface:       #f8fafc;
  --sc-text:          #1a202c;
  --sc-text-muted:    #6b7280;
  --sc-border:        #e5e7eb;
  --sc-shadow:        0 8px 32px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.10);
  --sc-radius:        18px;
  --sc-w:             370px;
  --sc-h:             min(420px, calc(100vh - 120px));
  --sc-offset:        20px;
}

/* ── Toggle Button ────────────────────────────────────────────────────────── */
.sc-toggle {
  position: fixed;
  bottom: var(--sc-offset);
  width:  60px;
  height: 60px;
  border-radius: 50%;
  background: var(--sc-primary);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999998;
  transition: transform .25s ease, background .2s;
  outline: none;
}
.sc-toggle:hover  { background: var(--sc-primary-dark); transform: scale(1.08); }
.sc-toggle:focus  { outline: 3px solid rgba(21,140,72,.4); }
.sc-toggle.right  { right: var(--sc-offset); }
.sc-toggle.left   { left:  var(--sc-offset); }

.sc-toggle svg { width: 28px; height: 28px; fill: #fff; transition: opacity .2s, transform .2s; }
.sc-toggle .sc-icon-chat  { position: absolute; }
.sc-toggle .sc-icon-close { position: absolute; opacity: 0; transform: rotate(-90deg); }
.sc-toggle.open .sc-icon-chat  { opacity: 0; transform: rotate(90deg); }
.sc-toggle.open .sc-icon-close { opacity: 1; transform: rotate(0deg); }

/* Notification badge */
.sc-badge {
  position: absolute;
  top: -2px; right: -2px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  animation: sc-pulse 2s infinite;
}
@keyframes sc-pulse {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.2); }
}

/* ── Chat Window ──────────────────────────────────────────────────────────── */
.sc-window {
  position: fixed;
  bottom: calc(var(--sc-offset) + 70px);
  width: var(--sc-w);
  height: var(--sc-h);
  max-height: calc(100vh - 120px);   /* fallback */
  max-height: calc(100svh - 120px);  /* svh = excludes browser chrome on mobile */
  background: var(--sc-bg);
  border-radius: var(--sc-radius);
  box-shadow: var(--sc-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999997;
  transform: scale(.92) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transform-origin: bottom right;
  transition: transform .28s cubic-bezier(.34,1.56,.64,1), opacity .22s ease;
  border: 1px solid var(--sc-border);
}
.sc-window.right { right: var(--sc-offset); transform-origin: bottom right; }
.sc-window.left  { left:  var(--sc-offset); transform-origin: bottom left; }
.sc-window.open  {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.sc-header {
  background: linear-gradient(135deg, var(--sc-primary), var(--sc-primary-dark));
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.sc-header-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
}
.sc-header-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.sc-header-info { flex: 1; min-width: 0; }
.sc-header-name {
  font-size: .95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: inherit;
}
.sc-header-status {
  font-size: .75rem;
  opacity: .85;
  display: flex;
  align-items: center;
  gap: 5px;
}
.sc-status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
  animation: sc-blink 2.5s infinite;
}
@keyframes sc-blink { 0%,100% {opacity:1} 50% {opacity:.4} }

.sc-header-close {
  background: none; border: none; color: rgba(255,255,255,.8);
  cursor: pointer; padding: 4px; border-radius: 6px; line-height: 1;
  transition: background .15s, color .15s;
}
.sc-header-close:hover { background: rgba(255,255,255,.15); color: #fff; }
.sc-header-close svg { width: 18px; height: 18px; fill: currentColor; }

/* ── Messages ─────────────────────────────────────────────────────────────── */
.sc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--sc-surface);
  scroll-behavior: smooth;
}
.sc-messages::-webkit-scrollbar { width: 4px; }
.sc-messages::-webkit-scrollbar-thumb { background: var(--sc-border); border-radius: 2px; }

/* Bubbles */
.sc-msg {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 88%;
  animation: sc-fadein .22s ease;
}
@keyframes sc-fadein { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }

.sc-msg.bot  { align-self: flex-start; }
.sc-msg.user { align-self: flex-end; flex-direction: row-reverse; }

.sc-msg-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--sc-primary-light);
  color: var(--sc-primary);
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-weight: 700;
}

.sc-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: .875rem;
  line-height: 1.45;
  color: var(--sc-text);
  word-break: break-word;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.sc-msg.bot  .sc-bubble { background: #fff; border: 1px solid var(--sc-border); border-bottom-left-radius: 5px; }
.sc-msg.user .sc-bubble { background: var(--sc-primary); color: #fff; border-bottom-right-radius: 5px; }

/* Typing indicator */
.sc-typing .sc-bubble {
  padding: 12px 16px;
  display: flex; gap: 5px; align-items: center;
}
.sc-typing-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--sc-text-muted);
  animation: sc-typing .9s infinite;
}
.sc-typing-dot:nth-child(2) { animation-delay: .18s; }
.sc-typing-dot:nth-child(3) { animation-delay: .36s; }
@keyframes sc-typing { 0%,80%,100% {transform:scale(.8);opacity:.5} 40% {transform:scale(1.2);opacity:1} }

/* ── Quick Reply Chips ────────────────────────────────────────────────────── */
.sc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 14px 10px;
  animation: sc-fadein .2s ease;
  background: var(--sc-surface);
}
.sc-chip {
  background: #fff;
  border: 1.5px solid var(--sc-primary);
  color: var(--sc-primary);
  padding: 7px 14px;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, transform .1s;
  white-space: nowrap;
  font-family: inherit;
}
.sc-chip:hover  { background: var(--sc-primary); color: #fff; transform: translateY(-1px); }
.sc-chip:active { transform: translateY(0); }

/* ── Input Area ───────────────────────────────────────────────────────────── */
.sc-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--sc-border);
  background: var(--sc-bg);
  flex-shrink: 0;
}
.sc-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.sc-input {
  flex: 1;
  border: 1.5px solid var(--sc-border);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: .875rem;
  font-family: inherit;
  color: var(--sc-text);
  background: var(--sc-bg);
  outline: none;
  resize: none;
  min-height: 42px;
  max-height: 100px;
  line-height: 1.4;
  transition: border-color .15s;
}
.sc-input:focus { border-color: var(--sc-primary); }
.sc-input::placeholder { color: var(--sc-text-muted); }

.sc-send {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--sc-primary);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.sc-send:hover   { background: var(--sc-primary-dark); transform: scale(1.08); }
.sc-send:active  { transform: scale(.95); }
.sc-send:disabled { background: #cbd5e1; cursor: default; transform: none; }
.sc-send svg { width: 18px; height: 18px; fill: #fff; }

.sc-footer-note {
  text-align: center;
  font-size: .7rem;
  color: var(--sc-text-muted);
  margin-top: 6px;
}
.sc-footer-note a { color: var(--sc-primary); text-decoration: none; }

/* ── Step Progress ────────────────────────────────────────────────────────── */
.sc-progress {
  height: 3px;
  background: var(--sc-border);
  flex-shrink: 0;
}
.sc-progress-bar {
  height: 100%;
  background: var(--sc-primary);
  transition: width .4s ease;
}

/* ── Success State ────────────────────────────────────────────────────────── */
.sc-success {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 24px;
  gap: 14px;
  background: var(--sc-surface);
}
.sc-success-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--sc-primary-light);
  display: flex; align-items: center; justify-content: center;
  animation: sc-popin .4s cubic-bezier(.34,1.56,.64,1);
}
@keyframes sc-popin { from {transform:scale(0);opacity:0} to {transform:scale(1);opacity:1} }
.sc-success-icon svg { width: 34px; height: 34px; fill: var(--sc-primary); }
.sc-success h3 { margin: 0; font-size: 1.1rem; color: var(--sc-text); }
.sc-success p  { margin: 0; font-size: .875rem; color: var(--sc-text-muted); line-height: 1.5; }
.sc-success-ref {
  background: var(--sc-primary-light);
  color: var(--sc-primary);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 700;
}
.sc-restart {
  background: none;
  border: 1.5px solid var(--sc-primary);
  color: var(--sc-primary);
  padding: 8px 20px;
  border-radius: 20px;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 600;
  transition: background .15s, color .15s;
}
.sc-restart:hover { background: var(--sc-primary); color: #fff; }

/* ── Inline embed ─────────────────────────────────────────────────────────── */
.suimas-inline-container .sc-window {
  position: relative;
  bottom: auto; right: auto; left: auto;
  width: 100%; max-width: 480px;
  height: min(400px, calc(100vh - 80px));
  max-height: calc(100vh - 80px);
  transform: none !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  border-radius: 14px;
  margin: 0 auto;
}
.suimas-inline-container .sc-toggle { display: none !important; }

/* ── Tablet (481 – 768 px) ────────────────────────────────────────────────── */
@media (max-width: 768px) and (min-width: 481px) {
  :root {
    --sc-w: min(340px, calc(100vw - 24px));
    --sc-h: min(380px, calc(100vh - 120px));
  }
}

/* ── Mobile (≤ 480 px) — full-screen overlay ──────────────────────────────── */
@media (max-width: 480px) {
  :root {
    --sc-w: 100vw;
    --sc-offset: 0px;
    --sc-radius: 0px;
  }

  .sc-window {
    border-radius: 0 !important;
    bottom: 0 !important;
    right: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    /* dvh respects dynamic browser chrome; -webkit-fill-available for iOS Safari */
    height: 100dvh !important;
    height: -webkit-fill-available !important;
    max-height: none !important;
    transform-origin: bottom center !important;
  }

  .sc-toggle {
    bottom: 16px !important;
  }
  .sc-toggle.right { right: 16px !important; }
  .sc-toggle.left  { left:  16px !important; }

  .sc-window.open + .sc-toggle { display: none; }

  .sc-header   { padding: 12px 14px; }
  .sc-messages { padding: 12px 10px; }
  .sc-chips    { padding: 0 10px 10px; }
  .sc-footer   { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 360px) {
  .sc-bubble { font-size: .82rem; }
  .sc-chip   { font-size: .78rem; padding: 6px 12px; }
}

/* ── Accessibility ────────────────────────────────────────────────────────── */
.sc-toggle:focus-visible { outline: 3px solid var(--sc-primary); outline-offset: 3px; }
.sc-chip:focus-visible   { outline: 2px solid var(--sc-primary); outline-offset: 2px; }
.sc-input:focus-visible  { border-color: var(--sc-primary); }
