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

.koropt-cb[aria-expanded="true"] {
  opacity: 0;
  pointer-events: none;
}

.koai-panel {
  --koai-ink: #36283a;
  --koai-muted: #746879;
  --koai-rose: #e84f83;
  --koai-rose-deep: #cf376e;
  position: fixed;
  z-index: 100002;
  left: 16px;
  bottom: 84px;
  display: flex;
  width: min(402px, calc(100vw - 32px));
  height: min(590px, calc(100dvh - 116px));
  flex-direction: column;
  overflow: hidden;
  color: var(--koai-ink);
  background: #fffafc;
  border: 1px solid rgba(78, 45, 83, 0.12);
  border-radius: 24px;
  box-shadow: 0 24px 70px rgba(70, 36, 74, 0.24), 0 4px 16px rgba(70, 36, 74, 0.12);
  font-family: Manrope, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  isolation: isolate;
}

.koai-head {
  display: flex;
  min-height: 68px;
  align-items: center;
  gap: 11px;
  padding: 11px 12px 11px 16px;
  color: var(--koai-ink);
  background: linear-gradient(135deg, #fff5f9 0%, #f6efff 100%);
  border-bottom: 1px solid rgba(78, 45, 83, 0.09);
}

.koai-avatar {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #ee6a96, #d63f76);
  border-radius: 15px;
  box-shadow: 0 7px 18px rgba(216, 62, 118, 0.24);
  font-family: Unbounded, Manrope, sans-serif;
  font-size: 20px;
  font-weight: 800;
}

.koai-title {
  min-width: 0;
  flex: 1;
}

.koai-title strong,
.koai-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.koai-title strong {
  font-size: 15px;
  line-height: 1.25;
}

.koai-title span {
  margin-top: 2px;
  color: var(--koai-muted);
  font-size: 12px;
}

.koai-head-actions {
  display: flex;
  gap: 4px;
}

.koai-icon-btn {
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  color: var(--koai-muted);
  background: transparent;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-size: 24px;
  line-height: 1;
}

.koai-icon-btn:hover,
.koai-icon-btn:focus-visible {
  color: var(--koai-ink);
  background: rgba(255, 255, 255, 0.78);
  outline: none;
}

.koai-messages {
  min-height: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 12px;
  background:
    radial-gradient(circle at 100% 0%, rgba(232, 79, 131, 0.08), transparent 32%),
    linear-gradient(180deg, #fffafd 0%, #f9f5fb 100%);
  scrollbar-width: thin;
  scrollbar-color: rgba(80, 54, 84, 0.2) transparent;
}

.koai-row {
  display: flex;
  align-items: flex-end;
  margin: 0 0 11px;
}

.koai-row.is-user {
  justify-content: flex-end;
}

.koai-bubble {
  max-width: 86%;
  padding: 11px 13px;
  overflow-wrap: anywhere;
  color: var(--koai-ink);
  background: #fff;
  border: 1px solid rgba(78, 45, 83, 0.08);
  border-radius: 17px 17px 17px 5px;
  box-shadow: 0 5px 18px rgba(64, 40, 68, 0.07);
  font-size: 14px;
  line-height: 1.52;
  white-space: pre-wrap;
}

.koai-row.is-user .koai-bubble {
  color: #382738;
  background: #f6d9e5;
  border-color: transparent;
  border-radius: 17px 17px 5px 17px;
  box-shadow: none;
}

.koai-bubble a {
  color: var(--koai-rose-deep);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.koai-bubble.is-error {
  color: #7c2946;
  background: #fff1f5;
  border-color: #f2bfd0;
}

.koai-bubble.is-thinking {
  min-width: 58px;
  color: var(--koai-muted);
}

.koai-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 18px;
}

.koai-dots i {
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
  animation: koai-dot 1s infinite ease-in-out;
  opacity: 0.45;
}

.koai-dots i:nth-child(2) { animation-delay: 0.14s; }
.koai-dots i:nth-child(3) { animation-delay: 0.28s; }

@keyframes koai-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-3px); opacity: 0.9; }
}

.koai-suggestions {
  display: flex;
  gap: 7px;
  padding: 0 14px 10px;
  overflow-x: auto;
  background: #f9f5fb;
  scrollbar-width: none;
}

.koai-suggestions::-webkit-scrollbar { display: none; }

.koai-chip {
  min-height: 34px;
  padding: 7px 11px;
  flex: 0 0 auto;
  color: #5e415f;
  background: #fff;
  border: 1px solid rgba(102, 67, 107, 0.15);
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.koai-chip:hover,
.koai-chip:focus-visible {
  color: var(--koai-rose-deep);
  border-color: rgba(207, 55, 110, 0.42);
  outline: none;
}

.koai-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid rgba(78, 45, 83, 0.09);
}

.koai-input {
  width: 100%;
  min-height: 44px;
  max-height: 112px;
  padding: 11px 13px;
  resize: none;
  color: var(--koai-ink);
  background: #faf7fb;
  border: 1px solid rgba(78, 45, 83, 0.14);
  border-radius: 15px;
  outline: none;
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
}

.koai-input:focus {
  background: #fff;
  border-color: rgba(232, 79, 131, 0.64);
  box-shadow: 0 0 0 3px rgba(232, 79, 131, 0.1);
}

.koai-send {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  flex: 0 0 44px;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, var(--koai-rose), var(--koai-rose-deep));
  border: 0;
  border-radius: 15px;
  box-shadow: 0 8px 18px rgba(214, 63, 118, 0.24);
  cursor: pointer;
}

.koai-send svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.koai-send:disabled {
  cursor: wait;
  opacity: 0.58;
  box-shadow: none;
}

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

@media (max-width: 760px) {
  .koai-panel {
    right: 8px;
    bottom: calc(132px + env(safe-area-inset-bottom));
    left: 8px;
    width: auto;
    height: min(500px, calc(100dvh - 148px - env(safe-area-inset-bottom)));
    border-radius: 22px;
  }

  .koai-messages { padding-right: 12px; padding-left: 12px; }
  .koai-bubble { max-width: 90%; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .koai-dots i { animation: none; }
}
