/* ═══════════════════════════════════════════════
   FLUXORI — Chat Widget Styles
   Uses design tokens from base.css
   ═══════════════════════════════════════════════ */

.chat-widget { width: 100%; max-width: 560px; margin: 36px auto 0; animation: fadeInUp 0.7s ease-out 0.3s both; }

.chat-widget__trigger-shell {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.chat-widget__trigger-shell:focus-visible {
  outline: 2px solid rgba(129, 140, 248, 0.7);
  outline-offset: 6px;
  border-radius: 18px;
}

.chat-widget__trigger-shell.hidden { display: none; }

.chat-widget__trigger-card {
  flex: 0 1 auto;
  width: clamp(220px, 30vw, 300px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1.5px solid rgba(99, 102, 241, 0.22);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: all 0.3s var(--ease-spring);
}

.chat-widget__trigger-label {
  display: block;
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.chat-widget__trigger-orb {
  position: relative;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border-radius: 50%;
}

.chat-widget__trigger-glow {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: #00c8f0;
  filter: blur(10px);
  opacity: 0.3;
  animation: oriGlowPulse 2.5s ease-in-out infinite;
}

.chat-widget__trigger-status {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 10px #22c55e;
  transform: translate(-50%, -50%);
  animation: oriStatusPulse 1.8s infinite ease-in-out;
}

.chat-widget__trigger-shell:hover .chat-widget__trigger-card {
  border-color: rgba(99, 102, 241, 0.45);
  background: rgba(99, 102, 241, 0.14);
  transform: translateY(-1px);
  box-shadow: 0 10px 26px rgba(12, 17, 32, 0.45);
}

.chat-widget__trigger-shell:hover .chat-widget__trigger-glow {
  transform: scale(1.35);
  opacity: 0.45;
}

.chat-widget__trigger-shell:active .chat-widget__trigger-card {
  transform: translateY(0);
}

@keyframes oriGlowPulse {
  0% {
    transform: scale(1);
    opacity: 0.2;
  }
  50% {
    transform: scale(1.35);
    opacity: 0.4;
  }
  100% {
    transform: scale(1);
    opacity: 0.2;
  }
}

@keyframes oriStatusPulse {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.8;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.3);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.8;
  }
}

/* ── Panel ── */
.chat-widget__panel {
  display: none; margin-top: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-glass-border);
  background: var(--color-bg-elevated);
  overflow: hidden;
  max-width: 100%;
  animation: widgetSlideDown 0.4s var(--ease-spring);
}
.chat-widget__panel.open { display: block; }

.chat-widget__close {
  margin-left: 8px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--color-text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

.chat-widget__close svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.chat-widget__close:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}

@keyframes widgetSlideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Capture Form ── */
.chat-widget__capture {
  position: relative;
  padding: 54px 24px 28px;
}

.chat-widget__close--capture {
  position: absolute;
  top: 12px;
  right: 12px;
  margin-left: 0;
  z-index: 4;
}

.chat-widget__capture-header { text-align: center; margin-bottom: 24px; }

.chat-widget__capture-icon {
  width: 72px; height: 72px; border-radius: 20px;
  border: 1px solid rgba(34, 211, 238, 0.28);
  background: #121a2b;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  overflow: hidden;
}

.chat-widget__capture-icon img {
  width: 58px;
  height: 58px;
  object-fit: contain;
  filter: none;
}

.chat-widget__capture-title {
  font-size: 1.15rem; font-weight: 700;
  color: var(--color-text); margin-bottom: 4px;
}

.chat-widget__capture-sub {
  font-size: 0.85rem; color: var(--color-text-muted);
}

.chat-widget__field { margin-bottom: 14px; }

.chat-widget__field label {
  display: block; font-size: 0.75rem; font-weight: 600;
  color: var(--color-text-muted); margin-bottom: 6px;
  letter-spacing: 0.01em;
}

.chat-widget__input-wrap {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.03);
  transition: border-color var(--transition-fast);
}
.chat-widget__input-wrap:focus-within { border-color: rgba(99,102,241,0.4); }

.chat-widget__input-wrap input {
  flex: 1; background: transparent; border: none; outline: none;
  font-family: var(--font-display); font-size: 0.9rem; color: var(--color-text);
}
.chat-widget__input-wrap input::placeholder { color: var(--color-text-dim); }

.chat-widget__error { font-size: 0.7rem; color: #EF4444; margin-top: 4px; display: block; min-height: 16px; }

.chat-widget__submit {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 0;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
  color: white; border: none; border-radius: var(--radius-md);
  font-family: var(--font-display); font-size: 0.95rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition-base); margin-top: 20px;
}
.chat-widget__submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 25px rgba(99,102,241,0.3);
}
.chat-widget__submit:disabled { opacity: 0.6; cursor: default; transform: none; }

.chat-widget__disclaimer {
  font-size: 0.7rem; color: var(--color-text-dim);
  text-align: center; margin-top: 12px; line-height: 1.5;
}

/* ── Chat ── */
.chat-widget__chat { display: flex; flex-direction: column; height: 440px; }

.chat-widget__chat-header {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--color-glass-border);
  background: rgba(255,255,255,0.02);
}

.chat-widget__status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #10b981; box-shadow: 0 0 8px rgba(16,185,129,0.5);
}
.chat-widget__chat-name { font-size: 0.88rem; font-weight: 600; color: var(--color-text); }
.chat-widget__chat-badge {
  font-size: 0.6rem; font-weight: 700; padding: 2px 6px;
  background: rgba(99,102,241,0.2); color: var(--color-primary-light);
  border-radius: 6px; letter-spacing: 0.05em;
}
.chat-widget__chat-user {
  margin-left: auto;
  max-width: 55%;
  font-size: 0.7rem;
  color: var(--color-text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-widget__messages {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  overflow-x: hidden;
  display: flex; flex-direction: column; gap: 12px;
}

/* Messages */
.chat-msg--user { display: flex; justify-content: flex-end; }
.chat-msg--assistant { display: flex; align-items: flex-start; gap: 8px; }

.chat-msg__avatar {
  width: 28px; height: 28px; min-width: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  display: flex; align-items: center; justify-content: center; margin-top: 2px;
}

.chat-msg__bubble--user {
  max-width: 80%; padding: 10px 16px;
  border-radius: 16px 16px 4px 16px;
  background: rgba(99,102,241,0.15);
  color: var(--color-text); font-size: 0.88rem; line-height: 1.6;
  overflow-wrap: anywhere;
}

.chat-msg__bubble--assistant {
  max-width: 85%; padding: 10px 16px;
  border-radius: 16px 16px 16px 4px;
  background: var(--color-glass);
  color: var(--color-text); font-size: 0.88rem; line-height: 1.6;
  overflow-wrap: anywhere;
}

/* Typing */
.chat-typing { display: flex; gap: 4px; padding: 4px 0; }
.chat-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--color-primary-light); display: inline-block;
  animation: typingDot 1s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingDot {
  0%,100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* Schedule card */
.chat-schedule-card {
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap;
  margin-left: 0; margin-top: 8px; padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: linear-gradient(135deg, rgba(99,102,241,0.06), rgba(34,211,238,0.03));
}
.chat-schedule-card__icon {
  width: 36px; height: 36px; min-width: 36px; border-radius: 10px;
  background: rgba(99,102,241,0.12);
  display: flex; align-items: center; justify-content: center;
}
.chat-schedule-card__title { font-size: 0.82rem; font-weight: 600; color: var(--color-text); }
.chat-schedule-card__desc { font-size: 0.75rem; color: var(--color-text-muted); }
.chat-schedule-card__btn {
  margin-left: auto; padding: 8px 16px;
  background: var(--color-primary); color: white; border: none;
  border-radius: 10px; font-family: var(--font-display);
  font-size: 0.82rem; font-weight: 600; cursor: pointer;
  transition: background var(--transition-fast); white-space: nowrap;
}
.chat-schedule-card__btn:hover { background: var(--color-primary-light); }

/* Input bar */
.chat-widget__input-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--color-glass-border);
  background: rgba(255,255,255,0.02);
}
.chat-widget__input-bar textarea {
  flex: 1; background: transparent; border: none; outline: none; resize: none;
  font-family: var(--font-display); font-size: 0.88rem; line-height: 1.5;
  color: var(--color-text); padding: 6px 0;
}
.chat-widget__input-bar textarea::placeholder { color: var(--color-text-dim); }

.chat-widget__send {
  width: 36px; height: 36px; min-width: 36px; border-radius: 10px;
  background: var(--color-primary); color: white; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--transition-fast);
}
.chat-widget__send:disabled { opacity: 0.35; cursor: default; }
.chat-widget__send:not(:disabled):hover { background: var(--color-primary-light); }

/* ── Cal.com embed in chat ── */
.chat-cal-embed {
  margin-left: 36px;
  margin-top: 8px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--color-bg-elevated);
  overflow: hidden;
  animation: widgetSlideDown 0.3s ease-out;
}

.chat-cal-embed__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-cal-embed__title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-cal-embed__title svg { color: var(--color-primary-light); }

.chat-cal-embed__body {
  height: 380px;
  background: white;
  border-radius: 0 0 14px 14px;
}

.chat-cal-embed__body iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* ── Conversation ended state ── */
.chat-widget__ended {
  padding: 20px;
  text-align: center;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.02);
}

.chat-widget__ended-text {
  font-size: 0.82rem;
  color: var(--color-text-dim);
  margin-bottom: 12px;
}

.chat-widget__restart {
  padding: 8px 20px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: var(--color-text-muted);
  font-family: var(--font-display);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.chat-widget__restart:hover {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.3);
  color: var(--color-primary-light);
}

/* ── Booking confirmed message ── */
.chat-booking-confirmed {
  margin-left: 36px;
  margin-top: 8px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(16, 185, 129, 0.25);
  background: rgba(16, 185, 129, 0.08);
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-booking-confirmed__icon {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-booking-confirmed__text {
  font-size: 0.82rem;
  color: #34d399;
  font-weight: 600;
}

.chat-booking-confirmed__detail {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* ── Responsive ── */
/* ── Select / Interest ── */
.chat-widget__select-wrap {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.03);
  transition: border-color 0.2s;
}
.chat-widget__select-wrap:focus-within { border-color: rgba(99,102,241,0.4); }
.chat-widget__select-wrap select {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--color-text);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0 center;
  padding-right: 20px;
}
.chat-widget__select-wrap select option {
  background: var(--color-bg-elevated);
  color: var(--color-text);
  padding: 8px;
}

/* ── Mobile overlay backdrop ── */
.chat-widget__overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 15, 0.85);
  z-index: 219;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

@media (max-width: 768px) {
  body.chat-widget--mobile-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    overscroll-behavior: none;
    touch-action: none;
  }

  body.chat-widget--mobile-open .chat-widget__overlay {
    display: block;
  }

  body.chat-widget--mobile-open .chat-widget {
    animation: none;
    transform: none;
  }

  .chat-widget { max-width: 100%; }
  .chat-widget__panel {
    max-width: 100%;
    overflow-x: hidden;
  }
  .chat-widget__panel.open {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin-top: 0;
    z-index: 220;
    display: flex;
    flex-direction: column;
    max-height: none;
    border-radius: 0;
    border: none;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .chat-widget__close {
    width: 28px;
    height: 28px;
  }
  .chat-widget__close--capture {
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: 10px;
  }
  .chat-widget__close svg {
    width: 14px;
    height: 14px;
  }
  .chat-widget__capture-icon {
    width: 64px;
    height: 64px;
    margin-bottom: 14px;
  }
  .chat-widget__capture-icon img {
    width: 50px;
    height: 50px;
  }
  .chat-widget__trigger-card {
    width: clamp(190px, 62vw, 240px);
    padding: 11px 14px;
    gap: 10px;
  }
  .chat-widget__trigger-label { font-size: 0.88rem; }
  .chat-widget__trigger-orb {
    width: 20px;
    height: 20px;
    flex-basis: 20px;
  }
  .chat-widget__trigger-glow { filter: blur(9px); }
  .chat-widget__trigger-status {
    width: 8px;
    height: 8px;
  }
  .chat-widget__chat-header {
    padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 12px;
  }
  .chat-widget__messages { padding: 14px; }

  /* Prevent iOS auto-zoom on focus (triggers at font-size < 16px) */
  .chat-widget__input-wrap input,
  .chat-widget__select-wrap select,
  .chat-widget__input-bar textarea {
    font-size: 16px;
  }
  .chat-cal-embed {
    margin-left: 0;
    width: 100%;
  }
  .chat-cal-embed__body { height: 340px; }
  .chat-booking-confirmed {
    margin-left: 0;
    width: 100%;
  }
  .chat-widget__chat-user {
    margin-left: 0;
    max-width: 100%;
    width: 100%;
    white-space: normal;
  }
  .chat-schedule-card { gap: 10px; }
  .chat-schedule-card {
    margin-left: 0 !important;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  .chat-schedule-card__btn {
    margin-left: 0;
    width: 100%;
  }
  .chat-widget__chat { height: 360px; }
  .chat-widget__chat {
    height: 100%;
    min-height: 0;
  }
  .chat-widget__capture {
    padding: calc(46px + env(safe-area-inset-top, 0px)) 18px 24px;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .chat-widget__messages {
    min-height: 0;
  }
  .chat-widget__input-bar {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .chat-schedule-card,
  #scheduleCard,
  #bookingQuestion,
  #endButtons {
    margin-left: 0 !important;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
}

@media (max-width: 420px) {
  .chat-widget__trigger-card {
    width: clamp(170px, 58vw, 220px);
    padding: 10px 12px;
    gap: 9px;
  }
  .chat-widget__trigger-label { font-size: 0.84rem; }
  .chat-widget__trigger-orb {
    width: 18px;
    height: 18px;
    flex-basis: 18px;
  }
  .chat-cal-embed__body { height: 300px; }
}
