/* ═══════════════════════════════════════════════════════════════
   Meeraan Banquets — AI chat widget (isolated, mobile-first)
   ═══════════════════════════════════════════════════════════════ */

html.chat-scroll-lock,
html.chat-scroll-lock body {
  overflow: hidden;
  overscroll-behavior: none;
}

html.chat-scroll-lock body {
  touch-action: none;
}

/* Root anchors to viewport; children use absolute coords inside this box */
.chat-widget {
  --chat-edge: var(--float-edge-r, max(24px, env(safe-area-inset-right, 0px) + 16px));
  --chat-edge-b: var(--float-edge-b, max(24px, env(safe-area-inset-bottom, 0px) + 16px));
  --chat-launcher-size: var(--float-btn-size, 44px);
  --chat-stack-gap: var(--float-stack-gap, 12px);
  --chat-launcher-b: calc(var(--chat-edge-b) + var(--chat-launcher-size) + var(--chat-stack-gap));
  position: fixed;
  inset: 0;
  z-index: 1050;
  pointer-events: none;
  overflow: visible;
}

.chat-widget[data-open='true'] {
  z-index: 1060;
}

.chat-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── Scrim ─── */
.chat-scrim {
  position: absolute;
  inset: 0;
  z-index: 1040;
  background: rgba(6, 4, 4, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s;
  pointer-events: none;
}

.chat-widget[data-open='true'] .chat-scrim {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ─── Launcher ─── */
.chat-launcher {
  position: absolute;
  right: var(--chat-edge);
  bottom: var(--chat-launcher-b);
  left: auto;
  top: auto;
  z-index: 1051;
  width: var(--chat-launcher-size);
  height: var(--chat-launcher-size);
  border: none;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--gold, #d4af37) 0%, #c9a227 48%, var(--gold-dark, #a8891c) 100%);
  color: var(--black, #111);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  box-shadow:
    0 8px 24px rgba(212, 175, 55, 0.42),
    0 0 0 1px rgba(255, 255, 255, 0.12) inset;
  transition: transform 0.3s var(--ease-luxury, ease), box-shadow 0.3s ease;
}

.chat-launcher:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow:
    0 14px 32px rgba(212, 175, 55, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.16) inset;
}

.chat-launcher:focus-visible {
  outline: 2px solid var(--gold-light, #e8cc6a);
  outline-offset: 3px;
}

.chat-launcher__icon {
  width: 22px;
  height: 22px;
  display: block;
  position: relative;
  z-index: 1;
}

.chat-launcher__pulse {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(232, 204, 106, 0.6);
  opacity: 0;
  pointer-events: none;
}

.chat-launcher--pulse .chat-launcher__pulse {
  animation: chatPulse 2.2s ease-out 3;
}

@keyframes chatPulse {
  0% { transform: scale(0.95); opacity: 0.75; }
  100% { transform: scale(1.4); opacity: 0; }
}

.chat-widget[data-open='true'] .chat-launcher {
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════
   Panel — mobile bottom sheet (default)
   ═══════════════════════════════════════════════════════════════ */
.chat-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1052;
  width: 100%;
  max-width: 100%;
  height: min(90dvh, calc(var(--chat-vvh, 100dvh) * 0.9));
  max-height: min(90dvh, calc(var(--chat-vvh, 100dvh) * 0.9));
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  border: none;
  background: #141010;
  border-top: 1px solid rgba(212, 175, 55, 0.28);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 48px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
  overflow: hidden;
  transform: translate3d(0, 100%, 0);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.38s var(--ease-luxury, cubic-bezier(0.22, 1, 0.36, 1)),
    opacity 0.28s ease,
    visibility 0.28s;
}

.chat-widget[data-open='true'] .chat-panel:not([hidden]) {
  transform: translate3d(0, 0, 0);
  opacity: 1;
  visibility: visible;
}

.chat-widget--keyboard .chat-panel {
  height: calc(var(--chat-vvh, 100dvh) - 4px);
  max-height: calc(var(--chat-vvh, 100dvh) - 4px);
}

.chat-panel__handle {
  flex-shrink: 0;
  width: 40px;
  height: 4px;
  margin: 10px auto 4px;
  border-radius: 99px;
  background: rgba(212, 175, 55, 0.4);
}

/* ─── Header ─── */
.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px 14px;
  background: linear-gradient(180deg, rgba(212, 175, 55, 0.08) 0%, transparent 100%);
  border-bottom: 1px solid rgba(212, 175, 55, 0.12);
}

.chat-header__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-header__logo {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(212, 175, 55, 0.45);
  object-fit: cover;
  flex-shrink: 0;
  background: #1a1414;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.chat-header__titles {
  min-width: 0;
}

.chat-header__title {
  font-family: var(--font-serif, Georgia, serif);
  font-size: 1rem;
  font-weight: 500;
  color: var(--ivory, #f8f4ec);
  line-height: 1.3;
  letter-spacing: 0.02em;
}

.chat-header__subtitle {
  font-family: var(--font-sans, sans-serif);
  font-size: 0.62rem;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold, #d4af37);
  margin-top: 4px;
}

.chat-header__close {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(248, 244, 236, 0.9);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.25s, border-color 0.25s, color 0.25s;
}

.chat-header__close:hover {
  color: var(--gold, #d4af37);
  border-color: var(--gold, #d4af37);
  background: rgba(212, 175, 55, 0.12);
}

.chat-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chat-header__new {
  border: none;
  background: transparent;
  color: rgba(212, 175, 55, 0.85);
  font-family: var(--font-sans, sans-serif);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 6px 4px;
  white-space: nowrap;
}

.chat-header__new:hover,
.chat-header__new:focus-visible {
  color: var(--gold-light, #e8cc6a);
  outline: none;
}

.chat-header__close:focus-visible {
  outline: 2px solid var(--gold-light, #e8cc6a);
  outline-offset: 2px;
}

/* ─── Messages ─── */
.chat-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #100c0c;
}

.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 175, 55, 0.35) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(212, 175, 55, 0.35);
  border-radius: 99px;
}

.chat-msg {
  max-width: 88%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: chatMsgIn 0.28s ease both;
}

@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg--ai { align-self: flex-start; }
.chat-msg--user { align-self: flex-end; }

.chat-msg__meta {
  font-family: var(--font-sans, sans-serif);
  font-size: 0.56rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(212, 175, 55, 0.85);
  padding: 0 6px;
}

.chat-msg--user .chat-msg__meta {
  text-align: right;
  color: rgba(232, 204, 106, 0.9);
}

.chat-msg__body {
  padding: 11px 14px;
  border-radius: 14px;
}

.chat-msg--ai .chat-msg__body {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(212, 175, 55, 0.12);
  border-bottom-left-radius: 4px;
}

.chat-msg--user .chat-msg__body {
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.22) 0%, rgba(168, 137, 28, 0.18) 100%);
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-bottom-right-radius: 4px;
}

.chat-msg__text {
  font-family: var(--font-sans, sans-serif);
  font-size: 0.9rem;
  font-weight: 300;
  line-height: 1.6;
  color: rgba(248, 244, 236, 0.92);
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg__actions {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chat-msg__actions:not([hidden]) {
  display: flex;
}

/* ─── Composer ─── */
.chat-footer {
  flex-shrink: 0;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  background: #0e0a0a;
  border-top: 1px solid rgba(212, 175, 55, 0.14);
}

.chat-composer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 4px 4px 4px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(212, 175, 55, 0.2);
  border-radius: 999px;
  transition: border-color 0.25s, background 0.25s;
}

.chat-composer:focus-within {
  border-color: rgba(212, 175, 55, 0.45);
  background: rgba(255, 255, 255, 0.06);
}

.chat-input {
  flex: 1;
  min-width: 0;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--ivory, #f8f4ec);
  font-family: var(--font-sans, sans-serif);
  font-size: 16px;
  font-weight: 300;
  line-height: 40px;
  padding: 0;
  margin: 0;
  outline: none;
  box-shadow: none;
  appearance: none;
  -webkit-appearance: none;
}

.chat-input::placeholder {
  color: rgba(248, 244, 236, 0.42);
}

.chat-send {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--gold, #d4af37);
  color: var(--black, #111);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.25s, transform 0.2s;
}

.chat-send:hover {
  background: var(--gold-light, #e8cc6a);
}

.chat-send:active {
  transform: scale(0.94);
}

.chat-send:focus-visible {
  outline: 2px solid var(--gold-light, #e8cc6a);
  outline-offset: 2px;
}

.chat-send svg {
  display: block;
  width: 18px;
  height: 18px;
}

/* ═══════════════════════════════════════════════════════════════
   Desktop
   ═══════════════════════════════════════════════════════════════ */
@media (min-width: 820px) {
  .chat-panel {
    left: auto;
    right: var(--chat-edge);
    bottom: calc(var(--chat-launcher-b) + var(--chat-launcher-size) + 16px);
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100dvh - var(--chat-launcher-b) - var(--chat-launcher-size) - 48px);
    border: 1px solid rgba(212, 175, 55, 0.22);
    border-radius: 12px;
    box-shadow:
      0 24px 64px rgba(0, 0, 0, 0.55),
      0 0 0 1px rgba(212, 175, 55, 0.08);
    transform: translate3d(0, 16px, 0) scale(0.96);
    transform-origin: bottom right;
  }

  .chat-widget[data-open='true'] .chat-panel:not([hidden]) {
    transform: translate3d(0, 0, 0) scale(1);
  }

  .chat-panel__handle {
    display: none;
  }

  .chat-header__title {
    font-size: 1.08rem;
  }

  .chat-footer {
    padding-bottom: 14px;
  }

  .chat-input {
    font-size: 0.9rem;
  }
}

/* ─── Loading & action buttons (API integration) ─── */
.chat-msg--loading .chat-msg__meta {
  opacity: 0.75;
}

.chat-msg__typing {
  min-height: 1.6em;
  display: flex;
  align-items: center;
}

.chat-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 10px;
}

.chat-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(212, 175, 55, 0.85);
  animation: chatTypingDot 1.1s 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 chatTypingDot {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.chat-action-btn {
  appearance: none;
  border: 1px solid rgba(212, 175, 55, 0.35);
  background: rgba(212, 175, 55, 0.08);
  color: rgba(248, 244, 236, 0.95);
  font-family: var(--font-sans, sans-serif);
  font-size: 0.78rem;
  line-height: 1.3;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, border-color 0.2s;
}

.chat-action-btn:hover,
.chat-action-btn:focus-visible {
  background: rgba(212, 175, 55, 0.16);
  border-color: rgba(212, 175, 55, 0.55);
  outline: none;
}

.chat-action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-action-btn--secondary {
  background: transparent;
  border-color: rgba(212, 175, 55, 0.28);
  color: rgba(248, 244, 236, 0.8);
}

.chat-action-btn--secondary:hover,
.chat-action-btn--secondary:focus-visible {
  background: rgba(212, 175, 55, 0.1);
  border-color: rgba(212, 175, 55, 0.45);
}

.chat-composer[aria-busy='true'] .chat-send {
  opacity: 0.55;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .chat-launcher,
  .chat-launcher__pulse,
  .chat-panel,
  .chat-scrim,
  .chat-msg,
  .chat-send,
  .chat-header__close {
    transition: none !important;
    animation: none !important;
  }

  .chat-panel,
  .chat-widget[data-open='true'] .chat-panel:not([hidden]) {
    transform: none !important;
  }

  .chat-launcher--pulse .chat-launcher__pulse {
    opacity: 0 !important;
  }

  .chat-typing-dots span {
    animation: none !important;
    opacity: 0.75 !important;
  }
}
