/* ============================================================
   Design tokens — modern AI workspace (slate + indigo, light)
   ============================================================ */
:root {
  /* Palette: slate (neutrals) + indigo (accent) */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  --indigo-50:  #eef2ff;
  --indigo-100: #e0e7ff;
  --indigo-200: #c7d2fe;
  --indigo-500: #6366f1;
  --indigo-600: #4f46e5;
  --indigo-700: #4338ca;

  --emerald-50:  #ecfdf5;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --emerald-700: #047857;

  --amber-50:  #fffbeb;
  --amber-100: #fef3c7;
  --amber-500: #f59e0b;
  --amber-700: #b45309;

  --rose-50:   #fff1f2;
  --rose-500:  #f43f5e;
  --rose-600:  #e11d48;
  --rose-700:  #be123c;

  /* Semantic — surfaces & text */
  --bg:           var(--slate-50);
  --surface:      #ffffff;
  --surface-2:    var(--slate-50);
  --surface-3:    var(--slate-100);
  --border:       var(--slate-200);
  --border-strong: var(--slate-300);

  --text:           var(--slate-900);
  --text-secondary: var(--slate-500);
  --text-tertiary:  var(--slate-400);

  /* Accent */
  --primary:        var(--indigo-600);
  --primary-hover:  var(--indigo-700);
  --primary-soft:   var(--indigo-50);
  --primary-soft-2: var(--indigo-100);
  --primary-text:   #ffffff;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);

  /* Status */
  --danger:        var(--rose-600);
  --danger-soft:   var(--rose-50);
  --success:       var(--emerald-600);
  --success-soft:  var(--emerald-50);
  --warning:       var(--amber-700);
  --warning-soft:  var(--amber-50);

  /* Sidebar (chat) — slightly off-white panel rather than dark */
  --sidebar-bg:     var(--slate-900);
  --sidebar-text:   #e2e8f0;
  --sidebar-muted:  rgba(226, 232, 240, 0.55);
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-hover:  rgba(255, 255, 255, 0.06);
  --sidebar-active: rgba(99, 102, 241, 0.22);

  /* Bubbles */
  --user-bg:       var(--indigo-50);
  --user-border:   var(--indigo-100);
  --assistant-bg:  var(--surface);
  --assistant-border: var(--slate-200);

  /* Radii */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-2xl: 22px;
  --radius-full: 9999px;

  /* Shadows — soft, layered */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow:    0 4px 12px rgba(15, 23, 42, 0.06), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 10px 25px rgba(15, 23, 42, 0.08), 0 4px 10px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 40px rgba(15, 23, 42, 0.10), 0 8px 16px rgba(15, 23, 42, 0.05);
  --shadow-xl: 0 30px 60px rgba(15, 23, 42, 0.18);
  --ring: 0 0 0 3px rgba(99, 102, 241, 0.18);

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 120ms;
  --dur:      180ms;
  --dur-slow: 280ms;

  /* Type scale */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;
}

/* ============================================================
   Reset & base
   ============================================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Абзацы без «сирот» в последней строке. */
  text-wrap: pretty;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a { color: var(--primary); text-decoration: none; transition: color var(--dur) var(--ease); }

/* Заголовки переносим сбалансированно: строки выравниваются по длине,
   вместо «шесть слов + одно» на второй строке. */
h1, h2, h3, .tz-card-title, .questions-block-title { text-wrap: balance; }
a:hover { color: var(--primary-hover); }

.hidden { display: none !important; }

/* Lucide icons sizing */
[data-lucide], .lucide {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  flex-shrink: 0;
  vertical-align: -2px;
}

/* ============================================================
   Screens
   ============================================================ */
.screen { height: 100vh; }

/* ============================================================
   Login
   ============================================================ */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at top left, rgba(99, 102, 241, 0.18), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(139, 92, 246, 0.18), transparent 60%),
    linear-gradient(160deg, var(--slate-900) 0%, var(--slate-800) 100%);
  padding: 24px;
}

.login-card {
  background: var(--surface);
  padding: 48px 44px;
  border-radius: var(--radius-2xl);
  text-align: center;
  box-shadow: var(--shadow-xl);
  max-width: 420px;
  width: 100%;
  animation: cardIn var(--dur-slow) var(--ease);
}

.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-gradient);
  color: white;
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
}
.login-logo [data-lucide], .login-logo .lucide {
  width: 28px;
  height: 28px;
}
/* Знак сервиса. Крупнее иконок lucide: у него нет внутренней «воздушной» рамки. */
.brand-mark {
  width: 32px;
  height: 32px;
}

.login-card h1 {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.login-card p {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 15px;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.2;
  transition: background var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease),
              transform var(--dur-fast) var(--ease),
              scale var(--dur-fast) var(--ease);
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-color: var(--primary);
}

.btn:active { scale: 0.96; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.30);
}

.btn-primary:focus-visible {
  box-shadow: var(--ring), 0 1px 2px rgba(79, 70, 229, 0.25);
}

.btn-danger {
  color: var(--danger);
  border-color: var(--rose-200, #fecdd3);
  background: var(--surface);
}

.btn-danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.btn-large { padding: 13px 26px; font-size: 15px; border-radius: var(--radius); }
.btn-small { padding: 5px 10px; font-size: 12px; }
.btn-full  { width: 100%; }

/* Compact icon-only button (used in sidebar header etc.) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--sidebar-border);
  background: transparent;
  color: var(--sidebar-text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              scale var(--dur-fast) var(--ease);
}
/* Визуально 30px, но палец/курсор попадают по 40px — минимальная цель. */
.icon-btn::after {
  content: '';
  position: absolute;
  inset: -5px;
}
.icon-btn:active { scale: 0.96; }
.icon-btn:hover {
  background: var(--sidebar-hover);
  border-color: rgba(255,255,255,0.18);
}
.icon-btn [data-lucide], .icon-btn .lucide { width: 15px; height: 15px; }

/* ============================================================
   Main layout
   ============================================================ */
#main-screen {
  display: flex;
  height: 100vh;
}

/* ============================================================
   Sidebar
   ============================================================ */
#sidebar {
  width: 304px;
  min-width: 304px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 14px 12px 12px;
  gap: 10px;
  border-right: 1px solid var(--sidebar-border);
}

/* Панель нового запроса: режим + направление + кнопка как одна группа.
   Радиусы концентричные: 18 снаружи, padding 8 → 10 у вложенных. */
.compose-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.045);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.compose-panel #btn-new-session {
  margin-bottom: 0;
  border-radius: 10px;
}

/* === Сегментированный переключатель режима === */
.segmented {
  position: relative;
  display: grid;
  /* Число сегментов задаёт JS: у направления может быть 2 режима или 3. */
  /* minmax(0,…) обязателен: с обычным 1fr сегменты не сжимаются ниже своего
     содержимого и вылезают за трек, когда режимов три. */
  grid-template-columns: repeat(var(--segmented-count, 2), minmax(0, 1fr));
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  --segmented-index: 0;
}
/* Подложка едет к выбранному сегменту; ширина = доля трека минус padding и зазоры. */
.segmented-thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px - (var(--segmented-count, 2) - 1) * 2px) / var(--segmented-count, 2));
  border-radius: 7px;
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.95) 0%, rgba(79, 70, 229, 0.95) 100%);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transform: translateX(calc(var(--segmented-index) * (100% + 2px)));
  transition: transform 420ms cubic-bezier(0.32, 0.72, 0, 1);
  pointer-events: none;
}
.segmented-option {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 6px 8px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--sidebar-muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: color 200ms var(--ease), scale var(--dur-fast) var(--ease);
}
.segmented-option [data-lucide], .segmented-option .lucide { width: 14px; height: 14px; }
.segmented-option:hover { color: rgba(226, 232, 240, 0.85); }
.segmented-option.is-active { color: #ffffff; }
.segmented-option:active { scale: 0.96; }
.segmented-option:focus-visible {
  outline: 2px solid rgba(165, 180, 252, 0.8);
  outline-offset: 1px;
}

/* Режим без права: опция видна, но с замком — клик открывает окно заявки.
   Скрывать её нельзя, иначе о существовании режима никто не узнаёт. */
.segmented-option.is-locked { color: rgba(226, 232, 240, 0.42); }
.segmented-option.is-locked:hover { color: rgba(226, 232, 240, 0.72); }
/* Режима нет в этом направлении — сегмент не показываем вовсе
   (в отличие от .is-locked: тот виден и ведёт в окно заявки). */
.segmented-option.is-unavailable { display: none; }

/* Три режима в 260-пиксельном сайдбаре: подпись важнее иконки, иначе
   «Отчёт» обрезается многоточием. Класс ставит updateModePicker. */
.segmented.is-compact .segmented-option { padding: 6px 4px; gap: 4px; font-size: 11.5px; }
.segmented.is-compact .segmented-option > svg,
.segmented.is-compact .segmented-option > i { display: none; }
.segmented-option span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.segmented-option .segmented-lock { display: none; }
.segmented-option.is-locked .segmented-lock {
  display: inline-block;
  width: 11px;
  height: 11px;
  opacity: 0.8;
}

/* === Выбор направления === */
.direction-field {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  transition: background 200ms var(--ease), box-shadow 200ms var(--ease), opacity 200ms var(--ease);
}
.direction-field:hover { background: rgba(255, 255, 255, 0.09); }
.direction-field:focus-within { box-shadow: inset 0 0 0 1px rgba(129, 140, 248, 0.75); }
.direction-field.is-locked { opacity: 0.45; pointer-events: none; }
.direction-field-icon {
  position: absolute;
  left: 10px;
  display: flex;
  color: #a5b4fc;
  pointer-events: none;
}
.direction-field-icon [data-lucide], .direction-field-icon .lucide { width: 15px; height: 15px; }
.direction-field-caret {
  position: absolute;
  right: 10px;
  width: 14px;
  height: 14px;
  color: var(--sidebar-muted);
  pointer-events: none;
}
.direction-select {
  width: 100%;
  min-height: 34px;
  padding: 7px 30px 7px 32px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--sidebar-text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
}
/* Раскрытый список рисует ОС — там нужен читаемый контраст на светлом фоне. */
.direction-select option { background: var(--surface); color: var(--text); }

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px 12px;
  border-bottom: 1px solid var(--sidebar-border);
  font-size: 13.5px;
  font-weight: 500;
  gap: 8px;
}

#user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.sidebar-header-actions {
  display: flex;
  /* gap = 40 - 30: hit-области кнопок (40px через ::after) соприкасаются, но не
     перекрываются — иначе промах по «Админка» попадал бы в «Выйти». */
  gap: 10px;
  flex-shrink: 0;
}

#btn-new-session {
  margin-bottom: 4px;
}

/* Sessions search */
.sessions-search {
  position: relative;
  margin-bottom: 4px;
}
.sessions-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--sidebar-muted);
  pointer-events: none;
  width: 14px;
  height: 14px;
}
.sessions-search input {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  padding: 7px 10px 7px 30px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.sessions-search input::placeholder { color: var(--sidebar-muted); }
.sessions-search input:focus {
  background: rgba(255,255,255,0.08);
  border-color: rgba(99, 102, 241, 0.5);
}
.sessions-search input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--sidebar-muted);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M18 6L6 18M6 6l12 12' stroke='black' stroke-width='2' fill='none'/></svg>") center/contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M18 6L6 18M6 6l12 12' stroke='black' stroke-width='2' fill='none'/></svg>") center/contain no-repeat;
  cursor: pointer;
}

/* Sessions list — group headings */
.sessions-group-title {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-muted);
  padding: 12px 8px 4px;
  user-select: none;
}
.sessions-empty {
  padding: 24px 12px;
  text-align: center;
  font-size: 12.5px;
  color: var(--sidebar-muted);
  line-height: 1.55;
}

.sessions-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 0 -4px;
  padding: 0 4px;
  /* Мягкий край вместо жёсткой границы: содержимое «растворяется» под поиском. */
  mask-image: linear-gradient(to bottom, transparent 0, #000 10px);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 10px);
}

/* Появление списка — только при первой отрисовке: на каждом обновлении
   (пришёл ответ, сменился статус) повторная анимация читалась бы как дёрганье. */
.sessions-list.is-first-render .session-item {
  animation: sessionIn 320ms cubic-bezier(0.32, 0.72, 0, 1) backwards;
}
.sessions-list.is-first-render .session-item:nth-child(2)  { animation-delay: 20ms; }
.sessions-list.is-first-render .session-item:nth-child(3)  { animation-delay: 40ms; }
.sessions-list.is-first-render .session-item:nth-child(4)  { animation-delay: 60ms; }
.sessions-list.is-first-render .session-item:nth-child(5)  { animation-delay: 80ms; }
.sessions-list.is-first-render .session-item:nth-child(n+6) { animation-delay: 100ms; }
@keyframes sessionIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Custom scrollbar for sidebar */
.sessions-list::-webkit-scrollbar { width: 6px; }
.sessions-list::-webkit-scrollbar-track { background: transparent; }
.sessions-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.10);
  border-radius: var(--radius-full);
}
.sessions-list::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

/* Карточка чата: [значок направления] [название + состояние] [«⋯»].
   Радиусы концентричные: 14 снаружи при padding 6 → 8 у значка. */
.session-item {
  position: relative;
  display: flex;
  /* Не center: при двухстрочном названии значок должен стоять у первой строки,
     иначе он «плавает» в зависимости от длины заголовка. */
  align-items: flex-start;
  gap: 9px;
  padding: 6px;
  border-radius: 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              scale var(--dur-fast) var(--ease);
}

.session-item:hover { background: var(--sidebar-hover); }
.session-item:active { scale: 0.99; }
.session-item.active {
  background: var(--sidebar-active);
  box-shadow: inset 0 0 0 1px rgba(165, 180, 252, 0.28);
}
.session-item.menu-open { background: var(--sidebar-hover); }

/* Значок принадлежности: направление или «разработка отчёта». */
.session-avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.session-avatar [data-lucide], .session-avatar .lucide { width: 15px; height: 15px; }
.session-avatar[data-kind="1c"]       { background: rgba(99, 102, 241, 0.20);  color: #a5b4fc; }
.session-avatar[data-kind="catalog"]  { background: rgba(16, 185, 129, 0.18);  color: #6ee7b7; }
.session-avatar[data-kind="web"]      { background: rgba(56, 189, 248, 0.18);  color: #7dd3fc; }
.session-avatar[data-kind="self_dev"] { background: rgba(168, 85, 247, 0.20);  color: #d8b4fe; }
.session-avatar[data-kind="support"]  { background: rgba(56, 189, 248, 0.18); color: #7dd3fc; }
.session-avatar[data-kind="bitrix24"] { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }

.session-item .session-main {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

/* Название — до двух строк: у сгенерированных заголовков смысл часто во второй
   половине («…добавить сроки к АЗ»), а одна строка обрезала её на середине. */
.session-item .session-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 500;
  letter-spacing: -0.006em;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

/* Вторая строка: что с чатом происходит и когда была активность. */
.session-sub {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
  font-size: 11.5px;
  line-height: 1.4;
}
.session-state {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--sidebar-muted);
}
.session-state-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-dot {
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.session-state[data-tone="live"]      { color: #c4b5fd; font-weight: 500; }
.session-state[data-tone="attention"] { color: #fbbf24; }
.session-state[data-tone="open"]      { color: #34d399; }
.session-state[data-tone="done"]      { color: rgba(226, 232, 240, 0.55); }
.session-state[data-tone="handoff"] { color: #7dd3fc; }
.session-state[data-tone="muted"]     { color: rgba(226, 232, 240, 0.38); }

.session-time {
  flex-shrink: 0;
  color: rgba(226, 232, 240, 0.42);
  font-variant-numeric: tabular-nums;
}

/* Терминальные чаты приглушены — видно, что продолжать там нечего. */
.session-item.is-closed .session-title { color: rgba(226, 232, 240, 0.62); font-weight: 400; }
.session-item.is-closed .session-avatar { opacity: 0.65; }

/* «Агент отвечает»: подсветка карточки + пульс значка + бегущие точки.
   Работающий чат должен быть виден с одного взгляда, даже если открыт другой. */
.session-item.is-running {
  background: rgba(139, 92, 246, 0.10);
  box-shadow: inset 0 0 0 1px rgba(167, 139, 250, 0.22);
}
.session-item.is-running:hover { background: rgba(139, 92, 246, 0.16); }
.session-item.is-running.active {
  background: var(--sidebar-active);
  box-shadow: inset 0 0 0 1px rgba(167, 139, 250, 0.45);
}
.session-item.is-running .session-avatar {
  animation: sessionPulse 2s var(--ease) infinite;
}
@keyframes sessionPulse {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06), 0 0 0 0 rgba(167, 139, 250, 0.40); }
  50%      { box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06), 0 0 0 5px rgba(167, 139, 250, 0.02); }
}
.session-typing {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
  padding-bottom: 1px;
}
.session-typing i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  animation: typingDot 1.2s var(--ease) infinite;
}
.session-typing i:nth-child(2) { animation-delay: 0.15s; }
.session-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingDot {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30%           { opacity: 1;    transform: translateY(-2px); }
}

/* Кнопка «⋯»: место под неё зарезервировано всегда, поэтому название
   не прыгает при наведении. Хит-область добирается до 40px через ::after. */
.session-menu-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur) var(--ease), background var(--dur) var(--ease),
              color var(--dur) var(--ease), scale var(--dur-fast) var(--ease);
}
.session-menu-btn::after { content: ''; position: absolute; inset: -6px; }
.session-menu-btn [data-lucide], .session-menu-btn .lucide { width: 15px; height: 15px; }
.session-item:hover .session-menu-btn,
.session-item.menu-open .session-menu-btn,
.session-menu-btn:focus-visible { opacity: 1; }
.session-menu-btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.session-menu-btn:active { scale: 0.96; }

/* Всплывающее меню действий (общее на весь список). */
.session-menu {
  position: fixed;
  z-index: 120;
  min-width: 176px;
  padding: 5px;
  border-radius: 14px;
  background: rgba(30, 41, 59, 0.92);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 18px 40px rgba(2, 6, 23, 0.45), 0 2px 8px rgba(2, 6, 23, 0.35),
              inset 0 0 0 1px rgba(255, 255, 255, 0.09);
  display: flex;
  flex-direction: column;
  gap: 1px;
  animation: menuIn 180ms cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes menuIn {
  from { opacity: 0; transform: scale(0.94); filter: blur(4px); }
  to   { opacity: 1; transform: scale(1);    filter: blur(0); }
}
.session-menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  padding: 8px 10px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--sidebar-text);
  font-family: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.session-menu-item [data-lucide], .session-menu-item .lucide { width: 15px; height: 15px; opacity: 0.75; }
.session-menu-item:hover { background: rgba(255, 255, 255, 0.10); }
.session-menu-item.danger { color: #fda4af; }
.session-menu-item.danger:hover { background: rgba(244, 63, 94, 0.20); color: #fecdd3; }

/* Точки статусов в админке (таблица сессий) — своя разметка, не сайдбар. */
.session-status {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.04);
}

.session-status.active    { background: var(--emerald-500); box-shadow: 0 0 8px rgba(16,185,129,0.55); }
.session-status.tz_review { background: var(--amber-500);   box-shadow: 0 0 8px rgba(245,158,11,0.45); }
.session-status.completed { background: var(--indigo-500); }
.session-status.cancelled { background: var(--slate-500); }
.session-status.expired   { background: var(--slate-600); }

.sidebar-footer {
  padding-top: 10px;
  border-top: 1px solid var(--sidebar-border);
  font-size: 11.5px;
  color: var(--sidebar-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* === Модалка настроек (доступ к данным 1С) === */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}

.settings-card {
  background: var(--surface, #fff);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px 22px;
  animation: modalIn var(--dur) cubic-bezier(0.2, 0, 0, 1);
}
/* Появление — заметное, уход (.closing) — мягче: смещение вдвое меньше. */
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.settings-overlay.closing { animation: overlayOut var(--dur-fast) var(--ease) forwards; }
.settings-overlay.closing .settings-card { animation: modalOut var(--dur-fast) var(--ease) forwards; }
@keyframes overlayOut { to { opacity: 0; } }
@keyframes modalOut { to { opacity: 0; transform: translateY(4px); } }

.settings-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.settings-card-header h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
}

.settings-card-header h3 [data-lucide],
.settings-card-header h3 .lucide {
  width: 18px;
  height: 18px;
  color: var(--indigo-600, #4f46e5);
}

.settings-hint {
  font-size: 13px;
  color: var(--text-muted, #64748b);
  margin-bottom: 12px;
}

.settings-status {
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  line-height: 1.5;
}

.settings-status.is-ok { border-color: #bbf7d0; background: #f0fdf4; }
.settings-status.is-warn { border-color: #fde68a; background: #fffbeb; }
.settings-status.is-blocked { border-color: #fecaca; background: #fef2f2; }

.settings-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin: 10px 0 4px;
}

#odata-creds-form input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface, #fff);
}

#odata-creds-form input:focus {
  outline: 2px solid var(--indigo-200, #c7d2fe);
  border-color: var(--indigo-400, #818cf8);
}

#selfdev-note {
  width: 100%;
  min-height: 72px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  background: var(--surface, #fff);
}

#selfdev-note:focus {
  outline: 2px solid var(--indigo-200, #c7d2fe);
  border-color: var(--indigo-400, #818cf8);
}

.settings-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.settings-note {
  font-size: 12px;
  color: var(--text-muted, #64748b);
  margin-top: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.status-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--emerald-500);
  box-shadow: 0 0 6px rgba(16,185,129,0.55);
}

/* ============================================================
   Chat area
   ============================================================ */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  padding: 32px;
  text-align: center;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
}
.empty-state-icon [data-lucide], .empty-state-icon .lucide {
  width: 32px;
  height: 32px;
}

.empty-state h2 {
  margin-bottom: 8px;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.empty-state p {
  font-size: 14px;
  max-width: 520px;
}

.empty-state-templates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 28px;
  width: 100%;
  max-width: 760px;
}

.template-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: border-color var(--dur) var(--ease),
              transform var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
  box-shadow: var(--shadow-xs);
}
.template-card:active { scale: 0.96; }
.template-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.template-card:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-color: var(--primary);
}
.template-card [data-lucide],
.template-card .lucide {
  width: 20px;
  height: 20px;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 6px;
  border-radius: var(--radius-sm);
  box-sizing: content-box;
  margin-bottom: 4px;
}
.template-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.template-card-hint {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ============================================================
   Messages
   ============================================================ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: var(--slate-200);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg);
}
.messages::-webkit-scrollbar-thumb:hover { background: var(--slate-300); }

.message {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  animation: msgIn var(--dur) var(--ease);
  box-shadow: var(--shadow-xs);
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  color: var(--text);
  border-bottom-right-radius: var(--radius-xs);
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  border: 1px solid var(--assistant-border);
  border-bottom-left-radius: var(--radius-xs);
}

.message .time {
  display: block;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   TZ card (in message stream)
   ============================================================ */
.tz-card {
  align-self: flex-start;
  background: linear-gradient(135deg, var(--primary-soft) 0%, #ffffff 100%);
  border: 1px solid var(--primary-soft-2);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  font-size: 14px;
  max-width: 78%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  animation: msgIn var(--dur) var(--ease);
}
.tz-card .tz-card-title {
  font-weight: 600;
  color: var(--indigo-700);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14.5px;
}
.tz-card .tz-card-title [data-lucide],
.tz-card .tz-card-title .lucide {
  width: 18px;
  height: 18px;
  color: var(--primary);
}
.tz-card .tz-card-hint { color: var(--text-secondary); font-size: 13px; line-height: 1.5; }
.tz-card .tz-card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

/* Этап разработчика (Релиз 2): строка статуса подзадачи программисту */
.tz-card .dev-stage-note {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px dashed var(--primary-soft-2);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.tz-card .dev-stage-note [data-lucide],
.tz-card .dev-stage-note .lucide { width: 16px; height: 16px; flex-shrink: 0; }
.tz-card .dev-stage-note a { color: var(--primary); font-weight: 600; }

/* ============================================================
   Structured questions block
   ============================================================ */
.questions-block {
  align-self: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 92%;
  box-shadow: var(--shadow-sm);
  animation: msgIn var(--dur) var(--ease);
}
.questions-block-title {
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
}
.questions-block-title [data-lucide],
.questions-block-title .lucide {
  width: 20px;
  height: 20px;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 4px;
  border-radius: var(--radius-sm);
  box-sizing: content-box;
}
.questions-block-hint {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: -6px;
  line-height: 1.5;
}
.questions-block-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.questions-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 200px;
}

.questions-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--surface-3);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.questions-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-gradient);
  border-radius: var(--radius-full);
  transition: width var(--dur-slow) var(--ease);
}

.questions-progress-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-weight: 500;
}

/* Single question card */
.question-card {
  display: flex;
  gap: 12px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--dur) var(--ease);
}
.question-card:hover { border-color: var(--border-strong); }
.question-num {
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
  min-width: 22px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.question-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.question-text {
  font-weight: 500;
  color: var(--text);
  line-height: 1.45;
  word-wrap: break-word;
}
.question-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.question-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--dur) var(--ease);
  line-height: 1.4;
  border: 1px solid transparent;
}
.question-option:hover {
  background: var(--surface);
  border-color: var(--border);
}
.question-option:has(input:checked) {
  background: var(--primary-soft);
  border-color: var(--primary-soft-2);
}
.question-option input {
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}
.question-option span {
  word-wrap: break-word;
  word-break: break-word;
  min-width: 0;
}
.question-text-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 44px;
  background: var(--surface);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.question-text-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
.question-custom {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.question-custom-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

/* ============================================================
   Streaming / pending indicators
   ============================================================ */
.tz-streaming-indicator {
  align-self: flex-start;
  padding: 12px 16px;
  background: var(--amber-50);
  color: var(--amber-700);
  border: 1px solid var(--amber-100);
  border-radius: var(--radius-lg);
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  box-shadow: var(--shadow-xs);
}
.tz-streaming-indicator::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid var(--amber-500);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Typing — animated dots, softer style */
.typing-indicator {
  align-self: flex-start;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-xs);
  font-size: 13.5px;
  color: var(--text-secondary);
  font-style: italic;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  min-height: 20px;
  box-shadow: var(--shadow-xs);
}

.typing-indicator .typing-label {
  transition: opacity 0.25s ease;
  opacity: 1;
}

.typing-indicator::after {
  content: '...';
  animation: dots 1.5s steps(3) infinite;
  font-style: normal;
  margin-left: 1px;
  color: var(--primary);
  font-weight: 600;
}

@keyframes dots {
  0%   { content: '.'; }
  33%  { content: '..'; }
  66%  { content: '...'; }
}

/* ============================================================
   Input area
   ============================================================ */
.input-area {
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 14px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.input-row:focus-within {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.input-row textarea {
  flex: 1;
  border: none;
  background: transparent;
  padding: 7px 0;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 120px;
  color: var(--text);
}

.input-row textarea::placeholder {
  color: var(--text-tertiary);
}

.btn-icon-text {
  flex-shrink: 0;
  align-self: flex-end;
}

.input-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.char-counter {
  font-size: 11.5px;
  color: var(--text-tertiary);
  margin-right: auto;
  font-variant-numeric: tabular-nums;
}

.char-counter.warning { color: var(--amber-700); }
.char-counter.danger  { color: var(--danger); }

/* ============================================================
   TZ fullscreen
   ============================================================ */
.tz-fullscreen {
  position: fixed;
  inset: 0;
  background: var(--surface);
  z-index: 100;
  display: flex;
  flex-direction: column;
  animation: slideIn var(--dur-slow) var(--ease);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tz-fullscreen-header {
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 1;
  box-shadow: var(--shadow-xs);
}

.tz-fullscreen-title h2 {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.tz-fullscreen-title h2 [data-lucide],
.tz-fullscreen-title h2 .lucide {
  width: 22px;
  height: 22px;
  color: var(--primary);
}
.tz-fullscreen-subtitle {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
  margin-left: 32px;
}

.tz-fullscreen-actions {
  display: flex;
  gap: 8px;
}

.tz-fullscreen-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.tz-fullscreen-toc {
  width: 260px;
  min-width: 260px;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  overflow-y: auto;
  padding: 24px 8px 24px 20px;
  font-size: 13px;
}

.tz-fullscreen-toc-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  padding: 0 10px 10px;
}

.tz-fullscreen-toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.tz-fullscreen-toc li a {
  display: block;
  padding: 7px 10px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  text-decoration: none;
  line-height: 1.4;
  font-weight: 500;
  border-left: 2px solid transparent;
  margin-left: -12px;
  padding-left: 12px;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.tz-fullscreen-toc li a:hover {
  background: var(--surface);
  color: var(--text);
}

.tz-fullscreen-toc li.is-h3 a {
  padding-left: 24px;
  font-weight: 400;
  font-size: 12.5px;
}

.tz-fullscreen-toc li a.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-left-color: var(--primary);
}

.tz-fullscreen-toc::-webkit-scrollbar { width: 6px; }
.tz-fullscreen-toc::-webkit-scrollbar-thumb {
  background: var(--slate-200);
  border-radius: var(--radius-full);
}

.tz-fullscreen-content {
  flex: 1;
  overflow-y: auto;
  padding: 40px 56px 80px;
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
  line-height: 1.7;
  font-size: 15px;
  color: var(--text);
  scroll-behavior: smooth;
}

.tz-fullscreen-content h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 28px 0 14px;
}
.tz-fullscreen-content h2 {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 26px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.tz-fullscreen-content h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 18px 0 8px;
}
.tz-fullscreen-content p { margin: 8px 0; }
.tz-fullscreen-content ul, .tz-fullscreen-content ol { padding-left: 28px; margin: 8px 0; }
.tz-fullscreen-content li { margin: 4px 0; }
.tz-fullscreen-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 14px 0;
  font-size: 14px;
}
.tz-fullscreen-content th, .tz-fullscreen-content td {
  border: 1px solid var(--border);
  padding: 9px 13px;
  text-align: left;
}
.tz-fullscreen-content th {
  background: var(--surface-2);
  font-weight: 600;
}
.tz-fullscreen-content code {
  background: var(--surface-3);
  color: var(--indigo-700);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-family: var(--font-mono);
}
.tz-fullscreen-content pre {
  background: var(--slate-900);
  color: var(--slate-100);
  padding: 16px 18px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 12px 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
}
.tz-fullscreen-content pre code {
  background: none;
  color: inherit;
  padding: 0;
}
.tz-fullscreen-content details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  margin: 14px 0;
  padding: 0 16px;
}
.tz-fullscreen-content details[open] {
  padding-bottom: 12px;
}
.tz-fullscreen-content summary {
  cursor: pointer;
  font-weight: 600;
  padding: 12px 0;
  color: var(--text);
  user-select: none;
}
.tz-fullscreen-content summary:hover {
  color: var(--indigo-700);
}

/* ============================================================
   Markdown inside chat messages
   ============================================================ */
.message h1, .message h2, .message h3 {
  margin: 10px 0 6px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.message h1 { font-size: 18px; }
.message h2 { font-size: 16px; }
.message h3 { font-size: 15px; }
.message ul, .message ol { padding-left: 22px; margin: 4px 0; }
.message li { margin: 2px 0; }
.message table { border-collapse: collapse; margin: 8px 0; width: 100%; }
.message th, .message td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  font-size: 13px;
}
.message th { background: var(--surface-3); font-weight: 600; }
.message code {
  background: var(--surface-3);
  color: var(--indigo-700);
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-family: var(--font-mono);
}
.message pre {
  background: var(--slate-900);
  color: var(--slate-100);
  padding: 12px 14px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 8px 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
}
.message pre code { background: none; color: inherit; padding: 0; }

/* ============================================================
   Chat header status bar
   ============================================================ */
.chat-header-status {
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  gap: 12px;
  align-items: center;
}

.chat-header-status a {
  color: var(--primary);
  font-weight: 500;
}
.chat-header-status a:hover { text-decoration: underline; }

/* === Направления ===
   Селектор направления и переключатель режима живут в сайдбаре — их стили
   в разделе «Sidebar» выше (.direction-field / .segmented). */
.chat-header-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.chat-header-row .chat-header-status { flex: 1; }
.chat-direction {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  margin: 8px 0 8px 24px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
  white-space: nowrap;
}
/* ============================================================
   Саморазработка: бейдж режима в шапке чата, карточки
   ============================================================ */
.chat-mode {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  margin: 8px 0;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #ecfdf5;
  color: #047857;
  white-space: nowrap;
}
.mode-note {
  align-self: center;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--text-secondary);
  background: var(--surface-3);
  animation: msgIn var(--dur) var(--ease);
}
.artifact-card { border-color: #a7f3d0; background: linear-gradient(135deg, #ecfdf5 0%, #ffffff 100%); }
.artifact-card .tz-card-title { color: #047857; }
.artifact-card .tz-card-title [data-lucide],
.artifact-card .tz-card-title .lucide { color: #059669; }
.artifact-card .tz-card-actions a.btn { text-decoration: none; }
.offer-card { border-style: dashed; }

/* Карточка предложенной эскалации: та же основа, что у .tz-card, но акцент
   спокойнее — это не финал работы, а предложение следующего шага. */
.support-card { border-left: 3px solid var(--primary); }
.support-card[data-action="channel"] { border-left-color: var(--amber-500); }
.support-card[data-action="task"] { border-left-color: var(--emerald-500, #10b981); }

/* Адресат называется словами до нажатия: «кто это увидит» — главный вопрос. */
.support-target {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.support-target svg { width: 14px; height: 14px; }

/* Текст, который уйдёт живым людям, показываем целиком. */
.support-preview {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-subtle, rgba(148, 163, 184, 0.12));
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 180px;
  overflow-y: auto;
}

.support-anydesk-input {
  width: 160px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  letter-spacing: 0.04em;
}
.support-anydesk-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* Ошибка ввода принадлежит полю, а не правому верхнему углу экрана. */
.support-error {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--rose-700, #be123c);
}

/* ============================================================
   TZ result banner inside modal
   ============================================================ */
.tz-result {
  margin: 14px 32px;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: var(--success-soft);
  color: var(--emerald-700);
  font-size: 14px;
  border: 1px solid #bbf7d0;
}
.tz-result strong { color: var(--emerald-700); }
.tz-result a { color: var(--emerald-700); text-decoration: underline; }

/* ============================================================
   Toast (stack)
   ============================================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 420px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 12px 14px 12px 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  line-height: 1.45;
  border: 1px solid var(--border);
  animation: toastIn var(--dur-slow) var(--ease);
  pointer-events: auto;
  border-left: 3px solid var(--slate-400);
}

.toast.dismissing {
  animation: toastOut var(--dur) var(--ease) forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateX(24px); }
}

.toast .toast-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.toast .toast-icon [data-lucide],
.toast .toast-icon .lucide { width: 18px; height: 18px; }

.toast .toast-text { flex: 1; min-width: 0; word-wrap: break-word; }
.toast .toast-text a { color: var(--primary); text-decoration: underline; }

.toast .toast-close {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: var(--radius-xs);
  color: var(--text-tertiary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.toast .toast-close:hover { background: var(--surface-3); color: var(--text); }
.toast .toast-close [data-lucide],
.toast .toast-close .lucide { width: 14px; height: 14px; }

.toast.success { border-left-color: var(--emerald-500); }
.toast.success .toast-icon { color: var(--emerald-600); }
.toast.error   { border-left-color: var(--rose-500); }
.toast.error   .toast-icon { color: var(--rose-600); }
.toast.warning { border-left-color: var(--amber-500); }
.toast.warning .toast-icon { color: var(--amber-700); }
.toast.info    { border-left-color: var(--indigo-500); }
.toast.info    .toast-icon { color: var(--primary); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  #sidebar { width: 64px; min-width: 64px; padding: 8px 6px; }
  /* Узкий сайдбар — колонка значков: от чата остаётся аватар направления,
     от режима и направления — иконки, названия и статусы уезжают. */
  .sidebar-header span:not(.lucide),
  .session-item .session-main,
  .session-item .session-menu-btn,
  .sessions-group-title,
  .sessions-search,
  .segmented-option span,
  .direction-field-icon,
  .direction-field-caret,
  #btn-new-session span { display: none; }
  .compose-panel { padding: 5px; gap: 6px; border-radius: 14px; }
  /* Три сегмента в узком сайдбаре дали бы ~17px на кнопку — ниже минимальной
     хит-области. На мобильном переключатель становится колонкой, бегунок не нужен. */
  .segmented { grid-template-columns: 1fr; gap: 3px; }
  .segmented-thumb { display: none; }
  .segmented-option { padding: 7px 6px; min-height: 34px; justify-content: flex-start; }
  .segmented-option.is-active {
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.95) 0%, rgba(79, 70, 229, 0.95) 100%);
    color: #fff;
  }
  .direction-select { padding: 7px 2px; font-size: 11px; text-align: center; text-align-last: center; }
  .session-item { justify-content: center; padding: 5px; }
  .sessions-list { mask-image: none; -webkit-mask-image: none; }
  /* Настройки («Доступ к данным 1С») должны быть доступны и с телефона —
     прячем только статус-пилюлю, шестерёнку центрируем. */
  .sidebar-footer { justify-content: center; padding: 6px 0; }
  .sidebar-footer .status-pill { display: none; }
  #btn-new-session { padding: 10px; }
  .message { max-width: 92%; }
  .questions-block { max-width: 100%; }
  .tz-fullscreen-content { padding: 24px 18px 60px; }
  .tz-fullscreen-header { padding: 14px 18px; }
  .tz-fullscreen-toc { display: none; }
  .empty-state-templates { grid-template-columns: 1fr; }
}

/* === Стоп-кнопка (во время генерации ответа) === */
.btn-stop {
  background: var(--danger, #dc2626);
  border-color: var(--danger, #dc2626);
  color: #fff;
  box-shadow: 0 1px 2px rgba(220, 38, 38, 0.25);
}

.btn-stop:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

/* === Прикрепляемые файлы === */
.btn-attach {
  padding: 8px 10px;
  align-self: flex-end;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.btn-attach:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--surface);
}

.attach-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 2px 0;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  padding: 4px 8px;
  font-size: 12.5px;
  color: var(--text-secondary);
  background: var(--surface-muted, #f1f5f9);
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
}

.attach-chip svg { width: 14px; height: 14px; flex: none; }

.attach-chip.uploading svg { animation: spin 1s linear infinite; }

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

.attach-chip-name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-chip-size { opacity: 0.7; font-size: 11.5px; }

.attach-chip-remove {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  color: var(--text-secondary);
  padding: 0 2px;
}

.attach-chip-remove:hover { color: var(--danger, #dc2626); }

a.attach-chip.readonly:hover { border-color: var(--primary); color: var(--primary); }

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

/* === Оценка ответов (👍/👎) === */
.msg-feedback {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.message.assistant:hover .msg-feedback { opacity: 1; }

.msg-feedback-btn {
  border: none;
  background: none;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 6px;
  color: var(--text-secondary);
}

.msg-feedback-btn svg { width: 14px; height: 14px; }

.msg-feedback-btn:hover { background: var(--surface-muted, #f1f5f9); }

.msg-feedback-btn.active { color: var(--primary); opacity: 1; }

.msg-feedback:has(.active) { opacity: 1; }

/* === Retry при ошибке === */
.retry-note { margin: 4px 0 8px; }

/* === Статус «Отвечено» (точка в таблице админки) === */
.session-status.answered { background: #22c55e; }

/* === Название и ID сессии в шапке чата, кнопка шэринга === */
/* Отступ слева был на .chat-direction; теперь первым в строке идёт название,
   поэтому отступ у контейнера — иначе он «прыгает» в зависимости от того,
   что показано. */
.chat-header-row { padding-left: 24px; }
.chat-direction { margin: 8px 0; }

.chat-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  max-width: 42ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-session-id {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted, var(--slate-50));
  color: var(--text-muted);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  cursor: pointer;
  position: relative;
  /* Цифры и буквы UUID — моноширинные, чтобы префикс не «дышал» при смене сессии. */
  font-variant-numeric: tabular-nums;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
              border-color var(--dur) var(--ease), scale var(--dur-fast) var(--ease);
}
/* Кнопка низкая (~22px) — растягиваем цель по вертикали до 40px.
   По горизонтали она и так шире 40px, поэтому соседей не задевает. */
.chat-session-id::after {
  content: '';
  position: absolute;
  inset: -9px 0;
}
.chat-session-id:active { scale: 0.96; }
.chat-session-id:hover {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}
.chat-session-id i { width: 12px; height: 12px; }
.icon-btn.active { color: var(--primary); background: var(--primary-soft); }

/* === Страница просмотра расшаренной сессии === */
.shared-body { background: var(--bg); }
.shared-screen {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 64px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
/* Появление не одним блоком: шапка, мета и переписка входят по очереди —
   так страница читается сверху вниз, а не «вспыхивает» целиком. */
.shared-header,
.shared-meta,
.shared-notice,
.shared-messages { animation: sharedIn var(--dur-slow) cubic-bezier(0.2, 0, 0, 1) both; }
.shared-header { animation-delay: 0ms; }
.shared-meta { animation-delay: 80ms; }
.shared-notice { animation-delay: 160ms; }
.shared-messages { animation-delay: 240ms; }
@keyframes sharedIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.shared-header { display: flex; flex-direction: column; gap: 10px; }
.shared-header-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.shared-header-row h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  /* Длинное название сессии не должно оставлять одно слово на второй строке. */
  text-wrap: balance;
}
.shared-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.shared-meta-item {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--slate-100);
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.shared-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--amber-50);
  color: #92400e;
  font-size: 13px;
}
.shared-notice i { width: 16px; height: 16px; }
.shared-error {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
.shared-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: visible;
  height: auto;
  padding: 0;
}
.shared-extras { display: flex; gap: 8px; flex-wrap: wrap; }
.shared-tz {
  padding: 20px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  line-height: 1.6;
}

@media (max-width: 768px) {
  .chat-header-row { padding-left: 12px; }
  .chat-title { max-width: 20ch; }
  .shared-screen { padding: 16px 12px 48px; }
}

/* === Кросс-фейд иконок «Отправить» ↔ «Стоп» ===
   Обе иконки в DOM, переключение — по классу .btn-stop на кнопке. Мгновенная
   подмена элемента читалась как рывок; здесь уходящая иконка сжимается и
   размывается, входящая — наоборот. */
.icon-swap {
  position: relative;
  display: inline-flex;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.icon-swap > span {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--dur) cubic-bezier(0.2, 0, 0, 1),
              scale var(--dur) cubic-bezier(0.2, 0, 0, 1),
              filter var(--dur) cubic-bezier(0.2, 0, 0, 1);
}
.icon-swap-stop,
.btn-stop .icon-swap-send {
  opacity: 0;
  scale: 0.25;
  filter: blur(4px);
}
.btn-stop .icon-swap-stop {
  opacity: 1;
  scale: 1;
  filter: blur(0);
}

/* === icon-btn вне сайдбара ===
   Базовые цвета .icon-btn рассчитаны на тёмный сайдбар (--sidebar-text почти
   белый). На светлых поверхностях — шапка чата, заголовок модалки — кнопка
   получалась призрачной: иконка сливалась с фоном. */
.chat-header-row .icon-btn,
.settings-card-header .icon-btn {
  color: var(--text-muted);
  border-color: var(--border);
}
.chat-header-row .icon-btn:hover,
.settings-card-header .icon-btn:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}
.chat-header-row .icon-btn.active {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: var(--primary);
}

/* Длинная ссылка не влезает в поле — уменьшаем кегль и выделяем целиком по клику
   (см. share-link в app.js), чтобы копирование вручную было в один жест. */
#share-link {
  /* Пропорциональный шрифт вмещает больше символов ссылки, чем моно. */
  font-size: 12.5px;
}

/* Путь к файлу в сетевой папке под кнопкой скачивания артефакта. */
.artifact-share {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.artifact-share-path {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: left;
  transition: background-color 0.15s ease, border-color 0.15s ease, scale 0.1s ease;
}

.artifact-share-path:hover {
  background: var(--surface);
  border-color: var(--primary);
}

.artifact-share-path:active {
  scale: 0.98;
}

/* ============================================================
   Доступность: снижение движения и прозрачности
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  /* Пульс значка и бегущие точки — вестибулярно неприятные повторы: гасим их,
     оставляя цвет и текст как носители смысла («Агент отвечает» читается). */
  .session-item.is-running .session-avatar { animation: none; }
  .session-typing i { animation: none; opacity: 0.75; }
  .sessions-list.is-first-render .session-item { animation: none; }
  .segmented-thumb { transition: none; }
  .session-menu { animation: none; }
  .session-item:active, .session-menu-btn:active, .segmented-option:active { scale: 1; }
}

@media (prefers-reduced-transparency: reduce) {
  .session-menu {
    background: #1e293b;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}
