:root {
  --pn-aichat-bg: #ffffff;
  --pn-aichat-panel: #ffffff;
  --pn-aichat-text: #1b2430;
  --pn-aichat-muted: rgba(27, 36, 48, 0.72);
  --pn-aichat-accent: #0ea5b7; /* send button */
  --pn-aichat-header-bg: #0ea5b7;
  --pn-aichat-fab-bg: #0ea5b7;
  --pn-aichat-border: rgba(15, 23, 42, 0.14);
  --pn-aichat-shadow: 0 18px 50px rgba(2, 6, 23, 0.22);
  --pn-aichat-radius: 14px;
  --pn-aichat-font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
}

.pn-aichat {
  position: fixed !important;
  /* Max-ish z-index to beat aggressive theme overlays/footers. */
  z-index: 2147483647 !important;
  font-family: var(--pn-aichat-font);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-end;
}

.pn-aichat.pn-aichat-pos-bottom_right {
  right: 18px;
  bottom: 18px;
  flex-direction: column-reverse;
}
.pn-aichat.pn-aichat-pos-bottom_left {
  left: 18px;
  bottom: 18px;
  flex-direction: column-reverse;
  align-items: flex-start;
}
.pn-aichat.pn-aichat-pos-bottom_left_displaced {
  left: calc(18px + var(--pn-aichat-displace-x, 100px));
  bottom: 18px;
  flex-direction: column-reverse;
  align-items: flex-start;
}
.pn-aichat.pn-aichat-pos-top_right {
  right: 18px;
  top: 18px;
}
.pn-aichat.pn-aichat-pos-top_left {
  left: 18px;
  top: 18px;
  align-items: flex-start;
}

.pn-aichat-fab {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  border: 1px solid rgba(2, 6, 23, 0.10);
  background: var(--pn-aichat-fab-bg);
  color: #ffffff;
  box-shadow: 0 16px 44px rgba(2, 6, 23, 0.22), 0 3px 10px rgba(2, 6, 23, 0.18);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 120ms ease, filter 120ms ease;
}
.pn-aichat-fab:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}
.pn-aichat-fab:active {
  transform: translateY(0);
}
.pn-aichat-fab-icon {
  font-size: 22px;
  line-height: 1;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 2px 2px rgba(2, 6, 23, 0.28));
}
.pn-aichat-fab-img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 2px 2px rgba(2, 6, 23, 0.28));
}

.pn-aichat-panel {
  width: min(380px, calc(100vw - 36px));
  height: min(560px, calc(100vh - 110px));
  border-radius: var(--pn-aichat-radius);
  border: 1px solid var(--pn-aichat-border);
  background: var(--pn-aichat-panel);
  color: var(--pn-aichat-text);
  box-shadow: var(--pn-aichat-shadow);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  transform-origin: 90% 90%;
}
.pn-aichat-panel[hidden] {
  display: none !important;
}

.pn-aichat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 10px;
  border-bottom: 1px solid rgba(2, 6, 23, 0.10);
  background: var(--pn-aichat-header-bg);
}
.pn-aichat-title {
  font-weight: 650;
  letter-spacing: 0.2px;
  color: #ffffff;
}
.pn-aichat-header-actions {
  display: flex;
  gap: 8px;
}
.pn-aichat-header-actions button {
  appearance: none;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: #ffffff;
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
}
.pn-aichat-header-actions button:hover {
  background: rgba(255, 255, 255, 0.24);
}

.pn-aichat-icon-btn {
  width: 34px;
  height: 30px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}
.pn-aichat-icon {
  display: block;
}
.pn-aichat-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;
}

.pn-aichat-messages {
  padding: 12px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pn-aichat-msg {
  max-width: 92%;
  padding: 10px 11px;
  border-radius: 14px;
  border: 1px solid rgba(2, 6, 23, 0.10);
  background: rgba(2, 6, 23, 0.03);
  line-height: 1.35;
  font-size: 14px;
  white-space: normal;
  overflow-wrap: anywhere;
}
.pn-aichat-msg.pn-aichat-user {
  align-self: flex-end;
  background: rgba(14, 165, 183, 0.12);
  border-color: rgba(14, 165, 183, 0.20);
}
.pn-aichat-msg.pn-aichat-assistant {
  align-self: flex-start;
}
.pn-aichat-msg a {
  color: var(--pn-aichat-accent);
  text-decoration: none;
}
.pn-aichat-msg a:hover {
  text-decoration: underline;
}
.pn-aichat-msg pre {
  background: rgba(2, 6, 23, 0.06);
  padding: 10px;
  border-radius: 12px;
  overflow: auto;
  border: 1px solid rgba(2, 6, 23, 0.10);
}
.pn-aichat-msg code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12.5px;
}

/* Scoped typography reset for Markdown content (prevents theme global styles from blowing up headings). */
.pn-aichat-msg h1,
.pn-aichat-msg h2,
.pn-aichat-msg h3,
.pn-aichat-msg h4,
.pn-aichat-msg h5,
.pn-aichat-msg h6 {
  margin: 10px 0 8px;
  line-height: 1.15;
  letter-spacing: 0;
  font-weight: 750;
  color: inherit;
  text-transform: none;
}
.pn-aichat-msg h1 { font-size: 18px !important; margin: 10px 0 8px !important; line-height: 1.15 !important; }
.pn-aichat-msg h2 { font-size: 16px !important; margin: 10px 0 8px !important; line-height: 1.15 !important; }
.pn-aichat-msg h3 { font-size: 15px !important; margin: 10px 0 8px !important; line-height: 1.15 !important; }
.pn-aichat-msg h4,
.pn-aichat-msg h5,
.pn-aichat-msg h6 { font-size: 14px !important; margin: 10px 0 8px !important; line-height: 1.15 !important; }

.pn-aichat-msg p { margin: 8px 0; }

.pn-aichat-msg :where(ul, ol) {
  margin: 8px 0 8px 18px;
  padding: 0;
}
.pn-aichat-msg :where(li) {
  margin: 4px 0;
}

.pn-aichat-msg :where(blockquote) {
  margin: 8px 0;
  padding: 8px 10px;
  border-left: 3px solid rgba(2, 6, 23, 0.18);
  background: rgba(2, 6, 23, 0.03);
  border-radius: 10px;
}

.pn-aichat-msg :where(hr) {
  border: 0;
  border-top: 1px solid rgba(2, 6, 23, 0.12);
  margin: 10px 0;
}

.pn-aichat-msg :where(img) {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
}

.pn-aichat-msg :where(table) {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
}
.pn-aichat-msg :where(th, td) {
  border: 1px solid rgba(2, 6, 23, 0.12);
  padding: 6px 8px;
  vertical-align: top;
}
.pn-aichat-msg :where(th) {
  background: rgba(2, 6, 23, 0.03);
  font-weight: 700;
}

.pn-aichat-composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(2, 6, 23, 0.10);
  background: rgba(2, 6, 23, 0.02);
}

.pn-aichat-disclaimer {
  padding: 0 12px 12px;
  font-size: 12px;
  line-height: 1.25;
  color: rgba(27, 36, 48, 0.70);
}
.pn-aichat-input {
  resize: none;
  border-radius: 14px;
  border: 1px solid rgba(2, 6, 23, 0.14);
  background: #ffffff;
  color: var(--pn-aichat-text);
  padding: 10px 10px;
  font-size: 14px;
  min-height: 40px;
  outline: none;
}
.pn-aichat-input::placeholder {
  color: rgba(233, 238, 252, 0.55);
}
.pn-aichat-send {
  border-radius: 14px;
  border: 1px solid rgba(2, 6, 23, 0.10);
  background: var(--pn-aichat-accent);
  color: #ffffff;
  padding: 10px 12px;
  cursor: pointer;
  min-width: 74px;
}
.pn-aichat-send:hover {
  filter: brightness(0.98);
}
.pn-aichat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.pn-aichat-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.pn-aichat-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(27, 36, 48, 0.44);
  animation: pn-aichat-bounce 900ms infinite ease-in-out;
}
.pn-aichat-dot:nth-child(2) { animation-delay: 120ms; }
.pn-aichat-dot:nth-child(3) { animation-delay: 240ms; }
@keyframes pn-aichat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.55; }
  40% { transform: translateY(-4px); opacity: 0.95; }
}

@media (max-width: 480px) {
  .pn-aichat-fab {
    width: 52px;
    height: 52px;
  }
  .pn-aichat-panel {
    height: min(520px, calc(100vh - 100px));
  }
}
