/* Раздел «Агент»: связь с локальной программой, что она видит на машине и что делала.
   Карточки одного вида, потому что это один разговор — не витрина из разных блоков. */

.ag {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  padding-bottom: calc(var(--s-8) + env(safe-area-inset-bottom, 0px));
}

/* ---------- Top bar ---------- */
.ag-top {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.ag-top__inner {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  min-height: calc(64px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
}
.ag-top__right { margin-left: auto; }

/* Шапка — общая .container (1200px), как на всех экранах с навигацией в
   ней: иначе при прямом переходе между вкладками (js/nav.js) сама
   навигация каждый раз прыгает по ширине — 24.09, жалоба на «сайт
   съезжает». Контент — своей узкой шириной, как и был: код связи и статус
   читаются одной колонкой, растягивать их на все 1200px не нужно. */
.ag-main { max-width: calc(760px + 2 * var(--gutter)); padding-top: var(--s-6); }

/* ---------- Heading ---------- */
.ag-head {
  display: grid;
  gap: var(--s-3);
  margin-bottom: var(--s-6);
}
.ag-head__title {
  font-size: clamp(2rem, 6vw, 3rem);
  letter-spacing: -0.03em;
}
.ag-head__sub {
  max-width: 58ch;
  color: var(--text-2);
  font-size: var(--fs-18);
}

.ag-stack { display: grid; gap: var(--s-4); }

/* ---------- Карточки ---------- */
.ag-card {
  display: grid;
  gap: var(--s-3);
  padding: var(--s-5);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
}
.ag-card--live { border-color: var(--spot-border); }
.ag-card--quiet { background: transparent; }
.ag-card--demo {
  border-style: dashed;
  border-color: var(--border-strong);
  background: transparent;
}

.ag-card__head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
}
.ag-card__title {
  font-family: var(--font-display);
  font-size: var(--fs-18);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.ag-card__head .badge { margin-left: auto; }
.ag-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.ag-note { color: var(--text-2); line-height: 1.6; }
.ag-fine { color: var(--text-3); font-size: var(--fs-14); line-height: 1.6; }

/* Аварийный стоп (В45?): кнопка и пояснение под ней, а не в общий ряд ag-card__actions —
   это разовое резкое действие, не рядовая ссылка вроде «Отвязать». */
.ag-stop { display: grid; gap: var(--s-2); }

/* ---------- Правила чата ---------- */
.ag-rules { display: grid; gap: var(--s-3); }
.ag-rule {
  display: grid;
  gap: var(--s-2);
  padding: var(--s-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.ag-rule.is-off .field { opacity: .6; }
.ag-rule__top { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.ag-rule__top .toggle { min-width: 0; text-align: left; }
.ag-rule__top .btn,
.ag-rule__top .toggle__track { flex: none; }

/* ---------- Код связи ---------- */
/* Код диктуют вслух и переписывают руками, поэтому он крупный и разрежённый,
   а не аккуратная мелкая строчка. */
.ag-token {
  display: grid;
  gap: var(--s-3);
  justify-items: start;
  padding: var(--s-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.ag-token__label {
  color: var(--text-3);
  font-size: var(--fs-12);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.ag-token__code {
  /* Код переписывают руками в программу на компьютере: в пиксельном шрифте
     2 и Z, 5 и S неотличимы. Моноширинный — буква под буквой, без гаданий. */
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-weight: 700;
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: clamp(1.125rem, 5vw, 1.75rem);
  line-height: 1.3;
  letter-spacing: 0.06em;
  user-select: all;
}
.ag-token__actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }

/* ---------- Строки-переходы ---------- */
.ag-rows {
  display: grid;
  gap: var(--s-2);
}
.ag-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  font-family: inherit;
  font-size: var(--fs-16);
  cursor: pointer;
  transition: border-color var(--dur-micro) var(--ease-out), background-color var(--dur-micro) var(--ease-out);
}
.ag-row:hover { border-color: var(--spot-border); background: var(--surface-2); }
.ag-row > svg { width: 18px; height: 18px; color: var(--text-3); transition: transform var(--dur-state) var(--ease-out); }
.ag-row:hover > svg { transform: translateX(4px); color: var(--accent-text); }
.ag-row__dot {
  width: 8px;
  height: 8px;
  border-radius: var(--r-full);
  background: var(--success);
}
.ag-row.is-warn .ag-row__dot { background: var(--warning); }
.ag-row.is-off .ag-row__dot { background: var(--danger); }
.ag-row__dot--flat { background: var(--border-strong); }
.ag-row__body { display: grid; gap: 2px; min-width: 0; }
.ag-row__title { font-weight: 600; }
.ag-row__meta { color: var(--text-2); font-size: var(--fs-12); }

/* ---------- Что уходит, а что нет ---------- */
.ag-list {
  display: grid;
  gap: var(--s-3);
  margin: 0;
  padding: 0;
  list-style: none;
}
.ag-list__item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--s-3);
  color: var(--text-2);
  line-height: 1.6;
}
.ag-list__item b { color: var(--text); font-weight: 600; }
.ag-list__item svg { width: 18px; height: 18px; margin-top: 3px; }
.ag-list__item--yes svg { color: var(--success); }
.ag-list__item--no svg { color: var(--text-3); }

/* ---------- Демо ---------- */
.ag-demo__label {
  color: var(--text-3);
  font-size: var(--fs-12);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ---------- Сон машины (В43) ---------- */
/* Полоса дня: фон — сон, отрезок — машина не спит, метки — пары, черта — сейчас. */
.mc-day {
  position: relative;
  height: 14px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  overflow: hidden;
}
.mc-day > span { position: absolute; top: 0; bottom: 0; }
.mc-day__awake { background: var(--accent-soft); }
.mc-day__pair {
  top: 3px !important;
  bottom: 3px !important;
  border-radius: 2px;
  background: var(--accent);
}
.mc-day__now {
  width: 2px;
  margin-left: -1px;
  background: var(--text);
}
.mc-day__legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s-1) var(--s-3);
  color: var(--text-3);
  font-size: var(--fs-12);
}
.mc-confirm { color: var(--text); }

/* Heartbeat line: the one place that says whether the program is actually talking to us. */
.ag-pulse.is-on { color: var(--text); }
.ag-pulse.is-off { color: var(--text); font-weight: 600; }

/* ---------- Page v2 (Max 05.10): the mascot says the status, today's strip, folded groups ---------- */
.ag-title {
  margin-bottom: var(--s-5);
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  letter-spacing: -0.03em;
  line-height: 1.1;
}

/* The hero: mascot left, its line in a speech bubble, actions under the bubble. */
.ag-hero {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: var(--s-5);
  row-gap: var(--s-4);
  align-items: center;
  padding: var(--s-5);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
}
.ag-hero.is-on { border-color: var(--spot-border); }
.ag-hero__pet {
  grid-row: span 2;
  align-self: start;
  width: 112px;
}
.ag-hero__pet svg { display: block; width: 100%; height: auto; }
.ag-hero__say {
  position: relative;
  padding: var(--s-4) var(--s-5);
  border-radius: var(--r-lg);
  background: var(--surface-raised);
  box-shadow: var(--shadow-sm), var(--shadow-inset);
}
/* The tail points at the mascot. */
.ag-hero__say::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 28px;
  width: 16px;
  height: 16px;
  background: inherit;
  transform: rotate(45deg);
  border-radius: 3px;
}
.ag-hero__line {
  position: relative;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2.6vw, 1.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  text-wrap: balance;
}
.ag-hero__meta {
  position: relative;
  margin-top: var(--s-2);
  color: var(--text-3);
  font-size: var(--fs-14);
}
.ag-hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.ag-hero__actions:empty { display: none; }
.ag-hero .ag-token { grid-column: 1 / -1; }

/* Today: the journal's day strip, big enough to be the way in. */
.ag-today {
  display: grid;
  gap: var(--s-3);
  padding: var(--s-5);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
}
.ag-today__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
}
.ag-today__title { font-size: var(--fs-24); letter-spacing: -0.02em; }
.ag-today__all {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: var(--s-1) 0;
  border: 0;
  background: none;
  color: var(--accent-text);
  font-weight: 700;
  cursor: pointer;
}
.ag-today__all svg { width: 16px; height: 16px; transition: transform var(--dur-micro) var(--ease-out); }
.ag-today__all:hover svg { transform: translateX(3px); }
.ag-today__sum { color: var(--text-2); font-size: var(--fs-14); font-variant-numeric: tabular-nums; }

/* Folded groups: one line each with what is set, open for the controls. */
.ag-groups {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
}
.ag-group + .ag-group { border-top: 1px solid var(--border); }
.ag-group__head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-4) var(--s-5);
  cursor: pointer;
  list-style: none;
  transition: background var(--dur-micro) var(--ease-out);
}
.ag-group__head::-webkit-details-marker { display: none; }
.ag-group__head:hover { background: var(--spot); }
.ag-group__head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ag-group__icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.ag-group__icon svg { width: 18px; height: 18px; }
.ag-group__text { display: grid; gap: 2px; min-width: 0; }
.ag-group__title { font-weight: 700; }
.ag-group__meta {
  overflow: hidden;
  color: var(--text-3);
  font-size: var(--fs-14);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ag-group__chevron svg { width: 18px; height: 18px; color: var(--text-3); transition: transform var(--dur-state) var(--ease-out); }
.ag-group[open] .ag-group__chevron svg { transform: rotate(180deg); }
.ag-group__body {
  display: grid;
  gap: var(--s-5);
  padding: var(--s-1) var(--s-5) var(--s-5);
}
.ag-set { display: grid; gap: var(--s-3); }
/* Выбор главной группы: по ширине своих пунктов, а не во всю карточку. */
.ag-set > .seg { justify-self: start; max-width: 100%; }
.ag-group .ag-row { background: var(--surface-raised); }
.ag-privacy { display: grid; gap: var(--s-3); }
.ag-privacy__title { font-size: var(--fs-16); }

@media (max-width: 560px) {
  .ag-hero {
    grid-template-columns: minmax(0, 1fr);
    padding: var(--s-4);
  }
  .ag-hero__pet { grid-row: auto; width: 80px; }
  .ag-hero__pet.ag-pet--pair { margin-bottom: 26px; }
  .ag-hero__say::before { left: 28px; top: -8px; }
  .ag-today, .ag-group__head { padding: var(--s-4); }
  .ag-group__body { padding: var(--s-1) var(--s-4) var(--s-4); }
}

/* ---------- The living mascot ---------- */
.ag-hero__pet { position: relative; }
.ag-pet__body { display: block; }
.ag-pet__body svg {
  transform-origin: 50% 100%;
  animation: ag-breathe 3.2s var(--ease-in-out) infinite;
}
.ag-pet--none .ag-pet__body svg,
.ag-pet--offline .ag-pet__body svg { animation-duration: 5s; }
@keyframes ag-breathe { 50% { transform: scale(1.02, 0.975); } }

.ag-hero__pet.is-hop { animation: ag-hop 560ms var(--ease-out); }
@keyframes ag-hop {
  0% { transform: translateY(0) scale(1, 1); }
  20% { transform: translateY(0) scale(1.08, 0.9); }
  50% { transform: translateY(-16px) scale(0.95, 1.06); }
  80% { transform: translateY(0) scale(1.05, 0.95); }
  100% { transform: translateY(0) scale(1, 1); }
}

/* Asleep: three z's float up from the head. */
.ag-pet__z { position: absolute; top: 6px; right: -6px; width: 30px; height: 40px; pointer-events: none; }
.ag-pet__z i {
  position: absolute;
  left: 0;
  bottom: 0;
  color: var(--text-2);
  font: 700 16px/1 var(--font-pixel);
  font-style: normal;
  opacity: 0;
  animation: ag-z 2.7s var(--ease-out) infinite;
}
.ag-pet__z i:nth-child(2) { animation-delay: .9s; font-size: 20px; }
.ag-pet__z i:nth-child(3) { animation-delay: 1.8s; font-size: 25px; }
@keyframes ag-z {
  0% { transform: translate(0, 8px) scale(.6); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translate(16px, -26px) scale(1.1); opacity: 0; }
}

/* On a pair: a red «пишу» tag under its feet, never over the drawing. */
.ag-pet__rec {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: var(--r-full);
  background: var(--danger);
  color: var(--live-ink);
  font-size: var(--fs-12);
  font-weight: 800;
  line-height: 1.5;
  white-space: nowrap;
  transform: translateX(-50%);
}
.ag-pet__rec i { width: 6px; height: 6px; border-radius: 50%; background: var(--live-ink); animation: bx-rec 1.2s var(--ease-in-out) infinite; }

/* Waiting for a pair: radio waves off the cheat sheet on its antenna, both sides, centred on the sheet
   (sheet = grid cells 6–9 × 1–3 of 16, so its centre sits at 50% / 15.6% of the drawing). */
.ag-pet__sig {
  position: absolute;
  top: 15.6%;
  left: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
}
.ag-pet__sig i {
  position: absolute;
  left: -19px;
  top: -14px;
  width: 38px;
  height: 28px;
  border: 2px solid transparent;
  border-left-color: var(--accent-text);
  border-right-color: var(--accent-text);
  border-radius: 50%;
  opacity: 0;
  animation: ag-sig 2.2s var(--ease-out) infinite;
}
.ag-pet__sig i:nth-child(2) { animation-delay: 1.1s; }
@keyframes ag-sig {
  0% { transform: scale(.75); opacity: 0; }
  25% { opacity: .9; }
  100% { transform: scale(1.7); opacity: 0; }
}

/* Recording not allowed: a muted speaker by its side. */
.ag-pet__mute {
  position: absolute;
  right: -6px;
  bottom: 16px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface-raised);
  color: var(--warning);
}
.ag-pet__mute svg { width: 16px; height: 16px; }

/* The little one in «Сегодня» walks under the timeline at «now». */
.ag-today .bx-day { padding-bottom: 30px; }
.bx-day__pet {
  position: absolute;
  top: calc(100% + 2px);
  width: 26px;
  transform: translateX(-50%);
  line-height: 0;
  pointer-events: none;
}
.bx-day__pet svg { max-width: none; }


@media (prefers-reduced-motion: reduce) {
  .ag-pet__body svg, .ag-hero__pet.is-hop, .ag-pet__z i, .ag-pet__sig i, .ag-pet__rec i { animation: none; }
  .ag-pet__z i { opacity: .7; }
  .ag-pet__z i:nth-child(1) { transform: translate(0, 4px); }
  .ag-pet__z i:nth-child(2) { transform: translate(8px, -8px); }
  .ag-pet__z i:nth-child(3) { transform: translate(16px, -20px); }
}

/* The flight from the logo into the plate (agent.js jumpIn). */
.ag-fly {
  position: fixed;
  z-index: var(--z-overlay);
  pointer-events: none;
  line-height: 0;
}
.ag-fly svg { max-width: none; }

/* The window switch sits under the hero's buttons, in the text column. */
.ag-hero__window { grid-column: 2; }
.ag-locked .toggle[disabled] { opacity: .5; cursor: not-allowed; }
@media (max-width: 560px) {
  .ag-hero__window { grid-column: 1; }
}

/* While he sits in the agent plate the logo is empty; the word keeps its place. */
.logo__mark.is-away { visibility: hidden; }

/* ================= Редизайн 3: агент 1:1 с прототипом 4 (ROADMAP §16.1) =================
   Две колонки: слева карточка состояния (иконка со статусом сверху, крупный
   заголовок, код связи на песке, фиолетовое действие) и компьютер; справа
   переходы одним списком, приватность, тумблер прототипа. */
.ag-main { max-width: var(--container); padding-top: var(--s-7); }
.ag-head { display: grid; gap: 12px; margin-bottom: 36px; }
.ag-head__sub { max-width: 46ch; font-size: clamp(1.05rem, 1.5vw, 1.2rem); font-weight: 400; color: var(--text-2); }
.ag-stack { gap: 16px; align-items: start; }
@media (min-width: 1024px) { .ag-stack { grid-template-columns: 1.2fr 1fr; } }
.ag-col { display: grid; gap: 16px; align-content: start; }
.ag-card { gap: 22px; padding: 32px; }
@media (max-width: 599px) { .ag-card { padding: 22px; } }
.ag-card__top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.ag-card__top > .agent-stage { width: 64px; height: 64px; border-radius: 20px; }
.ag-card__top > .agent-stage svg { width: 30px; height: 30px; }
.ag-card__top > .agent-stage .agent-stage__dot { top: -3px; right: -3px; width: 14px; height: 14px; }
.ag-card .ag-card__title.ag-card__title--big { font-family: var(--font-headline); font-size: clamp(1.6rem, 3vw, 2.4rem); font-weight: 600; letter-spacing: -0.05em; line-height: 1.08; }
.ag-card__title:not(.ag-card__title--big) { font-family: var(--font-ui); font-size: 1.25rem; font-weight: 600; letter-spacing: -0.025em; }
.ag-note { color: var(--text-2); }
.ag-token { gap: 10px; padding: 20px; border: 0; border-radius: var(--r-lg); }
.ag-token__label { text-transform: none; letter-spacing: 0; font-size: 0.8125rem; }
.ag-token .btn--ghost { --btn-bg: var(--surface); }
.ag-rows { gap: 0; border-radius: var(--r-xl); background: var(--surface); box-shadow: var(--shadow-card); overflow: hidden; }
.ag-card--demo { box-shadow: none; border: 0; background: var(--surface-2); }

/* «За неделю»: three numbers in tiles, each opens the journal (Max 06.10: half the page was empty). */
.ag-week {
  display: grid;
  gap: var(--s-3);
  padding: var(--s-5);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
.ag-week__tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.ag-stat {
  display: grid;
  justify-items: start;
  gap: 4px;
  padding: 16px 18px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  text-align: start;
  cursor: pointer;
  transition: background-color var(--dur-micro) var(--ease-out);
}
.ag-stat:hover:not(:disabled) { background: var(--accent-soft); }
.ag-stat[aria-expanded="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.ag-stat:disabled { cursor: default; }
/* What a tile counts, unfolded under the tiles; each row opens the journal on that pair (ROADMAP-26.09 §31). */
.ag-week__list { display: grid; margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--border); }
.ag-week__row + .ag-week__row { border-top: 1px solid var(--border); }
.ag-week__go { display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: 2px 12px; width: 100%; padding: 10px 4px; border: 0; background: transparent; color: var(--text); text-align: start; text-decoration: none; cursor: pointer; border-radius: var(--r-sm); }
.ag-week__go:hover { background: var(--surface-2); }
.ag-week__when { color: var(--text-3); font-size: var(--fs-14); white-space: nowrap; }
.ag-week__what { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-week__extra { grid-column: 2; color: var(--text-2); font-size: var(--fs-14); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-week__empty { color: var(--text-3); font-size: var(--fs-14); }
.ag-stat__icon { display: grid; place-items: center; width: 30px; height: 30px; margin-bottom: 6px; border-radius: 10px; background: var(--surface); color: var(--accent-text); }
.ag-stat__icon svg { width: 16px; height: 16px; }
.ag-stat__n { font-family: var(--font-headline); font-size: 2rem; font-weight: 600; letter-spacing: -0.04em; line-height: 1; }
.ag-stat__label { color: var(--text-2); font-size: var(--fs-14); }

/* His props wait for the landing (Max 07.10): hidden in flight, they fade in once he is in the plate. */
.ag-hero__pet.is-arriving > :not([data-pet-body]) { visibility: hidden; }
.ag-hero__pet.is-landed > :not([data-pet-body]) { animation: ag-props-in 0.45s var(--ease-out) both; }
@keyframes ag-props-in { from { opacity: 0; } to { opacity: 1; } }

/* Браузер для пар (13.10): таблетки-выбор, как фильтр предметов. */
.ag-browser { display: grid; gap: var(--s-2); margin-top: var(--s-4); }
.ag-browser__label { color: var(--text); font-weight: 600; font-size: var(--fs-14); }
.ag-browser__list { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.ag-browser__off { margin-top: var(--s-3); }

/* The chat rules save themselves; this line says where they are (no Save button). */
.ag-rules__state { align-self: center; }
.ag-rules__state.is-bad { color: var(--danger-text); }
