/* Halveron homepage floating assistant
   Outside launcher: Halveron mascot.
   Inside panel: FloatingAiAssistant dark-glass ditto. */

.ha-root {
  --ha-ember: var(--brand-ember, #ff4301);
  --ha-zinc-100: #f4f4f5;
  --ha-zinc-200: #e4e4e7;
  --ha-zinc-300: #d4d4d8;
  --ha-zinc-400: #a1a1aa;
  --ha-zinc-500: #71717a;
  --ha-zinc-600: #52525b;
  --ha-zinc-700: #3f3f46;
  --ha-zinc-800: #27272a;
  --ha-zinc-900: #18181b;
  --ha-red-400: #f87171;
  --ha-red-500: #ef4444;
  --ha-red-600: #dc2626;
  --ha-green-500: #22c55e;
  --ha-safe-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
  --ha-safe-right: max(1.25rem, env(safe-area-inset-right, 0px));
  --ha-font: var(--font-sans, "Plus Jakarta Sans", ui-sans-serif, system-ui, sans-serif);
  position: fixed;
  right: var(--ha-safe-right);
  bottom: var(--ha-safe-bottom);
  z-index: 960;
  font-family: var(--ha-font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ha-zinc-100);
  pointer-events: none;
}

.ha-root *,
.ha-root *::before,
.ha-root *::after {
  box-sizing: border-box;
}

.ha-launcher,
.ha-panel {
  pointer-events: auto;
}

/* —— Launcher (mascot, Halveron brand outside) —— */

.ha-launcher {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4rem;
  height: 4rem;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(10, 10, 10, 0.12);
  border-radius: 9999px;
  background:
    linear-gradient(to bottom, rgba(255, 255, 255, 0.98), rgba(250, 250, 248, 0.94));
  color: #0a0a0a;
  box-shadow:
    0 14px 32px rgba(10, 10, 10, 0.1),
    0 4px 12px rgba(10, 10, 10, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  overflow: hidden;
  transition:
    transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 0.35s cubic-bezier(0.16, 1, 0.3, 1),
    border-color 0.25s ease,
    background-color 0.25s ease,
    color 0.25s ease;
}

.ha-launcher:hover {
  transform: translateY(-2px);
  border-color: rgba(10, 10, 10, 0.2);
  box-shadow:
    0 18px 40px rgba(10, 10, 10, 0.12),
    0 6px 16px rgba(10, 10, 10, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.ha-launcher:focus-visible {
  outline: 2px solid var(--ha-ember);
  outline-offset: 3px;
}

.ha-launcher[aria-expanded="true"] {
  background: #0a0a0a;
  color: #fff;
  border-color: #0a0a0a;
}

.ha-launcher-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    opacity 0.25s ease,
    transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.ha-launcher-icon svg {
  width: 1.35rem;
  height: 1.35rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ha-mascot {
  display: block;
  width: 78%;
  height: 78%;
  object-fit: contain;
  object-position: center 55%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.ha-launcher-icon--close {
  opacity: 0;
  transform: rotate(-45deg) scale(0.85);
  pointer-events: none;
}

.ha-launcher[aria-expanded="true"] .ha-launcher-icon--open {
  opacity: 0;
  transform: rotate(45deg) scale(0.85);
  pointer-events: none;
}

.ha-launcher[aria-expanded="true"] .ha-launcher-icon--close {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* —— Panel chrome (React ditto) —— */

.ha-panel {
  position: absolute;
  right: 0;
  bottom: calc(4rem + 0.85rem);
  display: flex;
  flex-direction: column;
  width: min(28rem, calc(100vw - 2 * var(--ha-safe-right)));
  height: min(36rem, calc(100dvh - 6.5rem - var(--ha-safe-bottom)));
  max-height: calc(100svh - 6.5rem - var(--ha-safe-bottom));
  overflow: hidden;
  border: 1px solid rgba(113, 113, 122, 0.5);
  border-radius: 1.5rem;
  background: linear-gradient(
    135deg,
    rgba(39, 39, 42, 0.88) 0%,
    rgba(24, 24, 27, 0.94) 100%
  );
  box-shadow:
    0 25px 50px -12px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  backdrop-filter: blur(40px) saturate(140%);
  -webkit-backdrop-filter: blur(40px) saturate(140%);
  opacity: 0;
  visibility: hidden;
  transform: scale(0.8) translateY(20px);
  transform-origin: bottom right;
  pointer-events: none;
}

.ha-panel.is-open {
  visibility: visible;
  pointer-events: auto;
  animation: ha-popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.ha-panel-overlay {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(
    135deg,
    rgba(239, 68, 68, 0.05),
    transparent,
    rgba(147, 51, 234, 0.05)
  );
  z-index: 2;
}

@keyframes ha-popIn {
  0% {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes ha-pulse-dot {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

@keyframes ha-send-ping {
  75%,
  100% {
    transform: scale(1.35);
    opacity: 0;
  }
}

/* —— Header —— */

.ha-header {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem 0.55rem;
}

.ha-header-left {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.ha-status-dot {
  flex-shrink: 0;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  background: var(--ha-green-500);
  animation: ha-pulse-dot 1.6s ease-in-out infinite;
}

.ha-title {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ha-zinc-400);
  white-space: nowrap;
}

.ha-header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.ha-close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 9999px;
  background: transparent;
  color: var(--ha-zinc-400);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.ha-close:hover {
  color: var(--ha-zinc-200);
  background: rgba(63, 63, 70, 0.5);
}

.ha-close:focus-visible {
  outline: 2px solid var(--ha-red-500);
  outline-offset: 2px;
}

.ha-close svg {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* —— Messages —— */

.ha-messages {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 0.65rem 1.1rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  scroll-behavior: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(113, 113, 122, 0.45) transparent;
}

.ha-msg {
  max-width: 92%;
  padding: 0.7rem 0.85rem;
  border-radius: 1rem;
  font-size: 0.875rem;
  font-weight: 450;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.ha-msg a {
  color: var(--ha-red-400);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ha-msg a:hover {
  color: #fca5a5;
}

.ha-intent-title {
  display: block;
  font-weight: 650;
  color: var(--ha-zinc-100);
  margin: 0;
  line-height: 1.35;
}

.ha-msg--assistant {
  align-self: flex-start;
  background: rgba(39, 39, 42, 0.72);
  border: 1px solid rgba(63, 63, 70, 0.65);
  color: var(--ha-zinc-200);
  border-bottom-left-radius: 0.35rem;
}

.ha-msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.92), rgba(239, 68, 68, 0.85));
  color: #fff;
  border-bottom-right-radius: 0.35rem;
  border: 1px solid rgba(248, 113, 113, 0.25);
}

.ha-msg--typing {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 2.4rem;
  padding-inline: 0.95rem;
}

.ha-msg--typing span {
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 9999px;
  background: var(--ha-zinc-400);
  opacity: 0.45;
  animation: ha-dot 1s ease-in-out infinite;
}

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

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

@keyframes ha-dot {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.ha-msg--streaming::after {
  content: "";
  display: inline-block;
  width: 0.4rem;
  height: 0.95em;
  margin-left: 0.12rem;
  vertical-align: text-bottom;
  background: rgba(244, 244, 245, 0.75);
  border-radius: 1px;
  animation: ha-caret 0.9s steps(1, end) infinite;
}

@keyframes ha-caret {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

/* —— Guided tree / search hits —— */

.ha-tree {
  margin-top: 0.15rem;
}

.ha-tree-prompt {
  margin: 0 0 0.55rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ha-zinc-200);
}

.ha-tree-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.ha-tree-btn {
  display: inline-flex;
  align-items: center;
  margin: 0;
  padding: 0.4rem 0.75rem;
  border: 1px solid rgba(63, 63, 70, 0.8);
  border-radius: 9999px;
  background: rgba(24, 24, 27, 0.65);
  color: var(--ha-zinc-200);
  font: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease;
}

.ha-tree-btn:hover {
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.1);
  color: #fecaca;
}

.ha-tree-btn:focus-visible {
  outline: 2px solid var(--ha-red-500);
  outline-offset: 2px;
}

.ha-hits {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.35rem;
  white-space: normal;
}

.ha-hit {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  padding: 0.55rem 0.65rem;
  border: 1px solid rgba(63, 63, 70, 0.7);
  border-radius: 0.75rem;
  background: rgba(24, 24, 27, 0.55);
}

.ha-hit-rank {
  flex: 0 0 auto;
  width: 1.25rem;
  height: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  background: var(--ha-red-600);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  margin-top: 0.1rem;
}

.ha-hit-body {
  min-width: 0;
}

.ha-hit-body strong {
  display: block;
  font-size: 0.84rem;
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.ha-hit-body p {
  margin: 0;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--ha-zinc-400);
  line-height: 1.4;
}

.ha-msg--assistant .ha-hits,
.ha-msg--assistant .ha-tree {
  white-space: normal;
}

/* —— Composer —— */

.ha-composer {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  padding: 0.65rem 0.85rem 0.7rem;
  border-top: 1px solid rgba(82, 82, 91, 0.7);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  background: linear-gradient(
    to bottom,
    rgba(24, 24, 27, 0.4) 0%,
    transparent 0.9rem
  );
}

.ha-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.55rem;
  max-height: 4.75rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-right: 0.15rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(113, 113, 122, 0.4) transparent;
}

.ha-chip {
  display: inline-flex;
  align-items: center;
  margin: 0;
  padding: 0.28rem 0.6rem;
  border: 1px solid rgba(63, 63, 70, 0.75);
  border-radius: 9999px;
  background: rgba(39, 39, 42, 0.55);
  color: var(--ha-zinc-300);
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    transform 0.2s ease;
}

.ha-chip:hover {
  border-color: rgba(239, 68, 68, 0.4);
  color: #fecaca;
  background: rgba(239, 68, 68, 0.1);
}

.ha-chip:focus-visible {
  outline: 2px solid var(--ha-red-500);
  outline-offset: 2px;
}

.ha-input-bar {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  padding: 0.35rem 0.35rem 0.35rem 0.7rem;
  border: 1px solid rgba(63, 63, 70, 0.7);
  border-radius: 0.85rem;
  background: rgba(24, 24, 27, 0.55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ha-input-bar:focus-within {
  border-color: rgba(113, 113, 122, 0.85);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 0 0 1px rgba(113, 113, 122, 0.25);
}

.ha-input {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  min-height: 2.1rem;
  max-height: 5.5rem;
  margin: 0;
  padding: 0.45rem 0.15rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ha-zinc-100);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 400;
  line-height: 1.4;
  resize: none;
  outline: none;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.ha-input::-webkit-scrollbar {
  display: none;
}

.ha-input::placeholder {
  color: var(--ha-zinc-500);
  font-size: 0.8rem;
}

.ha-input-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
  padding-bottom: 0.05rem;
}

.ha-char {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--ha-zinc-500);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.ha-char span {
  color: var(--ha-zinc-400);
}

.ha-char.is-warn {
  color: var(--ha-red-400);
}

.ha-send {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0.65rem;
  background: linear-gradient(90deg, var(--ha-red-600), var(--ha-red-500));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 14px -3px rgba(0, 0, 0, 0.28);
  transition:
    transform 0.25s ease,
    box-shadow 0.25s ease,
    opacity 0.2s ease,
    filter 0.25s ease;
  overflow: visible;
}

.ha-send::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--ha-red-600), var(--ha-red-500));
  opacity: 0;
  filter: blur(12px);
  transform: scale(1.15);
  transition: opacity 0.3s ease;
  z-index: -1;
}

.ha-send:hover:not(:disabled) {
  transform: scale(1.1) rotate(-2deg);
  background: linear-gradient(90deg, var(--ha-red-500), #f87171);
  box-shadow: 0 12px 28px rgba(239, 68, 68, 0.35);
}

.ha-send:hover:not(:disabled)::before {
  opacity: 0.55;
}

.ha-send:hover:not(:disabled)::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(239, 68, 68, 0.45);
  animation: ha-send-ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
  z-index: -1;
  pointer-events: none;
}

.ha-send:active:not(:disabled) {
  transform: scale(0.95);
}

.ha-send:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.ha-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ha-send svg {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  position: relative;
  z-index: 1;
  transition: transform 0.3s ease;
}

.ha-send:hover:not(:disabled) svg {
  transform: translate(2px, -2px) rotate(12deg) scale(1.1);
}

.ha-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-top: 0.5rem;
  padding-top: 0;
  border-top: 0;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--ha-zinc-500);
}

.ha-footer-hint {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.ha-footer-hint svg {
  flex-shrink: 0;
  width: 0.75rem;
  height: 0.75rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ha-kbd {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  margin: 0 0.15rem;
  background: var(--ha-zinc-800);
  border: 1px solid var(--ha-zinc-600);
  border-radius: 0.3rem;
  color: var(--ha-zinc-400);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.65rem;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  white-space: nowrap;
}

.ha-footer-status {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
  white-space: nowrap;
}

.ha-footer-status-dot {
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 9999px;
  background: var(--ha-green-500);
}

@media (max-width: 480px) {
  .ha-root {
    --ha-safe-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
    --ha-safe-right: max(1rem, env(safe-area-inset-right, 0px));
  }

  .ha-panel {
    width: min(100vw - 2rem, 28rem);
    height: min(72dvh, 34rem);
  }

  .ha-launcher {
    width: 3.25rem;
    height: 3.25rem;
  }

  .ha-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.45rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ha-launcher,
  .ha-launcher-icon,
  .ha-chip,
  .ha-send,
  .ha-close {
    transition: none !important;
  }

  .ha-panel.is-open {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .ha-status-dot,
  .ha-msg--typing span,
  .ha-send:hover:not(:disabled)::after,
  .ha-msg--streaming::after {
    animation: none !important;
  }

  .ha-msg--streaming::after {
    display: none;
  }

  .ha-msg--typing span {
    opacity: 0.7;
  }

  .ha-messages {
    scroll-behavior: auto;
  }
}
