/* The conversation shares the viewport with the reader. Its measured height
   reserves enough scroll space to bring the last line above the mobile dock. */
body:has(#ana-avda-mini:not([hidden])) {
  padding-bottom: var(--ana-avda-height, 6rem);
}
html:has(#ana-avda-mini:not([hidden])) {
  scroll-padding-bottom: calc(var(--ana-avda-height, 6rem) + 1rem);
}
#ana-avda-mini {
  max-height: min(56dvh, 38rem, calc(var(--ana-avda-viewport-height, 100dvh) - 1rem));
  bottom: var(--ana-avda-keyboard, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#ana-avda-mini[data-min] header[data-mini-chrome] {
  display: none;
}
#ana-avda-mini[data-min] form {
  margin-top: 0;
  margin-bottom: 0.75rem;
}
#persistent-audio-player:not([hidden]) ~ #ana-avda-mini {
  bottom: calc(5rem + var(--ana-avda-keyboard, 0px));
  max-height: min(56dvh, calc(var(--ana-avda-viewport-height, 100dvh) - 6rem));
}
body:has(#ana-avda-mini:not([hidden])):has(#persistent-audio-player:not([hidden])) {
  padding-bottom: calc(var(--ana-avda-height, 6rem) + 5rem);
}

/* The keyboard replaces the space for the audio player and home indicator. */
@media (max-width: 1023px) {
  #ana-avda-mini[data-keyboard],
  #persistent-audio-player:not([hidden]) ~ #ana-avda-mini[data-keyboard] {
    bottom: var(--ana-avda-keyboard, 0px);
    max-height: min(56dvh, calc(var(--ana-avda-viewport-height, 100dvh) - 1rem));
    padding-bottom: 0;
  }
  #ana-avda-mini[data-keyboard] form {
    margin-bottom: 0.5rem;
  }
}

@media (min-width: 1024px) {
  body:has(#ana-avda-mini:not([hidden])) {
    padding-right: 24rem;
    padding-bottom: 0;
  }
  html:has(#ana-avda-mini:not([hidden])) {
    scroll-padding-bottom: 1rem;
  }
  #ana-avda-mini,
  #persistent-audio-player:not([hidden]) ~ #ana-avda-mini {
    top: 0;
    bottom: 0;
    left: auto;
    right: 0;
    width: 24rem;
    height: 100dvh;
    max-height: none;
  }
  body:has(#ana-avda-mini:not([hidden])) #persistent-audio-player {
    right: 24rem;
  }
  body:has(#ana-avda-mini:not([hidden])):has(#persistent-audio-player:not([hidden])) {
    padding-bottom: 5rem;
  }
  #ana-avda-mini[data-min] header[data-mini-chrome] {
    display: flex;
  }
  #ana-avda-mini[data-min] form {
    margin-top: auto;
  }
}

@media print {
  #ana-avda-mini { display: none !important; }
  body:has(#ana-avda-mini:not([hidden])) {
    padding: 0 !important;
  }
}

/* One conversation surface: the header and composer frame a single scrolling
   thread in every size. The original search control returns to its slot on close. */
.ana-avda-panel {
  height: min(76dvh, 56rem);
  min-height: min(28rem, 76dvh);
  container-type: inline-size;
}
.ana-avda-panel[data-full] {
  position: fixed;
  inset: 0;
  z-index: 60;
  top: var(--chat-viewport-top, 0px);
  bottom: auto;
  height: var(--chat-viewport-height, 100dvh);
  margin: 0;
  border: 0;
  border-radius: 0;
}
.ana-avda-panel[data-full] .ana-avda-composer {
  width: 100%;
  max-width: 76rem;
  align-self: center;
}
.ana-avda-turns {
  container-type: inline-size;
  scroll-behavior: smooth;
  scroll-padding-block: 1rem;
}
.ana-avda-turns > section {
  max-width: 76rem;
  margin-inline: auto;
  scroll-margin-top: 1rem;
}
[data-chat] .ana-avda-composer {
  flex-shrink: 0;
  padding: 0.75rem 1rem max(1rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-subtle);
  background: white;
}
[data-chat] .ana-avda-composer [data-search-reveal-target="button"] {
  display: none;
}
[data-chat] .ana-avda-composer [data-chat-input-shell] {
  height: 3.25rem;
  border-radius: 1.5rem;
  box-shadow: none;
}
[data-chat] .ana-avda-composer button[type="submit"] {
  border-radius: 999px;
}
[data-chat] .ana-avda-composer input {
  border-radius: inherit;
}
[data-chat] .ana-avda-note {
  order: 2;
  padding-top: 0;
  text-align: center;
}
[data-chat] .ana-avda-composer {
  order: 1;
}
[data-sidebar] > .ana-avda-panel {
  position: fixed;
  inset: auto 0 var(--chat-keyboard-offset, 0px);
  z-index: 55;
  margin: 0;
  height: min(60dvh, 38rem, calc(var(--chat-viewport-height, 100dvh) - 1rem));
  min-height: 0;
  border-radius: 1.25rem 1.25rem 0 0;
}
/* Reveal today's content again while keeping this very same thread docked. */
[data-chat][data-sidebar] > [data-chat-home-content] {
  display: block;
}
@media (min-width: 768px) {
  [data-chat][data-sidebar] > div[data-chat-home-content] { display: flex; }
}
@media (min-width: 1024px) {
  body:has([data-chat][data-sidebar]) { padding-right: 24rem; }
  [data-sidebar] > .ana-avda-panel {
    inset: 0 0 0 auto;
    width: 24rem;
    height: 100dvh;
    border-radius: 0;
  }
}
@media (max-width: 1023px) {
  body:has([data-chat][data-sidebar]) { padding-bottom: 61dvh; }
}
@container (max-width: 28rem) {
  [data-chat-control-label], [data-ana-avda-chat-target="count"] { display: none; }
}
/* Source columns respond to the conversation's width, including the sidebar. */
#ana-avda-mini-content { container-type: inline-size; }
@container (max-width: 52rem) {
  [data-seforim-answer-target="layout"] { grid-template-columns: minmax(0, 1fr); }
  [data-seforim-answer-target="sources"] { position: static; max-height: none; }
}
@media (prefers-reduced-motion: no-preference) {
  #ana-avda-mini:not([hidden]) { animation: ana-avda-dock-in 260ms cubic-bezier(0.22, 1, 0.36, 1); }
  @keyframes ana-avda-dock-in {
    from { opacity: 0; }
    to { opacity: 1; }
  }
}
@media (prefers-reduced-motion: reduce) {
  .ana-avda-turns { scroll-behavior: auto; }
}
