/* ==========================================================================
   ai.css — the AI assistant panel (js/ai.js)
   Desktop: a glass panel docked on the right. From 1500px the app steps
   aside (body.ai-open) so the page stays fully usable; below that the
   panel floats over the page. Phone: a full-height sheet from the bottom.
   ========================================================================== */
:root {
  --ai-w: 28rem;
  /* the assistant's colour: the wallpaper's accent flowing into violet, pink and amber */
  --ai-grad: conic-gradient(from 210deg, var(--accent), #8b7bff, #ff8fb1, #ffc56b, var(--accent));
}

/* ------------------------------------------------- the app steps aside -- */
.app {
  transition: padding-right 0.6s var(--ease);
}
@media (min-width: 1500px) {
  body.ai-open .app {
    padding-right: calc(var(--ai-w) + clamp(1rem, 3.2vw, 4.5rem));
  }
  /* the page is narrower now — use the laptop layouts */
  body.ai-open .g-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  body.ai-open .g-3 > :last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
  body.ai-open .g-props {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* ------------------------------------------------------------- panel -- */
.ai {
  position: fixed;
  z-index: 90;
  top: 1.375rem;
  bottom: 1.375rem;
  right: clamp(.75rem, 3.2vw, 4.5rem);
  width: var(--ai-w);
  display: flex;
  flex-direction: column;
  border-radius: 2rem;
  background: linear-gradient(160deg, var(--sheen), transparent 40%), var(--glass-strong);
  backdrop-filter: blur(44px) saturate(1.7);
  -webkit-backdrop-filter: blur(44px) saturate(1.7);
  border: 1px solid var(--edge);
  box-shadow: 0 2.5rem 6.25rem -1.875rem rgb(0 0 0 / 0.55);
  color: var(--ink);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none; /* while it fades out, clicks go to the page underneath */
  transform: translateX(2.5rem) scale(0.98);
  transition:
    transform 0.6s var(--ease),
    opacity 0.35s,
    visibility 0s 0.6s;
}
.ai.on {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition:
    transform 0.6s var(--ease),
    opacity 0.35s,
    visibility 0s;
}
.ai-grab {
  display: none;
}

.ai-head {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.125rem .875rem .875rem 1.125rem;
}
.ai-title {
  flex: 1;
  min-width: 0;
}
.ai-title h3 {
  font-size: 1.0625rem;
  font-weight: 650;
  letter-spacing: -0.2px;
}
.ai-title p {
  display: flex;
  align-items: center;
  gap: .375rem;
  font-size: .75rem;
  color: var(--muted);
}
.ai-title p span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-live {
  width: .4375rem;
  height: .4375rem;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--green);
  --accent: var(--green);
  animation: pulse 2.4s infinite;
}

/* the orb — avatar of the assistant */
.ai-orb {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow:
    inset 0 0 0 1px rgb(255 255 255 / 0.35),
    0 .5rem 1.25rem -.5rem color-mix(in srgb, var(--accent) 80%, transparent);
}
.ai-orb::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--ai-grad);
}
.ai-orb.sm {
  width: 2rem;
  height: 2rem;
}
.ai-orb.xl {
  width: 4.75rem;
  height: 4.75rem;
}
/* the colours slowly flow around the big orb */
.ai-orb.xl::before {
  inset: -25%;
  animation: spin 7s linear infinite;
}

/* «Розмова про об’єкт» */
.ai-ctx {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin: 0 .875rem .5rem;
  padding: .375rem;
  border-radius: 1.125rem;
  background: var(--soft);
  box-shadow: inset 0 0 0 1px var(--line);
}
.ai-ctx[hidden] {
  display: none;
}
.ai-ctx-link {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .625rem;
  border-radius: .75rem;
}
.ai-ctx img {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: .75rem;
  object-fit: cover;
}
.ai-ctx-link span {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.ai-ctx small {
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--muted);
}
.ai-ctx b {
  font-size: .8125rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-ctx .icon-btn {
  width: 2.125rem;
  height: 2.125rem;
}

/* --------------------------------------------------------- messages -- */
.ai-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: .5rem 1rem 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}
.ai-msgs {
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
  min-height: 100%;
}
.ai-msgs.is-empty {
  gap: .875rem;
}

.ai-hello {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  padding: 1.5rem .5rem .5rem;
  text-align: center;
}
.ai-hello h4 {
  margin-top: .875rem;
  font-size: 1.375rem;
  font-weight: 650;
  letter-spacing: -0.4px;
}
.ai-hello p {
  max-width: 19rem;
  font-size: .8438rem;
  color: var(--muted);
}
.ai-sugs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .5rem;
}
.ai-sug {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: .625rem;
  min-height: 5.25rem;
  padding: .8125rem .875rem;
  border-radius: 1.125rem;
  background: var(--soft);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: .8438rem;
  font-weight: 550;
  line-height: 1.3;
  text-align: left;
  transition:
    background-color 0.25s,
    transform 0.3s var(--spring);
}
.ai-sug:hover {
  background: var(--soft-2);
}
.ai-sug:active {
  transform: scale(0.97);
}
.ai-sug .ic {
  color: var(--accent);
}

.msg {
  display: flex;
  gap: .625rem;
  min-width: 0;
}
.msg.me {
  justify-content: flex-end;
}
.msg.me p {
  max-width: 85%;
  padding: .625rem .9375rem;
  border-radius: 1.25rem 1.25rem .375rem 1.25rem;
  background: var(--solid);
  color: var(--on-solid);
  font-size: .875rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.msg-text {
  padding-top: .3125rem;
  font-size: .875rem;
  line-height: 1.55;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}
.msg-text p + p {
  margin-top: .625rem;
}
.msg-text b {
  color: var(--ink);
  font-weight: 650;
}
/* a soft dot rides the end of the text while it streams in */
.msg-text.streaming p:last-child::after {
  content: '';
  display: inline-block;
  width: .5rem;
  height: .5rem;
  margin-left: .3125rem;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
  animation: pulse 1.2s infinite;
}

.ai-dots {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  height: 2rem;
  padding: 0 .875rem;
  border-radius: 1rem;
  background: var(--soft);
  box-shadow: inset 0 0 0 1px var(--line);
}
.ai-dots i {
  width: .4375rem;
  height: .4375rem;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite both;
}
.ai-dots i:nth-child(2) {
  animation-delay: 0.15s;
}
.ai-dots i:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: none;
  }
  40% {
    opacity: 1;
    transform: translateY(-.1875rem);
  }
}

.ai-cards {
  display: flex;
  flex-direction: column;
  gap: .375rem;
}
.ai-card {
  display: grid;
  grid-template-columns: 2.75rem minmax(0, 1fr) auto;
  align-items: center;
  gap: .75rem;
  padding: .4375rem .875rem .4375rem .4375rem;
  border-radius: 1rem;
  background: var(--soft);
  box-shadow: inset 0 0 0 1px var(--line);
  transition:
    background-color 0.2s,
    transform 0.3s var(--spring);
}
.ai-card:hover {
  background: var(--soft-2);
}
.ai-card:active {
  transform: scale(0.98);
}
.ai-card img,
.ai-card-ic {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: .75rem;
}
.ai-card img {
  object-fit: cover;
}
.ai-card-ic {
  display: grid;
  place-items: center;
  background: var(--soft-2);
}
.ai-card-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.ai-card-main b,
.ai-card-main small {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-card-main b {
  font-size: .8125rem;
  font-weight: 600;
}
.ai-card-main small {
  font-size: .7188rem;
  color: var(--muted);
}
.ai-card-val {
  font-size: .8438rem;
  font-weight: 700;
}

/* answer buttons: pairs of equal width; an odd last one takes the row */
.ai-acts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .5rem;
}
.ai-acts .btn {
  width: 100%;
  min-width: 0;
  padding: 0 .75rem;
}
.ai-acts .btn:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}
.ai-acts .btn span {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------ composer -- */
.ai-form {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  margin: 0 .875rem;
  padding: .3125rem .3125rem .3125rem 1.125rem;
  border-radius: 1.5rem;
  background: var(--soft-2);
  box-shadow: inset 0 0 0 1px var(--line-2);
  transition: box-shadow 0.25s;
}
.ai-form:focus-within {
  box-shadow:
    inset 0 0 0 1.5px var(--ink-2),
    0 0 0 .25rem color-mix(in srgb, var(--accent) 18%, transparent);
}
.ai-form textarea {
  flex: 1;
  min-width: 0;
  max-height: 8rem;
  padding: .625rem 0;
  border: 0;
  background: none;
  resize: none;
  font-size: .9062rem;
  line-height: 1.4;
  color: var(--ink);
}
.ai-form textarea::placeholder {
  color: var(--faint);
}
.ai-send {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--solid);
  color: var(--on-solid);
  transition:
    opacity 0.2s,
    transform 0.3s var(--spring);
}
.ai-send:disabled {
  opacity: 0.3;
}
.ai-send:not(:disabled):active {
  transform: scale(0.9);
}
.ai-note {
  padding: .5625rem 1rem .875rem;
  font-size: .6875rem;
  text-align: center;
  color: var(--faint);
}

/* ------------------------------------------------------------- phone -- */
@media (max-width: 760px) {
  body.ai-open {
    overflow: hidden;
  }
  .ai {
    top: calc(var(--vvt, 0px) + var(--safe-t) + .5rem);
    bottom: auto;
    left: 0;
    right: 0;
    width: 100%;
    height: calc(var(--vvh, 100dvh) - var(--safe-t) - .5rem);
    border-radius: 1.875rem 1.875rem 0 0;
    border-bottom: 0;
    padding-bottom: var(--safe-b);
    transform: translateY(100%);
  }
  .ai.on {
    transform: none;
  }
  .ai-grab {
    display: flex;
    justify-content: center;
    padding-top: .625rem;
    touch-action: none;
  }
  .ai-grab i {
    width: 2.5rem;
    height: .3125rem;
    border-radius: .1875rem;
    background: var(--faint);
  }
  .ai-head {
    padding: .5rem .625rem .75rem 1rem;
    touch-action: none;
  }
  .ai-form {
    margin: 0 .75rem;
  }
  /* iOS zooms into fields under 16px */
  .ai-form textarea {
    font-size: 16px;
  }
}
