:root {
  --pi-blue: #0093dd;
  --pi-blue-dark: #025e8d;
  --pi-blue-mid: #0077b3;
  --pi-green: #2dd317;
  --pi-text: #153044;
  --pi-muted: #4d6272;
  --pi-bg: #ffffff;
  --pi-panel: #eef6fb;
  --pi-chip: #f3fafd;
  --pi-border: #cfe3ef;
  --pi-shadow: 0 18px 48px rgba(2, 94, 141, 0.22);
  --pi-radius: 20px;
  --pi-offset: 110px;
}

#pi-chat-root,
#pi-chat-root * {
  box-sizing: border-box;
}

.pi-chat-hidden {
  display: none !important;
}

#pi-chat-root {
  position: fixed;
  right: 20px;
  bottom: var(--pi-offset);
  z-index: 99990;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: "Segoe UI", "Nunito Sans", Tahoma, sans-serif;
  color: var(--pi-text);
}

.pi-launcher {
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, #1aa4e8 0%, var(--pi-blue) 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(0, 147, 221, 0.38);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.pi-launcher:hover,
.pi-launcher:focus-visible {
  background: var(--pi-blue-mid);
  transform: translateY(-2px) scale(1.03);
  outline: 3px solid rgba(45, 211, 23, 0.45);
  outline-offset: 2px;
}

#pi-chat-root.pi-open .pi-launcher {
  display: none;
}

.pi-window {
  width: min(392px, calc(100vw - 24px));
  height: min(600px, calc(100vh - var(--pi-offset) - 16px));
  max-height: min(600px, calc(100vh - var(--pi-offset) - 16px));
  background: var(--pi-bg);
  border: 1px solid rgba(0, 147, 221, 0.14);
  border-radius: var(--pi-radius);
  box-shadow: var(--pi-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 12px;
  animation: pi-in 0.22s ease;
}

#pi-chat-root.pi-open .pi-window {
  margin-bottom: 0;
}

@keyframes pi-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.pi-header {
  background: linear-gradient(135deg, #0b8fd4 0%, #025e8d 100%);
  color: #fff;
  padding: 14px 12px 14px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.pi-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pi-header-text {
  min-width: 0;
  flex: 1;
}

.pi-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.pi-status {
  margin: 3px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  opacity: 0.95;
}

.pi-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pi-green);
  box-shadow: 0 0 0 3px rgba(45, 211, 23, 0.25);
}

.pi-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 0;
  color: #fff;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pi-icon-btn:hover,
.pi-icon-btn:focus-visible {
  background: rgba(255, 255, 255, 0.24);
  outline: 2px solid #fff;
}

.pi-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 14px 16px;
  background: linear-gradient(180deg, #f7fbfe 0%, var(--pi-panel) 100%);
  scrollbar-width: thin;
  scrollbar-color: #9dc8de transparent;
}

.pi-messages::-webkit-scrollbar {
  width: 6px;
}

.pi-messages::-webkit-scrollbar-thumb {
  background: #9dc8de;
  border-radius: 999px;
}

.pi-msg {
  max-width: 92%;
  margin-bottom: 10px;
  padding: 11px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  animation: pi-msg-in 0.2s ease;
}

@keyframes pi-msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.pi-msg a {
  color: var(--pi-blue-dark);
}

.pi-msg-user {
  margin-left: auto;
  background: var(--pi-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.pi-msg-assistant {
  background: #fff;
  border: 1px solid var(--pi-border);
  border-bottom-left-radius: 4px;
  white-space: normal;
  box-shadow: 0 4px 12px rgba(2, 94, 141, 0.05);
}

.pi-msg-assistant ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.pi-sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--pi-border);
}

.pi-sources a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: #e7f5fc;
  color: var(--pi-blue-dark);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.pi-sources a:hover,
.pi-sources a:focus-visible {
  background: var(--pi-blue);
  color: #fff;
}

.pi-followup {
  margin: 4px 0 0;
}

.pi-suggestions-label {
  margin: 10px 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--pi-muted);
}

.pi-suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pi-chip {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  border: 1px solid #b7d7ea;
  background: var(--pi-chip);
  color: var(--pi-blue-dark);
  border-radius: 12px;
  padding: 10px 12px 10px 14px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.pi-chip::after {
  content: "";
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  opacity: 0.7;
}

.pi-chip:hover,
.pi-chip:focus-visible {
  background: var(--pi-blue);
  border-color: var(--pi-blue);
  color: #fff;
  transform: translateX(2px);
  outline: none;
}

.pi-chip-active {
  background: #025e8d;
  border-color: #025e8d;
  color: #fff;
}

.pi-form-intro {
  margin: 14px 0 8px;
  font-size: 13px;
  color: var(--pi-muted);
}

.pi-form-toggle {
  display: inline-flex;
  align-items: center;
  margin: 0 0 10px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--pi-blue-dark);
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.pi-form-toggle:hover,
.pi-form-toggle:focus-visible {
  color: var(--pi-blue);
}

.pi-ask-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--pi-border);
  border-radius: 14px;
  background: #fff;
  position: relative;
}

.pi-ask-form input,
.pi-ask-form textarea {
  width: 100%;
  border: 1px solid var(--pi-border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--pi-text);
  background: #f7fbfe;
}

.pi-ask-form input:focus,
.pi-ask-form textarea:focus {
  outline: 2px solid rgba(0, 147, 221, 0.35);
  border-color: var(--pi-blue);
  background: #fff;
}

.pi-ask-form textarea {
  resize: vertical;
  min-height: 72px;
}

.pi-hp {
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
}

.pi-send {
  align-self: flex-end;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  background: var(--pi-green);
  color: #123;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.pi-send:hover,
.pi-send:focus-visible {
  filter: brightness(0.96);
  outline: 3px solid rgba(45, 211, 23, 0.35);
}

.pi-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.pi-form-status {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--pi-muted);
}

.pi-status.is-offline::before {
  background: #c5d0d8;
  box-shadow: none;
}

.pi-typing {
  margin: 0;
  padding: 0 16px 8px;
  font-size: 12px;
  color: var(--pi-muted);
  background: var(--pi-panel);
}

.pi-composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--pi-border);
  background: #fff;
  flex-shrink: 0;
}

.pi-composer textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 90px;
  border: 1px solid var(--pi-border);
  border-radius: 10px;
  padding: 10px;
  font: inherit;
}

.pi-composer .pi-send {
  align-self: stretch;
}

@media (max-width: 640px) {
  #pi-chat-root {
    right: 12px;
    bottom: var(--pi-offset);
  }

  .pi-window {
    width: calc(100vw - 24px);
    height: min(70vh, calc(100vh - var(--pi-offset) - 12px));
    max-height: calc(100vh - var(--pi-offset) - 12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .pi-window,
  .pi-msg,
  .pi-launcher,
  .pi-chip {
    animation: none;
    transition: none;
  }
}
