/**
 * HADAFIN Smart Floating Agent — responsive shell (imports quantum base)
 * Use rem-relative scaling; mobile = near full-screen panel; desktop = glass card.
 */
@import url("./hadafin-ai-quantum.css");

html {
  font-size: 100%;
}

/* Surface font scale inside chat */
#ai-assistant-panel.hadafin-ai-surface {
  font-size: clamp(0.8125rem, 0.72rem + 0.45vw, 0.9375rem);
}

#ai-assistant-panel.hadafin-ai-theme-dark {
  --ai-card-bg: rgba(15, 23, 42, 0.92);
  --ai-card-text: #e2e8f0;
  --ai-soft-text: #94a3b8;
  --ai-border: rgba(148, 163, 184, 0.28);
  --ai-log-bg: linear-gradient(160deg, rgba(15, 23, 42, 0.58) 0%, rgba(30, 41, 59, 0.44) 100%);
}

#ai-assistant-panel.hadafin-ai-theme-light {
  --ai-card-bg: rgba(248, 250, 252, 0.96);
  --ai-card-text: #0f172a;
  --ai-soft-text: #334155;
  --ai-border: rgba(15, 23, 42, 0.18);
  --ai-log-bg: linear-gradient(160deg, rgba(255, 255, 255, 0.92) 0%, rgba(241, 245, 249, 0.96) 100%);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.74) 0%, rgba(226, 232, 240, 0.84) 100%);
  border-color: rgba(148, 163, 184, 0.35);
}

#ai-assistant-panel .hadafin-ai-log {
  background: var(--ai-log-bg);
  color: var(--ai-card-text);
}

#ai-assistant-panel .hadafin-ai-msg--user {
  color: var(--ai-card-text);
}

#ai-assistant-panel.hadafin-ai-theme-light .hadafin-ai-msg--user {
  background: rgba(226, 232, 240, 0.9);
  border-color: rgba(148, 163, 184, 0.45);
}

#ai-assistant-panel.hadafin-ai-theme-light .hadafin-ai-msg--ai {
  background: linear-gradient(135deg, rgba(209, 250, 229, 0.9) 0%, rgba(241, 245, 249, 0.95) 100%);
  border-color: rgba(16, 185, 129, 0.28);
  color: #0f172a;
}

#ai-assistant-panel.hadafin-ai-theme-light .hadafin-ai-md a {
  color: #0f766e;
}

#ai-assistant-panel .hadafin-ai-toolbar,
#ai-assistant-panel .hadafin-ai-sidebar {
  color: var(--ai-card-text);
}

#ai-assistant-panel.hadafin-ai-theme-light .hadafin-ai-sidebar {
  background: rgba(241, 245, 249, 0.9);
  border-right-color: rgba(148, 163, 184, 0.35);
}

/* Hard guard: panel opens only via chat.js toggle */
body:not(.hadafin-ai-chat-open) #ai-assistant-panel.hadafin-ai-panel {
  display: none !important;
  opacity: 0;
  pointer-events: none;
}

body.hadafin-ai-chat-open #ai-assistant-panel.hadafin-ai-panel.hadafin-ai-panel--open {
  display: flex !important;
  opacity: 1;
  pointer-events: auto;
}

/* FAB: compact circle + always-visible active pulse */
.hadafin-ai-fab.hadafin-ai-fab--pulse {
  width: 3.25rem !important;
  height: 3.25rem !important;
  min-width: 3.25rem;
  min-height: 3.25rem;
  padding: 0 !important;
  gap: 0 !important;
  animation: hadafinFabGlowPulse 2.4s ease-in-out infinite;
}

.hadafin-ai-fab__pulse-ring {
  position: absolute;
  inset: -6px;
  border-radius: inherit;
  border: 2px solid rgba(34, 197, 94, 0.55);
  opacity: 0.85;
  pointer-events: none;
  animation: hadafinFabRingPulse 2.4s ease-in-out infinite;
  z-index: 0;
}

@keyframes hadafinFabGlowPulse {
  0%,
  100% {
    box-shadow:
      0 0 0 0 rgba(34, 197, 94, 0.35),
      0 12px 40px rgba(8, 47, 73, 0.55);
  }
  50% {
    box-shadow:
      0 0 0 12px rgba(34, 197, 94, 0),
      0 16px 52px rgba(8, 47, 73, 0.62);
  }
}

@keyframes hadafinFabRingPulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.65;
  }
  50% {
    transform: scale(1.08);
    opacity: 1;
  }
}

.hadafin-ai-fab__label {
  display: none !important;
}

/* Toolbar quick actions trigger */
.hadafin-ai-toolbar-qa {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.65rem;
  font-weight: 600;
  border: 1px solid rgba(251, 191, 36, 0.45);
  background: rgba(120, 53, 15, 0.35);
  color: #fde68a;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.hadafin-ai-toolbar-qa:hover {
  background: rgba(180, 83, 9, 0.45);
  border-color: rgba(252, 211, 77, 0.6);
}

/* Chat history: readable in both themes */
#ai-chat-history-dropdown {
  background: var(--ai-card-bg) !important;
  border-color: var(--ai-border) !important;
}

#ai-chat-list {
  color: var(--ai-card-text) !important;
  background: transparent !important;
}

#ai-chat-list option {
  color: var(--ai-card-text) !important;
  background: rgba(30, 41, 59, 0.92);
  padding: 0.3rem 0.45rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

#ai-assistant-panel.hadafin-ai-theme-light #ai-chat-list option {
  background: rgba(248, 250, 252, 0.98);
  color: #0f172a !important;
  border-bottom-color: rgba(148, 163, 184, 0.3);
}

/* Pill emoji icons — scale with root */
.hadafin-ai-pill__emoji {
  font-size: 1.05em;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.hadafin-ai-pill__emoji--mic {
  font-size: 1.1em;
}

.hadafin-ai-send .hadafin-ai-pill__emoji {
  font-size: 1.15em;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

/* Quick actions slide-over (inside fixed chat panel; absolute positions vs. the fixed box) */

.hadafin-ai-qa-backdrop {
  position: absolute;
  inset: 0;
  z-index: 28;
  background: rgba(0, 0, 0, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}

.hadafin-ai-qa-backdrop.is-on {
  opacity: 1;
  pointer-events: auto;
}

.hadafin-ai-qa-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  width: min(100%, 17.5rem);
  max-width: 92%;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98) 0%, rgba(10, 15, 28, 0.99) 100%);
  border-left: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.hadafin-ai-qa-drawer.hadafin-ai-qa-drawer--open {
  transform: translateX(0);
}

.hadafin-ai-qa-drawer__head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.hadafin-ai-qa-drawer__title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
}

.hadafin-ai-qa-drawer__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 0.5rem;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
}

.hadafin-ai-qa-drawer__close:hover {
  color: #f1f5f9;
  background: rgba(255, 255, 255, 0.06);
}

.hadafin-ai-qa-drawer__body {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.hadafin-ai-qa-item {
  text-align: left;
  padding: 0.55rem 0.65rem;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  color: #e2e8f0;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.hadafin-ai-qa-item:hover {
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.25);
}

/* Tablet + phone: chat uses most of the viewport */
@media (max-width: 1023px) {
  #ai-assistant-panel.hadafin-ai-panel:not(.hidden) {
    left: 0.35rem !important;
    right: 0.35rem !important;
    top: 0.35rem !important;
    bottom: 0.35rem !important;
    width: auto !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    border-radius: 1rem;
  }

  .hadafin-ai-fab-host {
    bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
    right: max(0.75rem, env(safe-area-inset-right, 0px));
  }

  .hadafin-ai-log {
    font-size: 0.85rem !important;
  }

  .hadafin-ai-pill {
    flex-wrap: wrap;
    row-gap: 0.35rem;
  }
}

/* Optional: reduce page scroll behind chat on small screens */
@media (max-width: 1023px) {
  body.hadafin-ai-chat-open {
    overflow: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hadafin-ai-fab--pulse,
  .hadafin-ai-fab__pulse-ring {
    animation: none !important;
  }

  .hadafin-ai-qa-drawer {
    transition: none !important;
  }
}

/* Phase 1 SEO: mobile-first touch targets (min 44×44px) */
@media (pointer: coarse) {
  a,
  button,
  [role="button"],
  input[type="submit"],
  input[type="button"],
  .property-action-btn,
  .veh-st-btn,
  .mod-land-btn {
    min-height: 44px;
    min-width: 44px;
  }
}

/* CLS: reserve aspect ratio for listing card images */
.property-neo-card img,
.veh-premium-card img,
.aspect-\[16\/9\] {
  aspect-ratio: 16 / 9;
  object-fit: cover;
}
