/* ==========================================================================
   AI-агенты: кейсы, чаты Telegram и Mattermost, ядро агента и субагенты
   ========================================================================== */

.cases {
  display: grid;
  gap: 0.25rem;
  margin-top: 1.75rem;
  padding: 0;
  list-style: none;
}

.case {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  padding: 0.6rem 0.75rem;
  overflow: hidden;
  color: var(--text-2);
  font-size: 1rem;
  line-height: 1.35;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.case:hover { color: var(--text); background: rgb(255 255 255 / 0.04); }
.case.is-active { color: var(--text); background: rgb(79 209 197 / 0.08); }
html:not(.js) .case { cursor: default; }
html:not(.js) .case:hover { background: transparent; }
html:not(.js) .case.is-active { background: rgb(79 209 197 / 0.08); }

.case-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.1rem;
  height: 2.1rem;
  background: var(--accent-soft);
  border-radius: 9px;
}

.case-icon svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* полоска внизу активного сценария показывает, когда сменится следующий */
.case::after {
  content: "";
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: 0;
  height: 1px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
}

.case.is-running::after {
  transform: scaleX(1);
  transition: transform var(--cycle, 11s) linear;
}

.visual--ai {
  max-width: 40rem;
  container-type: inline-size;
}

.ai {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-areas:
    "tg mm"
    "stage stage";
  gap: 3rem 0.75rem;
}

@container (min-width: 34rem) {
  .ai {
    grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
    grid-template-areas:
      "tg stage"
      "mm stage";
    gap: 1rem 2.5rem;
  }
}

.ai-links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.ai-link {
  fill: none;
  stroke: rgb(120 200 210 / 0.2);
  stroke-width: 1.25;
  stroke-dasharray: 3 5;
  transition: stroke 0.4s ease;
}

.ai-link.is-hot { stroke: rgb(127 240 228 / 0.6); }

.ai-packet {
  fill: #a5f5ec;
  filter: drop-shadow(0 0 4px rgb(79 209 197 / 0.95));
}

/* чаты */
.chat {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: linear-gradient(160deg, rgb(40 48 56 / 0.92), rgb(22 27 32 / 0.92));
  border: 1px solid rgb(255 255 255 / 0.08);
  border-radius: 16px;
  transition: border-color 0.5s ease;
}

.chat--tg { grid-area: tg; }
.chat--mm { grid-area: mm; }
.chat.is-active { border-color: rgb(79 209 197 / 0.35); }

.chat-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid rgb(255 255 255 / 0.06);
}

.chat-name { color: var(--text); font-family: var(--font-mono); font-size: 0.95rem; }

.chat-meta {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-body {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.45rem;
  height: 10.5rem;
  padding: 0.65rem;
  overflow: hidden;
}

@container (min-width: 34rem) {
  .chat-body { height: 8.75rem; }
}

.bubble {
  max-width: 90%;
  padding: 0.45rem 0.65rem;
  font-size: 0.78rem;
  line-height: 1.35;
  border-radius: 12px;
  opacity: 0;
  transform: translateY(0.4rem);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.bubble.is-in { opacity: 1; transform: none; }

.bubble--out {
  align-self: flex-end;
  color: #d9f7f3;
  background: rgb(79 209 197 / 0.16);
  border-bottom-right-radius: 4px;
}

.bubble--in {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  align-self: flex-start;
  color: var(--text);
  background: rgb(255 255 255 / 0.06);
  border-bottom-left-radius: 4px;
}

.bubble-av {
  flex: none;
  width: 0.95rem;
  height: 0.95rem;
  margin-top: 0.1rem;
  background: conic-gradient(from 200deg, #4fd1c5, #3b6fe0, #8a6df0, #4fd1c5);
  border-radius: 50%;
  box-shadow: 0 0 8px rgb(79 209 197 / 0.6);
}

.bubble--sys {
  align-self: center;
  padding: 0.2rem 0.65rem;
  color: var(--muted);
  font-size: 0.72rem;
  background: none;
  border: 1px solid rgb(255 255 255 / 0.1);
  border-radius: 999px;
}

.bubble--voice { display: flex; align-items: center; gap: 0.5rem; }

.voice-play {
  position: relative;
  flex: none;
  width: 1.4rem;
  height: 1.4rem;
  background: var(--accent);
  border-radius: 50%;
}

.voice-play::after {
  content: "";
  position: absolute;
  left: 0.52rem;
  top: 0.4rem;
  border-style: solid;
  border-width: 0.3rem 0 0.3rem 0.48rem;
  border-color: transparent transparent transparent var(--on-accent);
}

.voice-wave {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 1.2rem;
}

.voice-wave i {
  width: 2px;
  height: calc(var(--h) * 1%);
  background: #9ff0e8;
  border-radius: 1px;
}

.voice-len { color: #9fd8d1; font-size: 0.7rem; }

.bubble--file { display: flex; align-items: center; gap: 0.55rem; }

.file-ico {
  flex: none;
  width: 1.5rem;
  height: 1.9rem;
  background:
    linear-gradient(225deg, rgb(18 22 26 / 0.9) 0 0.35rem, transparent 0.36rem),
    repeating-linear-gradient(180deg, rgb(11 31 29 / 0.55) 0 1px, transparent 1px 4px) 0.25rem 0.6rem / 1rem 1rem no-repeat,
    #bfeee8;
  border-radius: 3px;
}

.file-text { display: grid; }
.file-name { font-weight: 500; }

.bubble--typing { display: flex; gap: 0.25rem; padding-block: 0.6rem; }

.bubble--typing i {
  width: 0.35rem;
  height: 0.35rem;
  background: var(--muted);
  border-radius: 50%;
}

.bubble.is-gone { opacity: 0; transform: translateY(-0.4rem); }

/* сцена: агент и субагенты */
.ai-stage {
  position: relative;
  grid-area: stage;
  display: grid;
  justify-items: center;
  gap: 2.75rem;
}

@container (min-width: 34rem) {
  .ai-stage {
    grid-template-columns: minmax(0, 1fr) 6.75rem;
    align-items: center;
    gap: 1.5rem;
  }
}

.ai-core {
  display: grid;
  justify-items: center;
  gap: 1.5rem;
}

.orb-label {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* по бокам от подписи — логотипы OpenClaw и Hermes, если они указаны в logos/logos.js */
.orb-logo:not(.has-logo) { display: none; }
.orb-logo { display: inline-flex; }

.orb {
  position: relative;
  width: 7rem;
  aspect-ratio: 1;
}

@container (min-width: 34rem) {
  .orb { width: 8rem; }
}

.orb-glow {
  position: absolute;
  inset: -40%;
  background: radial-gradient(circle, rgb(79 209 197 / 0.32), rgb(70 100 230 / 0.12) 45%, transparent 68%);
  border-radius: 50%;
  opacity: 0.75;
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.orb.is-busy .orb-glow { opacity: 1; transform: scale(1.12); }

.orb-pulse {
  position: absolute;
  inset: 0;
  border: 1px solid rgb(127 240 228 / 0.6);
  border-radius: 50%;
  opacity: 0;
}

/* орбиты вокруг ядра: окружности, наклонённые в плоскость */
.orb-ring {
  position: absolute;
  inset: -24%;
  border: 1px solid rgb(127 240 228 / 0.28);
  border-radius: 50%;
  transform: rotateX(74deg) rotateZ(0deg);
}

.orb-ring--2 {
  inset: -14%;
  border-color: rgb(140 160 255 / 0.25);
  transform: rotate(-28deg) rotateX(72deg) rotateZ(0deg);
}

.orb-ring::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -3px;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  background: #b9fff6;
  border-radius: 50%;
  box-shadow: 0 0 8px 2px rgb(79 209 197 / 0.9);
}

.orb-ring--2::after { background: #c9d3ff; box-shadow: 0 0 8px 2px rgb(120 140 255 / 0.8); }

.orb-body {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 55%, #10303a, #0a1417 72%);
  border-radius: 50%;
  box-shadow:
    inset 0 0 1.25rem rgb(79 209 197 / 0.55),
    inset 0 -0.6rem 1.5rem rgb(90 110 240 / 0.35);
  isolation: isolate;
  /* Safari не обрезает скруглением вращающиеся слои внутри (без маски виден квадрат),
     маска по кругу обрезает всё содержимое ядра в любом браузере */
  -webkit-mask-image: radial-gradient(circle closest-side, #000 98.5%, transparent 100%);
  mask-image: radial-gradient(circle closest-side, #000 98.5%, transparent 100%);
}

/* внешнее свечение ядра: маска обрезала бы тень самого ядра, поэтому оно на блике */
.orb > .orb-shine { box-shadow: 0 0 2.5rem rgb(79 209 197 / 0.25); }

.orb-swirl {
  position: absolute;
  inset: -30%;
  background: conic-gradient(from 0deg, transparent 0 6%, #3fe8d8 18%, transparent 34%, #4d6bff 50%, transparent 66%, #a77bff 78%, transparent 92%);
  border-radius: 50%;
  filter: blur(8px);
  opacity: 0.95;
  mix-blend-mode: screen;
}

.orb-swirl--2 {
  inset: -8%;
  background: conic-gradient(from 120deg, transparent, #b9fff6 12%, transparent 26%, transparent 58%, #4fd1c5 72%, transparent 86%);
  filter: blur(6px);
  opacity: 0.55;
}

/* каркас сферы: меридианы вращаются, параллели стоят */
.orb-mesh {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: none;
  stroke: rgb(185 255 246 / 0.2);
  stroke-width: 0.75;
  vector-effect: non-scaling-stroke;
  mix-blend-mode: screen;
}

.orb-mesh * { vector-effect: non-scaling-stroke; }
.orb-mesh .mer { transform: scaleX(var(--s)); }

.orb-shine {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 32% 26%, rgb(255 255 255 / 0.55), transparent 20%),
    radial-gradient(circle at 70% 82%, rgb(79 209 197 / 0.25), transparent 42%);
  border-radius: 50%;
  pointer-events: none;
}

/* субагенты */
.subs {
  display: flex;
  justify-content: space-around;
  width: 100%;
}

@container (min-width: 34rem) {
  .subs {
    flex-direction: column;
    gap: 1.6rem;
    width: auto;
  }
}

/* фиксированная ширина: подписи разной длины не сдвигают схему при смене сценария */
.sub {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  width: 6.75rem;
  transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1), opacity 0.45s ease;
}

.js .sub:not(.is-out) {
  opacity: 0;
  transform: translate(var(--fx, 0), var(--fy, 0)) scale(0.25);
}

.sub-orb {
  position: relative;
  width: 3.25rem;
  height: 3.25rem;
}

.sub-orb .orb-body { inset: 0.4rem; box-shadow: inset 0 0 0.6rem rgb(79 209 197 / 0.6); }

.sub-orb::before {
  content: "";
  position: absolute;
  inset: 0.4rem;
  border-radius: 50%;
  box-shadow: 0 0 1.2rem rgb(79 209 197 / 0.25);
}

.sub-orb .orb-swirl { filter: blur(5px); }
.sub-orb .orb-swirl--2 { filter: blur(3px); }

.sub-orb .orb-body::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: radial-gradient(circle at 38% 32%, #b9fff6, var(--accent) 60%);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.sub.is-done .orb-body::after { opacity: 1; }

.sub-ring {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
}

.sub-track,
.sub-prog {
  fill: none;
  stroke-width: 1.8;
}

.sub-track { stroke: rgb(255 255 255 / 0.1); }

.sub-prog {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.sub.is-working .sub-prog {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset var(--dur, 2s) linear;
}

.sub.is-done .sub-prog { stroke-dashoffset: 0; }

.sub-check {
  position: absolute;
  inset: 0.85rem;
  z-index: 2;
  fill: none;
  stroke: var(--on-accent);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.sub.is-done .sub-check { opacity: 1; transform: none; }

.sub-label {
  color: var(--text-2);
  font-size: 0.74rem;
  white-space: nowrap;
}

/* узел-сервис среди субагентов: Home Assistant или Sure */
.tool-face {
  position: absolute;
  inset: 0.5rem;
  z-index: 2;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, rgb(var(--tool) / 0.35), rgb(var(--tool) / 0.12));
  border: 1px solid rgb(var(--tool) / 0.7);
  border-radius: 9px;
  box-shadow: 0 0 1rem rgb(var(--tool) / 0.45);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.tool-mark {
  display: none;
  place-items: center;
  transition: opacity 0.3s ease;
}

.tool-mark .logo { width: 1.4rem; height: 1.4rem; }
.tool-mark.has-logo .tool-ico { display: none; }

.tool-ico {
  display: block;
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: rgb(var(--tool));
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sub--ha { --tool: 255 176 110; }
.sub--sure { --tool: 110 150 255; }
.sub--tool .tool-face { opacity: 1; }
.sub--ha .tool-mark--ha,
.sub--sure .tool-mark--sure { display: grid; }
.sub--tool .orb-body,
.sub--tool .sub-orb::before { opacity: 0; }
.sub--tool .sub-prog { stroke: rgb(var(--tool)); }
.sub--tool .sub-label { color: rgb(var(--tool)); }
.sub--tool.is-done .tool-face { background: rgb(var(--tool)); }
.sub--tool.is-done .tool-mark { opacity: 0; }

/* ==========================================================================
   Движение
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  .bubble--typing i { animation: dot 1.1s ease-in-out infinite; }
  .bubble--typing i:nth-child(2) { animation-delay: 0.15s; }
  .bubble--typing i:nth-child(3) { animation-delay: 0.3s; }

  /* ядро агента */
  .orb-swirl { animation: spin 7s linear infinite; }
  .orb-swirl--2 { animation-duration: 11s; animation-direction: reverse; }
  .orb > .orb-body { animation: breathe 5s ease-in-out infinite; }
  .orb-ring { animation: orbit-1 9s linear infinite; }
  .orb-ring--2 { animation: orbit-2 13s linear infinite; }
  .orb.is-busy .orb-pulse { animation: ping 1.6s ease-out infinite; }
  .orb-mesh .mer { animation: meridian 12s ease-in-out infinite; animation-delay: calc(var(--i) * -1.5s); }
}

@keyframes meridian {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(-1); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

@keyframes orbit-1 {
  from { transform: rotateX(74deg) rotateZ(0deg); }
  to { transform: rotateX(74deg) rotateZ(360deg); }
}

@keyframes orbit-2 {
  from { transform: rotate(-28deg) rotateX(72deg) rotateZ(360deg); }
  to { transform: rotate(-28deg) rotateX(72deg) rotateZ(0deg); }
}

@keyframes ping {
  from { opacity: 0.8; transform: scale(1); }
  to { opacity: 0; transform: scale(1.6); }
}
