/* Haminja AI — floating support-style widget */

/* Shared dimmer behind AI / messages panels */
.hmj-chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1388;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.hmj-chat-backdrop.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

body.hmj-chat-overlay-open {
  overflow: hidden;
}

.hmj-ai {
  --ai-ink: var(--hmj-text, #0f172a);
  --ai-muted: var(--hmj-text-muted, #64748b);
  --ai-panel: #ffffff;
  --ai-surface: #f1f5f4;
  --ai-accent: var(--hmj-primary, #0F9F8A);
  --ai-accent-dark: var(--hmj-primary-dark, #087F70);
  --ai-line: rgba(15, 23, 42, 0.08);
  --ai-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
  --ai-fab-size: 3.5rem;
  --ai-z: 1400;
  position: relative;
  z-index: var(--ai-z);
  font-family: inherit;
  pointer-events: none;
}

.hmj-ai>* {
  pointer-events: auto;
}

.hmj-ai__launcher {
  position: fixed;
  inset-inline-end: 1.15rem;
  bottom: 1.15rem;
  width: var(--ai-fab-size);
  height: var(--ai-fab-size);
  border: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--ai-accent) 0%, var(--ai-accent-dark) 100%);
  color: #fff;
  box-shadow:
    0 10px 28px rgba(15, 159, 138, 0.38),
    0 2px 8px rgba(15, 23, 42, 0.12);
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: calc(var(--ai-z) + 2);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.28s ease;
}

body.has-bottom-nav .hmj-ai__launcher {
  bottom: var(--hmj-fab-bottom, 1.15rem);
}

.hmj-ai__launcher:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow:
    0 14px 34px rgba(15, 159, 138, 0.45),
    0 4px 12px rgba(15, 23, 42, 0.14);
}

.hmj-ai__launcher:active {
  transform: scale(0.96);
}

.hmj-ai__launcher-icon {
  position: absolute;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  transition: opacity 0.2s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.hmj-ai__launcher-icon--close {
  opacity: 0;
  transform: rotate(-40deg) scale(0.6);
}

.hmj-ai.is-open .hmj-ai__launcher-icon--open {
  opacity: 0;
  transform: rotate(40deg) scale(0.6);
}

.hmj-ai.is-open .hmj-ai__launcher-icon--close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.hmj-ai__pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(15, 159, 138, 0.45);
  animation: hmj-ai-pulse 2.4s ease-out infinite;
  pointer-events: none;
}

.hmj-ai.is-open .hmj-ai__pulse,
.hmj-ai.has-interacted .hmj-ai__pulse {
  display: none;
}

@keyframes hmj-ai-pulse {
  0% {
    transform: scale(1);
    opacity: 0.7;
  }

  70% {
    transform: scale(1.55);
    opacity: 0;
  }

  100% {
    transform: scale(1.55);
    opacity: 0;
  }
}

.hmj-ai__panel {
  position: fixed;
  inset-inline-end: 1rem;
  bottom: calc(1.15rem + var(--ai-fab-size) + 0.75rem);
  width: min(400px, calc(100vw - 1.5rem));
  height: min(620px, calc(100dvh - 6.5rem));
  max-height: calc(100dvh - 5.5rem);
  display: flex;
  flex-direction: column;
  background: var(--ai-panel);
  border: 1px solid var(--ai-line);
  border-radius: 22px;
  box-shadow: var(--ai-shadow);
  overflow: hidden;
  z-index: calc(var(--ai-z) + 1);
  transform-origin: bottom center;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  pointer-events: none;
  visibility: hidden;
  transition:
    opacity 0.28s ease,
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0.32s;
}

body.has-bottom-nav .hmj-ai__panel {
  bottom: calc(var(--hmj-fab-bottom, 1.15rem) + var(--ai-fab-size) + 0.75rem);
  max-height: calc(100dvh - var(--hmj-fab-bottom, 1.15rem) - 8rem);
}

.hmj-ai.is-open .hmj-ai__panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
}

.hmj-ai.is-open .hmj-ai__panel[hidden] {
  display: flex !important;
}

.hmj-ai__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--ai-accent) 92%, #0b3d36) 0%, var(--ai-accent-dark) 100%);
  color: #fff;
}

.hmj-ai__brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.hmj-ai__avatar {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.18);
  flex-shrink: 0;
}

.hmj-ai__eyebrow {
  margin: 0;
  font-size: 0.68rem;
  opacity: 0.85;
  letter-spacing: 0.02em;
}

.hmj-ai__title {
  margin: 0.05rem 0 0;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.2;
}

.hmj-ai__head-actions {
  display: flex;
  gap: 0.25rem;
}

.hmj-ai__icon-btn {
  width: 2.1rem;
  height: 2.1rem;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: grid;
  place-items: center;
  transition: background 0.2s ease;
}

.hmj-ai__icon-btn:hover {
  background: rgba(255, 255, 255, 0.26);
}

.hmj-ai__icon-btn.is-on {
  background: rgba(255, 255, 255, 0.32);
}

.hmj-ai__body {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
  overflow: hidden;
}

.hmj-ai__chat {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.hmj-ai__history {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-inline-end: 1px solid var(--ai-line);
  transform: translateX(0);
  animation: hmj-ai-history-in 0.22s ease;
}

.hmj-ai__history[hidden] {
  display: none !important;
}

@keyframes hmj-ai-history-in {
  from {
    opacity: 0;
    transform: translateX(12px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.hmj-ai__history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--ai-line);
  font-size: 0.9rem;
}

.hmj-ai__history-close {
  width: 1.85rem;
  height: 1.85rem;
  border: 0;
  border-radius: 50%;
  background: var(--ai-surface);
  color: var(--ai-ink);
  display: grid;
  place-items: center;
}

.hmj-ai__history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.hmj-ai__history-empty {
  margin: 1.5rem 0.75rem;
  text-align: center;
  color: var(--ai-muted);
  font-size: 0.85rem;
}

.hmj-ai__history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 0.5rem;
  align-items: start;
  width: 100%;
  border: 1px solid var(--ai-line);
  background: #fff;
  border-radius: 12px;
  padding: 0.65rem 0.7rem;
  text-align: start;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.hmj-ai__history-item:hover,
.hmj-ai__history-item.is-active {
  border-color: color-mix(in srgb, var(--ai-accent) 45%, var(--ai-line));
  background: color-mix(in srgb, var(--ai-accent) 6%, #fff);
}

.hmj-ai__history-item-main {
  min-width: 0;
}

.hmj-ai__history-item-title {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ai-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hmj-ai__history-item-preview {
  margin: 0.2rem 0 0;
  font-size: 0.72rem;
  color: var(--ai-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hmj-ai__history-item-meta {
  margin: 0.25rem 0 0;
  font-size: 0.68rem;
  color: var(--ai-muted);
}

.hmj-ai__history-del {
  width: 1.7rem;
  height: 1.7rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #b42318;
  display: grid;
  place-items: center;
  opacity: 0.7;
}

.hmj-ai__history-del:hover {
  background: #fde8e8;
  opacity: 1;
}

.hmj-ai__messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 0.9rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  background:
    radial-gradient(500px 180px at 100% 0%, color-mix(in srgb, var(--ai-accent) 8%, transparent), transparent 70%),
    #fafbfb;
  scroll-behavior: smooth;
}

.ai-bubble {
  max-width: 92%;
  padding: 0.7rem 0.85rem;
  border-radius: 16px;
  line-height: 1.65;
  white-space: pre-wrap;
  font-size: 0.875rem;
  animation: hmj-ai-bubble-in 0.28s ease;
}

@keyframes hmj-ai-bubble-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.ai-bubble--bot {
  align-self: flex-start;
  background: var(--ai-surface);
  color: var(--ai-ink);
  border-bottom-right-radius: 5px;
}

.ai-bubble--user {
  align-self: flex-end;
  background: var(--ai-accent);
  color: #fff;
  border-bottom-left-radius: 5px;
}

.ai-bubble--typing {
  display: inline-flex;
  gap: 0.28rem;
  align-items: center;
  padding: 0.85rem 1rem;
}

.ai-bubble--typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ai-muted);
  animation: hmj-ai-dot 1.2s ease-in-out infinite;
}

.ai-bubble--typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.ai-bubble--typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes hmj-ai-dot {

  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.hmj-ai__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.15rem;
}

.hmj-ai__chip {
  border: 1px solid color-mix(in srgb, var(--ai-accent) 28%, var(--ai-line));
  background: #fff;
  color: var(--ai-accent-dark);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.hmj-ai__chip:hover {
  background: color-mix(in srgb, var(--ai-accent) 10%, #fff);
  border-color: var(--ai-accent);
}

.ai-results-block {
  margin-top: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.ai-results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  background: #ffffff;
  border: 1px solid var(--ai-line);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.ai-results-bar__count {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ai-ink);
}

.ai-btn-map-all {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  background: linear-gradient(135deg, var(--ai-accent) 0%, var(--ai-accent-dark) 100%);
  color: #fff !important;
  font-size: 0.74rem;
  font-weight: 600;
  border-radius: 999px;
  text-decoration: none !important;
  box-shadow: 0 4px 12px rgba(15, 159, 138, 0.28);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.ai-btn-map-all:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(15, 159, 138, 0.38);
  color: #fff !important;
}

.ai-cards {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.ai-card {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border: 1px solid var(--ai-line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.ai-card:hover {
  border-color: color-mix(in srgb, var(--ai-accent) 40%, var(--ai-line));
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
  transform: translateY(-1px);
}

.ai-card__main {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 0.7rem;
  align-items: start;
  padding: 0.65rem 0.7rem 0.45rem;
  text-decoration: none !important;
  color: inherit !important;
}

.ai-card img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  background: #e8eeec;
}

.ai-card__fallback-media {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  user-select: none;
  flex-shrink: 0;
  background:
    radial-gradient(circle at 80% 20%, rgba(20, 184, 166, 0.45) 0%, transparent 60%),
    radial-gradient(circle at 20% 80%, rgba(13, 148, 136, 0.5) 0%, transparent 60%),
    linear-gradient(135deg, #0f4c42 0%, #062b25 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.ai-card__fallback-blur {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1.8);
  font-size: 1.8rem;
  color: rgba(255, 255, 255, 0.22);
  filter: blur(8px);
  pointer-events: none;
  transition: transform 0.4s ease, filter 0.4s ease;
}

.ai-card:hover .ai-card__fallback-blur {
  transform: translate(-50%, -50%) scale(2.2);
  filter: blur(10px);
}

.ai-card__fallback-icon-wrap {
  position: relative;
  z-index: 2;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 0.95rem;
  transition: transform 0.3s ease, background 0.3s ease;
}

.ai-card:hover .ai-card__fallback-icon-wrap {
  transform: scale(1.1);
  background: rgba(255, 255, 255, 0.25);
}

.ai-card__body {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.ai-card__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.ai-card__title {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ai-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-card__badge {
  font-size: 0.68rem;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ai-accent) 12%, #fff);
  color: var(--ai-accent-dark);
  white-space: nowrap;
  font-weight: 600;
  flex-shrink: 0;
}

.ai-card__meta {
  margin: 0;
  color: var(--ai-muted);
  font-size: 0.74rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-card__address {
  margin: 0;
  color: #64748b;
  font-size: 0.7rem;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ai-card__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  padding: 0.45rem 0.7rem 0.65rem;
  border-top: 1px dashed rgba(15, 23, 42, 0.07);
  background: #fbfdfc;
}

.ai-card__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.4rem 0.65rem;
  font-size: 0.74rem;
  font-weight: 600;
  border-radius: 9px;
  text-decoration: none !important;
  transition: all 0.18s ease;
}

.ai-card__btn--view {
  background: #ffffff;
  color: var(--ai-ink) !important;
  border: 1px solid var(--ai-line);
}

.ai-card__btn--view:hover {
  background: #f1f5f4;
  border-color: #cbd5e1;
}

.ai-card__btn--map {
  background: color-mix(in srgb, var(--ai-accent) 14%, #ffffff);
  color: var(--ai-accent-dark) !important;
  border: 1px solid color-mix(in srgb, var(--ai-accent) 30%, transparent);
}

.ai-card__btn--map:hover {
  background: var(--ai-accent);
  color: #ffffff !important;
  border-color: var(--ai-accent);
}

.ai-tools {
  margin-top: 0.4rem;
  font-size: 0.68rem;
  color: var(--ai-muted);
}

.hmj-ai__hint {
  margin: 0;
  padding: 0.35rem 1rem 0;
  color: var(--ai-muted);
  font-size: 0.72rem;
  background: #fafbfb;
}

.hmj-ai__composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem 0.85rem;
  border-top: 1px solid var(--ai-line);
  background: #fff;
  align-items: end;
}

.hmj-ai__composer textarea {
  width: 100%;
  border: 1px solid var(--ai-line);
  border-radius: 14px;
  padding: 0.7rem 0.85rem;
  resize: none;
  max-height: 110px;
  background: #f8faf9;
  color: var(--ai-ink);
  font-size: 0.875rem;
  line-height: 1.45;
  outline: none;
  overflow: hidden;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.hmj-ai__composer textarea:focus {
  border-color: color-mix(in srgb, var(--ai-accent) 45%, var(--ai-line));
  background: #fff;
}

.hmj-ai__composer-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.hmj-ai__voice {
  width: 2.65rem;
  height: 2.65rem;
  border: 1px solid var(--ai-line);
  border-radius: 12px;
  background: #f8faf9;
  color: var(--ai-ink);
  display: grid;
  place-items: center;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.hmj-ai__voice:hover {
  background: color-mix(in srgb, var(--ai-accent) 12%, #fff);
  border-color: var(--ai-accent);
  color: var(--ai-accent);
}

.hmj-ai__voice:active {
  transform: scale(0.95);
}

.hmj-ai__voice.is-listening {
  background: #fee2e2;
  border-color: #ef4444;
  color: #ef4444;
  animation: hmjVoicePulse 1.2s infinite ease-in-out;
}

@keyframes hmjVoicePulse {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    transform: scale(1.06);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    transform: scale(1);
  }
}

.hmj-ai__send {
  width: 2.65rem;
  height: 2.65rem;
  border: 0;
  border-radius: 12px;
  background: var(--ai-accent);
  color: #fff;
  display: grid;
  place-items: center;
  transition: background 0.2s ease, transform 0.15s ease;
}

.hmj-ai__send:hover {
  background: var(--ai-accent-dark);
}

.hmj-ai__send:active {
  transform: scale(0.95);
}

.hmj-ai__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .hmj-ai__panel {
    inset-inline-start: 0.5rem;
    inset-inline-end: 0.5rem;
    width: auto;
    height: min(72dvh, 560px);
    border-radius: 18px;
    transform-origin: bottom center;
    max-height: unset !important;
    height: 90vh;
    bottom: 5px !important;
  }

  .ai-card {
    grid-template-columns: 48px 1fr;
  }

  .ai-card__badge {
    grid-column: 2;
    justify-self: start;
  }
}

/* Legacy full-page (kept minimal if /Ai still hit briefly) */
.ai-chat-page {
  display: none;
}