/* ==========================================================================
   HoopsIQ Chat Widget — floating chat bubble + expandable panel
   Theme: black + #ffc400 yellow, Bebas Neue + Space Grotesk
   ========================================================================== */

#hoopsiq-widget {
  --hiq-yellow: #ffc400;
  --hiq-yellow-soft: #ffe066;
  --hiq-black: #0c0c0c;
  --hiq-panel-bg: #ffffff;
  --hiq-text: #1a1a1a;
  --hiq-muted: #6b7280;
  --hiq-bot-bubble: #f3f4f6;
  --hiq-user-bubble: #ffc400;
  --hiq-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);

  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100000;
  font-family: 'Space Grotesk', 'Inter', sans-serif;
}

#hoopsiq-widget *,
#hoopsiq-widget *::before,
#hoopsiq-widget *::after {
  box-sizing: border-box;
}

/* Neutralize host-page global `button` rules that set min-width/padding/font */
#hoopsiq-widget button {
  min-width: 0;
  margin: 0;
  font: inherit;
  letter-spacing: normal;
  text-transform: none;
}

/* ===== Floating launcher bubble ===== */
.hiq-launcher {
  width: 64px;
  height: 64px;
  min-width: 64px;
  min-height: 64px;
  max-width: 64px;
  aspect-ratio: 1 / 1;
  flex: 0 0 auto;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--hiq-yellow), #ffb000);
  color: var(--hiq-black);
  border: 3px solid var(--hiq-black);
  cursor: pointer;
  box-shadow: var(--hiq-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  line-height: 1;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  position: relative;
  padding: 0;
}

.hiq-launcher:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 14px 44px rgba(255, 196, 0, 0.45);
}

.hiq-launcher:focus-visible {
  outline: 3px solid var(--hiq-yellow-soft);
  outline-offset: 3px;
}

.hiq-launcher-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--hiq-yellow);
  opacity: 0;
  pointer-events: none;
  animation: hiq-pulse 2.4s ease-out infinite;
}

@keyframes hiq-pulse {
  0% { transform: scale(0.95); opacity: 0.7; }
  80% { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1.4); opacity: 0; }
}

#hoopsiq-widget.hiq-open .hiq-launcher {
  transform: scale(0.85) rotate(-90deg);
  opacity: 0;
  pointer-events: none;
}

/* ===== Chat panel ===== */
.hiq-panel {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 24px);
  height: 560px;
  max-height: calc(100vh - 40px);
  background: var(--hiq-panel-bg);
  border-radius: 16px;
  border: 3px solid var(--hiq-yellow);
  box-shadow: var(--hiq-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.28s ease;
}

#hoopsiq-widget.hiq-open .hiq-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* ===== Header ===== */
.hiq-header {
  background: var(--hiq-black);
  color: var(--hiq-yellow);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  border-bottom: 3px solid var(--hiq-yellow);
}

.hiq-avatar {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--hiq-yellow), #ffb000);
  color: var(--hiq-black);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: 2px solid var(--hiq-yellow);
}

.hiq-header-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 0;
}

.hiq-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.4rem;
  letter-spacing: 1.5px;
  color: var(--hiq-yellow);
}

.hiq-status {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-family: 'Inter', sans-serif;
}

.hiq-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px #4ade80;
}

.hiq-header-actions {
  display: flex;
  gap: 0.25rem;
}

.hiq-icon-btn {
  background: transparent;
  border: none;
  color: var(--hiq-yellow);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.2s ease;
  padding: 0;
  font-family: inherit;
}

.hiq-icon-btn:hover {
  background: rgba(255, 196, 0, 0.18);
  transform: scale(1.1);
}

.hiq-icon-btn:focus-visible {
  outline: 2px solid var(--hiq-yellow);
  outline-offset: 1px;
}

.hiq-icon-btn:disabled,
.hiq-icon-btn[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.hiq-icon-btn:disabled:hover,
.hiq-icon-btn[aria-disabled="true"]:hover {
  background: transparent;
  transform: none;
}

/* ===== Live scoreboard ticker ===== */
.hiq-ticker {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: var(--hiq-black);
  border-bottom: 2px solid var(--hiq-yellow);
  min-height: 38px;
}

.hiq-ticker[hidden] { display: none; }

.hiq-ticker-label {
  display: inline-flex;
  align-items: center;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 0.78rem;
  letter-spacing: 1.2px;
  color: var(--hiq-black);
  background: var(--hiq-yellow);
  padding: 0.05rem 0.45rem;
  border-radius: 4px;
  flex: 0 0 auto;
}

.hiq-ticker-track {
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
  overflow-x: auto;
  overflow-y: hidden;
  flex: 1 1 auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.hiq-ticker-track::-webkit-scrollbar { display: none; }

.hiq-ticker-game {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 196, 0, 0.25);
  color: #f5f5f5;
  font-family: 'Inter', 'Space Grotesk', sans-serif;
  font-size: 0.75rem;
  line-height: 1.1;
  white-space: nowrap;
  text-decoration: none;
  flex: 0 0 auto;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

a.hiq-ticker-game { cursor: pointer; }

a.hiq-ticker-game:hover,
a.hiq-ticker-game:focus-visible {
  background: rgba(255, 196, 0, 0.18);
  border-color: var(--hiq-yellow);
  outline: none;
  transform: translateY(-1px);
}

.hiq-ticker-teams {
  font-weight: 600;
  letter-spacing: 0.4px;
  color: #ffffff;
}

.hiq-ticker-team {
  color: inherit;
  font: inherit;
}

.hiq-ticker-team.hiq-ticker-leader {
  color: #ffffff;
  font-weight: 800;
}

.hiq-ticker-team.hiq-ticker-trailing {
  color: rgba(255, 255, 255, 0.55);
  font-weight: 500;
}

.hiq-ticker-score {
  font-weight: 700;
  color: var(--hiq-yellow);
  font-variant-numeric: tabular-nums;
}

.hiq-ticker-score-side {
  color: inherit;
  font: inherit;
  font-variant-numeric: tabular-nums;
}

.hiq-ticker-score-side.hiq-ticker-leader {
  color: var(--hiq-yellow);
  font-weight: 800;
  text-shadow: 0 0 6px rgba(255, 196, 0, 0.45);
}

.hiq-ticker-score-side.hiq-ticker-trailing {
  color: rgba(255, 196, 0, 0.55);
  font-weight: 600;
}

.hiq-ticker-status {
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.7);
  font-variant-numeric: tabular-nums;
}

.hiq-ticker-in .hiq-ticker-status {
  color: #4ade80;
  font-weight: 600;
}

.hiq-ticker-in {
  border-color: rgba(74, 222, 128, 0.45);
}

.hiq-ticker-post .hiq-ticker-status {
  color: rgba(255, 255, 255, 0.55);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hiq-ticker-empty {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  background: rgba(255, 196, 0, 0.08);
  border: 1px dashed rgba(255, 196, 0, 0.45);
  color: rgba(255, 255, 255, 0.78);
  font-family: 'Inter', 'Space Grotesk', sans-serif;
  font-size: 0.75rem;
  line-height: 1.1;
  letter-spacing: 0.2px;
  white-space: nowrap;
  flex: 0 0 auto;
}

/* ===== Messages area ===== */
.hiq-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: #fafafa;
  scroll-behavior: smooth;
}

.hiq-messages::-webkit-scrollbar { width: 6px; }
.hiq-messages::-webkit-scrollbar-track { background: transparent; }
.hiq-messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.18);
  border-radius: 3px;
}

.hiq-msg {
  max-width: 82%;
  padding: 0.65rem 0.9rem;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: hiq-msg-in 0.25s ease-out;
}

@keyframes hiq-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hiq-msg-bot {
  align-self: flex-start;
  background: var(--hiq-bot-bubble);
  color: var(--hiq-text);
  border-bottom-left-radius: 4px;
}

.hiq-msg-user {
  align-self: flex-end;
  background: var(--hiq-user-bubble);
  color: var(--hiq-black);
  font-weight: 500;
  border-bottom-right-radius: 4px;
}

.hiq-msg-error {
  align-self: center;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  font-size: 0.85rem;
  text-align: center;
  max-width: 92%;
}

/* Message wrappers (so we can stack a sources strip under a bot bubble) */
.hiq-msg-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-width: 100%;
}

.hiq-wrap-user { align-items: flex-end; }
.hiq-wrap-bot  { align-items: flex-start; }

/* Live source attribution under bot replies */
.hiq-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
  max-width: 90%;
  padding: 0 0.1rem;
}

.hiq-sources-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--hiq-black);
  background: var(--hiq-yellow);
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-family: 'Inter', sans-serif;
}

.hiq-source-link {
  font-size: 0.7rem;
  color: var(--hiq-text);
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  text-decoration: none;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
  font-family: 'Inter', sans-serif;
}

.hiq-source-link:hover,
.hiq-source-link:focus-visible {
  background: var(--hiq-yellow-soft);
  border-color: var(--hiq-yellow);
  outline: none;
}

/* Greeting / empty state */
.hiq-greeting {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1.5rem 1rem 0.5rem;
  color: var(--hiq-text);
}

.hiq-greeting-emoji {
  font-size: 2.5rem;
  margin-bottom: 0.25rem;
}

.hiq-greeting h3 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.6rem;
  letter-spacing: 1.5px;
  color: var(--hiq-black);
  margin: 0.25rem 0 0.5rem;
}

.hiq-greeting p {
  font-size: 0.9rem;
  color: var(--hiq-muted);
  line-height: 1.5;
  max-width: 280px;
  margin: 0 0 1rem;
}

.hiq-suggestions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 100%;
  margin-top: 0.25rem;
}

.hiq-suggestion {
  background: white;
  border: 1.5px solid var(--hiq-yellow);
  color: var(--hiq-black);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.55rem 0.85rem;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}

.hiq-suggestion:hover {
  background: var(--hiq-yellow);
  transform: translateX(2px);
}

.hiq-suggestion:focus-visible {
  outline: 2px solid var(--hiq-black);
  outline-offset: 1px;
}

/* Typing indicator */
.hiq-typing {
  align-self: flex-start;
  background: var(--hiq-bot-bubble);
  padding: 0.7rem 0.95rem;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.hiq-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hiq-muted);
  animation: hiq-typing-bounce 1.2s infinite ease-in-out;
}

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

@keyframes hiq-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.55; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ===== Rate-limit / budget banner ===== */
.hiq-rate-banner {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.85rem;
  background: linear-gradient(135deg, #fff7d6, #ffe9a8);
  border-top: 1px solid rgba(255, 196, 0, 0.6);
  border-bottom: 1px solid rgba(255, 196, 0, 0.45);
  color: #5a3d00;
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  line-height: 1.35;
}

.hiq-rate-banner[hidden] { display: none; }

.hiq-rate-icon {
  font-size: 1.1rem;
  flex: 0 0 auto;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.6));
}

.hiq-rate-text {
  flex: 1 1 auto;
  font-weight: 500;
}

/* ===== Input area ===== */
.hiq-input-area {
  border-top: 1px solid #e5e7eb;
  padding: 0.7rem;
  background: white;
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.hiq-input:disabled {
  background: #f3f4f6;
  color: var(--hiq-muted);
  cursor: not-allowed;
  border-color: #e5e7eb;
}

.hiq-input {
  flex: 1;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--hiq-text);
  resize: none;
  outline: none;
  background: #fafafa;
  max-height: 100px;
  min-height: 42px;
  line-height: 1.4;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.hiq-input:focus {
  border-color: var(--hiq-yellow);
  background: white;
  box-shadow: 0 0 0 3px rgba(255, 196, 0, 0.15);
}

.hiq-input::placeholder {
  color: #9ca3af;
}

.hiq-send-btn {
  background: var(--hiq-black);
  color: var(--hiq-yellow);
  border: 2px solid var(--hiq-black);
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.2s ease;
  font-family: inherit;
  padding: 0;
}

.hiq-send-btn:hover:not(:disabled) {
  background: var(--hiq-yellow);
  color: var(--hiq-black);
  transform: translateY(-1px);
}

.hiq-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hiq-send-btn:focus-visible {
  outline: 2px solid var(--hiq-yellow);
  outline-offset: 2px;
}

.hiq-footer-note {
  font-size: 0.65rem;
  color: var(--hiq-muted);
  text-align: center;
  padding: 0.3rem 0.5rem 0.5rem;
  background: white;
  border-top: 1px solid #f3f4f6;
  font-family: 'Inter', sans-serif;
}

/* ===== Mobile ===== */
@media (max-width: 600px) {
  #hoopsiq-widget {
    bottom: max(14px, env(safe-area-inset-bottom));
    right: max(14px, env(safe-area-inset-right));
  }

  .hiq-launcher {
    width: 60px;
    height: 60px;
    min-width: 60px;
    min-height: 60px;
    max-width: 60px;
    font-size: 28px;
  }

  /* Full-screen panel on mobile, anchored to viewport (not the launcher) */
  .hiq-panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    border-top: 3px solid var(--hiq-yellow);
  }

  .hiq-header {
    padding-top: max(0.85rem, env(safe-area-inset-top));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .hiq-icon-btn {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }

  .hiq-title { font-size: 1.3rem; }
  .hiq-msg { font-size: 0.95rem; max-width: 88%; }

  .hiq-input-area {
    padding: 0.7rem;
    padding-bottom: max(0.7rem, env(safe-area-inset-bottom));
    padding-left: max(0.7rem, env(safe-area-inset-left));
    padding-right: max(0.7rem, env(safe-area-inset-right));
  }

  .hiq-send-btn {
    width: 46px;
    height: 46px;
    min-width: 46px;
  }

  .hiq-greeting { padding: 1.75rem 1rem 0.75rem; }
  .hiq-greeting h3 { font-size: 1.75rem; }
}

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