/* ============================================================
   Chat Assistant — Telegram Mini App
   Порядок: токены -> база -> фон -> оболочка -> примитивы -> экраны
   ============================================================ */

:root {
  color-scheme: light dark;

  /* --- радиусы / отступы / типографика --- */
  --r-xl: 22px;
  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 9px;
  --r-full: 999px;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 28px;

  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-lg: 17px;

  /* --- цвета: тянем из темы Telegram, свои значения только как запасные --- */
  --bg: var(--tg-theme-secondary-bg-color, #f2f4f8);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --surface-muted: var(--tg-theme-secondary-bg-color, #eaedf3);
  --text: var(--tg-theme-text-color, #10131a);
  --subtle: var(--tg-theme-subtitle-text-color, #6b7280);
  --hint: var(--tg-theme-hint-color, #8b929c);
  --accent: var(--tg-theme-button-color, #2f8fff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, var(--accent));
  --danger: var(--tg-theme-destructive-text-color, #ff453a);

  --accent-soft: color-mix(in srgb, var(--accent) 13%, transparent);
  --accent-softer: color-mix(in srgb, var(--accent) 7%, transparent);
  --border: color-mix(in srgb, var(--hint) 24%, transparent);
  --border-strong: color-mix(in srgb, var(--hint) 40%, transparent);
  --field-bg: color-mix(in srgb, var(--hint) 8%, var(--surface));
  --overlay: color-mix(in srgb, #000 45%, transparent);

  --shadow-sm: 0 1px 2px rgba(16, 19, 26, 0.05);
  --shadow-md: 0 2px 6px rgba(16, 19, 26, 0.06), 0 12px 28px -18px rgba(16, 19, 26, 0.35);
  --shadow-lg: 0 8px 40px -12px rgba(16, 19, 26, 0.28);

  /* --- движение --- */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.5, 1);
  --dur-fast: 0.14s;
  --dur: 0.24s;
  --dur-slow: 0.36s;

  /* высота вьюпорта Mini App — обновляется из JS по viewportChanged */
  --app-h: 100dvh;
  --chat-h: 60vh;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* В тёмной теме Telegram section_bg часто совпадает с bg — разводим поверхности
   сами, иначе карточки сливаются с фоном и интерфейс выглядит плоским. */
:root[data-theme="dark"] {
  --bg: var(--tg-theme-secondary-bg-color, #0f1218);
  --surface: var(--tg-theme-bg-color, #191d25);
  --surface-muted: var(--tg-theme-secondary-bg-color, #12161d);
  --text: var(--tg-theme-text-color, #eef1f6);
  --subtle: var(--tg-theme-subtitle-text-color, #99a1ad);
  --hint: var(--tg-theme-hint-color, #8b929c);
  --field-bg: color-mix(in srgb, #ffffff 7%, var(--surface));
  --border: color-mix(in srgb, #ffffff 14%, transparent);
  --border-strong: color-mix(in srgb, #ffffff 26%, transparent);
  --overlay: color-mix(in srgb, #000 62%, transparent);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.34), 0 14px 30px -18px rgba(0, 0, 0, 0.75);
  --shadow-lg: 0 10px 44px -12px rgba(0, 0, 0, 0.65);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-secondary-bg-color, #0f1218);
    --surface: var(--tg-theme-bg-color, #191d25);
    --surface-muted: var(--tg-theme-secondary-bg-color, #12161d);
    --text: var(--tg-theme-text-color, #eef1f6);
    --subtle: var(--tg-theme-subtitle-text-color, #99a1ad);
    --field-bg: color-mix(in srgb, #ffffff 7%, var(--surface));
    --border: color-mix(in srgb, #ffffff 14%, transparent);
    --border-strong: color-mix(in srgb, #ffffff 26%, transparent);
    --overlay: color-mix(in srgb, #000 62%, transparent);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.34), 0 14px 30px -18px rgba(0, 0, 0, 0.75);
    --shadow-lg: 0 10px 44px -12px rgba(0, 0, 0, 0.65);
  }
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
}

*::-webkit-scrollbar-track {
  background: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: var(--fs-md);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body.no-scroll {
  overflow: hidden;
}

/* ---------- фоновая подсветка ---------- */

.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background: var(--bg);
}

:root[data-theme="dark"] .ambient .blob {
  opacity: 0.22;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ambient .blob {
    opacity: 0.22;
  }
}

.ambient .blob {
  position: absolute;
  display: block;
  width: 78vw;
  max-width: 520px;
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.45;
}

.ambient .blob-a {
  top: -18vh;
  right: -22vw;
  background: radial-gradient(circle, var(--accent) 0%, transparent 68%);
  animation: drift-a 22s ease-in-out infinite alternate;
}

.ambient .blob-b {
  bottom: -22vh;
  left: -26vw;
  background: radial-gradient(circle, var(--link) 0%, transparent 68%);
  opacity: 0.3;
  animation: drift-b 28s ease-in-out infinite alternate;
}

@keyframes drift-a {
  to {
    transform: translate3d(-6vw, 5vh, 0) scale(1.12);
  }
}

@keyframes drift-b {
  to {
    transform: translate3d(5vw, -4vh, 0) scale(1.08);
  }
}

/* ---------- оболочка ---------- */

#app {
  max-width: 680px;
  margin: 0 auto;
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-5) + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

body.no-scroll #app {
  height: var(--app-h);
  padding-bottom: 0;
}

/* ---------- баннер ошибки ---------- */

.error-banner {
  display: none;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: var(--danger);
  font-size: var(--fs-sm);
  line-height: 1.45;
  animation: fade-slide var(--dur) var(--ease-out);
}

.error-banner.visible {
  display: flex;
}

/* ---------- сегментированные вкладки ---------- */

.segmented {
  position: sticky;
  top: var(--sp-2);
  z-index: 20;
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-muted) 88%, transparent);
  backdrop-filter: blur(18px) saturate(1.6);
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
  box-shadow: var(--shadow-md);
}

.seg-btn {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 4px;
  border: none;
  background: none;
  border-radius: var(--r-md);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--subtle);
  cursor: pointer;
  transition: color var(--dur) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.seg-btn .ico {
  width: 16px;
  height: 16px;
  opacity: 0.7;
  transition: opacity var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}

.seg-btn:active {
  transform: scale(0.97);
}

.seg-btn.active {
  color: var(--text);
}

.seg-btn.active .ico {
  opacity: 1;
  color: var(--accent);
}

.seg-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc((100% - 12px) / 3);
  height: calc(100% - 8px);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--border);
  transition: transform var(--dur-slow) var(--ease-spring);
  will-change: transform;
}

/* ---------- панели и карточки ---------- */

.tab-panel {
  display: none;
  flex-direction: column;
  gap: var(--sp-3);
}

.tab-panel.active {
  display: flex;
  animation: panel-in var(--dur-slow) var(--ease-out);
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.card.flat {
  box-shadow: none;
  background: color-mix(in srgb, var(--surface) 65%, transparent);
}

.card-title {
  font-size: var(--fs-lg);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

.field-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--subtle);
}

.hint {
  margin: 0;
  font-size: var(--fs-xs);
  line-height: 1.5;
  color: var(--hint);
}

.hint-center {
  text-align: center;
}

.muted {
  color: var(--subtle);
  font-size: var(--fs-sm);
}

/* ---------- поля ввода ---------- */

.field {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--field-bg);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-md);
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}

.field::placeholder {
  color: var(--hint);
}

.field:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-softer);
}

textarea.field {
  resize: vertical;
  min-height: 44px;
  line-height: 1.45;
}

/* ---------- кнопки ---------- */

.primary-btn {
  padding: 14px 18px;
  border: none;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 92%, #fff) 0%, var(--accent) 100%);
  color: var(--accent-text);
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 650;
  cursor: pointer;
  box-shadow: 0 6px 18px -8px color-mix(in srgb, var(--accent) 80%, transparent);
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur) var(--ease-out),
    opacity var(--dur) var(--ease-out);
}

.primary-btn:active {
  transform: scale(0.985) translateY(1px);
  box-shadow: 0 3px 10px -6px color-mix(in srgb, var(--accent) 80%, transparent);
}

.primary-btn:disabled {
  opacity: 0.55;
  box-shadow: none;
}

.chip-btn {
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--link);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur) var(--ease-out);
}

.chip-btn:active {
  transform: scale(0.95);
}

.chip-btn:disabled {
  opacity: 0.5;
}

.chip-btn.danger {
  background: color-mix(in srgb, var(--danger) 13%, transparent);
  color: var(--danger);
}

.chip-btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--subtle);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur) var(--ease-out),
    border-color var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}

.icon-btn .ico {
  width: 15px;
  height: 15px;
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn:disabled {
  opacity: 0.5;
}

.icon-btn.active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--link);
}

.icon-btn.square {
  padding: 9px;
}

.icon-btn.plain {
  border-color: transparent;
  background: transparent;
}

.ico {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ico.chevron {
  width: 16px;
  height: 16px;
}

.placeholder-icon .ico {
  width: 20px;
  height: 20px;
}

.sheet-row .ico.check {
  width: 17px;
  height: 17px;
}

/* ---------- чип выбора модели ---------- */

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--field-bg);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), border-color var(--dur) var(--ease-out);
}

.model-chip:active {
  transform: scale(0.96);
}

.model-chip .dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.model-chip.smart .dot {
  background: #ff9f0a;
}

.model-chip.custom .dot {
  background: #bf5af2;
}

.model-chip .label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- пилюли категорий ---------- */

.context-pills {
  display: flex;
  gap: 6px;
  padding: 3px;
  border-radius: var(--r-md);
  background: var(--surface-muted);
}

.context-pill {
  flex: 1;
  padding: 7px 4px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--subtle);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur) var(--ease-out), color var(--dur) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.context-pill:active {
  transform: scale(0.96);
}

.context-pill.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ---------- выбор чата ---------- */

.picker-trigger {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: 9px 12px 9px 9px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--field-bg);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), border-color var(--dur) var(--ease-out);
}

.picker-trigger:active {
  transform: scale(0.99);
  border-color: var(--border-strong);
}

.picker-trigger:disabled {
  opacity: 0.6;
  pointer-events: none;
}

.picker-trigger .placeholder {
  color: var(--hint);
  font-size: var(--fs-md);
}

.picker-trigger .chevron {
  margin-left: auto;
  color: var(--hint);
}

.placeholder-icon {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface-muted);
  color: var(--hint);
}

/* ---------- аватары ---------- */

.avatar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background-position: center;
  background-size: cover;
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: 650;
  overflow: hidden;
}

.avatar.small {
  width: 32px;
  height: 32px;
  font-size: var(--fs-xs);
}

.chat-name-block {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.chat-name {
  font-size: var(--fs-md);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-kind {
  font-size: var(--fs-xs);
  color: var(--hint);
}

/* ---------- нижний шит ---------- */

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in var(--dur) var(--ease-out);
}

.sheet-overlay[hidden] {
  display: none;
}

.sheet-overlay.closing {
  animation: fade-out var(--dur) var(--ease-out) forwards;
}

.sheet {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: 100%;
  max-width: 680px;
  max-height: 86vh;
  padding: var(--sp-2) var(--sp-4) calc(var(--sp-4) + var(--safe-b));
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: sheet-up var(--dur-slow) var(--ease-spring);
}

.sheet-overlay.closing .sheet {
  animation: sheet-down var(--dur) var(--ease-out) forwards;
}

.sheet-handle {
  width: 38px;
  height: 4px;
  margin: var(--sp-1) auto var(--sp-2);
  border-radius: var(--r-full);
  background: var(--border-strong);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

.sheet-title {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  overflow-y: auto;
  padding-bottom: var(--sp-1);
  -webkit-overflow-scrolling: touch;
}

.sheet-section-label {
  padding: var(--sp-2) var(--sp-1) 2px;
  font-size: 11px;
  font-weight: 650;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sheet-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2);
  border: none;
  width: 100%;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
}

.sheet-row:active {
  background: var(--surface-muted);
}

.sheet-row.selected {
  background: var(--accent-soft);
}

.sheet-row .check {
  margin-left: auto;
  color: var(--accent);
}

.sheet-empty {
  padding: var(--sp-5) var(--sp-2);
  text-align: center;
  color: var(--hint);
  font-size: var(--fs-sm);
}

/* ---------- экран "Общение" ---------- */

.chat-screen {
  gap: var(--sp-2);
}

.tab-panel.chat-screen.active {
  height: var(--chat-h);
  min-height: 320px;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-sm);
}

.chat-header .picker {
  flex: 1;
  min-width: 0;
}

.chat-header .picker-trigger {
  border-color: transparent;
  background: transparent;
  padding: 3px 6px;
}

.chat-thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 0;
  padding: var(--sp-2) 2px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 80%;
  padding: 8px 13px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.42;
  white-space: pre-wrap;
  word-break: break-word;
  animation: bubble-in var(--dur) var(--ease-out);
}

.bubble.in {
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.bubble.out {
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 94%, #fff), var(--accent));
  color: var(--accent-text);
  box-shadow: 0 4px 14px -8px color-mix(in srgb, var(--accent) 90%, transparent);
}

@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
}

/* стикер-бабл: без фона, без рамки */
.bubble.sticker-bubble {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  padding: 2px;
}

/* ---------- медиа внутри бабла ---------- */

.bubble-media {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.media-img {
  max-width: 240px;
  max-height: 280px;
  border-radius: var(--r-md);
  object-fit: contain;
  cursor: pointer;
}

.media-img.sticker {
  max-width: 160px;
  max-height: 160px;
  background: transparent;
}

.media-video {
  max-width: 260px;
  max-height: 260px;
  border-radius: var(--r-md);
}

.media-video.round {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  object-fit: cover;
}

.media-audio {
  width: 100%;
  max-width: 240px;
  height: 36px;
}

.media-filename {
  font-size: var(--fs-xs);
  color: var(--hint);
}

.voice-label {
  display: block;
  font-size: var(--fs-xs);
  color: var(--hint);
  margin-bottom: 2px;
}

.voice-text {
  display: block;
  font-size: var(--fs-md);
  font-style: italic;
}

.media-doc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--link);
  font-size: var(--fs-sm);
  font-weight: 600;
  text-decoration: none;
}

.bubble-text {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- реакции ---------- */

.reactions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.reaction-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-muted);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}

.reaction-btn.chosen {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.reaction-btn:active {
  transform: scale(0.92);
}

/* ---------- пикер реакций ---------- */

.reaction-picker {
  position: fixed;
  z-index: 100;
  display: flex;
  gap: 2px;
  padding: 6px 8px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: badge-pop var(--dur) var(--ease-spring);
}

.reaction-picker[hidden] { display: none; }

.reaction-emoji-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  border-radius: 50%;
  transition: background var(--dur-fast), transform var(--dur-fast);
}

.reaction-emoji-btn:hover {
  background: var(--accent-soft);
}

.reaction-emoji-btn:active {
  transform: scale(1.25);
}

.chat-dock {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-3) calc(var(--sp-3) + var(--safe-b));
  margin: 0 calc(-1 * var(--sp-4));
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
}

.dock-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  overflow-x: auto;
  padding-bottom: 2px;
}

.dock-toolbar .icon-btn,
.dock-toolbar .model-chip {
  flex: none;
}

.chat-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.option-row {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--field-bg);
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  animation: option-in var(--dur) var(--ease-out) backwards;
  transition: transform var(--dur-fast) var(--ease-out), border-color var(--dur) var(--ease-out),
    background var(--dur) var(--ease-out);
}

.option-row:nth-child(2) {
  animation-delay: 0.05s;
}

.option-row:nth-child(3) {
  animation-delay: 0.1s;
}

.option-row:nth-child(4) {
  animation-delay: 0.15s;
}

.option-row:active {
  transform: scale(0.985);
  border-color: var(--accent);
  background: var(--accent-softer);
}

.option-row:disabled {
  opacity: 0.55;
}

.option-row-other {
  color: var(--link);
  border-style: dashed;
  background: transparent;
  font-weight: 600;
}

@keyframes option-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.chat-custom-row {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-end;
}

.chat-custom-row[hidden] {
  display: none;
}

.chat-custom-row .field {
  flex: 1;
}

.chat-custom-row .primary-btn {
  flex: none;
  padding: 12px 16px;
  border-radius: var(--r-md);
}

.waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3);
  color: var(--hint);
  font-size: var(--fs-sm);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.6s var(--ease-out) infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.25;
    transform: scale(0.85);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ---------- бейдж непрочитанных чатов в пикере ---------- */

.picker-unread-badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-full);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  margin-left: auto;
  margin-right: 2px;
  animation: badge-pop var(--dur) var(--ease-spring);
}

.picker-unread-badge + .chevron {
  margin-left: 0;
}

.picker-unread-badge[hidden] { display: none; }

@keyframes badge-pop {
  from { transform: scale(0); }
}

/* ---------- бейдж непрочитанных ---------- */

.unread-badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 700;
  margin-left: auto;
}

/* ---------- кнопка «Обновить» — ошибка ---------- */

.icon-btn.error-flash {
  border-color: var(--danger);
  color: var(--danger);
  animation: btn-flash 0.5s ease 3;
}

@keyframes btn-flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.error-hint {
  color: var(--danger);
}

/* ---------- ряд кнопок вектора ---------- */

.goal-btn-row {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}

.goal-btn-row .primary-btn {
  flex: 1;
}

.goal-btn-row .chip-btn {
  flex: none;
}

/* ---------- Анализ ---------- */

.session-card {
  display: none;
}

.session-card.visible {
  display: flex;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  line-height: 1.4;
  cursor: pointer;
}

.toggle-row input {
  flex: none;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.advanced {
  border-top: 1px solid var(--border);
  padding-top: var(--sp-2);
}

.advanced > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  color: var(--subtle);
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.advanced > summary::-webkit-details-marker {
  display: none;
}

.advanced > summary .ico {
  width: 14px;
  height: 14px;
  transition: transform var(--dur) var(--ease-out);
}

.advanced[open] > summary .ico {
  transform: rotate(90deg);
}

.advanced-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding-top: var(--sp-2);
  animation: fade-slide var(--dur) var(--ease-out);
}

.result-card {
  display: none;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: 14.5px;
  line-height: 1.55;
}

.result-card.visible {
  display: flex;
  animation: fade-slide var(--dur-slow) var(--ease-out);
}

.result-card.error {
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.result-text p {
  margin: 0 0 var(--sp-3);
}

.result-text p:last-child {
  margin-bottom: 0;
}

.result-text ul {
  margin: 0 0 var(--sp-3);
  padding-left: 1.2em;
}

.result-text ul:last-child {
  margin-bottom: 0;
}

.result-text li {
  margin-bottom: var(--sp-1);
}

.result-text li:last-child {
  margin-bottom: 0;
}

.result-text strong {
  font-weight: 600;
}

.result-card.error .result-text {
  color: var(--danger);
}

.result-actions {
  display: flex;
  justify-content: flex-end;
}

.result-loading {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--subtle);
  font-size: var(--fs-sm);
}

/* ---------- Стиль ---------- */

.style-grid {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.style-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.style-badge {
  padding: 3px 9px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--link);
  font-size: 11px;
  font-weight: 650;
}

.style-badge.empty {
  background: color-mix(in srgb, var(--hint) 15%, transparent);
  color: var(--hint);
}

.style-text {
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.style-text.placeholder {
  color: var(--hint);
}

.model-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
}

.model-row + .model-row {
  border-top: 1px solid var(--border);
}

.model-row-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  font-size: var(--fs-sm);
}

.model-row-label small {
  color: var(--hint);
  font-size: var(--fs-xs);
}

.model-row .model-chip {
  max-width: 54%;
}

/* ---------- список профилей стиля (аккордеон) ---------- */

.style-item {
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: border-color var(--dur) var(--ease-out);
}

.style-item.open {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.style-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-4);
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.style-row .style-name {
  font-size: var(--fs-md);
  font-weight: 650;
}

.style-row .ico.chevron {
  margin-left: auto;
  color: var(--hint);
  transition: transform var(--dur) var(--ease-out);
}

.style-item.open .style-row .ico.chevron {
  transform: rotate(90deg);
}

.style-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: 0 var(--sp-4) var(--sp-4);
  animation: fade-slide var(--dur) var(--ease-out);
}

.style-body[hidden] {
  display: none;
}

.style-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 0;
  padding-left: 18px;
  font-size: 13.5px;
  line-height: 1.5;
}

.style-list li::marker {
  color: var(--accent);
}

.style-section {
  margin-top: var(--sp-3);
  margin-bottom: 6px;
  font-size: var(--fs-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.style-section:first-child {
  margin-top: 0;
}

.style-note-block {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}

.theme-switch {
  display: flex;
  gap: 6px;
}

.theme-switch .chip-btn {
  flex: 1;
  text-align: center;
}

.theme-switch .chip-btn:not(.active) {
  background: transparent;
  border-color: var(--border);
  color: var(--subtle);
}

/* ---------- индикатор генерации ("думает") ---------- */

.thinking {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--field-bg);
  color: var(--subtle);
  font-size: 13.5px;
  animation: fade-slide var(--dur) var(--ease-out);
}

.thinking-dots {
  display: inline-flex;
  flex: none;
  gap: 4px;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: thinking-bounce 1.1s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes thinking-bounce {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

/* ---------- скелетоны и спиннер ---------- */

.skeleton-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2);
}

.skeleton-circle,
.skeleton-line {
  border-radius: var(--r-sm);
  background: linear-gradient(
    90deg,
    var(--surface-muted) 25%,
    color-mix(in srgb, var(--hint) 14%, var(--surface-muted)) 37%,
    var(--surface-muted) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

.skeleton-circle {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
}

.skeleton-line {
  width: 60%;
  height: 12px;
  border-radius: 6px;
}

@keyframes shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

.spinner {
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ---------- общие анимации ---------- */

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes fade-out {
  to {
    opacity: 0;
  }
}

@keyframes fade-slide {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@keyframes sheet-up {
  from {
    transform: translateY(100%);
  }
}

@keyframes sheet-down {
  to {
    transform: translateY(100%);
  }
}

/* ---------- адаптив ---------- */

@media (min-width: 620px) {
  #app {
    padding: var(--sp-4) var(--sp-5) calc(var(--sp-6) + var(--safe-b));
    gap: var(--sp-4);
  }

  .tab-panel {
    gap: var(--sp-4);
  }

  .seg-btn {
    font-size: var(--fs-md);
  }

  .chat-dock {
    margin: 0;
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
  }

  /* Раньше тут был grid в несколько колонок — из-за аккордеона (у каждой категории
     своя высота: открыта/закрыта) колонки выравнивались по самой высокой карточке
     и оставляли рваные пустоты снизу у соседних. Список в один столбец без этой
     проблемы, а на такой ширине карточка и так не становится неудобно широкой. */
}

@media (max-width: 360px) {
  .seg-btn .ico {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
