/* Floating parts chatbot — polished theme + transitions */

.chat-widget {
  --chat-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --chat-duration: 0.34s;
  position: fixed;
  right: max(1rem, var(--safe-right));
  bottom: max(1rem, var(--safe-bottom-stable, var(--safe-bottom)));
  z-index: 2400;
  font-family: var(--font);
  color: var(--text);
}

.chat-widget.is-placed {
  right: auto !important;
  bottom: auto !important;
  left: var(--chat-x, auto);
  top: var(--chat-y, auto);
}

.chat-widget.is-dragging {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  pointer-events: auto;
  will-change: transform;
}

/* Release glide / edge snap (transform is animated from the drop point back to 0). */
.chat-widget.is-settling {
  transition: transform 0.28s var(--chat-ease);
  will-change: transform;
}

.chat-widget.is-dragging .chat-launcher::before {
  animation: none;
  opacity: 0;
}

.chat-widget.is-dragging .chat-launcher {
  pointer-events: auto;
}

.chat-icon {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
  flex-shrink: 0;
}

.chat-launcher .chat-icon {
  width: 1.4rem;
  height: 1.4rem;
}

.chat-launcher {
  position: relative;
  width: 3.6rem;
  height: 3.6rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(145deg, var(--primary) 0%, #1e3a8a 72%, #172554 100%);
  color: #fff;
  box-shadow:
    var(--shadow-md),
    0 10px 28px rgba(29, 78, 216, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  cursor: grab;
  touch-action: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  overflow: visible;
  transition:
    transform var(--chat-duration) var(--chat-ease),
    opacity 0.22s ease,
    box-shadow var(--chat-duration) ease,
    background 0.25s ease;
}

.chat-launcher::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  border: 2px solid rgba(29, 78, 216, 0.35);
  opacity: 0.7;
  animation: chat-launcher-ring 2.4s var(--chat-ease) infinite;
  pointer-events: none;
}

.chat-launcher::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.28), transparent 55%);
  pointer-events: none;
}

.chat-launcher:hover {
  background: linear-gradient(145deg, var(--primary-hover) 0%, #1e3a8a 70%, #172554 100%);
  transform: translateY(-3px) scale(1.05);
  box-shadow:
    var(--shadow-md),
    0 16px 36px rgba(29, 78, 216, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.chat-launcher:hover::before {
  animation-duration: 1.4s;
  opacity: 1;
}

.chat-launcher:active {
  transform: translateY(0) scale(0.95);
  cursor: grabbing;
}

.chat-widget.is-dragging .chat-launcher,
.chat-widget.is-dragging .chat-launcher:hover,
.chat-widget.is-dragging .chat-launcher:active {
  /* "Picked up" feel; short transition so it doesn't lag behind the finger. */
  transform: scale(1.08);
  cursor: grabbing;
  transition: transform 0.15s var(--chat-ease), box-shadow 0.15s ease;
  box-shadow:
    var(--shadow-md),
    0 18px 38px rgba(29, 78, 216, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.chat-launcher:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 4px;
}

.chat-widget.is-open .chat-launcher {
  opacity: 0;
  transform: scale(0.55) translateY(12px);
  pointer-events: none;
}

.chat-widget.is-open .chat-launcher::before {
  animation: none;
  opacity: 0;
}

@keyframes chat-launcher-ring {
  0% {
    transform: scale(1);
    opacity: 0.65;
  }
  70% {
    transform: scale(1.22);
    opacity: 0;
  }
  100% {
    transform: scale(1.22);
    opacity: 0;
  }
}

.chat-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: min(24.5rem, calc(100vw - 1.5rem));
  height: min(35rem, calc(100vh - 5.5rem));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px) saturate(1.15);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  border: 1px solid color-mix(in srgb, var(--border) 80%, var(--primary) 20%);
  border-radius: calc(var(--radius-lg) + 2px);
  box-shadow:
    var(--shadow-md),
    0 22px 56px rgba(15, 23, 42, 0.16),
    0 0 0 1px rgba(255, 255, 255, 0.4) inset;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(18px) scale(0.92);
  filter: blur(2px);
  transition:
    opacity var(--chat-duration) var(--chat-ease),
    transform 0.4s var(--chat-ease),
    visibility 0.4s,
    filter 0.35s ease;
}

.chat-widget.is-open .chat-panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  filter: blur(0);
}

.chat-header {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-shrink: 0;
  padding: 0.95rem 1rem 0.9rem;
  background: linear-gradient(135deg, var(--primary) 0%, #1e3a8a 55%, #172554 100%);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.chat-widget.is-dragging .chat-header {
  cursor: grabbing;
}

.chat-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 120% at 100% -20%, rgba(255, 255, 255, 0.22), transparent 55%),
    radial-gradient(ellipse 50% 80% at -10% 120%, rgba(56, 189, 248, 0.18), transparent 50%);
  pointer-events: none;
}

.chat-header > * {
  position: relative;
  z-index: 1;
}

.chat-header-title {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.chat-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.chat-online-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: #4ade80;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.55);
  animation: chat-online-pulse 2s ease-out infinite;
  flex-shrink: 0;
}

@keyframes chat-online-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(74, 222, 128, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0);
  }
}

.chat-header p {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.35;
  opacity: 0.9;
  transition: opacity 0.25s ease;
}

.chat-header-actions {
  cursor: auto;
  touch-action: auto;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.chat-header-actions button {
  border: 0;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-radius: var(--radius-sm);
  width: 2rem;
  height: 2rem;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  line-height: 0;
  transition:
    background 0.2s ease,
    transform 0.2s var(--chat-ease),
    box-shadow 0.2s ease,
    opacity 0.22s ease,
    min-width 0.28s var(--chat-ease);
}

.chat-header-actions .chat-clear-btn {
  width: auto;
  min-width: 2rem;
  padding: 0 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
}

.chat-header-actions .chat-clear-btn .chat-icon {
  width: 0.95rem;
  height: 0.95rem;
}

.chat-header-actions .chat-clear-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.chat-header-actions .chat-clear-btn.is-loading {
  opacity: 1;
  cursor: wait;
  min-width: 5.25rem;
  transform: none;
}

.chat-header-actions .chat-clear-btn.is-loading .btn-spinner {
  border-color: rgba(255, 255, 255, 0.35);
  border-right-color: transparent;
}

.chat-header-actions button:disabled:not(.is-loading) {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.chat-header-actions button:hover {
  background: rgba(255, 255, 255, 0.26);
  transform: scale(1.07);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.chat-header-actions button:active {
  transform: scale(0.94);
}

.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex-shrink: 0;
  padding: 0.75rem 0.85rem 0.6rem;
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg) 88%, var(--primary-soft)) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  max-height: 8rem;
  opacity: 1;
  transition:
    max-height 0.32s var(--chat-ease),
    opacity 0.26s ease,
    padding 0.32s var(--chat-ease),
    border-color 0.26s ease;
}

.chat-chip {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.38rem 0.72rem;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  animation: chat-chip-in 0.4s var(--chat-ease) both;
  transition:
    border-color 0.2s ease,
    color 0.2s ease,
    background 0.2s ease,
    transform 0.22s var(--chat-ease),
    box-shadow 0.22s ease;
}

.chat-chip:nth-child(1) { animation-delay: 0.04s; }
.chat-chip:nth-child(2) { animation-delay: 0.08s; }
.chat-chip:nth-child(3) { animation-delay: 0.12s; }
.chat-chip:nth-child(4) { animation-delay: 0.16s; }
.chat-chip:nth-child(5) { animation-delay: 0.2s; }

@keyframes chat-chip-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(29, 78, 216, 0.12);
}

.chat-chip:active {
  transform: translateY(0) scale(0.97);
}

.chat-msg-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.chat-msg-chip {
  opacity: 1;
  animation: none;
}

.chat-messages {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background:
    radial-gradient(ellipse 90% 60% at 0% 0%, color-mix(in srgb, var(--primary-soft) 70%, transparent), transparent 55%),
    radial-gradient(ellipse 70% 50% at 100% 100%, color-mix(in srgb, var(--primary-soft) 45%, transparent), transparent 50%),
    var(--bg);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.chat-messages::before {
  content: '';
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  height: 0.75rem;
  margin: -0.9rem -0.9rem 0;
  background: linear-gradient(180deg, var(--bg), transparent);
  pointer-events: none;
  z-index: 2;
  opacity: 0.9;
}

.chat-empty {
  margin: auto 0.5rem;
  padding: 1.25rem 1rem;
  text-align: center;
  color: var(--muted);
  opacity: 0;
  animation: chat-msg-in 0.45s var(--chat-ease) 0.12s both;
}

.chat-empty-icon {
  width: 2.75rem;
  height: 2.75rem;
  margin: 0 auto 0.75rem;
  border-radius: 1rem;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--border));
  box-shadow: var(--shadow-sm);
}

.chat-empty-icon .chat-icon {
  width: 1.35rem;
  height: 1.35rem;
}

.chat-empty strong {
  display: block;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 650;
  margin-bottom: 0.25rem;
}

.chat-empty p {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
}

.chat-widget.has-messages .chat-empty {
  display: none;
}

.chat-msg {
  display: flex;
  animation: chat-msg-in 0.38s var(--chat-ease) both;
}

.chat-msg-user {
  justify-content: flex-end;
  animation-name: chat-msg-in-user;
}

.chat-msg-assistant {
  justify-content: flex-start;
  animation-name: chat-msg-in-assistant;
}

@keyframes chat-msg-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes chat-msg-in-user {
  from {
    opacity: 0;
    transform: translateX(12px) translateY(6px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateX(0) translateY(0) scale(1);
  }
}

@keyframes chat-msg-in-assistant {
  from {
    opacity: 0;
    transform: translateX(-12px) translateY(6px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateX(0) translateY(0) scale(1);
  }
}

.chat-bubble {
  max-width: 92%;
  padding: 0.72rem 0.88rem;
  border-radius: 1rem;
  font-size: 0.875rem;
  line-height: 1.48;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.chat-msg-user .chat-bubble {
  background: linear-gradient(145deg, var(--primary) 0%, #1e40af 100%);
  color: #fff;
  border-color: transparent;
  border-bottom-right-radius: 0.3rem;
  box-shadow: 0 6px 16px rgba(29, 78, 216, 0.22);
}

.chat-msg-assistant .chat-bubble {
  border-bottom-left-radius: 0.3rem;
}

.chat-msg.is-pending .chat-bubble {
  min-width: 5.5rem;
}

.chat-typing {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-style: normal;
  font-size: 0.82rem;
}

.chat-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
}

.chat-typing-dots span {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 999px;
  background: var(--primary);
  animation: chat-dot-bounce 1.05s ease-in-out infinite;
}

.chat-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chat-dot-bounce {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0) scale(0.9);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px) scale(1);
  }
}

.chat-cards {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.7rem;
}

.chat-card {
  border: 1px solid color-mix(in srgb, var(--border) 70%, var(--primary) 30%);
  border-radius: var(--radius-md);
  padding: 0.68rem 0.78rem;
  background: linear-gradient(160deg, var(--card) 0%, var(--primary-soft) 120%);
  opacity: 0;
  animation: chat-card-in 0.4s var(--chat-ease) both;
  transition:
    transform 0.22s var(--chat-ease),
    box-shadow 0.22s ease,
    border-color 0.2s ease;
}

.chat-card:nth-child(1) { animation-delay: 0.05s; }
.chat-card:nth-child(2) { animation-delay: 0.1s; }
.chat-card:nth-child(3) { animation-delay: 0.15s; }
.chat-card:nth-child(4) { animation-delay: 0.2s; }
.chat-card:nth-child(5) { animation-delay: 0.25s; }
.chat-card:nth-child(6) { animation-delay: 0.3s; }

@keyframes chat-card-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  box-shadow: 0 8px 18px rgba(29, 78, 216, 0.12);
}

.chat-card.has-image:hover {
  transform: none;
}

.chat-card.has-image {
  padding: 0.55rem;
}

.chat-card-layout {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
}

.chat-card-media {
  flex: 0 0 4.65rem;
  width: 4.65rem;
  height: 4.65rem;
  padding: 0.28rem;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  cursor: zoom-in;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  transition:
    transform 0.22s var(--chat-ease),
    box-shadow 0.22s ease,
    border-color 0.2s ease;
}

.chat-card-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.chat-card-media:hover,
.chat-card-media:focus-visible {
  transform: scale(1.03);
  border-color: #cbd5e1;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
  outline: none;
}

.chat-card-body {
  flex: 1;
  min-width: 0;
}

.chat-image-flyout {
  position: fixed;
  z-index: 2600;
  width: min(16.75rem, calc(100vw - 1.5rem));
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.96);
  transition:
    opacity 0.2s ease,
    transform 0.24s var(--chat-ease),
    visibility 0.2s ease;
}

.chat-image-flyout.is-open {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
}

.chat-image-flyout-card {
  padding: 0.5rem;
  border-radius: 14px;
  background: #fff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
}

.chat-image-flyout img {
  width: 100%;
  max-height: 15rem;
  object-fit: contain;
  display: block;
  border-radius: 10px;
  background: #f8fafc;
}

.chat-image-flyout-caption {
  margin: 0.4rem 0.1rem 0.05rem;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--text);
  text-align: center;
  word-break: break-all;
}

.chat-image-flyout.is-overlay {
  inset: 0;
  width: auto;
  height: auto;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(15, 23, 42, 0.52);
  transform: none;
}

.chat-image-flyout.is-overlay .chat-image-flyout-card {
  width: min(22rem, 100%);
}

.chat-image-flyout.is-overlay img {
  max-height: min(22rem, 62dvh);
}

.chat-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.chat-card-pn {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text);
  letter-spacing: 0.01em;
}

.chat-card-pn-link {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--primary);
  letter-spacing: 0.01em;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
  transition: color 0.15s ease;
}

.chat-card-pn-link:hover {
  color: var(--primary-hover, #1d4ed8);
}

.chat-card-source {
  color: var(--primary) !important;
  font-weight: 600;
}

.chat-card-copy {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--primary);
  border-radius: var(--radius-sm);
  padding: 0.28rem 0.58rem;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    transform 0.2s var(--chat-ease);
}

.chat-card-copy:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
}

.chat-card-copy.is-copied {
  background: var(--success, #16a34a);
  border-color: transparent;
  color: #fff;
  transform: scale(1.04);
}

.chat-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.chat-card-meta span {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.16rem 0.52rem;
  transition: border-color 0.15s ease;
}

.chat-card-submodel {
  color: var(--text, #1a1a1a);
  font-weight: 650;
}

.chat-card-mrp {
  color: var(--text, #1a1a1a);
  font-weight: 650;
  letter-spacing: 0.01em;
}

.chat-card-years {
  color: var(--muted);
  font-weight: 600;
}

.chat-card-notes {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
  word-break: break-word;
}

.chat-bubble-note {
  margin-bottom: 0.55rem;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--muted);
}

.chat-card-stock {
  margin-top: 0.48rem;
  font-size: 0.78rem;
  font-weight: 650;
}

.chat-card-stock-in {
  color: var(--success);
}

.chat-card-stock-out {
  color: var(--warning);
}

.chat-card-stock-missing {
  color: var(--muted);
}

.chat-form {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
  padding: 0.8rem 0.85rem 0.95rem;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--card) 94%, var(--bg));
  box-shadow: 0 -8px 20px rgba(15, 23, 42, 0.04);
}

.chat-form textarea {
  flex: 1;
  min-height: 2.65rem;
  max-height: 7.5rem;
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 0.62rem 0.95rem;
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--text);
  background: var(--card);
  outline: none;
  resize: none;
  overflow-y: hidden;
  transition:
    border-color 0.2s ease,
    box-shadow 0.25s ease,
    background 0.2s ease,
    height 0.12s ease;
}

.chat-form textarea::placeholder {
  color: var(--muted);
}

.chat-form textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.14);
  background: #fff;
}

.chat-form textarea.is-scrollable {
  overflow-y: auto;
}

.chat-form button[type='submit'] {
  border: 0;
  border-radius: 999px;
  background: linear-gradient(145deg, var(--primary) 0%, #1e40af 100%);
  color: #fff;
  width: 2.65rem;
  height: 2.65rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 6px 14px rgba(29, 78, 216, 0.22);
  transition:
    background 0.2s ease,
    transform 0.22s var(--chat-ease),
    box-shadow 0.22s ease;
}

.chat-form button[type='submit'] .chat-icon {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  display: block;
  transition: transform 0.22s var(--chat-ease);
}

.chat-form button[type='submit']:hover {
  background: linear-gradient(145deg, var(--primary-hover) 0%, #1e3a8a 100%);
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(29, 78, 216, 0.3);
}

.chat-form button[type='submit']:hover .chat-icon {
  transform: translateX(1px) translateY(-1px);
}

.chat-form button[type='submit']:active {
  transform: scale(0.95);
}

.chat-mic-btn {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--primary);
  width: 2.65rem;
  height: 2.65rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    transform 0.22s var(--chat-ease),
    box-shadow 0.22s ease;
}

.chat-mic-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-2px);
}

.chat-mic-btn.is-listening {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.35);
  animation: chat-mic-ring 1.2s ease-out infinite;
}

.chat-mic-btn.is-listening .chat-mic-idle {
  display: none;
}

.chat-mic-btn .chat-mic-stop {
  display: none;
}

.chat-mic-btn.is-listening .chat-mic-stop {
  display: block;
}

.chat-mic-btn.is-unsupported,
.chat-mic-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

@keyframes chat-mic-ring {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(220, 38, 38, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0);
  }
}

@media (max-width: 768px) {
  /* Closed: only the launcher floats — sit above the bottom mode tab bar. */
  .chat-widget {
    position: fixed;
    right: max(0.85rem, var(--safe-right));
    bottom: max(
      calc(var(--mode-bar-height, 3.1rem) + 0.65rem + var(--safe-bottom-stable, var(--safe-bottom))),
      4.4rem
    );
    left: auto;
    top: auto;
    width: auto;
    height: auto;
    pointer-events: none;
  }

  .chat-launcher {
    pointer-events: auto;
    position: relative;
    right: auto;
    bottom: auto;
    width: 3.35rem;
    height: 3.35rem;
  }

  .chat-widget.is-open,
  .chat-widget.is-open.is-placed {
    inset: 0;
    right: 0;
    bottom: 0;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
  }

  .chat-widget.is-open .chat-header {
    cursor: default;
    touch-action: auto;
  }

  .chat-panel {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: auto;
    width: 100%;
    height: 100dvh;
    max-width: none;
    max-height: 100dvh;
    border-radius: 0;
    border: 0;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: #ffffff;
    transform: translateY(100%);
    filter: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    isolation: isolate;
    transition:
      transform 0.4s var(--chat-ease),
      opacity var(--chat-duration) var(--chat-ease),
      visibility 0.4s,
      top 0.28s var(--chat-ease),
      height 0.28s var(--chat-ease);
  }

  .chat-panel::before {
    content: '';
    position: absolute;
    z-index: 3;
    left: 0;
    right: 0;
    top: 0;
    height: env(safe-area-inset-top, 0px);
    background: linear-gradient(135deg, var(--primary) 0%, #1e3a8a 55%, #172554 100%);
    pointer-events: none;
  }

  .chat-widget.is-open .chat-panel {
    transform: translateY(0);
  }

  .chat-header {
    align-items: center;
    padding: 1rem 1rem 0.95rem;
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
    padding-left: calc(1rem + env(safe-area-inset-left, 0px));
    padding-right: calc(1rem + env(safe-area-inset-right, 0px));
    border-radius: 0;
  }

  .chat-chips {
    padding-left: calc(0.85rem + env(safe-area-inset-left, 0px));
    padding-right: calc(0.85rem + env(safe-area-inset-right, 0px));
    max-height: 5.5rem;
  }

  .chat-widget.chat-keyboard-open .chat-chips {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-bottom-color: transparent;
    pointer-events: none;
  }

  /* Keyboard replaces the home indicator — keep a small fixed pad only. */
  .chat-widget.chat-keyboard-open .chat-form {
    padding-bottom: 0.35rem;
  }

  .chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    padding-left: calc(0.9rem + env(safe-area-inset-left, 0px));
    padding-right: calc(0.9rem + env(safe-area-inset-right, 0px));
    -webkit-overflow-scrolling: touch;
    transition: padding 0.28s var(--chat-ease);
  }

  /* WhatsApp-style composer: one row, input grows up, action on the right. */
  .chat-form {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-end;
    gap: 0.4rem;
    flex-shrink: 0;
    margin-top: auto;
    padding: 0.35rem 0.5rem;
    padding-left: calc(0.5rem + env(safe-area-inset-left, 0px));
    padding-right: calc(0.5rem + env(safe-area-inset-right, 0px));
    padding-bottom: var(--pad-bottom-compact, calc(0.5rem + env(safe-area-inset-bottom, 0px)));
    border-top: 1px solid #d1d7db;
    background: #f0f2f5;
    box-shadow: none;
    transition:
      padding 0.28s var(--chat-ease),
      background 0.2s ease;
  }

  .chat-form textarea {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    min-height: 2.5rem;
    max-height: 5.5rem;
    margin: 0;
    padding: 0.55rem 0.85rem;
    font-size: 16px;
    line-height: 1.35;
    border: 0;
    border-radius: 1.35rem;
    background: #ffffff;
    box-shadow: none;
    transition:
      height 0.18s var(--chat-ease),
      border-radius 0.2s ease,
      background 0.2s ease;
  }

  .chat-form textarea:focus {
    box-shadow: none;
    outline: none;
  }

  .chat-mic-btn,
  .chat-form button[type='submit'] {
    width: 2.5rem;
    height: 2.5rem;
    flex: 0 0 2.5rem;
    margin-bottom: 0.05rem;
    box-shadow: none;
    transition:
      opacity 0.22s var(--chat-ease),
      transform 0.22s var(--chat-ease),
      width 0.22s var(--chat-ease),
      flex-basis 0.22s var(--chat-ease),
      margin 0.22s var(--chat-ease),
      background 0.2s ease;
  }

  .chat-mic-btn.is-hidden,
  .chat-form button[type='submit'].is-hidden {
    opacity: 0;
    width: 0;
    flex-basis: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    pointer-events: none;
    transform: scale(0.82);
  }

  .chat-form button[type='submit'] {
    background: var(--primary);
  }

  .chat-form button[type='submit']:hover {
    transform: none;
    box-shadow: none;
  }

  .chat-mic-btn {
    border-color: transparent;
    background: transparent;
    color: var(--muted);
  }

  .chat-mic-btn:hover {
    transform: none;
    background: rgba(0, 0, 0, 0.05);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-launcher,
  .chat-launcher::before,
  .chat-panel,
  .chat-msg,
  .chat-card,
  .chat-chip,
  .chat-empty,
  .chat-online-dot,
  .chat-header-actions button,
  .chat-form button[type='submit'],
  .chat-mic-btn,
  .chat-typing-dots span,
  .chat-mic-btn.is-listening {
    transition: none !important;
    animation: none !important;
  }

  .chat-chip,
  .chat-card,
  .chat-empty {
    opacity: 1;
  }

  .chat-widget.is-open .chat-panel {
    transform: none;
    filter: none;
  }
}

/* Touch screens keep :hover after a tap/drag — the launcher would stay lifted and enlarged. */
@media (hover: none) {
  .chat-widget:not(.is-dragging) .chat-launcher:hover {
    transform: none;
    background: linear-gradient(145deg, var(--primary) 0%, #1e3a8a 72%, #172554 100%);
    box-shadow:
      var(--shadow-md),
      0 10px 28px rgba(29, 78, 216, 0.32),
      inset 0 1px 0 rgba(255, 255, 255, 0.18);
  }

  .chat-widget:not(.is-dragging) .chat-launcher:hover::before {
    animation-duration: 2.4s;
    opacity: 0.7;
  }
}

/* Lock page scroll behind full-screen mobile chat */
body.chat-fullscreen-open {
  overflow: hidden;
  touch-action: none;
}
