.puru-chat-mount {
  position: fixed;
  z-index: 60;
  top: var(--site-header-bar-offset);
  right: 0;
  bottom: 0;
  left: auto;
  width: min(400px, 100vw);
  font-family: var(--font-sans);
  pointer-events: none;
}

.puru-chat-fab {
  display: none !important;
}

.puru-chat-panel {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--stroke-strong);
  border-right: none;
  background: linear-gradient(165deg, var(--elev), var(--elev2));
  backdrop-filter: blur(var(--blur-strong));
  box-shadow: -20px 0 56px color-mix(in srgb, var(--fg) 7%, transparent);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
}

.puru-chat-panel[hidden] {
  display: none;
}

.puru-chat-head {
  padding: var(--space-4);
  border-bottom: 1px solid var(--stroke);
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  align-items: flex-start;
}

.puru-chat-head h2 {
  margin: 0;
  font-size: var(--step-1);
  font-family: var(--font-display);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid color-mix(in srgb, var(--stroke) 45%, transparent);
}

.puru-chat-sub {
  margin: var(--space-2) 0 0;
  font-size: var(--step--1);
  color: var(--fg-muted);
  line-height: 1.35;
}

.puru-chat-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

.puru-chat-icon-btn {
  border: 1px solid var(--stroke-strong);
  background: color-mix(in srgb, var(--fg) 5%, transparent);
  border-radius: var(--radius-md);
  width: 36px;
  height: 36px;
  cursor: pointer;
  color: var(--fg-muted);
  font-size: 1.1rem;
  line-height: 1;
}

.puru-chat-msgs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4) calc(var(--space-4) + 12px);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--bg1);
}

.puru-chat-msgs[aria-busy="true"] {
  opacity: 0.68;
  pointer-events: none;
}

.puru-chat-bubble {
  --puru-bubble-bot-fill: color-mix(in srgb, var(--fg) 7%, var(--bg1));
  max-width: 92%;
  padding: var(--space-2) var(--space-4);
  border-radius: 15px;
  font-size: var(--step--1);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
  box-sizing: border-box;
  animation: puru-chat-msg-in 0.3s ease;
}

@keyframes puru-chat-msg-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .puru-chat-bubble {
    animation: none;
  }
}

.puru-chat-bubble--user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-radius: 20px;
}

.puru-chat-bubble--user::before {
  content: "";
  position: absolute;
  bottom: 0;
  right: -8px;
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-bottom-left-radius: 15px;
}

.puru-chat-bubble--user::after {
  content: "";
  position: absolute;
  bottom: 0;
  right: -10px;
  width: 10px;
  height: 20px;
  background: var(--bg1);
  border-bottom-left-radius: 10px;
}

.puru-chat-bubble--bot {
  align-self: flex-start;
  background: var(--puru-bubble-bot-fill);
  color: var(--fg-muted);
}

.puru-chat-bubble--bot::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: -8px;
  width: 20px;
  height: 20px;
  background: var(--puru-bubble-bot-fill);
  border-bottom-right-radius: 15px;
}

.puru-chat-bubble--bot::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: -10px;
  width: 10px;
  height: 20px;
  background: var(--bg1);
  border-bottom-right-radius: 10px;
}

.puru-chat-typing-row {
  align-self: flex-start;
  display: flex;
  animation: puru-chat-msg-in 0.3s ease;
}

.puru-chat-typing {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 15px;
  border-radius: 20px;
  box-sizing: border-box;
  background: color-mix(in srgb, var(--fg) 7%, var(--bg1));
}

.puru-chat-typing span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 62%, var(--fg)));
  animation: puru-chat-typing-pulse 1.4s infinite ease-in-out;
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 32%, transparent);
}

.puru-chat-typing span:nth-child(1) {
  animation-delay: -0.32s;
}

.puru-chat-typing span:nth-child(2) {
  animation-delay: -0.16s;
}

.puru-chat-typing span:nth-child(3) {
  animation-delay: 0s;
}

@keyframes puru-chat-typing-pulse {
  0%,
  80%,
  100% {
    transform: scale(0.8);
    opacity: 0.5;
    box-shadow: 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
  }
  40% {
    transform: scale(1.15);
    opacity: 1;
    box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 42%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .puru-chat-typing-row {
    animation: none;
  }

  .puru-chat-typing span {
    animation: none;
    opacity: 0.72;
  }
}

.puru-chat-foot {
  --puru-chat-foot-y: var(--space-4);
  flex-shrink: 0;
  padding: var(--puru-chat-foot-y) var(--space-4) calc(var(--puru-chat-foot-y) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--stroke);
  display: flex;
  flex-direction: column;
  gap: var(--puru-chat-foot-y);
  align-items: stretch;
}

.puru-chat-row {
  display: flex;
  width: 100%;
  align-items: center;
}

.puru-chat-composer {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  gap: 0.15rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--stroke-strong);
  padding: 0.12rem 0.35rem 0.12rem 0.85rem;
  background: color-mix(in srgb, var(--elev) 85%, transparent);
}

.puru-chat-input {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 0;
  padding: 0.45rem 0.25rem 0.45rem 0;
  font: inherit;
  background: transparent;
  color: var(--fg);
}

.puru-chat-input:focus {
  outline: none;
}

.puru-chat-composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--stroke-strong));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);
}

.puru-chat-send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: pointer;
  color: var(--fg-muted);
}

.puru-chat-send.is-active {
  color: var(--accent);
}

.puru-chat-send-ico {
  display: block;
  pointer-events: none;
}

.puru-chat-composer.is-busy {
  opacity: 0.72;
  pointer-events: none;
}

.puru-chat-composer.is-busy:focus-within {
  border-color: var(--stroke-strong);
  box-shadow: none;
}

.puru-chat-input:disabled {
  cursor: not-allowed;
  opacity: 0.85;
}

.puru-chat-send:disabled {
  cursor: not-allowed;
  color: var(--fg-muted);
}

.puru-chat-send:disabled.is-active {
  color: var(--fg-muted);
}

.puru-chat-form {
  display: grid;
  gap: var(--space-2);
  padding: 0 0 var(--space-7);
  border-top: 1px dashed var(--stroke);
}

.puru-chat-form[hidden] {
  display: none;
}

.puru-chat-form h3 {
  margin: 0;
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-muted);
}

.puru-chat-input-full {
  border-radius: var(--radius-md);
  border: 1px solid var(--stroke-strong);
  padding: 0.5rem 0.65rem;
  font: inherit;
  background: color-mix(in srgb, var(--elev) 85%, transparent);
  color: var(--fg);
}

.puru-chat-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.puru-chat-status {
  font-size: 0.72rem;
  color: var(--ok);
  margin: var(--space-2) 0 0;
  padding-bottom: var(--space-2);
}

.puru-chat-status--err {
  color: var(--danger);
}

.puru-chat-form-submit {
  justify-self: end;
  margin-bottom: var(--space-4);
  border-radius: var(--radius-pill);
  border: none;
  padding: 0.55rem 1rem;
  font-weight: 650;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #6366f1));
  color: #fff;
}

@media (max-width: 900px) {
  .puru-chat-mount {
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    width: auto;
    z-index: 150;
    max-height: 100dvh;
  }

  .puru-chat-head {
    padding-top: calc(env(safe-area-inset-top, 0px) + var(--space-4));
  }

  .puru-chat-panel {
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    min-height: 100%;
    border-radius: 0;
    border: none;
  }
}
