/* player-kit — the chat sheet.
 *
 * Loaded alongside player.css, which supplies the design tokens. Everything here
 * is prefixed .pk-chat so a host's own styles cannot collide with it.
 */

#pk-chat {
  position: fixed;
  inset: 0;
  /* --z-player-sheet (1100), not --z-overlay-sheet (1000): the TTS full-screen
   * panel sits at 1001, so the chat sheet opened over it was drawn underneath
   * the thing it was opened from. Every other bottom sheet uses this layer. */
  z-index: var(--z-player-sheet);
  background: rgba(8, 9, 16, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#pk-chat[hidden] {
  display: none;
}

/* While the sheet is open the page behind it must not scroll — on iOS a
 * scrolling background under a fixed overlay is the classic way to end up
 * somewhere unexpected when it closes. */
.pk-chat-open,
.pk-chat-open body {
  overflow: hidden;
}

.pk-chat-inner {
  width: 100%;
  max-width: 44rem;
  height: 88vh;
  /* dvh where supported: on mobile Safari, vh includes the collapsing URL bar,
   * so a 88vh sheet puts its composer under the browser chrome. */
  height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg, #0c0e14);
  color: var(--color-text);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
  border: 1px solid var(--color-border);
  border-bottom: 0;
  overflow: hidden;
}

.pk-chat-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  flex: none;
}
.pk-chat-heading {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pk-chat-sub {
  color: var(--color-text-faint);
  font-size: 0.85rem;
}
.pk-chat-close {
  background: none;
  border: 0;
  color: var(--color-text-faint);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  flex: none;
}
.pk-chat-close:hover {
  color: var(--color-text);
}

/* ── What the model is working from ─────────────────────────────────────── */

.pk-chat-context {
  flex: none;
  padding: var(--space-3) var(--space-4) 0;
}
.pk-chat-note {
  display: flex;
  align-items: flex-start;
  gap: 0.45em;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--color-text-faint);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.65rem;
}
.pk-chat-note svg {
  flex: none;
  margin-top: 0.15em;
}
/* An excerpt is not an error, but it changes what the answer is worth — so it
 * is tinted rather than left to read as ordinary chrome. */
.pk-chat-note.is-partial {
  color: var(--color-primary-text);
  border-color: color-mix(in srgb, var(--color-primary) 35%, transparent);
}
.pk-chat-note.is-empty {
  color: var(--color-text);
}
.pk-chat-linkbtn {
  background: none;
  border: 0;
  color: var(--color-primary-text);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
}

.pk-chat-scope {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.pk-chat-scope button {
  flex: 1;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-faint);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.6rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.pk-chat-scope button[aria-pressed='true'] {
  color: var(--color-text);
  border-color: var(--color-primary);
  background: var(--color-surface-2);
}

.pk-chat-paste {
  margin-top: var(--space-2);
  font-size: 0.85rem;
}
.pk-chat-paste summary {
  cursor: pointer;
  color: var(--color-primary-text);
}
.pk-chat-paste textarea {
  width: 100%;
  margin: var(--space-2) 0;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.5rem;
  font: inherit;
  font-size: 0.85rem;
}
.pk-chat-paste button {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.8rem;
  cursor: pointer;
}
.pk-chat-hint {
  color: var(--color-text-faint);
  font-size: 0.8rem;
  line-height: 1.5;
  margin: 0.35rem 0;
}

/* ── The conversation ───────────────────────────────────────────────────── */

.pk-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  -webkit-overflow-scrolling: touch;
}
.pk-chat-log:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}
.pk-chat-empty {
  color: var(--color-text-faint);
  font-size: 0.9rem;
  line-height: 1.6;
  margin: auto 0;
  text-align: center;
}
.pk-chat-empty p {
  margin: 0 0 0.5rem;
}

.pk-chat-msg.is-user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--color-surface-2);
  border-radius: var(--radius-lg);
  padding: 0.6rem 0.8rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.pk-chat-msg.is-ai {
  max-width: 100%;
}
.pk-chat-body {
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.pk-chat-body > :first-child {
  margin-top: 0;
}
.pk-chat-body > :last-child {
  margin-bottom: 0;
}
.pk-chat-body h3,
.pk-chat-body h4,
.pk-chat-body h5,
.pk-chat-body h6 {
  margin: 1.1em 0 0.4em;
  line-height: 1.3;
}
.pk-chat-body h3 {
  font-size: 1.08rem;
}
.pk-chat-body h4 {
  font-size: 1rem;
}
.pk-chat-body p,
.pk-chat-body ul,
.pk-chat-body ol {
  margin: 0 0 0.75em;
}
.pk-chat-body li {
  margin-bottom: 0.3em;
}
.pk-chat-body blockquote {
  margin: 0 0 0.75em;
  padding-left: 0.9em;
  border-left: 2px solid var(--color-border);
  color: var(--color-text-faint);
}
.pk-chat-body code {
  background: var(--color-surface-2);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.35em;
  font-size: 0.9em;
}
.pk-chat-body pre {
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  padding: 0.7rem;
  overflow-x: auto;
}
.pk-chat-body pre code {
  background: none;
  padding: 0;
}
.pk-chat-body hr {
  border: 0;
  border-top: 1px solid var(--color-divider);
  margin: 1em 0;
}
.pk-chat-body a {
  color: var(--color-primary-text);
}

/* Waiting for the first token. Three dots rather than a spinner because it
 * sits inline where the text will appear, so nothing jumps when it does. */
.pk-chat-dots i {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 4px;
  border-radius: 50%;
  background: var(--color-text-faint);
  animation: pk-chat-blink 1.2s infinite ease-in-out;
}
.pk-chat-dots i:nth-child(2) {
  animation-delay: 0.15s;
}
.pk-chat-dots i:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes pk-chat-blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}
@media (prefers-reduced-motion: reduce) {
  .pk-chat-dots i {
    animation: none;
    opacity: 0.6;
  }
}

.pk-chat-acts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.pk-chat-acts button {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text-faint);
  border-radius: var(--radius-full);
  padding: 0.25rem 0.7rem;
  font-size: 0.78rem;
  cursor: pointer;
}
.pk-chat-acts button:hover {
  color: var(--color-text);
  border-color: var(--color-primary);
}

/* ── Composer ───────────────────────────────────────────────────────────── */

.pk-chat-composer {
  flex: none;
  padding: var(--space-3) var(--space-4);
  padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--color-divider);
  background: var(--color-surface);
}
.pk-chat-starters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.pk-chat-starters:empty {
  display: none;
}
.pk-chat-starters button {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: var(--radius-full);
  padding: 0.3rem 0.75rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.pk-chat-starters button:hover {
  border-color: var(--color-primary);
}
.pk-chat-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}
.pk-chat-row textarea {
  flex: 1;
  resize: none;
  /* 16px minimum: anything smaller makes iOS Safari zoom the page on focus. */
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 0.55rem 0.75rem;
  max-height: 160px;
  overflow-y: auto;
}
.pk-chat-row textarea:focus-visible {
  outline: none;
  border-color: var(--color-primary);
}
.pk-chat-send {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--color-primary);
  color: #1c1810;
  cursor: pointer;
}
.pk-chat-send:disabled {
  opacity: 0.45;
  cursor: default;
}

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

@media (min-width: 46rem) {
  .pk-chat-inner {
    height: 82dvh;
    margin-bottom: 4vh;
    border-radius: var(--radius-xl);
    border-bottom: 1px solid var(--color-border);
  }
  #pk-chat {
    align-items: center;
  }
}
