.ph-chat-widget {
  --ph-navy: #000E2B;
  --ph-navy-deep: #000714;
  --ph-sand: #F4E2D4;
  --ph-electric: #5BC0EB;
  --ph-gold: #FDB664;
  --ph-error: #C8312B;

  --ph-bg: #FFFFFF;
  --ph-bg-soft: #FAF7F3;
  --ph-bg-muted: #F4F0EA;
  --ph-text: #000E2B;
  --ph-text-muted: rgba(0, 14, 43, 0.62);
  --ph-text-faint: rgba(0, 14, 43, 0.42);
  --ph-border: rgba(0, 14, 43, 0.10);
  --ph-border-strong: rgba(0, 14, 43, 0.16);

  --ph-shadow-panel: 0 24px 60px -16px rgba(0, 14, 43, 0.25), 0 8px 24px -8px rgba(0, 14, 43, 0.12);
  --ph-shadow-launcher: 0 12px 28px -8px rgba(91, 192, 235, 0.55), 0 6px 16px rgba(0, 14, 43, 0.20);

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483000;
  font-family: "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ph-text);
}

.ph-chat-widget *,
.ph-chat-widget *::before,
.ph-chat-widget *::after {
  box-sizing: border-box;
}

.ph-chat-launcher,
.ph-chat-send,
.ph-chat-icon-btn {
  border: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.ph-chat-launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border-radius: 9999px;
  padding: 12px 20px 12px 16px;
  background: var(--ph-electric);
  color: var(--ph-navy);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  box-shadow: var(--ph-shadow-launcher);
  transition: transform 220ms cubic-bezier(.2,.7,.2,1), box-shadow 220ms ease, opacity 180ms ease;
}

.ph-chat-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 36px -10px rgba(91, 192, 235, 0.7), 0 8px 20px rgba(0, 14, 43, 0.25);
}

.ph-chat-launcher:active {
  transform: translateY(0);
}

.ph-chat-launcher svg {
  width: 20px;
  height: 20px;
}

.ph-chat-launcher.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.92);
}

.ph-chat-launcher-text {
  white-space: nowrap;
}

.ph-chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 14, 43, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 220ms ease;
  z-index: 2147482998;
}

.ph-chat-backdrop[hidden] { display: none; }
.ph-chat-backdrop.is-visible { opacity: 1; }

.ph-chat-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(400px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--ph-border);
  border-radius: 20px;
  background: var(--ph-bg);
  box-shadow: var(--ph-shadow-panel);
  color: var(--ph-text);
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition:
    opacity 200ms ease,
    transform 240ms cubic-bezier(.2,.7,.2,1),
    width 280ms cubic-bezier(.2,.7,.2,1),
    height 280ms cubic-bezier(.2,.7,.2,1),
    right 280ms cubic-bezier(.2,.7,.2,1),
    bottom 280ms cubic-bezier(.2,.7,.2,1),
    border-radius 280ms cubic-bezier(.2,.7,.2,1);
  z-index: 2147482999;
}

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

.ph-chat-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Full-screen mode — proper chat UI */
.ph-chat-panel.is-expanded {
  width: 100vw;
  height: 100vh;
  right: 0;
  bottom: 0;
  border-radius: 0;
  border: 0;
  background: var(--ph-bg-soft);
}

.ph-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--ph-bg);
  border-bottom: 1px solid var(--ph-border);
  flex-shrink: 0;
}

.ph-chat-panel.is-expanded .ph-chat-header {
  padding: 16px 32px;
}

.ph-chat-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ph-chat-title-main {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--ph-text);
}

.ph-chat-title-sub {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ph-text-muted);
}

.ph-chat-dot {
  width: 7px;
  height: 7px;
  border-radius: 9999px;
  background: var(--ph-electric);
  box-shadow: 0 0 0 0 rgba(91, 192, 235, 0.55);
  animation: ph-chat-pulse 2.2s ease-out infinite;
}

@keyframes ph-chat-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(91, 192, 235, 0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(91, 192, 235, 0); }
  100% { box-shadow: 0 0 0 0 rgba(91, 192, 235, 0); }
}

.ph-chat-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ph-chat-new {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 10px;
  border-radius: 9999px;
  background: var(--ph-bg-muted);
  color: var(--ph-text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: background 160ms ease, color 160ms ease;
}

.ph-chat-new:hover {
  background: rgba(15, 42, 68, 0.1);
  color: var(--ph-text);
}

.ph-chat-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9999px;
  background: transparent;
  color: var(--ph-text-muted);
  transition: background 160ms ease, color 160ms ease;
}

.ph-chat-icon-btn:hover {
  background: var(--ph-bg-muted);
  color: var(--ph-text);
}

.ph-chat-icon-btn svg {
  width: 16px;
  height: 16px;
}

/* Scrollable messages strip */
.ph-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  position: relative;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 14, 43, 0.22) transparent;
}

.ph-chat-messages::-webkit-scrollbar { width: 8px; }
.ph-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 14, 43, 0.18);
  border-radius: 9999px;
}
.ph-chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 14, 43, 0.32);
}

.ph-chat-messages-inner {
  padding: 18px 18px 8px;
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.ph-chat-panel.is-expanded .ph-chat-messages-inner {
  max-width: 760px;
  padding: 40px 32px 24px;
}

.ph-chat-message {
  display: flex;
  margin-bottom: 12px;
  animation: ph-chat-msg-in 320ms cubic-bezier(.2,.7,.2,1) both;
}

.ph-chat-panel.is-expanded .ph-chat-message {
  margin-bottom: 18px;
}

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

.ph-chat-message-body {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ph-chat-panel.is-expanded .ph-chat-message-body {
  max-width: 82%;
  padding: 14px 18px;
  font-size: 16px;
  line-height: 1.6;
  border-radius: 18px;
}

.ph-chat-message-assistant { justify-content: flex-start; }

.ph-chat-message-assistant .ph-chat-message-body {
  background: var(--ph-bg-muted);
  color: var(--ph-text);
  border-top-left-radius: 6px;
}

.ph-chat-message-user { justify-content: flex-end; }

.ph-chat-message-user .ph-chat-message-body {
  background: var(--ph-navy);
  color: var(--ph-sand);
  border-top-right-radius: 6px;
}

.ph-chat-message-error .ph-chat-message-body {
  background: rgba(200, 49, 43, 0.08);
  border: 1px solid rgba(200, 49, 43, 0.25);
  color: var(--ph-error);
}

/* Markdown rendered inside assistant bubbles.
 * These rules use `.ph-chat-widget` as a prefix so they outrank typical host
 * page typography rules (e.g. `body p { color: ... }`) that would otherwise
 * leak into the bubble and override our intended colour and font. */
.ph-chat-widget .ph-chat-message-body > :first-child { margin-top: 0; }
.ph-chat-widget .ph-chat-message-body > :last-child { margin-bottom: 0; }

.ph-chat-widget .ph-chat-message-body p,
.ph-chat-widget .ph-chat-message-body h1,
.ph-chat-widget .ph-chat-message-body h2,
.ph-chat-widget .ph-chat-message-body h3,
.ph-chat-widget .ph-chat-message-body ul,
.ph-chat-widget .ph-chat-message-body ol,
.ph-chat-widget .ph-chat-message-body li,
.ph-chat-widget .ph-chat-message-body strong,
.ph-chat-widget .ph-chat-message-body em,
.ph-chat-widget .ph-chat-message-body a {
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

.ph-chat-widget .ph-chat-message-body p { margin: 0 0 0.6em; font-weight: 400; }
.ph-chat-widget .ph-chat-message-body p:last-child { margin-bottom: 0; }

.ph-chat-widget .ph-chat-message-body h1,
.ph-chat-widget .ph-chat-message-body h2,
.ph-chat-widget .ph-chat-message-body h3 {
  margin: 0.6em 0 0.35em;
  line-height: 1.25;
  letter-spacing: -0.01em;
  font-weight: 600;
}
.ph-chat-widget .ph-chat-message-body h1 { font-size: 1.15em; }
.ph-chat-widget .ph-chat-message-body h2 { font-size: 1.08em; }
.ph-chat-widget .ph-chat-message-body h3 { font-size: 1em; }

.ph-chat-widget .ph-chat-message-body strong { font-weight: 600; }
.ph-chat-widget .ph-chat-message-body em { font-style: italic; }

.ph-chat-widget .ph-chat-message-body ul,
.ph-chat-widget .ph-chat-message-body ol {
  margin: 0.25em 0 0.6em;
  padding-left: 1.25em;
}
.ph-chat-widget .ph-chat-message-body li { margin: 0.15em 0; }
.ph-chat-widget .ph-chat-message-body li::marker { color: var(--ph-text-muted); }

.ph-chat-widget .ph-chat-message-body a {
  color: var(--ph-navy);
  text-decoration: underline;
  text-decoration-color: var(--ph-electric);
  text-underline-offset: 2px;
  text-decoration-thickness: 2px;
}
.ph-chat-widget .ph-chat-message-body a:hover { text-decoration-color: var(--ph-navy); }

.ph-chat-widget .ph-chat-message-user .ph-chat-message-body a {
  color: var(--ph-sand);
  text-decoration-color: var(--ph-electric);
}

.ph-chat-widget .ph-chat-message-body code {
  font-family: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.92em;
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(0, 14, 43, 0.06);
  color: inherit;
}

.ph-chat-widget .ph-chat-message-body pre {
  margin: 0.5em 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(0, 14, 43, 0.06);
  overflow-x: auto;
  font-size: 0.92em;
  color: inherit;
}

.ph-chat-widget .ph-chat-message-body pre code {
  padding: 0;
  background: transparent;
  border-radius: 0;
}

.ph-chat-widget .ph-chat-message-user .ph-chat-message-body code {
  background: rgba(244, 226, 212, 0.18);
}
.ph-chat-widget .ph-chat-message-user .ph-chat-message-body pre {
  background: rgba(244, 226, 212, 0.12);
}

.ph-chat-typing .ph-chat-message-body {
  padding: 14px 18px;
}

.ph-chat-typing-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.ph-chat-typing-dots i {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  background: rgba(0, 14, 43, 0.45);
  animation: ph-chat-dot 1.2s ease-in-out infinite;
}

.ph-chat-typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.ph-chat-typing-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes ph-chat-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.ph-chat-status {
  min-height: 18px;
  padding: 0 18px 6px;
  color: var(--ph-text-muted);
  font-size: 12px;
  font-family: "Geist Mono", ui-monospace, monospace;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.ph-chat-form {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--ph-border);
  background: var(--ph-bg);
  flex-shrink: 0;
}

.ph-chat-panel.is-expanded .ph-chat-form {
  padding: 16px 32px 24px;
  background: var(--ph-bg-soft);
  border-top-color: transparent;
}

.ph-chat-form-inner {
  max-width: 100%;
  margin: 0 auto;
}

.ph-chat-panel.is-expanded .ph-chat-form-inner {
  max-width: 760px;
}

.ph-chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--ph-border-strong);
  background: var(--ph-bg);
  border-radius: 18px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.ph-chat-panel.is-expanded .ph-chat-input-wrap {
  padding: 10px 10px 10px 18px;
  border-radius: 22px;
  box-shadow: 0 8px 24px -12px rgba(0, 14, 43, 0.18);
}

.ph-chat-input-wrap:focus-within {
  border-color: var(--ph-electric);
  box-shadow: 0 0 0 3px rgba(91, 192, 235, 0.20);
}

.ph-chat-input {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ph-text);
  font: inherit;
  font-size: 14.5px;
  line-height: 1.5;
  padding: 6px 0;
  max-height: 140px;
}

.ph-chat-panel.is-expanded .ph-chat-input {
  font-size: 16px;
  max-height: 200px;
  padding: 8px 0;
}

.ph-chat-input::placeholder {
  color: var(--ph-text-faint);
}

.ph-chat-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 9999px;
  background: var(--ph-electric);
  color: var(--ph-navy);
  transition: transform 160ms ease, opacity 160ms ease;
  flex-shrink: 0;
}

.ph-chat-panel.is-expanded .ph-chat-send {
  width: 40px;
  height: 40px;
}

.ph-chat-send:hover:not(:disabled) {
  transform: scale(1.05);
}

.ph-chat-send svg {
  width: 16px;
  height: 16px;
}

.ph-chat-panel.is-expanded .ph-chat-send svg {
  width: 18px;
  height: 18px;
}

.ph-chat-send:disabled,
.ph-chat-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ph-chat-send.is-loading svg {
  animation: ph-chat-spin 1s linear infinite;
}

@keyframes ph-chat-spin {
  to { transform: rotate(360deg); }
}

.ph-chat-hint {
  margin-top: 8px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--ph-text-faint);
  font-family: "Geist Mono", ui-monospace, monospace;
  letter-spacing: 0.04em;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .ph-chat-widget *,
  .ph-chat-widget *::before,
  .ph-chat-widget *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .ph-chat-messages { scroll-behavior: auto; }
}
