/* AI Edu · sheet + app shell — fullscreen layout, bottom-sheet on mobile, modal on desktop */

/* ============================================================
   APP — fullscreen (no iPhone frame)
   ============================================================ */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-page);
  position: relative;
}

.app-shell .app-top {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(var(--bg-page-rgb), 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  transition: border-color var(--t-base) var(--ease-ui);
}
.app-shell .app-top.scrolled { border-bottom-color: var(--hair); }

/* MOBILE: bottom tabbar (≤719px) — !important to beat old inline rules in legacy teacher/admin pages */
.app-tabbar,
.app-shell .app-tabbar {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  z-index: 30 !important;
  background: rgba(var(--bg-page-rgb), 0.94) !important;
  backdrop-filter: blur(14px) !important;
  -webkit-backdrop-filter: blur(14px) !important;
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr)) !important;   /* 4–5 вкладок (ученик: + «AI») */
  border-top: 1px solid var(--hair) !important;
  padding: 10px 0 max(12px, env(safe-area-inset-bottom)) 0 !important;
  margin: 0 !important;
}
.app-tabbar .tab,
.app-shell .app-tabbar .tab {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  gap: 4px !important;
  padding: 4px 0 !important;
  font-family: var(--font-body) !important;
  font-size: 10px !important;
  letter-spacing: 0.12em !important;
  text-transform: none !important;
  color: var(--ink-mute) !important;
  text-decoration: none !important;
  border: 0 !important;
  transition: color var(--t-fast) var(--ease-ui);
  position: relative;
  background: transparent !important;
}
.app-tabbar .tab svg,
.app-shell .app-tabbar .tab svg {
  stroke: currentColor !important;
  stroke-width: 1.4;
  fill: none !important;
  width: 22px !important;
  height: 22px !important;
  display: block !important;
}
.app-tabbar .tab.active,
.app-shell .app-tabbar .tab.active { color: var(--ink) !important; }
.app-tabbar .tab.active::after,
.app-shell .app-tabbar .tab.active::after {
  content: '' !important;
  position: absolute !important;
  bottom: -1px !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  width: 4px !important;
  height: 4px !important;
  border-radius: 50% !important;
  background: var(--accent) !important;
}

/* DESKTOP: tabs move to top — text-only, no SVG */
@media (min-width: 720px) {
  .app-tabbar,
  .app-shell .app-tabbar {
    position: static !important;
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border-top: none !important;
    padding: 0 !important;
    display: flex !important;
    grid-template-columns: none !important;
    gap: 28px !important;
    margin-left: auto !important;
    margin-right: 18px !important;
  }
  .app-tabbar .tab svg,
  .app-shell .app-tabbar .tab svg { display: none !important; }
  .app-tabbar .tab,
  .app-shell .app-tabbar .tab {
    flex-direction: row !important;
    padding: 6px 0 8px !important;
    font-family: var(--font-display) !important;
    font-style: normal !important;
    font-size: 16px !important;
    text-transform: none !important;
    letter-spacing: -0.005em !important;
    color: var(--ink-mute) !important;
    border-bottom: 1px solid transparent !important;
    gap: 0 !important;
  }
  .app-tabbar .tab:hover,
  .app-shell .app-tabbar .tab:hover { color: var(--ink) !important; }
  .app-tabbar .tab.active,
  .app-shell .app-tabbar .tab.active {
    color: var(--ink) !important;
    border-bottom-color: var(--accent) !important;
  }
  .app-tabbar .tab.active::after,
  .app-shell .app-tabbar .tab.active::after { display: none !important; }

  .app-shell .app-top { padding: 14px 28px; gap: 18px; }
  .app-shell .app-top .app-top__brand { margin-right: 8px; }
  .app-shell .app-main { padding-bottom: 60px; }
}

/* JS moves .app-tabbar inside .app-top on desktop, see app.js */

.app-shell .app-main {
  flex: 1;
  padding: 22px 16px 110px;
  position: relative;
}

/* Top brand mark — centered */
.app-top__brand {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.app-top__phi {
  font-family: var(--font-display);
  font-style: normal;
  font-weight: 500;
  font-size: 22px;
  line-height: 1;
}
.app-top__name {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.28em;
  text-transform: none;
  color: var(--ink-mute);
}

.fundament-brand-mark,
.fundament-brand-lockup {
  display: block;
  flex: 0 0 auto;
  background-color: currentColor;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-size: contain;
}
.fundament-brand-mark {
  width: 100%;
  height: 100%;
  color: var(--accent);
  -webkit-mask-image: url('assets/fundament-logo-mark.svg');
  mask-image: url('assets/fundament-logo-mark.svg');
}
.fundament-brand-lockup {
  width: var(--brand-lockup-top-width);
  aspect-ratio: 238 / 36;
  color: var(--ink);
  -webkit-mask-image: url('assets/fundament-logo-lockup.svg');
  mask-image: url('assets/fundament-logo-lockup.svg');
}
.fundament-brand-lockup--menu {
  width: var(--brand-lockup-menu-width);
}
.app-top[data-shell-role="student"] .app-top__brand,
.app-top[data-shell-role="teacher"] .app-top__brand {
  align-items: center;
}
/* Шапка преподавателя в общей оболочке (04.09): тот же логотип по центру. Между 720 и 1023px
   таббар переезжает внутрь шапки (app.js), поэтому сетку включаем только на телефоне и на ≥1024px. */
@media (max-width: 719px), (min-width: 1024px) {
  .app-shell .app-top[data-shell-role="teacher"] {
    display: grid;
    grid-template-columns: minmax(44px, 1fr) auto minmax(44px, 1fr);
    align-items: center;
    gap: 8px;
  }
  .app-top[data-shell-role="teacher"] > [data-burger-open] { grid-column: 1; justify-self: start; }
  .app-top[data-shell-role="teacher"] > .app-top__brand { grid-column: 2; justify-self: center; margin: 0; }
  .app-top[data-shell-role="teacher"] > .app-top__brand ~ .btn-square { grid-column: 3; justify-self: end; margin: 0; }
}
/* Шапка ученика (03.09): логотип строго по центру, слева бургер, справа «Фундамент AI». */
.app-shell .app-top[data-shell-role="student"] {
  display: grid;
  grid-template-columns: minmax(44px, 1fr) auto minmax(44px, 1fr);
  align-items: center;
  gap: 8px;
}
.app-top[data-shell-role="student"] > [data-burger-open] { grid-column: 1; justify-self: start; }
.app-top[data-shell-role="student"] > .app-top__brand { grid-column: 2; justify-self: center; margin: 0; }
.app-top[data-shell-role="student"] > .fai-launch { grid-column: 3; justify-self: end; margin: 0; }
.app-top__phi.fundament-brand-slot,
.app-top[data-shell-role="student"] .app-top__phi.fundament-brand-slot {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  font-size: 0;
}
.app-top[data-shell-role="student"] .app-top__name {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.btn-square {
  width: 40px;
  height: 40px;
  border: 1px solid var(--hair-strong);
  border-radius: var(--r-button);
  display: grid;
  place-items: center;
  background: transparent;
  cursor: pointer;
  padding: 0;
  position: relative;
  color: var(--ink);
  box-shadow: var(--shadow-half);
  transition: background-color var(--t-fast) var(--ease-ui), transform var(--t-micro) var(--ease-ui);
}
.btn-square:active { transform: scale(0.96); background: var(--bg-soft); }
.btn-square svg line { stroke: var(--ink); stroke-width: 1.4; stroke-linecap: round; }
.btn-square svg { fill: none; stroke: var(--ink); stroke-width: 1.3; }
.btn-square .dot {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
}

@media (max-width: 719px) {
  .btn-square {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }
}

/* ============================================================
   BURGER MENU — slide from left
   ============================================================ */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 17, 13, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 360ms var(--ease-ui);
  z-index: 90;
  backdrop-filter: blur(2px);
}
.menu-overlay.is-open { opacity: 1; pointer-events: auto; }

.menu {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 88%;
  max-width: 380px;
  background: var(--bg-page);
  z-index: 100;
  transform: translateX(-101%);
  transition: transform 460ms cubic-bezier(0.29, 0.75, 0.46, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 4px 0 40px rgba(0, 0, 0, 0.18);
}
.menu.is-open { transform: translateX(0); }

.menu__phi {
  position: absolute;
  bottom: -60px;
  right: -50px;
  font-family: var(--font-display);
  font-style: normal;
  font-size: 380px;
  line-height: 0.78;
  color: var(--accent);
  opacity: 0.05;
  pointer-events: none;
}
.menu__head {
  padding: 18px 22px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}
.menu__brand-phi {
  font-family: var(--font-display);
  font-style: normal;
  font-size: 36px;
  font-weight: 500;
  line-height: 1;
}
.menu__brand-name {
  display: block;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.30em;
  text-transform: none;
  color: var(--ink-mute);
  margin-top: 6px;
}
.menu[data-shell-role="student"] .menu__brand-phi.fundament-brand-slot {
  display: block;
  width: 34px;
  height: 34px;
  font-size: 0;
}
.menu[data-shell-role="student"] .menu__brand-name {
  margin-top: 7px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.menu[data-shell-role="student"] .menu__phi.fundament-brand-slot,
.menu[data-shell-role="teacher"] .menu__phi.fundament-brand-slot {
  width: 330px;
  height: 330px;
  right: -92px;
  bottom: -84px;
  font-size: 0;
  opacity: 0.05;
}
.menu__close {
  width: 44px;
  height: 44px;
  border: 1px solid var(--hair-strong);
  border-radius: var(--r-button);
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.menu__close svg line { stroke: var(--ink); stroke-width: 1.4; stroke-linecap: round; }

.menu__user {
  padding: 0 22px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--hair);
  position: relative;
  z-index: 1;
}
.menu__user-mono {
  width: 50px;
  height: 50px;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-style: normal;
  font-size: 20px;
  font-weight: 500;
  color: var(--accent);
}
.menu__user-name {
  font-family: var(--font-display);
  font-style: normal;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.1;
}
.menu__user-class {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.10em;
  text-transform: none;
  color: var(--ink-mute);
  margin-top: 4px;
}

.menu__list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0 8px;
  position: relative;
  z-index: 1;
}
.menu__list::-webkit-scrollbar { display: none; }
.menu__list { scrollbar-width: none; }

.menu__group { padding: 0 22px; margin-bottom: 14px; }
.menu__group-head {
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: none;
  letter-spacing: 0.22em;
  color: var(--ink-mute);
  margin: 10px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.menu__group-head::before {
  content: ''; display: none;
  color: var(--accent);
  font-family: var(--font-display);
  font-style: normal;
  font-size: 14px;
}
.menu__group-head::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--hair);
}

.menu__item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  font-family: var(--font-display);
  font-style: normal;
  font-size: 22px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: color var(--t-fast) var(--ease-ui), transform var(--t-fast) var(--ease-ui);
  border-left: 2px solid transparent;
  padding-left: 8px;
  margin-left: -8px;
}
@media (hover: hover) and (pointer: fine) {
  .menu__item:hover { color: var(--accent); border-left-color: var(--accent); }
}
.menu__item:active { transform: translateX(2px); color: var(--accent); }
.menu__item .badge {
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 9px;
  text-transform: none;
  letter-spacing: 0.10em;
  color: var(--ink-mute);
}
.menu__item .badge.accent { color: var(--accent); }
.menu__item.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
}
.menu__item.is-active::before {
  content: '▸ ';
  color: var(--accent);
  font-family: var(--font-mono);
  font-style: normal;
}

/* Logout — visually separated mono row */
.menu__item.logout-row {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--hair);
  font-family: var(--font-mono) !important;
  font-style: normal !important;
  font-size: 13px !important;
  text-transform: none;
  letter-spacing: 0.14em;
  font-weight: 500;
  color: var(--ink-mute) !important;
  border-left-color: transparent !important;
}
.menu__item.logout-row:hover { color: var(--garnet) !important; }

.menu__foot {
  padding: 12px 22px 18px;
  border-top: 1px solid var(--hair);
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: none;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  display: flex;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}
.menu__foot .accent { color: var(--accent); }

/* Stagger anim on menu items when opened */
.menu.is-open .menu__item {
  opacity: 0;
  animation: menu-item-in 360ms var(--ease-enter) forwards;
}
.menu.is-open .menu__group:nth-child(1) .menu__item:nth-child(2) { animation-delay: 60ms; }
.menu.is-open .menu__group:nth-child(1) .menu__item:nth-child(3) { animation-delay: 100ms; }
.menu.is-open .menu__group:nth-child(1) .menu__item:nth-child(4) { animation-delay: 140ms; }
.menu.is-open .menu__group:nth-child(1) .menu__item:nth-child(5) { animation-delay: 180ms; }
.menu.is-open .menu__group:nth-child(1) .menu__item:nth-child(6) { animation-delay: 220ms; }
.menu.is-open .menu__group:nth-child(2) .menu__item:nth-child(2) { animation-delay: 260ms; }
.menu.is-open .menu__group:nth-child(2) .menu__item:nth-child(3) { animation-delay: 300ms; }
.menu.is-open .menu__group:nth-child(2) .menu__item:nth-child(4) { animation-delay: 340ms; }
.menu.is-open .menu__group:nth-child(2) .menu__item:nth-child(5) { animation-delay: 380ms; }
.menu.is-open .menu__group:nth-child(2) .menu__item:nth-child(6) { animation-delay: 420ms; }
.menu.is-open .menu__group:nth-child(3) .menu__item:nth-child(2) { animation-delay: 460ms; }
.menu.is-open .menu__group:nth-child(3) .menu__item:nth-child(3) { animation-delay: 500ms; }
.menu.is-open .menu__group:nth-child(3) .menu__item:nth-child(4) { animation-delay: 540ms; }
.menu.is-open .menu__group:nth-child(3) .menu__item:nth-child(5) { animation-delay: 580ms; }

@keyframes menu-item-in {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   BOTTOM SHEET — 75-80% viewport on mobile, modal on desktop
   ============================================================ */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 17, 13, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 320ms var(--ease-ui);
  z-index: 80;
  backdrop-filter: blur(3px);
}
.sheet-backdrop.is-open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 78vh;
  max-height: 92vh;
  background: var(--bg-page);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  box-shadow: 0 -16px 60px rgba(20, 17, 13, 0.20);
  transform: translateY(100%);
  transition: transform 460ms cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 90;
}
.sheet.is-open { transform: translateY(0); }

.sheet__grip {
  width: 44px;
  height: 4px;
  background: var(--hair-strong);
  opacity: 0.35;
  border-radius: 4px;
  margin: 10px auto 4px;
  flex-shrink: 0;
}

.sheet__head {
  padding: 8px 22px 14px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--hair);
  flex-shrink: 0;
}
.sheet__head .eyebrow { margin: 0; }
.sheet__title {
  font-family: var(--font-display);
  font-weight: 500;
  font-style: normal;
  font-size: 24px;
  line-height: 1.1;
  margin: 4px 0 0;
  letter-spacing: -0.005em;
}
.sheet__close {
  width: 44px;
  height: 44px;
  border: 1px solid var(--hair-strong);
  border-radius: var(--r-button);
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  align-self: center;
}
.sheet__close svg line { stroke: var(--ink); stroke-width: 1.4; stroke-linecap: round; }

.sheet__body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 28px;
  position: relative;
}
.sheet__body::-webkit-scrollbar { display: none; }
.sheet__body { scrollbar-width: none; }

/* Sheet content building blocks */
.sheet__metric {
  font-family: var(--font-display);
  font-style: normal;
  font-weight: 500;
  font-size: 92px;
  line-height: 0.88;
  letter-spacing: -0.03em;
  color: var(--ink);
  margin: 8px 0 4px;
}
.sheet__metric small {
  font-size: 24px;
  color: var(--ink-mute);
}
.sheet__metric em { color: var(--accent); font-style: normal; }
.sheet__sub {
  font-family: var(--font-display);
  font-style: normal;
  font-size: 16px;
  color: var(--ink-mute);
  line-height: 1.5;
  margin: 0 0 22px;
}
.sheet__row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--hair-soft);
}
.sheet__row .l {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
}
.sheet__row .l small {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0.12em;
  color: var(--ink-mute);
  margin-top: 2px;
}
.sheet__row .r {
  font-family: var(--font-display);
  font-style: normal;
  font-size: 18px;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.sheet__row .r.accent { color: var(--accent); }

.sheet__bars {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 16px 0;
}
.sheet__bar {
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.sheet__bar .lbl {
  width: 100px;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink);
}
.sheet__bar .track {
  flex: 1;
  height: 2px;
  background: var(--hair);
  position: relative;
}
.sheet__bar .fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--ink);
}
.sheet__bar .fill::after {
  content: '';
  position: absolute;
  top: 50%;
  right: -3px;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  transform: translateY(-50%);
}
.sheet__bar .val {
  font-family: var(--font-display);
  font-style: normal;
  font-size: 16px;
  color: var(--accent);
  letter-spacing: -0.01em;
  min-width: 50px;
  text-align: right;
}

/* Desktop: sheet centers as modal */
@media (min-width: 720px) {
  .sheet {
    width: 540px;
    max-width: calc(100vw - 64px);
    height: auto;
    max-height: 78vh;
    min-height: 380px;
    left: 50%;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, calc(-50% + 30px));
    border-radius: 12px;
    opacity: 0;
    pointer-events: none;
    transition: transform 380ms var(--ease-enter), opacity 320ms ease;
  }
  .sheet.is-open {
    transform: translate(-50%, -50%);
    opacity: 1;
    pointer-events: auto;
  }
  .sheet__grip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .menu, .sheet, .menu-overlay, .sheet-backdrop { transition-duration: 0.01ms !important; }
  .menu.is-open .menu__item { animation-duration: 0.01ms !important; }
}

/* ============================================================
   SUPPORT CHAT — messenger-style sheet
   ============================================================ */
.sheet--chat {
  display: flex;
  flex-direction: column;
  height: 88vh;
  max-height: 92vh;
}
.sheet--chat .sheet__grip { flex-shrink: 0; }

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 18px 14px;
  border-bottom: 1px solid var(--hair);
  flex-shrink: 0;
}
.chat-header__avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--ink-on-dark);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-style: normal;
  font-weight: 500;
  font-size: 18px;
  flex-shrink: 0;
  position: relative;
}
.chat-header__avatar::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: var(--moss);
  border: 2px solid var(--bg-page);
  border-radius: 50%;
}
.chat-header__meta { flex: 1; min-width: 0; }
.chat-header__name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.2;
  margin: 0;
  color: var(--ink);
}
.chat-header__status {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0.10em;
  color: var(--moss);
  font-weight: 400;
}
.chat-header__role {
  font-family: var(--font-display);
  font-style: normal;
  font-size: 12px;
  color: var(--ink-mute);
  margin: 2px 0 0;
}

/* stream */
.chat-stream {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-page);
}
.chat-stream::-webkit-scrollbar { width: 6px; }
.chat-stream::-webkit-scrollbar-thumb { background: var(--hair); border-radius: 3px; }

.chat-meta {
  align-self: center;
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: none;
  letter-spacing: 0.16em;
  color: var(--ink-mute);
  padding: 8px 0 14px;
  text-align: center;
}
.chat-meta .ac { color: var(--accent); }

/* bubbles */
.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  animation: bubble-in 280ms var(--ease-enter);
}
.bubble--ai {
  align-self: flex-start;
  background: var(--bg-canvas);
  border: 1px solid var(--hair);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.bubble--user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--ink-on-dark);
  border-bottom-right-radius: 4px;
}
.bubble-meta {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.10em;
  color: var(--ink-faint);
  padding: 2px 12px 6px;
}
.bubble-meta--user { align-self: flex-end; }
.bubble-meta--ai { align-self: flex-start; }

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* typing indicator */
.chat-typing {
  align-self: flex-start;
  background: var(--bg-canvas);
  border: 1px solid var(--hair);
  border-bottom-left-radius: 4px;
  border-radius: 18px;
  padding: 12px 16px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}
.chat-typing span {
  width: 6px;
  height: 6px;
  background: var(--ink-mute);
  border-radius: 50%;
  display: inline-block;
  animation: chat-dot 1.4s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.16s; }
.chat-typing span:nth-child(3) { animation-delay: 0.32s; }
@keyframes chat-dot {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0) scale(1); }
  30% { opacity: 1; transform: translateY(-3px) scale(1.12); }
}

/* quick-reply chips — pills прижатые к низу стрима, над input-bar */
.chat-quick {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: auto 0 6px;       /* auto top — толкает чипы вниз стрима к input-bar */
  padding: 14px 0 4px;
  position: relative;
  align-items: center;
}
.chat-quick::before {
  content: 'можно начать с этого';
  display: block;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 9.5px;
  text-transform: none;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  margin-bottom: 6px;
}
.chat-quick button {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  padding: 9px 16px;
  border: 1px solid var(--accent);
  background: var(--bg-canvas);
  color: var(--accent);
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.1;
  transition: background var(--t-fast) var(--ease-ui),
              color var(--t-fast) var(--ease-ui),
              transform var(--t-micro) var(--ease-ui);
  box-shadow: 0 1px 2px rgba(31, 52, 97, 0.04);
}
.chat-quick button:hover {
  background: var(--accent);
  color: var(--ink-on-dark);
}
.chat-quick button:active { transform: scale(0.96); }
.chat-quick button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* chat-meta (присоединилась к чату) — компактнее */
.chat-meta {
  font-family: var(--font-mono);
  font-size: 9.5px;
  text-transform: none;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  text-align: center;
  padding: 8px 0 12px;
  align-self: center;
}
.chat-meta .ac { color: var(--accent); }

/* input bar */
.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px max(14px, env(safe-area-inset-bottom)) 14px;
  background: var(--bg-page);
  border-top: 1px solid var(--hair);
  flex-shrink: 0;
}
.chat-input-bar input {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg-canvas);
  border: 1px solid var(--hair);
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 14.5px;
  color: var(--ink);
  transition: border-color var(--t-fast) var(--ease-ui);
}
.chat-input-bar input:focus { outline: none; border-color: var(--ink); }
.chat-input-bar input::placeholder { color: var(--ink-faint); }
.chat-input-bar button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--ink-on-dark);
  border: 1px solid var(--accent);
  font-family: var(--font-mono);
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background-color var(--t-fast) var(--ease-ui), transform var(--t-micro) var(--ease-ui);
}
.chat-input-bar button:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.chat-input-bar button:active { transform: scale(0.94); }

/* ─── RICH BLOCKS ────────────────────────────────────────── */

/* quick-actions row */
.chat-actions {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 4px 14px 8px;
  align-self: flex-start;
  max-width: 88%;
}
.chat-action-btn {
  font-family: var(--font-body);
  font-size: 12px;
  padding: 6px 12px;
  border: 1px solid var(--accent);
  background: var(--accent-wash);
  color: var(--accent);
  border-radius: 16px;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-ui);
}
.chat-action-btn:hover { background: var(--accent); color: var(--ink-on-dark); }
.chat-action-btn:active { transform: scale(0.96); }

/* entity card */
.chat-entity {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 14px 8px;
  padding: 10px 12px;
  background: var(--bg-canvas);
  border: 1px solid var(--hair-strong);
  border-radius: 8px;
  text-decoration: none;
  color: var(--ink);
  max-width: 88%;
  align-self: flex-start;
  transition: border-color var(--t-fast) var(--ease-ui), transform var(--t-fast) var(--ease-ui);
}
.chat-entity:hover { border-color: var(--accent); transform: translateY(-1px); }
.chat-entity__ico {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: var(--accent-wash);
  color: var(--accent);
  font-family: var(--font-display); font-style: normal;
  font-size: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}
.chat-entity__body { flex: 1; min-width: 0; }
.chat-entity__title {
  font-family: var(--font-body);
  font-size: 13.5px; font-weight: 500;
  color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-entity__meta {
  font-family: var(--font-display); font-style: normal;
  font-size: 11.5px; color: var(--ink-mute);
  margin-top: 2px;
}
.chat-entity__arrow {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 14px;
  margin-left: 4px;
}

/* form step card */
.chat-form-step {
  margin: 4px 14px 8px;
  padding: 12px 14px;
  background: var(--bg-canvas);
  border: 1px solid var(--hair-strong);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  max-width: 92%;
  align-self: flex-start;
  display: flex; flex-direction: column; gap: 8px;
  animation: cfs-in 280ms var(--ease-enter, ease-out);
}
@keyframes cfs-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.chat-form-step.done { opacity: 0.5; pointer-events: none; }
.chat-form-step__lbl {
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.4;
}
.chat-form-step__hint {
  font-family: var(--font-display); font-style: normal;
  font-size: 11.5px; color: var(--ink-mute);
}
.chat-form-step input,
.chat-form-step textarea {
  width: 100%;
  padding: 9px 11px;
  font-family: var(--font-body);
  font-size: 13.5px;
  color: var(--ink);
  background: var(--bg-page);
  border: 1px solid var(--hair-strong);
  border-radius: 4px;
  resize: vertical;
}
.chat-form-step input:focus,
.chat-form-step textarea:focus { outline: none; border-color: var(--accent); }
.chat-form-step__opts {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 2px;
}
.chat-form-step__opt {
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 500;
  padding: 8px 14px;
  background: var(--bg-canvas);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 18px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--t-fast) var(--ease-ui);
  line-height: 1.1;
}
.chat-form-step__opt:hover { background: var(--accent); color: var(--ink-on-dark); }
.chat-form-step__opt:active { transform: scale(0.96); }
.chat-form-step__opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-form-step__send {
  align-self: flex-start;
  font-family: var(--font-body);
  font-size: 12px;
  padding: 7px 14px;
  background: var(--accent);
  color: var(--ink-on-dark);
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid var(--accent);
  transition: background-color var(--t-fast) var(--ease-ui);
}
.chat-form-step__send:hover { background: var(--accent-strong); }

/* form draft (final summary card) */
.chat-form-draft {
  margin: 6px 14px 8px;
  padding: 14px 16px;
  background: var(--accent-wash);
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  max-width: 92%;
  align-self: flex-start;
  display: flex; flex-direction: column; gap: 10px;
  animation: cfs-in 280ms var(--ease-enter, ease-out);
}
.chat-form-draft.done { background: var(--bg-soft); border-color: var(--moss); }
.chat-form-draft__head {
  display: flex; align-items: center; gap: 8px;
}
.chat-form-draft__ico {
  width: 28px; height: 28px;
  background: var(--accent);
  color: var(--ink-on-dark);
  font-family: var(--font-display); font-style: normal;
  font-size: 14px;
  display: grid; place-items: center;
  border-radius: 50%;
}
.chat-form-draft.done .chat-form-draft__ico { background: var(--moss); }
.chat-form-draft__title {
  font-family: var(--font-body);
  font-size: 13.5px; font-weight: 600;
  color: var(--ink);
}
.chat-form-draft__rows {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--bg-canvas);
  border-radius: 4px;
  padding: 8px 12px;
}
.chat-form-draft__row {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 12.5px;
}
.chat-form-draft__row .l {
  font-family: var(--font-display); font-style: normal;
  color: var(--ink-mute);
}
.chat-form-draft__row .v {
  font-family: var(--font-body);
  color: var(--ink);
  font-weight: 500;
  text-align: right;
}
.chat-form-draft__actions {
  display: flex; gap: 6px;
}
.chat-form-draft__actions button {
  font-family: var(--font-body); font-size: 12px;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  flex: 1;
}
.chat-form-draft .cfd-edit {
  background: var(--bg-canvas);
  border: 1px solid var(--hair-strong);
  color: var(--ink-mute);
}
.chat-form-draft .cfd-edit:hover { color: var(--ink); border-color: var(--ink-mute); }
.chat-form-draft .cfd-send {
  background: var(--accent);
  color: var(--ink-on-dark);
  border: 1px solid var(--accent);
}
.chat-form-draft .cfd-send:hover { background: var(--accent-strong); }
.chat-form-draft__ok {
  font-family: var(--font-body); font-size: 12.5px;
  color: var(--moss); font-weight: 500;
  padding: 8px 0;
}

/* escalate card */
.chat-escalate {
  margin: 6px 14px 8px;
  padding: 12px 14px;
  background: var(--state-pending-bg, #FBF1DD);
  border: 1px solid var(--amber, #d4a93a);
  border-radius: 8px;
  max-width: 88%;
  align-self: flex-start;
  display: flex; flex-direction: column; gap: 8px;
  animation: cfs-in 280ms var(--ease-enter, ease-out);
}
.chat-escalate.done { background: var(--bg-soft); border-color: var(--moss); }
.chat-escalate__head { display: flex; align-items: center; gap: 8px; }
.chat-escalate__ico {
  width: 24px; height: 24px;
  background: var(--amber, #d4a93a); color: white;
  display: grid; place-items: center;
  font-size: 13px; border-radius: 50%;
}
.chat-escalate__title { font-family: var(--font-body); font-weight: 600; font-size: 13px; }
.chat-escalate__prio {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--garnet);
  background: var(--bg-canvas);
  padding: 2px 7px;
  border-radius: 3px;
  text-transform: none;
  letter-spacing: 0.06em;
}
.chat-escalate__topic { font-family: var(--font-body); font-size: 13px; color: var(--ink); font-weight: 500; }
.chat-escalate__preview { font-family: var(--font-display); font-style: normal; font-size: 12px; color: var(--ink-mute); line-height: 1.4; }
.chat-escalate__actions { display: flex; gap: 6px; }
.chat-escalate__actions button {
  font-family: var(--font-body); font-size: 12px;
  padding: 7px 12px; border-radius: 4px; cursor: pointer; flex: 1;
}
.chat-escalate .ces-cancel { background: var(--bg-canvas); border: 1px solid var(--hair); color: var(--ink-mute); }
.chat-escalate .ces-send   { background: var(--accent); border: 1px solid var(--accent); color: var(--ink-on-dark); }
.chat-escalate__ok { font-family: var(--font-body); font-size: 12.5px; color: var(--moss); font-weight: 500; padding: 4px 0; }

/* attach + mic in chat-input-bar */
.chat-attach, .chat-mic {
  width: 36px; height: 36px;
  background: transparent;
  border: 1px solid var(--hair);
  border-radius: 50%;
  color: var(--ink-mute);
  display: grid; place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--t-fast) var(--ease-ui), border-color var(--t-fast) var(--ease-ui);
}
.chat-attach:hover, .chat-mic:hover { color: var(--accent); border-color: var(--accent); }
.chat-mic.rec {
  background: var(--garnet);
  color: white;
  border-color: var(--garnet);
  animation: mic-pulse 1.4s infinite ease-in-out;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(138, 46, 34, 0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(138, 46, 34, 0); }
}

/* mood-affected stream tints (subtle) · П1: токены вместо hex — доезжают в dark */
.chat-stream.mood-stressed,
.chat-stream.mood-frustrated { background: var(--state-overdue-bg, #fdf6f3); }
.chat-stream.mood-tired { background: var(--bg-soft, #f8f5f0); }
.chat-stream.mood-happy { background: var(--state-paid-bg, #f3f8f3); }

/* desktop: chat sheet centered modal */
@media (min-width: 720px) {
  .sheet--chat {
    width: 460px;
    max-width: calc(100vw - 64px);
    height: 640px;
    max-height: 80vh;
  }
}

/* ─── Sprint 6 B4: AI streaming bubble (typing + slow indicator) ─── */
.bubble.ai-typing {
  min-height: 30px;
  padding: 10px 14px;
}
.bubble.ai-typing .ai-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.bubble.ai-typing .ai-dots span {
  width: 5px;
  height: 5px;
  background: var(--ink-mute, #6B6B6B);
  border-radius: 50%;
  display: inline-block;
  animation: chat-dot 1.4s infinite ease-in-out;
}
.bubble.ai-typing .ai-dots span:nth-child(2) { animation-delay: 0.16s; }
.bubble.ai-typing .ai-dots span:nth-child(3) { animation-delay: 0.32s; }
.bubble.ai-typing.ai-slow::after {
  content: 'AI задержан…';
  display: block;
  font-family: var(--font-mono, monospace);
  font-size: 10px;
  color: var(--ink-mute, #6B6B6B);
  margin-top: 4px;
  letter-spacing: 0.04em;
  opacity: 0.7;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ============================================================
   IMPERSONATION BANNER — админ «Войти в кабинет» (v185)
   Фиксированная полоса над шапкой; страница сдвигается на её высоту
   (--impersonation-h выставляет app.js по фактической высоте).
   ============================================================ */
:root { --impersonation-h: 0px; }
.impersonation-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: var(--accent);
  color: var(--bg-canvas);
  font: 500 13px/1.35 var(--font-body);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
}
.impersonation-banner__text { flex: 1 1 auto; min-width: 0; text-align: center; }
.impersonation-banner__stop {
  flex: none;
  min-height: 32px;
  padding: 0 14px;
  border: 1px solid var(--bg-canvas);
  border-radius: var(--r-button, 12px);
  background: var(--bg-canvas);
  color: var(--accent);
  font: 600 13px/1 var(--font-body);
  cursor: pointer;
}
.impersonation-banner__stop:hover { background: transparent; color: var(--bg-canvas); }
.impersonation-banner__stop:focus-visible { outline: 2px solid var(--bg-canvas); outline-offset: 2px; }
.impersonation-banner__stop:disabled { opacity: 0.6; cursor: default; }
body.has-impersonation { padding-top: var(--impersonation-h); }
body.has-impersonation .app-shell .app-top { top: var(--impersonation-h); }
body.has-impersonation .menu { top: var(--impersonation-h); }
@media (min-width: 1024px) {
  body.has-impersonation .app-shell .app-side {
    top: var(--impersonation-h);
    height: calc(100vh - var(--impersonation-h));
  }
}
