/* AI Search — branded glass panel */

.ai-chat-widget {
  position: fixed;
  top: 50%;
  right: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  transform: translateY(-50%);
  overflow: visible;
}

/* ── Panel ── */
.ai-chat-panel {
  position: absolute;
  right: calc(100% + 0.75rem);
  top: 50%;
  bottom: auto;
  display: flex;
  flex-direction: column;
  width: 22rem;
  max-width: calc(100vw - 4.5rem);
  height: min(72dvh, 34rem);
  overflow: hidden;
  box-sizing: border-box;
  background: rgb(255 255 255 / 0.58);
  backdrop-filter: blur(24px) saturate(1.65);
  -webkit-backdrop-filter: blur(24px) saturate(1.65);
  border: 1px solid rgb(255 255 255 / 0.72);
  border-radius: 1.25rem;
  box-shadow:
    0 0 0 1px rgb(255 255 255 / 0.4) inset,
    0 1px 0 rgb(255 255 255 / 0.55) inset,
    0 24px 48px -12px rgb(7 3 141 / 0.28),
    0 8px 24px -8px rgb(15 23 42 / 0.12);
  transform: translateY(-50%) scale(0.94);
  transform-origin: center right;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    transform 0.34s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.28s ease,
    visibility 0.28s ease;
}

.ai-chat-panel[hidden] {
  display: none !important;
}

.ai-chat-panel.is-open {
  transform: translateY(-50%) scale(1);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.ai-chat-panel__tricolor {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    #ff9933 0%,
    #ff9933 33.33%,
    #ffffff 33.33%,
    #ffffff 66.66%,
    #138808 66.66%,
    #138808 100%
  );
  z-index: 3;
}

/* ── Navy header ── */
.ai-chat-header {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.95rem 1rem;
  background: linear-gradient(135deg, #04026a 0%, #07038d 55%, #0c06b5 100%);
}

.ai-chat-header__brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  overflow: hidden;
}

.ai-chat-header__logo {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  color: #fff;
  background: linear-gradient(145deg, #ff6821 0%, #ff9933 100%);
  border-radius: 0.75rem;
  box-shadow: 0 4px 14px rgb(255 104 33 / 0.4);
}

.ai-chat-header__logo svg {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
}

.ai-chat-header__title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-chat-header__subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.3;
  color: rgb(255 255 255 / 0.72);
}

.ai-chat-header__close {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  color: #fff;
  background: rgb(255 255 255 / 0.12);
  border: 1px solid rgb(255 255 255 / 0.22);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

.ai-chat-header__close svg {
  width: 1rem;
  height: 1rem;
}

.ai-chat-header__close:hover {
  background: rgb(255 255 255 / 0.22);
}

/* ── Messages area ── */
.ai-chat-messages {
  flex: 1;
  min-height: 0;
  min-width: 0;
  padding: 1rem;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(ellipse 85% 55% at 50% 0%, rgb(7 3 141 / 0.06), transparent 58%),
    rgb(255 255 255 / 0.15);
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 4px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

/* Empty state hero */
.ai-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 1.5rem 0.5rem;
  text-align: center;
}

.ai-chat-empty[hidden] {
  display: none !important;
}

.ai-chat-empty__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  margin-bottom: 0.85rem;
  color: var(--bharat-chakra);
  background: rgb(255 255 255 / 0.62);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgb(255 255 255 / 0.85);
  border-radius: 1rem;
  box-shadow: 0 4px 16px rgb(7 3 141 / 0.08);
}

.ai-chat-empty__icon svg {
  width: 1.5rem;
  height: 1.5rem;
}

.ai-chat-empty__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  color: #0f172a;
}

.ai-chat-empty__text {
  max-width: 16rem;
  margin: 0.45rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.55;
  color: #64748b;
}

/* ── Messages ── */
.ai-chat-msg {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  width: 100%;
  min-width: 0;
  animation: ai-chat-msg-in 0.25s ease both;
}

.ai-chat-msg--user {
  flex-direction: row-reverse;
}

.ai-chat-msg__avatar {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 1.625rem;
  height: 1.625rem;
  font-size: 0.5rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(145deg, #07038d, #0c06b5);
  border-radius: 0.45rem;
}

.ai-chat-msg--user .ai-chat-msg__avatar {
  display: none;
}

.ai-chat-msg__bubble {
  flex: 1;
  min-width: 0;
  max-width: calc(100% - 2.25rem);
  padding: 0.75rem 0.875rem;
  font-size: 0.8125rem;
  line-height: 1.55;
  color: #334155;
  word-wrap: break-word;
  overflow-wrap: break-word;
  background: rgb(255 255 255 / 0.68);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgb(255 255 255 / 0.82);
  border-radius: 0.875rem;
  box-shadow: 0 2px 8px rgb(15 23 42 / 0.05);
}

.ai-chat-msg--user .ai-chat-msg__bubble {
  flex: 0 1 auto;
  max-width: 88%;
  color: #fff;
  background: linear-gradient(135deg, #ff6821 0%, #e55a15 100%);
  border: none;
  box-shadow: 0 4px 12px rgb(255 104 33 / 0.28);
}

.ai-chat-msg__bubble--wide {
  flex: 1;
  max-width: calc(100% - 2.25rem);
  width: auto;
  padding: 0.75rem;
  overflow: hidden;
}

.ai-chat-msg__lead {
  margin: 0 0 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #1e293b;
}

.ai-chat-msg--typing .ai-chat-msg__bubble {
  display: flex;
  align-items: center;
  min-width: 10rem;
  padding: 0.85rem 1rem;
}

/* Loader */
.ai-chat-loader {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.ai-chat-loader__spinner {
  flex-shrink: 0;
  width: 1.125rem;
  height: 1.125rem;
  border: 2px solid #e2e8f0;
  border-top-color: var(--bharat-chakra);
  border-right-color: var(--bharat-primary);
  border-radius: 50%;
  animation: ai-loader-spin 0.7s linear infinite;
}

.ai-chat-loader__text {
  font-size: 0.8125rem;
  font-weight: 500;
  color: #64748b;
  animation: ai-loader-text 1.4s ease-in-out infinite;
}

@keyframes ai-loader-spin {
  to { transform: rotate(360deg); }
}

@keyframes ai-loader-text {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.ai-chat-msg--results {
  animation: ai-results-reveal 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.ai-chat-msg--results .ai-chat-msg__bubble {
  animation: ai-results-bubble 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.ai-chat-msg--results .ai-chat-msg__lead {
  animation: ai-results-reveal 0.35s ease both;
}

@keyframes ai-results-reveal {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes ai-results-bubble {
  from {
    opacity: 0;
    transform: scale(0.97);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes ai-chat-msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Results ── */
.ai-chat-results {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
  overflow: hidden;
}

.ai-chat-results__label {
  margin: 0.35rem 0 0;
  font-size: 0.625rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #94a3b8;
}

.ai-chat-results__label--recommended {
  color: #ea580c;
}

.ai-chat-result {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  padding: 0.6rem 0.65rem;
  color: inherit;
  text-decoration: none;
  background: rgb(255 255 255 / 0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgb(255 255 255 / 0.78);
  border-radius: 0.75rem;
  box-shadow: 0 1px 3px rgb(15 23 42 / 0.04);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-chat-msg--results .ai-chat-result {
  animation: ai-result-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.ai-chat-msg--results .ai-chat-result:nth-of-type(1) { animation-delay: 0.05s; }
.ai-chat-msg--results .ai-chat-result:nth-of-type(2) { animation-delay: 0.12s; }
.ai-chat-msg--results .ai-chat-result:nth-of-type(3) { animation-delay: 0.19s; }
.ai-chat-msg--results .ai-chat-result:nth-of-type(4) { animation-delay: 0.26s; }
.ai-chat-msg--results .ai-chat-result:nth-of-type(5) { animation-delay: 0.33s; }
.ai-chat-msg--results .ai-chat-result:nth-of-type(6) { animation-delay: 0.4s; }

@keyframes ai-result-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-chat-result:hover {
  border-color: #fed7aa;
  box-shadow: 0 4px 12px rgb(255 104 33 / 0.1);
}

.ai-chat-result__visual {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.125rem;
  height: 2.125rem;
  overflow: hidden;
  color: var(--bharat-chakra);
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
}

.ai-chat-result__visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ai-chat-result__visual svg {
  width: 0.95rem;
  height: 0.95rem;
}

.ai-chat-result__text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.ai-chat-result__title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.35;
  color: #111827;
  word-break: break-word;
}

.ai-chat-result__subtitle {
  display: block;
  margin-top: 0.05rem;
  font-size: 0.6875rem;
  line-height: 1.35;
  color: #64748b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chat-result .biz-verified {
  pointer-events: none;
}

.ai-chat-alert {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: #92400e;
}

.ai-chat-alert.is-error {
  color: #b91c1c;
}

/* ── Footer dock ── */
.ai-chat-footer {
  flex-shrink: 0;
  padding: 0.65rem 1rem;
  padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
  background: rgb(255 255 255 / 0.45);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgb(255 255 255 / 0.55);
  box-shadow: 0 -4px 16px rgb(15 23 42 / 0.04);
}

.ai-chat-quick {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.ai-chat-quick::-webkit-scrollbar {
  display: none;
}

.ai-chat-quick.is-hidden {
  display: none;
}

.ai-chat-quick__chip {
  flex-shrink: 0;
  padding: 0.4rem 0.75rem;
  font-family: inherit;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.3;
  color: #c2410c;
  white-space: nowrap;
  scroll-snap-align: start;
  cursor: pointer;
  background: rgb(255 240 232 / 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgb(255 212 188 / 0.9);
  border-radius: 999px;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.ai-chat-quick__chip:hover {
  background: #ffe8d9;
  border-color: #ffb366;
}

.ai-chat-compose {
  width: 100%;
}

.ai-chat-compose__box {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  width: 100%;
  box-sizing: border-box;
  padding: 0.4rem 0.4rem 0.4rem 0.875rem;
  background: rgb(255 255 255 / 0.55);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgb(255 255 255 / 0.78);
  border-radius: 0.875rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.ai-chat-compose__box:focus-within {
  background: rgb(255 255 255 / 0.78);
  border-color: #d1d5db;
  box-shadow: 0 0 0 3px rgb(209 213 219 / 0.4);
}

.ai-chat-compose__input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 3rem;
  min-height: 2.75rem;
  max-height: 5.5rem;
  padding: 0.5rem 0 !important;
  font-family: inherit;
  font-size: 0.9375rem;
  line-height: 1.45;
  color: #0f172a;
  resize: none;
  background: transparent;
  border: none !important;
  overflow-x: hidden;
  overflow-y: auto;
  field-sizing: content;
  box-shadow: none !important;
  --tw-ring-shadow: 0 0 #0000 !important;
  --tw-ring-offset-shadow: 0 0 #0000 !important;
}

.ai-chat-compose__input:focus,
.ai-chat-compose__input:focus-visible {
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
  --tw-ring-shadow: 0 0 #0000 !important;
  --tw-ring-offset-shadow: 0 0 #0000 !important;
}

.ai-chat-compose__input::placeholder {
  color: #94a3b8;
}

.ai-chat-compose__send {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  color: #fff;
  background: var(--bharat-primary);
  border: none;
  border-radius: 0.625rem;
  box-shadow: 0 2px 8px rgb(255 104 33 / 0.3);
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease;
}

.ai-chat-compose__send:hover:not(:disabled) {
  background: var(--bharat-primary-hover);
}

.ai-chat-compose__send:active:not(:disabled) {
  background: var(--bharat-primary-dark);
}

.ai-chat-compose__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-chat-compose__send svg {
  width: 1rem;
  height: 1rem;
}

.ai-chat-panel.is-busy .ai-chat-compose__send {
  opacity: 0.92;
  pointer-events: none;
}

.ai-chat-panel.is-busy .ai-chat-compose__send svg {
  opacity: 0;
}

.ai-chat-panel.is-busy .ai-chat-compose__send::after {
  content: "";
  position: absolute;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgb(255 255 255 / 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ai-loader-spin 0.65s linear infinite;
}

@keyframes ai-send-pulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}

/* ── FAB (side tab — styles in ai-search-fab.css) ── */
.ai-chat-widget .ai-search-fab {
  position: relative;
  right: auto;
  bottom: auto;
}

.ai-search-fab__icon--close {
  display: none;
}

.ai-search-fab.is-open .ai-search-fab__icon--open {
  display: none;
}

.ai-search-fab.is-open .ai-search-fab__icon--close {
  display: inline-flex;
}

/* ── Mobile ── */
@media (max-width: 639px) {
  .ai-chat-panel {
    width: min(calc(100vw - 3.75rem), 22rem);
    max-width: min(calc(100vw - 3.75rem), 22rem);
    height: min(70dvh, 30rem);
    right: calc(100% + 0.5rem);
  }

  .ai-chat-compose__input {
    font-size: 1rem;
  }
}

@media (min-width: 640px) {
  .ai-chat-panel {
    width: 24rem;
    max-width: calc(100vw - 2rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chat-panel,
  .ai-chat-msg,
  .ai-chat-result {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .ai-chat-panel {
    background: rgb(255 255 255 / 0.96);
  }

  .ai-chat-msg__bubble,
  .ai-chat-result,
  .ai-chat-compose__box,
  .ai-chat-empty__icon {
    background: #fff;
  }

  .ai-chat-footer {
    background: rgb(255 255 255 / 0.98);
  }
}
