/**
 * Ask — floating ask strip (extractable from Guide)
 * Scope: under .ask-wrap / .tutor.ask
 * Compact: CTA button + mic only (no "Ask" title header)
 * Open: field/wave + mic; thread (Q+A) above when present
 */

.ask-wrap {
  /* Align with Guide / Nav via shell --float-* tokens */
  --guide-ink: var(--ink, #1a1a1a);
  --guide-btn-fill: var(--float-btn-fill, rgb(255 255 255 / 0.7));
  --ask-control-h: var(--float-control-h, var(--touch, 44px));
  --ask-stroke: var(--float-stroke, 2px);
  --ask-label-size: var(--float-label-size, 0.85rem);
  --ask-icon: var(--float-icon, 20px);
  /* compose width from shell :root --ask-compose-w */
  width: 100%;
  min-width: 0;
}

.tutor {
  flex-shrink: 0;
  /* Same surface pad as nav/guide so row heights match */
  padding: var(--float-pad-y, 0.45rem) var(--float-pad-x, 0.55rem);
  border-top: none;
  display: flex;
  flex-direction: column;
  gap: var(--float-control-gap, 0.4rem);
  min-width: 0;
  box-sizing: border-box;
  /* Whole Ask card: chat + compose, cap at half viewport */
  max-height: 50vh;
}
.tutor:has(.tutor-thread:not([hidden]):not(:empty)) {
  padding: var(--float-pad-y, 0.45rem) var(--float-pad-x, 0.55rem);
}

/* Multi-turn chat above compose — scroll, never erase prior turns */
.tutor-thread {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* Thread itself may use most of the 50vh card (compose stays pinned bottom) */
  max-height: calc(50vh - 4.5rem);
  padding: 0.1rem 0.05rem 0.15rem;
  scrollbar-width: thin;
}
.tutor-thread[hidden],
.tutor-thread:empty {
  display: none !important;
}

/* One Q+A pair in the chat */
.tutor-turn {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex-shrink: 0;
}
.tutor-question {
  margin: 0;
  padding: 0.5rem 0.65rem;
  border-radius: 12px;
  background: rgb(47 95 154 / 0.1);
  border: 1px solid rgb(47 95 154 / 0.22);
  font-size: 0.88rem;
  line-height: 1.4;
  font-weight: 600;
  color: var(--guide-ink);
  white-space: pre-wrap;
  word-break: break-word;
}
.tutor-answer {
  margin: 0;
  padding: 0.55rem 0.65rem;
  border-radius: 12px;
  background: rgb(45 173 113 / 0.12);
  border: 1px solid rgb(45 173 113 / 0.28);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--guide-ink);
  white-space: pre-wrap;
  word-break: break-word;
}
.tutor-answer:empty {
  display: none;
}
.tutor-answer.is-pending:empty {
  display: block;
  min-height: 1.2em;
  opacity: 0.65;
}
.tutor-status[hidden] {
  display: none !important;
}

/*
 * Compose always at bottom: [ Ask about this slide | field/wave ] + mic RIGHT.
 * Idle compact: CTA + mic. Open: field + mic. Dictate: wave + mic→send.
 */
.tutor-compose-row {
  display: flex;
  align-items: center;
  gap: var(--float-control-gap, 0.4rem);
  flex-shrink: 0;
  margin-top: auto;
  box-sizing: border-box;
  /* Fixed width open/closed — no jump; height from --float-control-h */
  width: var(--ask-compose-w, 12.5rem);
  min-width: var(--ask-compose-w, 12.5rem);
  max-width: var(--ask-compose-w, 12.5rem);
  margin-left: auto; /* pin to right edge of dock */
}
.tutor-open {
  box-sizing: border-box;
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--ask-control-h);
  height: var(--ask-control-h);
  padding: 0 0.65rem;
  border-radius: var(--radius-pill, 999px);
  border: var(--ask-stroke) solid var(--guide-ink);
  background: var(--guide-btn-fill);
  color: var(--guide-ink);
  font-weight: var(--float-label-weight, 700);
  font-size: var(--ask-label-size);
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.tutor-open:hover {
  background: rgb(255 255 255 / 0.85);
}
.tutor[data-open="true"] .tutor-open {
  display: none;
}

.tutor-field-slot {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  /* Same flex slot as .tutor-open so width stays put when swapping */
  width: auto;
  max-width: none;
  min-height: var(--ask-control-h);
  overflow: hidden;
  display: none;
}
.tutor[data-open="true"] .tutor-field-slot {
  display: block;
}
.tutor-field-slot[hidden] {
  display: none !important;
}
.tutor[data-open="true"] .tutor-field-slot:not([hidden]) {
  display: block;
}
.tutor-field-slot.is-bar {
  height: var(--ask-control-h);
  max-height: var(--ask-control-h);
}
.tutor-field-slot.is-bar .tutor-input {
  transform: translateX(-110%);
  opacity: 0;
  pointer-events: none;
  height: var(--ask-control-h);
  max-height: var(--ask-control-h);
}
.tutor-input {
  box-sizing: border-box;
  display: block;
  width: 100%;
  min-width: 0;
  min-height: var(--ask-control-h);
  max-height: 5.5rem;
  margin: 0;
  padding: 0.55rem 0.75rem;
  /* Single pill stroke only — no nested outer corners */
  border: var(--ask-stroke) solid var(--guide-ink);
  border-radius: var(--radius-pill, 999px);
  background: rgb(255 255 255 / 0.92);
  color: var(--guide-ink);
  font-family: inherit;
  font-size: var(--text-input, 1rem);
  line-height: 1.4;
  resize: none;
  field-sizing: content;
  overflow-y: auto;
  box-shadow: none;
  outline: none;
  transition:
    border-radius 0.12s ease,
    transform 0.28s cubic-bezier(0.32, 0.72, 0, 1),
    opacity 0.22s ease;
  -webkit-appearance: none;
  appearance: none;
}
.tutor-input:focus,
.tutor-input:focus-visible {
  outline: none;
  border-color: var(--guide-ink);
  box-shadow: none;
  background: #fff;
}
.tutor-input:disabled {
  opacity: 0.7;
}

.tutor-wave-bar {
  box-sizing: border-box;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  height: var(--ask-control-h);
  min-height: var(--ask-control-h);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 0.55rem;
  border-radius: var(--radius-pill, 999px);
  background: var(--ink, #1a1a1a);
  border: var(--ask-stroke) solid var(--ink, #1a1a1a);
  opacity: 0;
  transform: translateX(16%);
  pointer-events: none;
  z-index: 2;
  transition:
    transform 0.28s cubic-bezier(0.32, 0.72, 0, 1),
    opacity 0.2s ease;
}
.tutor-wave-bar.is-on {
  display: flex;
  opacity: 1;
  transform: translateX(0);
}
.tutor-wave-bar[hidden] {
  display: none !important;
}
.tutor-wave {
  display: block;
  width: 100%;
  height: 28px;
  max-height: 100%;
  pointer-events: none;
}
.tutor-wave-label {
  display: none;
  width: 100%;
  margin: 0;
  padding: 0 0.25rem;
  color: var(--white, #fff);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.tutor-wave-bar[data-mode="label"] .tutor-wave {
  display: none !important;
}
.tutor-wave-bar[data-mode="label"] .tutor-wave-label {
  display: block;
}
.tutor-wave-bar[data-mode="label"] .tutor-wave-label[hidden] {
  display: none !important;
}

.tutor-mic {
  box-sizing: border-box;
  flex-shrink: 0;
  width: var(--ask-control-h);
  height: var(--ask-control-h);
  min-width: var(--ask-control-h);
  min-height: var(--ask-control-h);
  padding: 0;
  border-radius: var(--radius-pill, 999px);
  border: var(--ask-stroke) solid var(--guide-ink);
  background: var(--guide-btn-fill);
  color: var(--guide-ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.tutor-mic-face {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.tutor-mic-face[hidden] {
  display: none !important;
}
.tutor-mic svg {
  width: var(--ask-icon);
  height: var(--ask-icon);
  display: block;
}
.tutor-mic:hover {
  background: rgb(255 255 255 / 0.85);
}
.tutor-mic[data-mode="send"],
.tutor-mic[data-mode="listening"],
.tutor-mic[aria-pressed="true"] {
  background: var(--guide-ink);
  border-color: var(--guide-ink);
  color: var(--white, #fff);
  animation: none;
  box-shadow: none;
}
.tutor-mic[data-mode="send"]:hover,
.tutor-mic[data-mode="listening"]:hover {
  background: var(--guide-ink);
  opacity: 0.95;
}
.tutor-mic:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tutor-status {
  margin: 0;
  flex-shrink: 0;
  font-size: var(--text-sm, 0.8rem);
  line-height: 1.35;
  color: var(--muted, #4a463f);
  font-style: italic;
}
.tutor-status.is-error {
  color: var(--amber, #b45309);
  font-style: normal;
}

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