/* ==================================================================
   Панель управления ботом — стили
   1. Токены темы
   2. База и утилиты
   3. Кнопки
   4. Поля формы
   5. Выбор эмодзи
   6. Переключатель
   7. Карточки (7.1 — карточка «Бот»)
   8. Шапка и баннеры
   9. Экран входа
   10. Сетка страницы
   11. Предпросмотр сообщения Telegram
   12. Нижняя панель сохранения
   13. Уведомления
   14. Адаптив
   ================================================================== */

/* ------------------------------------------------------------------
   1. Токены темы
   ------------------------------------------------------------------ */

:root {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f4;

  --border: #e2e5ea;
  --border-strong: #ccd1da;

  --text: #16181d;
  --text-muted: #5d6572;
  --text-faint: #8d95a3;

  --accent: #2481cc;
  --accent-hover: #1f6fb1;
  --accent-soft: rgba(36, 129, 204, 0.1);
  --accent-contrast: #ffffff;

  --danger: #d4423f;
  --danger-soft: rgba(212, 66, 63, 0.09);
  --danger-border: rgba(212, 66, 63, 0.32);
  --warn: #b26a00;
  --warn-soft: rgba(178, 106, 0, 0.1);
  --warn-border: rgba(178, 106, 0, 0.3);
  --ok: #1f8a4c;
  --ok-soft: rgba(31, 138, 76, 0.1);

  --brand-accent: #2481cc;

  --tg-bg: #dfe6ee;
  --tg-bubble: #ffffff;
  --tg-btn: rgba(255, 255, 255, 0.92);

  --radius: 14px;
  --radius-sm: 9px;
  --radius-xs: 6px;

  --shadow-1: 0 1px 2px rgba(16, 22, 32, 0.05), 0 1px 3px rgba(16, 22, 32, 0.04);
  --shadow-2: 0 10px 30px rgba(16, 22, 32, 0.12);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    'Noto Sans', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --bg-elevated: #1b1e24;
    --surface: #1b1e24;
    --surface-2: #20242b;
    --surface-3: #262b33;

    --border: #2c313a;
    --border-strong: #3b414c;

    --text: #eceef2;
    --text-muted: #a3abb8;
    --text-faint: #767e8c;

    --accent: #4ea3e8;
    --accent-hover: #6cb4ee;
    --accent-soft: rgba(78, 163, 232, 0.14);
    --accent-contrast: #0e1116;

    --danger: #f0716d;
    --danger-soft: rgba(240, 113, 109, 0.12);
    --danger-border: rgba(240, 113, 109, 0.36);
    --warn: #e0a23f;
    --warn-soft: rgba(224, 162, 63, 0.12);
    --warn-border: rgba(224, 162, 63, 0.36);
    --ok: #4fc17f;
    --ok-soft: rgba(79, 193, 127, 0.12);

    --tg-bg: #1d2630;
    --tg-bubble: #222d38;
    --tg-btn: rgba(46, 60, 74, 0.95);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}

/* ------------------------------------------------------------------
   2. База и утилиты
   ------------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

/* Тонкие ненавязчивые полосы прокрутки вместо системных «рельсов» */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
}

ul {
  margin: 0;
  padding-left: 18px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--surface-3);
  border-radius: var(--radius-xs);
  padding: 1px 5px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

/* Загрузочный экран */

.boot-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-muted);
}

.spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2s;
  }
}

.boot-text {
  font-size: 14px;
}

/* ------------------------------------------------------------------
   3. Кнопки
   ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-3);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 32px;
  padding: 0 11px;
  font-size: 13px;
}

.btn.is-loading {
  position: relative;
  color: transparent;
}

.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-radius: 50%;
  border-top-color: transparent;
  color: var(--accent-contrast);
  animation: spin 0.7s linear infinite;
}

.btn-secondary.is-loading::after {
  color: var(--text);
}

/* ------------------------------------------------------------------
   4. Поля формы
   ------------------------------------------------------------------ */

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field-narrow {
  max-width: 420px;
}

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.field-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}

.field-note {
  font-size: 12.5px;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: var(--radius-xs);
  padding: 7px 10px;
  line-height: 1.45;
}

.field-note.is-ok {
  color: var(--ok);
  background: var(--ok-soft);
}

.field-note.is-error {
  color: var(--danger);
  background: var(--danger-soft);
}

/* Нейтральное состояние: «Проверяю…» и прочие промежуточные сообщения */
.field-note.is-info {
  color: var(--text-muted);
  background: var(--surface-2);
}

.field-error {
  font-size: 12.5px;
  color: var(--danger);
  line-height: 1.45;
}

.form-error {
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}

.counter {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.counter.is-warn {
  color: var(--warn);
}

.counter.is-over {
  color: var(--danger);
  font-weight: 600;
}

.input {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder {
  color: var(--text-faint);
}

.input:hover:not(:disabled):not(:read-only) {
  border-color: var(--text-faint);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input:read-only {
  background: var(--surface-2);
  color: var(--text-muted);
}

.input.has-error {
  border-color: var(--danger);
}

.input.has-error:focus {
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.input-mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

.textarea {
  /* Высоту подгоняет скрипт под содержимое, поэтому ни прокрутки, ни ручного ресайза */
  resize: none;
  overflow-y: hidden;
  min-height: 72px;
}

.select {
  appearance: none;
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 17px, calc(100% - 11px) 17px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.row-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.row-inline .input {
  flex: 1 1 200px;
}

/* Цвет оформления */

/* Блок картинки */

.image-field {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.progress {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s ease;
}

.image-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.image-preview-img {
  width: 88px;
  height: 62px;
  object-fit: cover;
  border-radius: var(--radius-xs);
  background: var(--surface-3);
}

.image-preview-note {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------
   5. Выбор эмодзи
   ------------------------------------------------------------------ */

.label-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.label-row .input {
  flex: 1 1 auto;
}

.emoji-cell:hover,
/* ------------------------------------------------------------------
   6. Переключатель
   ------------------------------------------------------------------ */

.switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-track {
  position: relative;
  width: 40px;
  height: 23px;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background-color 0.18s ease;
}

.switch-thumb {
  position: absolute;
  top: 2.5px;
  left: 2.5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.18s ease;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(17px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch-text {
  font-size: 13px;
  font-weight: 550;
  color: var(--text-muted);
}

.switch input:checked ~ .switch-text {
  color: var(--text);
}

/* ------------------------------------------------------------------
   7. Карточки
   ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  margin-bottom: 12px;
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.card-title {
  font-size: 14.5px;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 14px;
}

.card.is-disabled-section .card-body {
  opacity: 0.55;
}

/* ------------------------------------------------------------------
   7.1 Карточка «Бот»
   ------------------------------------------------------------------ */

/* Значок состояния бота в шапке карточки */
.status-badge {
  display: inline-flex;
  align-items: flex-start;
  gap: 7px;
  flex: 0 1 auto;
  max-width: 300px;
  padding: 5px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 550;
  line-height: 1.4;
  color: var(--text-muted);
}

.status-badge-text {
  word-break: break-word;
}

.status-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-top: 5px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.is-ok {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: transparent;
}

.status-badge.is-error {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

.status-badge.is-pending {
  color: var(--warn);
  background: var(--warn-soft);
  border-color: var(--warn-border);
}

.status-badge.is-pending .status-dot {
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status-badge.is-pending .status-dot {
    animation-duration: 2.4s;
  }
}

/* Замаскированная подсказка текущего токена */
.bot-current {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.bot-current-label {
  font-size: 12.5px;
  color: var(--text-muted);
}

.bot-token-hint {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.02em;
  background: var(--surface-3);
  border-radius: var(--radius-xs);
  padding: 2px 8px;
  word-break: break-all;
}

.bot-actions {
  gap: 8px;
}

/* Квадратная кнопка-иконка (показать/скрыть токен) */
.btn-icon {
  flex: 0 0 auto;
  width: 38px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}

.btn-icon[aria-pressed='true'] {
  border-color: var(--accent);
  color: var(--accent);
}

/* ------------------------------------------------------------------
   8. Шапка и баннеры
   ------------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1360px;
  margin: 0 auto;
  padding: 9px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--accent), var(--accent-hover));
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  font-size: 14.5px;
  font-weight: 650;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.banner {
  max-width: 1360px;
  margin: 16px auto 0;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
}

.banner strong {
  display: block;
  margin-bottom: 2px;
}

.banner-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  margin: 0 0 18px;
}

.errors-list {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* ------------------------------------------------------------------
   9. Экран входа
   ------------------------------------------------------------------ */

.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
}

.login-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(140deg, var(--accent), var(--accent-hover));
}

.login-title {
  font-size: 20px;
}

.login-sub {
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: -8px;
}

/* ------------------------------------------------------------------
   10. Сетка страницы
   ------------------------------------------------------------------ */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 620px) minmax(0, 420px);
  justify-content: center;
  gap: 18px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 16px 20px;
  align-items: start;
}

.col-form,
.col-preview {
  min-width: 0;
}

/* Колонку тянем на всю высоту ряда: при align-items:start она была бы
   ровно по содержимому, и липнуть предпросмотру было бы негде. */
.col-preview {
  align-self: stretch;
}

.preview-sticky {
  position: sticky;
  /* Ровно под шапкой: её высоту измеряет скрипт и кладёт в переменную. */
  top: calc(var(--topbar-height, 60px) + 12px);
}

/* ------------------------------------------------------------------
   11. Предпросмотр сообщения Telegram
   ------------------------------------------------------------------ */

.preview-card {
  overflow: hidden;
}

.tg-chat {
  padding: 14px;
  background: var(--tg-bg);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tg-message {
  position: relative;
  background: var(--tg-bubble);
  border-radius: 14px 14px 14px 4px;
  padding: 9px 12px 20px;
  box-shadow: 0 1px 2px rgba(16, 22, 32, 0.14);
  max-width: 100%;
  overflow: hidden;
}

.tg-photo {
  margin: -9px -12px 8px;
}

.tg-photo-img {
  display: block;
  width: 100%;
  max-height: 230px;
  object-fit: cover;
  background: var(--surface-3);
}

.tg-text {
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

.tg-text code {
  background: var(--surface-3);
}

.tg-link {
  color: var(--brand-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tg-spoiler {
  background: var(--text-faint);
  border-radius: 4px;
  color: transparent;
  padding: 0 2px;
}

.tg-spoiler:hover {
  background: transparent;
  color: inherit;
}

.tg-empty {
  color: var(--text-faint);
  font-style: italic;
}

.tg-time {
  position: absolute;
  right: 11px;
  bottom: 6px;
  font-size: 11px;
  color: var(--text-faint);
}

.tg-keyboard {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tg-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--tg-btn);
  box-shadow: 0 1px 2px rgba(16, 22, 32, 0.12);
  font-size: 13.5px;
  font-weight: 550;
  color: var(--brand-accent);
  text-align: center;
  word-break: break-word;
}

/* Кнопка без ссылки: бот её пропустит */
.tg-btn.is-inactive {
  color: var(--text-faint);
  box-shadow: none;
  border: 1px dashed var(--border-strong);
  background: transparent;
}

.tg-btn-tag {
  flex: 0 0 auto;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
}

.tg-btn-tag.is-warn {
  color: var(--warn);
  border-color: var(--warn-border);
}

/* ------------------------------------------------------------------
   12. Нижняя панель сохранения
   ------------------------------------------------------------------ */

.savebar-text {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.savebar-text.is-dirty {
  color: var(--warn);
  font-weight: 550;
}

/* ------------------------------------------------------------------
   13. Уведомления
   ------------------------------------------------------------------ */

.toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-2);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  animation: toast-in 0.18s ease;
  word-break: break-word;
}

.toast-success {
  border-left: 3px solid var(--ok);
}

.toast-error {
  border-left: 3px solid var(--danger);
}

.toast-info {
  border-left: 3px solid var(--accent);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

/* ------------------------------------------------------------------
   14. Адаптив
   ------------------------------------------------------------------ */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .preview-sticky {
    position: static;
  }

  .col-preview {
    order: -1;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14.5px;
  }

  .topbar-inner,
  .layout,
  .banner {
    margin-left: 14px;
    margin-right: 14px;
  }

  .banner-error {
    margin-left: 0;
    margin-right: 0;
  }

  .card-head,
  .card-body,
  .tg-chat {
    padding: 14px;
  }

  .brand-title {
    font-size: 13.5px;
  }

  .row-inline .btn {
    flex: 1 1 auto;
  }
}

@media (max-width: 400px) {
  .card-head {
    flex-direction: column;
    gap: 10px;
  }

  .image-preview {
    flex-direction: column;
    align-items: flex-start;
  }

  .image-preview-img {
    width: 100%;
    height: 110px;
  }
}

/* ------------------------------------------------------------------ */
/* Главный экран: плитки ботов                                         */
/* ------------------------------------------------------------------ */

.bots-layout {
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.bots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.bot-tile {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  min-height: 132px;
  padding: 16px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.bot-tile:hover,
.bot-tile:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  outline: none;
}

.bot-tile:active {
  transform: translateY(1px);
}

.bot-tile-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bot-tile-avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 600;
}

.bot-tile-names {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.bot-tile-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bot-tile-username {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Крестик проявляется при наведении, чтобы не мозолил глаза */
.bot-tile-remove {
  margin-left: auto;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.bot-tile:hover .bot-tile-remove,
.bot-tile:focus-within .bot-tile-remove {
  opacity: 1;
}

.bot-tile-foot {
  display: flex;
  align-items: center;
}

.bot-tile-add {
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-weight: 500;
  background: transparent;
  border-style: dashed;
  box-shadow: none;
}

.bot-tile-add:hover {
  color: var(--accent);
}

/* ------------------------------------------------------------------ */
/* Переключатель расположения кнопок                                   */
/* ------------------------------------------------------------------ */

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.segmented-item {
  padding: 7px 14px;
  font: inherit;
  font-size: 13.5px;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: calc(var(--radius-sm) - 3px);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented-item:hover {
  color: var(--text);
}

.segmented-item[aria-checked='true'] {
  color: var(--text);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
}

.segmented-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Предпросмотр: кнопки в один ряд */
.tg-keyboard.is-horizontal {
  display: flex;
  /* Базовое правило .tg-keyboard ставит column — его и перебиваем. */
  flex-direction: row;
  gap: 6px;
}

.tg-keyboard.is-horizontal .tg-btn {
  flex: 1 1 0;
  min-width: 0;
  /* Подпись и пометка друг под другом: рядом они в узкой кнопке не помещаются */
  flex-direction: column;
  gap: 4px;
  padding: 9px 10px;
  /* Базовое break-word рвёт слова по буквам, когда кнопка узкая */
  word-break: normal;
  overflow: hidden;
}

.tg-keyboard.is-horizontal .tg-btn-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tg-keyboard.is-horizontal .tg-btn-label {
  max-width: 100%;
}

/* Альбом из двух картинок: Telegram ставит их рядом */
.tg-photo.is-album {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
}

.tg-photo.is-album .tg-photo-img {
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

/* ------------------------------------------------------------------ */
/* Справка по разметке                                                 */
/* ------------------------------------------------------------------ */

.guide {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.guide-summary {
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.guide-summary::-webkit-details-marker {
  display: none;
}

.guide-summary::before {
  content: '▸';
  display: inline-block;
  width: 14px;
  color: var(--text-faint);
}

.guide[open] .guide-summary {
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.guide[open] .guide-summary::before {
  content: '▾';
}

.guide-body {
  padding: 10px 12px 12px;
}

.guide-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  padding: 4px 0;
  font-size: 13px;
}

.guide-code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text);
  word-break: break-word;
}

.guide-what {
  color: var(--text-muted);
}

.guide-note {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-muted);
}

.guide-note code {
  font-family: var(--font-mono);
  color: var(--text);
}

/* Шапка редактора: на узком экране статус сохранения прячем, кнопки важнее */
@media (max-width: 720px) {
  .savebar-text {
    display: none;
  }
}

/* Карточки кнопок повторяют выбранное расположение: так видно, как они лягут в боте */
#buttons-host {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

#buttons-host.is-horizontal {
  grid-template-columns: 1fr 1fr;
}

#buttons-host .card {
  margin-bottom: 0;
}

@media (max-width: 900px) {
  #buttons-host.is-horizontal {
    grid-template-columns: 1fr;
  }
}
