/* AI assistant FAB + modal — matches Davis plumbing theme */
.ai-chat-fab {
  position: fixed;
  right: calc(1rem + env(safe-area-inset-right, 0px));
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  z-index: 350;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem 0.65rem 0.75rem;
  min-height: 52px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font, system-ui, sans-serif);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: linear-gradient(145deg, #0284c7, #0369a1);
  box-shadow: 0 8px 28px rgba(3, 105, 161, 0.45);
  transition: transform 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ai-chat-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(3, 105, 161, 0.5);
}

.ai-chat-fab:focus-visible {
  outline: 2px solid #0ea5e9;
  outline-offset: 3px;
}

.ai-chat-fab svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.ai-chat-fab span {
  display: none;
}

@media (min-width: 380px) {
  .ai-chat-fab span {
    display: inline;
  }
}

.ai-chat-modal[hidden] {
  display: none !important;
}

.ai-chat-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
  pointer-events: none;
}

.ai-chat-modal > .ai-chat-backdrop,
.ai-chat-modal > .ai-chat-panel {
  pointer-events: auto;
}

@media (min-width: 520px) {
  .ai-chat-modal {
    align-items: center;
  }
}

.ai-chat-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(10, 22, 40, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
}

.ai-chat-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 400px);
  max-height: min(88dvh, 520px);
  min-height: 280px;
  display: flex;
  flex-direction: column;
  border-radius: 20px 20px 0 0;
  overflow: hidden;
  background: linear-gradient(165deg, #0c4a6e 0%, #0a1628 45%, #041525 100%);
  color: #fff;
  box-shadow: 0 -8px 48px rgba(0, 0, 0, 0.35);
}

@media (min-width: 520px) {
  .ai-chat-panel {
    border-radius: 20px;
    max-height: min(90vh, 520px);
  }
}

.ai-chat-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 0.85rem 0.85rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.35);
}

.ai-chat-panel__head h2 {
  margin: 0;
  font-family: var(--serif, Georgia, serif);
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
}

.ai-chat-panel__head p {
  margin: 0.15rem 0 0;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

#ai-chat-close {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}

#ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

#ai-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) rgba(255, 255, 255, 0.05);
}

.ai-msg-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ai-msg--system {
  text-align: center;
  font-size: 0.7rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.42);
  padding: 0 0.25rem;
}

.ai-msg--system strong {
  color: rgba(255, 255, 255, 0.65);
}

.ai-msg--user {
  align-self: flex-end;
  max-width: 90%;
  padding: 0.65rem 0.85rem;
  border-radius: 14px 14px 4px 14px;
  background: rgba(14, 165, 233, 0.35);
  color: #fff;
  font-size: 0.875rem;
  line-height: 1.45;
}

.ai-msg--assistant {
  align-self: flex-start;
  max-width: 92%;
}

.ai-msg__badge {
  display: block;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #7dd3fc;
  margin-bottom: 0.35rem;
}

.ai-msg__body {
  padding: 0.65rem 0.85rem;
  border-radius: 14px 14px 14px 4px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.875rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.95);
}

.ai-msg__body strong {
  color: #fff;
}

.ai-slot-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-left: 0;
  margin-top: 0.25rem;
}

.ai-slot-btn {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.ai-slot-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.ai-msg--typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.75rem 1rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
}

.ai-msg--typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  animation: ai-typing 1s ease-in-out infinite;
}

.ai-msg--typing span:nth-child(2) {
  animation-delay: 0.15s;
}
.ai-msg--typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes ai-typing {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-msg--typing span {
    animation: none;
    opacity: 0.7;
  }
}

.ai-chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem 0.65rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.35);
}

.ai-chat-quick-label {
  width: 100%;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(125, 211, 252, 0.75);
  margin-bottom: 0.1rem;
}

.ai-chat-quick button {
  border: 0;
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: background 0.15s;
}

.ai-chat-quick button:hover {
  background: rgba(255, 255, 255, 0.2);
}

.ai-chat-team {
  padding: 0.65rem 0.85rem 0.85rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.45);
}

.ai-chat-team-label {
  margin: 0 0 0.4rem;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

.ai-chat-team-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

#ai-chat-team-input {
  flex: 1;
  min-width: 0;
  padding: 0.65rem 0.85rem;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 16px;
}

#ai-chat-team-input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

#ai-chat-team-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.45);
}

#ai-chat-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#ai-chat-send:hover {
  background: rgba(255, 255, 255, 0.22);
}

#ai-chat-send svg {
  width: 18px;
  height: 18px;
}
