/**
 * Librarian chat sheet.
 *
 * The draft pinned this 150px from the top of a 720px artboard; here it is a
 * clamped proportion so it stays usable from 667 to 932 tall.
 */

.chat {
  position: absolute;
  inset: 0;
}

.chat__backdrop {
  position: absolute;
  inset: 0;
  background: var(--surface-veil);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  border: 0;
  cursor: pointer;
}

.chat__sheet {
  position: absolute;
  left: 0;
  right: 0;
  top: max(calc(var(--sat) + var(--space-sm)), clamp(56px, 20.8%, 220px));
  /* Sits above the keyboard; --kb is 0 whenever one is not showing. */
  bottom: var(--kb);
  display: flex;
  flex-direction: column;
  padding-inline: var(--space-lg);
  background: var(--gradient-sheet);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: var(--radius-3xl) var(--radius-3xl) 0 0;
  box-shadow: var(--shadow-sheet);
  transition: bottom var(--dur-ui) var(--ease-out);
}

.chat__sheet:focus {
  outline: none;
}

/* While typing, give the sheet the whole frame -- the list is the first thing
   the keyboard would otherwise squeeze out on a short phone. */
:root.is-kb-open .chat__sheet {
  top: calc(var(--sat) + var(--space-sm));
}

.chat__grip {
  flex: none;
  width: 36px;
  height: 4px;
  margin: 9px auto 0;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.22);
}

/* ---- Header ---- */

.chat__head {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 9px 4px 12px;
}

.chat__title {
  margin: 0;
  font-size: var(--fs-2xl);
  font-weight: 500;
  line-height: 1;
  color: #fff;
}

.chat__subtitle {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  letter-spacing: 0.09em;
  line-height: 1;
  color: var(--text-dim);
  padding-top: 2px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat__close {
  position: relative;
  flex: none;
  margin-left: auto;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Keeps the touch target comfortable without enlarging the circle. */
.chat__close::after {
  content: '';
  position: absolute;
  inset: -7px;
}

/* ---- Message list ---- */

.chat__list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 13px;
  overflow-y: auto;
  /* Stops the scroll from chaining out to the page behind the sheet. */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  margin-inline: calc(var(--space-lg) * -1);
  padding: 12px var(--space-lg) var(--space-lg);
  background: var(--surface-scrim);
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

.chat__question {
  flex: none;
  align-self: flex-end;
  max-width: 82%;
  padding: 11px var(--space-lg);
  background: var(--surface-bubble);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-lg) var(--radius-lg) 5px var(--radius-lg);
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--text-primary);
  text-wrap: pretty;
}

.chat__answer {
  flex: none;
  padding-inline: 2px;
  font-size: var(--fs-md);
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.85);
  text-wrap: pretty;
}

/* ---- Clip results ---- */

.clip {
  flex: none;
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  border: 0;
  cursor: pointer;
}

.clip--featured {
  background: var(--gradient-accent);
  border-radius: var(--radius-md);
  padding: 12px 13px;
  box-shadow: var(--shadow-clip), 0 0 0 5px var(--accent-faint);
}

.clip--featured .clip__meta {
  color: var(--text-on-accent-dim);
}

.clip__meta {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  font-weight: 500;
  line-height: 1;
  letter-spacing: var(--track-wide);
}

.clip__row {
  display: flex;
  gap: var(--space-md);
  margin-top: 5px;
}

.clip--featured .clip__text {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-lg);
  line-height: 1.4;
  color: var(--text-on-accent);
  text-wrap: pretty;
}

.clip__thumb {
  flex: none;
  align-self: center;
  width: 84px;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  /* Stand-in until real thumbnails are wired. */
  background: linear-gradient(150deg, #3a3a34, #17171a 60%, #26262c);
  box-shadow: 0 0 0 1px rgba(10, 10, 9, 0.25);
}

.clip__jump {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
  padding: 5px 10px;
  background: var(--on-accent);
  border-radius: var(--radius-pill);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  font-weight: 500;
  letter-spacing: var(--track-wider);
}

.clip--compact {
  background: none;
  padding: 2px;
}

.clip__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-sm);
}

.clip--compact .clip__meta {
  color: var(--accent);
}

.clip__chevron {
  flex: none;
  font-family: var(--font-mono);
  font-size: var(--fs-3xs);
  font-weight: 500;
  letter-spacing: var(--track-wider);
  color: var(--text-faint);
}

.clip--compact .clip__text {
  display: block;
  margin-top: 5px;
  font-size: var(--fs-md);
  line-height: 1.4;
  color: var(--text-secondary);
  text-wrap: pretty;
}

/* ---- Composer ---- */

.chat__composer {
  flex: none;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 2px;
  /* Clears the home indicator when no keyboard is covering it. */
  padding-bottom: max(var(--space-xl), calc(var(--sab) + var(--space-sm)));
}

:root.is-kb-open .chat__composer {
  padding-bottom: var(--space-xl);
}

.chat__input {
  flex: 1;
  min-width: 0;
  padding: 13px var(--space-lg);
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 23px;
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1;
  color: #fff;
}

.chat__input::placeholder {
  color: var(--text-dim);
}

.chat__input:focus {
  outline: none;
  border-color: var(--accent-line);
}

.chat__send {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: #e9e7df;
  color: var(--on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
