.koekie {
  --koekie-z: 70;
  position: relative;
  z-index: var(--koekie-z);
  font-family: var(--font-sans, "Outfit", "Avenir Next", "Segoe UI", sans-serif);
  color: var(--cream, #f4eadc);
}

.koekie-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.koekie-fab {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: calc(var(--koekie-z) + 2);
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 48px;
  padding: 0.7rem 1.15rem;
  border: 1px solid var(--line-strong, rgba(201, 160, 108, 0.38));
  border-radius: 999px;
  background: linear-gradient(160deg, var(--gold-soft, #e2c49a), var(--gold, #c9a06c) 55%, var(--gold-deep, #a57c43));
  color: #1a120c;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
  transition: transform 0.2s var(--ease, ease), box-shadow 0.2s var(--ease, ease);
}

.koekie-fab::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #1a120c;
  box-shadow: 0 0 0 3px rgba(26, 18, 12, 0.15);
}

.koekie-fab:hover,
.koekie-fab:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
  outline: none;
}

.koekie.is-open .koekie-fab {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.92);
}

.koekie-panel {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: calc(var(--koekie-z) + 3);
  display: flex;
  flex-direction: column;
  width: min(392px, calc(100vw - 1.5rem));
  height: min(640px, calc(100dvh - 1.5rem));
  max-height: calc(100dvh - 1.5rem);
  border: 1px solid var(--line, rgba(201, 160, 108, 0.16));
  border-radius: var(--radius-lg, 16px);
  background:
    linear-gradient(180deg, rgba(34, 28, 24, 0.96), rgba(14, 13, 15, 0.98)),
    var(--bg, #0c0c0e);
  box-shadow: var(--shadow, 0 30px 80px rgba(0, 0, 0, 0.45));
  overflow: hidden;
}

.koekie-panel[hidden] {
  display: none !important;
}

.koekie-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.85rem;
  border-bottom: 1px solid var(--line, rgba(201, 160, 108, 0.16));
  background: rgba(18, 17, 19, 0.72);
}

.koekie-kicker {
  margin: 0;
  color: var(--gold, #c9a06c);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.koekie-header h2 {
  margin: 0.1rem 0 0;
  font-family: var(--font-serif, "Fraunces", Georgia, serif);
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--cream, #f4eadc);
}

.koekie-close {
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--line, rgba(201, 160, 108, 0.16));
  border-radius: 999px;
  background: transparent;
  color: var(--cream-dim, #c6b39a);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.koekie-close:hover,
.koekie-close:focus-visible {
  color: var(--cream, #f4eadc);
  border-color: var(--line-strong, rgba(201, 160, 108, 0.38));
  outline: none;
}

.koekie-thread {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: rgba(0, 0, 0, 0.18);
}

.koekie-bubble {
  max-width: 88%;
  padding: 0.75rem 0.9rem;
  border-radius: 14px;
  border: 1px solid var(--line, rgba(201, 160, 108, 0.16));
  background: var(--bg-card, rgba(18, 17, 19, 0.58));
}

.koekie-bubble p {
  margin: 0;
  white-space: pre-wrap;
  color: var(--cream, #f4eadc);
  font-size: 0.95rem;
  line-height: 1.45;
}

.koekie-bubble--user {
  align-self: flex-end;
  background: rgba(201, 160, 108, 0.16);
  border-color: rgba(201, 160, 108, 0.28);
}

.koekie-bubble--assistant {
  align-self: flex-start;
}

.koekie-wa {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.75rem;
  padding: 0.65rem 0.9rem;
  border-radius: 999px;
  background: var(--wa, #25d366);
  color: #0f1a12;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
}

.koekie-wa:hover,
.koekie-wa:focus-visible {
  filter: brightness(1.05);
  color: #0f1a12;
  outline: none;
}

.koekie-typing {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  min-width: 3.2rem;
  padding: 0.9rem 1rem;
}

.koekie-typing span {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: var(--gold, #c9a06c);
  opacity: 0.35;
  animation: koekie-bounce 1s infinite ease-in-out;
}

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

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

@keyframes koekie-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.koekie-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.65rem 1rem 0.2rem;
}

.koekie-chips[hidden] {
  display: none !important;
}

.koekie-chip {
  border: 1px solid var(--line-strong, rgba(201, 160, 108, 0.38));
  border-radius: 999px;
  background: transparent;
  color: var(--cream-dim, #c6b39a);
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.koekie-chip:hover,
.koekie-chip:focus-visible {
  color: var(--cream, #f4eadc);
  border-color: var(--gold, #c9a06c);
  outline: none;
}

.koekie-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  align-items: end;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--line, rgba(201, 160, 108, 0.16));
  background: rgba(18, 17, 19, 0.72);
}

.koekie-form textarea {
  width: 100%;
  min-height: 44px;
  max-height: 120px;
  resize: none;
  border: 1px solid var(--line, rgba(201, 160, 108, 0.16));
  border-radius: 12px;
  background: rgba(10, 10, 12, 0.7);
  color: var(--cream, #f4eadc);
  padding: 0.7rem 0.85rem;
}

.koekie-form textarea:focus-visible {
  outline: 2px solid rgba(201, 160, 108, 0.55);
  outline-offset: 1px;
}

.koekie-send {
  min-height: 44px;
  padding: 0 1rem;
  border: 0;
  border-radius: 12px;
  background: var(--gold, #c9a06c);
  color: #1a120c;
  font-weight: 600;
  cursor: pointer;
}

.koekie-send:hover,
.koekie-send:focus-visible {
  background: var(--gold-soft, #e2c49a);
  outline: none;
}

.koekie-send:disabled {
  opacity: 0.55;
  cursor: wait;
}

@media (max-width: 720px) {
  .koekie-fab {
    bottom: calc(4.6rem + env(safe-area-inset-bottom));
  }

  .koekie-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
}
