/* ==========================================================================
   Components: buttons, chips, status LEDs, icons, agent portraits, controls
   ========================================================================== */

/* ---------- Icons (sprite in index.html) ---------- */

.icon {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Buttons (mirrors the usehotbot.com "hotbot" variant) ---------- */

.btn {
  --btn-h: 2.75em;
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55em;
  min-height: var(--btn-h);
  padding: 0 1.4em;
  border: 1px solid transparent;
  border-radius: var(--r-control);
  font-size: 14px;
  font-weight: 560;
  line-height: 1;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.36s var(--ease-spring),
    color 0.18s,
    background-color 0.18s,
    border-color 0.18s,
    box-shadow 0.18s,
    opacity 0.18s;
}

.btn .icon {
  transition: transform 0.32s var(--ease-spring);
}

.btn--hot {
  color: var(--brand-ink);
  background:
    linear-gradient(#ffffff2e 0, #ffffff0c 18%, #0000 40%),
    var(--brand);
}

.btn--hot::before,
.btn--hot::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
}

.btn--hot::before {
  opacity: 0;
  box-shadow: 0 0.5em 1.7em #f47a384d, 0 0 0 1px #ffbc7866;
  transition: opacity 0.22s;
}

.btn--hot::after {
  background: linear-gradient(110deg, #0000 40%, #fff5 50%, #0000 60%) 180% 0 / 250% 100% no-repeat;
  box-shadow: inset 0 1px #ffe2c566, inset 0 -1px #9c390c26;
  transition: background-position 0.6s cubic-bezier(0.2, 0.65, 0.3, 1);
}

.btn--hot.btn--glow::before {
  opacity: 0.65;
}

.btn--outline {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.035);
  border-color: rgba(255, 255, 255, 0.14);
}

.btn--ghost {
  color: var(--ink-soft);
  background: transparent;
}

.btn--sm {
  font-size: 12.5px;
  --btn-h: 2.6em;
  padding: 0 1.15em;
}

.btn--lg {
  font-size: 15px;
  --btn-h: 3.2em;
  padding: 0 1.6em;
}

.btn--block {
  width: 100%;
}

@media (hover: hover) {
  .btn--hot:not(:disabled):not([aria-disabled="true"]):hover {
    transform: translateY(-0.15em) scale(1.025);
  }

  .btn--hot:not(:disabled):not([aria-disabled="true"]):hover::before {
    opacity: 1;
  }

  .btn--hot:not(:disabled):not([aria-disabled="true"]):hover::after {
    background-position: -80% 0;
  }

  .btn:not(:disabled):not([aria-disabled="true"]):hover .icon--nudge-right {
    transform: translateX(0.2em);
  }

  .btn:not(:disabled):not([aria-disabled="true"]):hover .icon--nudge-up-right {
    transform: translate(0.18em, -0.18em);
  }

  .btn:not(:disabled):not([aria-disabled="true"]):hover .icon--nudge-down {
    transform: translateY(0.2em);
  }

  .btn--outline:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.22);
  }

  .btn--ghost:not(:disabled):hover {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.05);
  }
}

.btn--hot:focus-visible::before {
  opacity: 1;
}

.btn--hot:focus-visible::after {
  background-position: -80% 0;
}

.btn:not(:disabled):not([aria-disabled="true"]):active {
  transform: translateY(0.05em) scale(0.955);
  transition-duration: 80ms;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn[aria-busy="true"] {
  cursor: progress;
  opacity: 0.85;
}

.btn[aria-busy="true"] .icon {
  animation: hb-spin 0.9s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .btn--hot::after {
    background-image: none;
  }
}

/* ---------- Text link with arrow ---------- */

.link-arrow {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  color: var(--brand-soft);
  font-weight: 550;
  text-decoration: underline;
  text-decoration-color: rgba(255, 178, 125, 0.35);
  text-underline-offset: 3px;
  transition: color var(--dur-fast), text-decoration-color var(--dur-fast);
}

.link-arrow:hover {
  color: #ffd2b0;
  text-decoration-color: currentColor;
}

/* ---------- Chips ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 26px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

.chip--brand {
  color: var(--brand-soft);
  background: var(--brand-wash);
  border-color: rgba(244, 122, 56, 0.28);
}

.chip--ok {
  color: #a8e6c4;
  background: rgba(95, 211, 154, 0.1);
  border-color: rgba(95, 211, 154, 0.3);
}

.chip--bad {
  color: #ffb3ba;
  background: rgba(240, 97, 109, 0.1);
  border-color: rgba(240, 97, 109, 0.3);
}

.chip--pending {
  color: #ffd98f;
  background: rgba(245, 184, 74, 0.1);
  border-color: rgba(245, 184, 74, 0.3);
}

.chip--plain {
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
  text-transform: none;
  color: var(--ink-soft);
  min-height: 32px;
  padding: 0 13px;
}

.chip--plain .icon {
  color: var(--brand);
  font-size: 14px;
}

/* ---------- Status LEDs ---------- */

.led {
  --led: var(--tone-idle);
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--led);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--led) 16%, transparent), 0 0 12px color-mix(in srgb, var(--led) 55%, transparent);
}

.led[data-tone="idle"],
[data-tone="idle"] > .led,
[data-tone="idle"] .led {
  --led: var(--tone-idle);
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--tone-idle);
}

.led--brand,
[data-tone="brand"] .led {
  --led: var(--tone-brand);
}

.led--info,
[data-tone="info"] .led {
  --led: var(--tone-info);
}

.led--pending,
[data-tone="pending"] .led {
  --led: var(--tone-pending);
}

.led--ok,
[data-tone="ok"] .led {
  --led: var(--tone-ok);
}

.led--bad,
[data-tone="bad"] .led {
  --led: var(--tone-bad);
}

.led--pulse,
[data-tone="pending"] .led,
[data-tone="brand"] .led {
  animation: hb-led-pulse 2.4s ease-in-out infinite;
}

@keyframes hb-led-pulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.35;
  }
}

@keyframes hb-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Agent portrait (custom element <hb-agent>) ---------- */

hb-agent {
  position: relative;
  display: block;
  aspect-ratio: 1;
  width: 100%;
}

hb-agent > img,
hb-agent > svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

hb-agent .bot-look {
  transform: translate(var(--gx, 0px), var(--gy, 0px));
  transition: transform 0.35s var(--ease-out);
}

hb-agent[data-tracking] .bot-gaze {
  animation: none;
}

/* Idle animation for inlined portraits (same keyframes as the asset files). */
hb-agent .bot-acting {
  transform-origin: 0 40px;
  animation: hb-acting 10s ease-in-out infinite;
  animation-delay: var(--bot-delay, 0s);
}

hb-agent .hb-art--research .bot-acting {
  animation-name: hb-research-acting;
  animation-duration: 7s;
}

hb-agent .bot-gaze {
  animation: hb-gaze 10s ease-in-out infinite;
  animation-delay: var(--bot-delay, 0s);
}

hb-agent .bot-eyes {
  animation: hb-eyes 7.6s step-end infinite;
  animation-delay: var(--bot-delay, 0s);
}

hb-agent .bot-lids {
  opacity: 0;
  animation: hb-lids 7.6s step-end infinite;
  animation-delay: var(--bot-delay, 0s);
}

hb-agent.is-poked {
  animation: hb-squish 0.7s var(--ease-out);
  transform-origin: 50% 86%;
}

@keyframes hb-acting {
  0%, 22%, 58%, to { transform: translateY(0) rotate(0); }
  29%, 44% { transform: translateY(-1px) rotate(-2deg); }
  70%, 79% { transform: translateY(-1px) rotate(1deg); }
}

@keyframes hb-research-acting {
  0%, 18%, 62%, to { transform: rotate(-2deg); }
  24%, 33% { transform: translateY(-1px) rotate(2deg); }
  37%, 44% { transform: translateY(-1px) rotate(-3deg); }
  48%, 53% { transform: translateY(-1px) rotate(1deg); }
  79%, 88% { transform: rotate(-3deg); }
}

@keyframes hb-gaze {
  0%, 22%, 56%, to { transform: translate(0); }
  28%, 44% { transform: translate(3px, -1px); }
  68%, 78% { transform: translate(-3px); }
}

@keyframes hb-eyes {
  0%, 39%, 72%, to { opacity: 1; }
  37%, 70% { opacity: 0; }
}

@keyframes hb-lids {
  0%, 39%, 72%, to { opacity: 0; }
  37%, 70% { opacity: 1; }
}

@keyframes hb-squish {
  0%, to { transform: translateY(0) scale(1); }
  13% { transform: translateY(2px) scale(1.16, 0.74); }
  32% { transform: translateY(-4px) scale(0.91, 1.15); }
  50% { transform: translateY(1px) scale(1.055, 0.955); }
  70% { transform: translateY(-1px) scale(0.985, 1.025); }
  86% { transform: translateY(0) scale(1.005, 0.995); }
}

@media (prefers-reduced-motion: reduce) {
  hb-agent .bot-acting,
  hb-agent .bot-gaze,
  hb-agent .bot-eyes,
  hb-agent .bot-lids,
  hb-agent.is-poked {
    animation: none;
  }

  hb-agent .bot-look {
    transition: none;
  }
}

/* ---------- Poke speech bubble ---------- */

.poke-bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% - 8px);
  z-index: 3;
  padding: 6px 11px;
  border-radius: 12px 12px 12px 4px;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-30%, 6px) scale(0.92);
  transition: opacity 0.2s, transform 0.3s var(--ease-spring);
}

.poke-bubble.is-visible {
  opacity: 1;
  transform: translate(-30%, 0) scale(1);
}

/* ---------- Segmented control ---------- */

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
}

.segmented button {
  min-height: 32px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 560;
  transition: color var(--dur-fast), background-color var(--dur-fast);
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button[aria-checked="true"] {
  color: var(--ink);
  background: var(--surface-raised);
  box-shadow: 0 0 0 1px var(--line-strong), 0 6px 14px -8px rgba(0, 0, 0, 0.8);
}

/* ---------- Switch ---------- */

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
}

.switch__track {
  position: relative;
  flex-shrink: 0;
  width: 36px;
  height: 21px;
  border-radius: var(--r-pill);
  background: #2a2c33;
  box-shadow: inset 0 0 0 1px var(--line-strong);
  transition: background-color var(--dur);
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #d9dae2;
  transition: transform var(--dur) var(--ease-spring);
}

.switch[aria-checked="true"] .switch__track {
  background: var(--brand);
}

.switch[aria-checked="true"] .switch__track::after {
  background: #fff;
  transform: translateX(15px);
}

/* ---------- Generic panel ---------- */

.panel {
  position: relative;
  border-radius: var(--r-panel);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0) 40%),
    var(--surface);
  box-shadow: var(--shadow-panel);
}

.panel__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.panel__brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.panel__brand img {
  width: 13px;
  height: auto;
}

/* ---------- Toast (fallback notice, bottom of screen) ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: min(440px, calc(100% - 32px));
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--surface-raised);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.9), 0 0 0 1px var(--line-strong);
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
  transform: translate(-50%, 140%);
  transition: transform 0.45s var(--ease-spring);
}

.toast.is-visible {
  transform: translate(-50%, 0);
}

.toast .icon {
  margin-top: 2px;
  color: var(--brand);
  font-size: 18px;
}
