/* ==========================================================================
   Chat assistant

   The page's two voices carry straight into the conversation. The assistant
   speaks under a machine tag with a violet rule; the parent's answer comes
   back in the human voice with a coral rule. No bubbles: the tag and the rule
   already say who is talking.
   ========================================================================== */

/* --- Launcher --------------------------------------------------------------
   The same prompt chip as in the hero film, so it needs no explaining.
   Solid ink rather than the chip's translucent fill: over the light sections
   the translucent version dropped the violet text below AA. */
.chat-launcher {
  position: fixed;
  right: max(var(--gutter), env(safe-area-inset-right));
  bottom: max(var(--space-3), env(safe-area-inset-bottom));
  z-index: 90;
  background: var(--ink);
  box-shadow: 0 0.75rem 2rem color-mix(in srgb, var(--ink) 35%, transparent);
}

.chat-launcher::before {
  content: "> ";
  opacity: 0.6;
}

/* --- Pricing card entry ------------------------------------------------------
   Secondary to "Выбрать …": a text button, so the card keeps one main action. */
.tariff__help {
  align-self: center;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 0;
  background: none;
  color: var(--fg-muted);
  font-size: var(--step-small);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

.tariff__help:hover {
  color: var(--fg);
}

/* --- Panel ------------------------------------------------------------------ */
.chat {
  position: fixed;
  inset: auto var(--space-3) var(--space-3) auto;
  width: min(26rem, 100vw - var(--space-3) * 2);
  height: min(42rem, 100dvh - var(--space-3) * 2);
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}

.chat[open] {
  animation: chat-in var(--dur) var(--ease);
}

@keyframes chat-in {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }
}

.chat::backdrop {
  background: color-mix(in srgb, var(--ink) 45%, transparent);
}

html:has(.chat[open]) {
  overflow: hidden;
}

.chat__frame {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--hairline);
}

.chat__title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.125rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.chat__subtitle {
  margin-top: 0.25rem;
  font-size: var(--step-small);
  color: var(--fg-muted);
}

.chat__close {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  background: none;
  color: var(--fg);
  cursor: pointer;
}

.chat__close:hover {
  border-color: var(--fg-muted);
}

.chat__log {
  position: relative;
  flex: 1;
  display: grid;
  align-content: start;
  gap: var(--space-3);
  padding: var(--space-3);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--hairline) transparent;
}

.chat__footer {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--hairline);
}

.chat__composer {
  display: flex;
  gap: var(--space-1);
}

.chat__input {
  flex: 1;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  background: var(--bg-raised);
  color: var(--fg);
}

.chat__input::placeholder {
  color: var(--fg-muted);
}

.chat__send {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--catch);
  color: var(--ink);
  cursor: pointer;
}

.chat__send:disabled {
  opacity: 0.5;
  cursor: progress;
}

.chat__footer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
}

.chat__menu {
  min-height: 2.75rem;
  padding: 0.5rem 1.25rem;
  font-size: var(--step-small);
}

.chat__note {
  flex: 1 1 12rem;
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--fg-muted);
}

/* --- Turns ------------------------------------------------------------------ */
.chat__turn--bot {
  display: grid;
  gap: var(--space-2);
  padding-left: var(--space-2);
  border-left: 2px solid color-mix(in srgb, var(--fg-machine) 55%, transparent);
}

/* The turn takes focus only so a screen reader starts reading the answer.
   It is not a control, and a ring around the whole answer read as a selection. */
.chat__turn--bot:focus {
  outline: none;
}

.chat__turn--user {
  justify-self: end;
  max-width: 85%;
  padding-right: var(--space-2);
  border-right: 2px solid var(--catch);
  text-align: right;
  font-weight: 600;
}

.chat__text {
  white-space: pre-line;
  line-height: 1.55;
}

.chat__choices {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

/* Offered by the machine, said by the person: violet outline, human type. */
.chat-chip {
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid color-mix(in srgb, var(--fg-machine) 50%, transparent);
  border-radius: var(--radius-pill);
  background: none;
  color: var(--fg);
  font-size: var(--step-small);
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition:
    border-color var(--dur-fast) var(--ease),
    background-color var(--dur-fast) var(--ease);
}

.chat-chip:hover {
  border-color: var(--fg-machine);
  background: color-mix(in srgb, var(--fg-machine) 12%, transparent);
}

.chat__link {
  justify-self: start;
}

/* --- Tariff card and quote ---------------------------------------------------- */
.chat-card,
.chat-quote {
  display: grid;
  gap: 0.25rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-input);
  background: var(--bg-raised);
}

.chat-card__title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.chat-card__meta {
  font-family: var(--font-mono);
  font-size: var(--step-mono);
  letter-spacing: 0.04em;
  color: var(--fg-muted);
}

.chat-card__price {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.chat-quote__title {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 var(--space-2);
}

.chat-quote__schedule {
  font-size: var(--step-small);
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

/* --- Forms ------------------------------------------------------------------ */
.chat-form {
  display: grid;
  gap: var(--space-2);
}

.chat-form .btn {
  justify-self: start;
}

.chat-form input[aria-invalid="true"] {
  border-color: var(--fg-accent);
}

.chat-form__error {
  font-size: var(--step-small);
  color: var(--fg-accent);
}

.chat-form__error:empty {
  display: none;
}

/* --- Phones ------------------------------------------------------------------ */
@media (max-width: 40rem) {
  .chat {
    inset: 0;
    width: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }
}
