/* ─── TOBI CHAT WIDGET ───────────────────────────────────────────────────── */

/* CSS custom-property fallbacks so this plugin works independently of the
   theme's token sheet. When the theme loads first these are overridden. */
.tobi-widget {
  --tobi-gradient:     var(--gradient,     linear-gradient(135deg, #FF7A59 0%, #FF4F89 100%));
  --tobi-shadow-lg:    var(--shadow-lg,    0 20px 60px rgba(20,10,0,.12), 0 4px 16px rgba(20,10,0,.06));
  --tobi-shadow-btn:   var(--shadow-orange,0 8px 32px rgba(255,122,89,.24), 0 2px 8px rgba(255,122,89,.12));
  --tobi-radius-lg:    var(--radius-lg,    24px);
  --tobi-radius-sm:    var(--radius-sm,    10px);
  --tobi-border:       var(--border,       #E8E3DD);
  --tobi-border-lt:    var(--border-lt,    #F0EBE5);
  --tobi-text:         var(--text,         #2E2B44);
  --tobi-bg-warm:      var(--bg-warm,      #FDFAF8);
  --tobi-primary:      var(--primary,      #FF7A59);
  --tobi-font:         var(--font,         'Plus Jakarta Sans', system-ui, sans-serif);
}

/* ── Launcher button ─────────────────────────────────────────────────────── */

.tobi-widget {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
}

.tobi-launcher {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--tobi-gradient);
  box-shadow: var(--tobi-shadow-btn);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}
.tobi-launcher:hover { transform: scale(1.06); }

/* Toggle chat ↔ X icons */
.tobi-icon-chat,
.tobi-icon-x   { position: absolute; transition: opacity 0.18s ease, transform 0.18s ease; }
.tobi-icon-x   { opacity: 0; transform: rotate(-45deg) scale(0.7); }
.tobi-launcher.is-open .tobi-icon-chat { opacity: 0; transform: rotate(45deg) scale(0.7); }
.tobi-launcher.is-open .tobi-icon-x   { opacity: 1; transform: rotate(0) scale(1); }

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

.tobi-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 360px;
  max-width: calc(100vw - 48px);
  height: 500px;
  max-height: calc(100vh - 140px);
  background: #fff;
  border-radius: var(--tobi-radius-lg);
  box-shadow: var(--tobi-shadow-lg);
  border: 1px solid var(--tobi-border-lt);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
.tobi-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.tobi-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 14px 18px;
  background: var(--tobi-gradient);
  color: #fff;
  flex-shrink: 0;
}
.tobi-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tobi-header-name   { font-weight: 800; font-size: 0.92rem; }
.tobi-header-status { font-size: 0.72rem; opacity: 0.88; }
.tobi-close {
  margin-left: auto;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 50%;
  color: #fff;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.tobi-close:hover { background: rgba(255,255,255,0.28); }

/* ── Message log ─────────────────────────────────────────────────────────── */

.tobi-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--tobi-bg-warm);
  scroll-behavior: smooth;
}
.tobi-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--tobi-radius-sm);
  font-size: 0.84rem;
  line-height: 1.55;
  font-family: var(--tobi-font);
}
.tobi-msg a         { color: inherit; text-decoration: underline; }
.tobi-msg-suffix    { margin-top: 10px; }
.tobi-msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--tobi-border-lt);
  color: var(--tobi-text);
  border-bottom-left-radius: 4px;
}
.tobi-msg--user {
  align-self: flex-end;
  background: var(--tobi-gradient);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* ── Typing indicator ────────────────────────────────────────────────────── */

.tobi-typing {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.tobi-typing span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tobi-border);
  animation: tobi-bounce 1.2s infinite ease-in-out;
}
.tobi-typing span:nth-child(2) { animation-delay: 0.15s; }
.tobi-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes tobi-bounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.45; }
  30%            { transform: translateY(-5px); opacity: 1;    }
}

/* ── Quick-reply chips ───────────────────────────────────────────────────── */

.tobi-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 2px;
}
.tobi-qr {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--tobi-primary);
  background: #fff;
  color: var(--tobi-primary);
  font-size: 0.78rem;
  font-weight: 600;
  font-family: var(--tobi-font);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.tobi-qr:hover {
  background: var(--tobi-primary);
  color: #fff;
}

/* ── CTA button (demo link, etc.) ────────────────────────────────────────── */

.tobi-cta-btn {
  display: inline-block;
  padding: 8px 18px;
  background: var(--tobi-gradient);
  color: #fff !important;
  border-radius: var(--tobi-radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none !important;
  margin-top: 6px;
  transition: opacity 0.15s ease;
}
.tobi-cta-btn:hover { opacity: 0.88; }

/* ── Support ticket form ─────────────────────────────────────────────────── */

.tobi-ticket-form {
  background: #fff;
  border: 1px solid var(--tobi-border-lt);
  border-radius: var(--tobi-radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-family: var(--tobi-font);
  max-width: 92%;
}
.tobi-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tobi-field label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--tobi-text);
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tobi-field input,
.tobi-field textarea {
  border: 1px solid var(--tobi-border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.82rem;
  font-family: var(--tobi-font);
  color: var(--tobi-text);
  background: var(--tobi-bg-warm);
  outline: none;
  transition: border-color 0.15s ease;
  resize: none;
}
.tobi-field input:focus,
.tobi-field textarea:focus { border-color: var(--tobi-primary); }
.tobi-ticket-submit {
  padding: 9px 16px;
  background: var(--tobi-gradient);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  font-family: var(--tobi-font);
  cursor: pointer;
  transition: opacity 0.15s ease;
  align-self: flex-start;
}
.tobi-ticket-submit:hover   { opacity: 0.88; }
.tobi-ticket-submit:disabled { opacity: 0.55; cursor: not-allowed; }
.tobi-ticket-note {
  font-size: 0.7rem;
  color: var(--tobi-text);
  opacity: 0.5;
  margin: 0;
}
.tobi-ticket-error {
  font-size: 0.75rem;
  color: #d00;
  margin: 0;
}
.tobi-ticket-success {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 12px;
  text-align: center;
  color: var(--tobi-text);
}
.tobi-ticket-success svg { color: #00BDA5; margin-bottom: 2px; }
.tobi-ticket-success strong { font-size: 0.9rem; }
.tobi-ticket-success span   { font-size: 0.78rem; opacity: 0.7; }

/* ── CSAT emoji faces ────────────────────────────────────────────────────── */

.tobi-csat {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--tobi-border-lt);
  border-radius: var(--tobi-radius-sm);
  border-bottom-left-radius: 4px;
  padding: 14px 16px;
  max-width: 92%;
}

.tobi-csat-faces {
  display: flex;
  gap: 4px;
}

.tobi-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border: 1.5px solid transparent;
  border-radius: var(--tobi-radius-sm);
  background: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  font-family: var(--tobi-font);
}
.tobi-face:hover:not(:disabled) {
  background: var(--tobi-bg-warm);
  border-color: var(--tobi-border);
  transform: translateY(-2px);
}
.tobi-face.is-selected {
  background: var(--tobi-bg-warm);
  border-color: var(--tobi-primary);
}
.tobi-face:disabled { cursor: default; }
.tobi-face:disabled:not(.is-selected) { opacity: 0.35; }

.tobi-face-emoji {
  font-size: 1.6rem;
  line-height: 1;
  display: block;
}
.tobi-face-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--tobi-text);
  opacity: 0.6;
  white-space: nowrap;
}
.tobi-face.is-selected .tobi-face-label {
  opacity: 1;
  color: var(--tobi-primary);
}

/* Thanks card shown after rating */
.tobi-csat-thanks {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  text-align: center;
}
.tobi-csat-emoji  { font-size: 2rem; line-height: 1; }
.tobi-csat-thanks strong { font-size: 0.88rem; color: var(--tobi-text); margin-top: 2px; }
.tobi-csat-thanks span   { font-size: 0.76rem; color: var(--tobi-text); opacity: 0.6; }

/* ── Message input form ──────────────────────────────────────────────────── */

.tobi-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--tobi-border-lt);
  flex-shrink: 0;
  background: #fff;
}
.tobi-form input {
  flex: 1;
  border: 1px solid var(--tobi-border);
  border-radius: var(--tobi-radius-sm);
  padding: 10px 14px;
  font-family: var(--tobi-font);
  font-size: 0.84rem;
  outline: none;
  transition: border-color 0.15s ease;
  color: var(--tobi-text);
  background: var(--tobi-bg-warm);
}
.tobi-form input:focus { border-color: var(--tobi-primary); }
.tobi-form button {
  width: 40px;
  height: 40px;
  border-radius: var(--tobi-radius-sm);
  background: var(--tobi-gradient);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
}
.tobi-form button:hover { opacity: 0.88; }

/* ── Mobile — full-width bottom sheet ────────────────────────────────────── */

@media (max-width: 480px) {
  .tobi-widget {
    right: 16px;
    bottom: 16px;
  }

  /* Panel becomes a fixed bottom sheet that slides up.
     Height is capped so it never exceeds the visible viewport.
     dvh accounts for mobile browser chrome (address bar, nav); vh is the fallback. */
  .tobi-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 70vh;
    height: 70dvh;
    max-height: 70vh;
    max-height: 70dvh;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    opacity: 1;
  }
  .tobi-panel.open {
    transform: translateY(0);
    opacity: 1;
  }

  /* Larger close button for thumb tapping */
  .tobi-close {
    width: 38px;
    height: 38px;
  }

  /* Slightly larger touch targets */
  .tobi-qr {
    padding: 8px 16px;
    font-size: 0.82rem;
  }

  /* Slightly larger input/send on mobile */
  .tobi-form input {
    font-size: 16px; /* prevents iOS zoom on focus */
  }
}
