/* ==========================================================================
   LumoChat — дизайн-система
   Светлая тема по умолчанию, тёмная — по системной настройке.
   ========================================================================== */

:root {
  /* Поверхности */
  --bg: #f4f4f8;
  --bg-glow: radial-gradient(1200px 600px at 85% -10%, rgb(124 108 255 / 0.10), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgb(255 143 163 / 0.08), transparent 60%);
  --surface: #ffffff;
  --surface-2: #f1f1f6;
  --surface-3: #e8e8f0;
  --chat-bg: #efeef6;
  --header-bg: rgb(244 244 248 / 0.82);
  --line: #e3e3ec;
  --line-strong: #cfcfdb;

  /* Текст */
  --ink: #17171f;
  --ink-2: #3a3a48;
  --muted: #646475;
  --placeholder: #8b8b9c;

  /* Бренд и акценты */
  --primary: #5b47e0;
  --primary-hover: #4c39cf;
  --primary-ink: #4a37c9;      /* акцентный текст на светлом фоне */
  --primary-soft: #ecebff;
  --primary-soft-2: #dedbff;
  --on-primary: #ffffff;
  --brand-gradient: linear-gradient(135deg, #7b6bff 0%, #a66cff 52%, #ff8fa3 100%);

  --green: #0f9d6e;
  --green-ink: #08734f;
  --green-soft: #ddf5ea;
  --amber-ink: #8a5a00;
  --amber-soft: #fbefd2;
  --red: #d0353a;
  --red-hover: #b72a2f;
  --red-soft: #fde8e8;

  /* Пузыри */
  --bubble-in: #ffffff;
  --bubble-in-ink: var(--ink);
  --bubble-out: #5b47e0;
  --bubble-out-ink: #ffffff;
  --bubble-accent: var(--primary-ink);

  /* Форма */
  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --shadow-xs: 0 1px 2px rgb(23 23 31 / 0.06);
  --shadow-sm: 0 1px 2px rgb(23 23 31 / 0.05), 0 2px 8px rgb(23 23 31 / 0.05);
  --shadow-md: 0 4px 12px rgb(23 23 31 / 0.06), 0 12px 32px rgb(23 23 31 / 0.08);
  --shadow-lg: 0 12px 28px rgb(23 23 31 / 0.12), 0 32px 64px rgb(23 23 31 / 0.14);
  --ring: 0 0 0 3px rgb(91 71 224 / 0.28);
  --focus: #5b47e0;

  --header-h: 68px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  --sans: 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;

  /* Иконки для масок */
  --i-back: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m15 5-7 7 7 7'/%3E%3C/svg%3E");
  --i-close: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12M18 6 6 18'/%3E%3C/svg%3E");
  --i-chat: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 12a8 8 0 0 1-11.6 7.1L4 20l1-4.2A8 8 0 1 1 20 12Z'/%3E%3Cpath d='M8.5 11h7M8.5 14h4'/%3E%3C/svg%3E");
  --i-plug: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 3v4M15 3v4M6 7h12v4a6 6 0 0 1-12 0V7ZM12 17v4'/%3E%3C/svg%3E");
  --i-file: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8l-5-5Z'/%3E%3Cpath d='M14 3v5h5'/%3E%3C/svg%3E");
  --i-play: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M8 5.5v13a1 1 0 0 0 1.5.86l10.6-6.5a1 1 0 0 0 0-1.72L9.5 4.64A1 1 0 0 0 8 5.5Z'/%3E%3C/svg%3E");

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e13;
    --bg-glow: radial-gradient(1200px 600px at 85% -10%, rgb(124 108 255 / 0.12), transparent 60%),
               radial-gradient(900px 500px at -10% 110%, rgb(255 143 163 / 0.05), transparent 60%);
    --surface: #17171e;
    --surface-2: #202029;
    --surface-3: #2a2a35;
    --chat-bg: #111117;
    --header-bg: rgb(14 14 19 / 0.8);
    --line: #2a2a35;
    --line-strong: #3a3a48;

    --ink: #ededf3;
    --ink-2: #c9c9d6;
    --muted: #9c9cae;
    --placeholder: #7c7c8e;

    --primary: #6a57f0;
    --primary-hover: #7b6af5;
    --primary-ink: #a99dff;
    --primary-soft: #26223f;
    --primary-soft-2: #322c57;

    --green: #2cc28e;
    --green-ink: #5fdcab;
    --green-soft: #15302a;
    --amber-ink: #f0c060;
    --amber-soft: #352a12;
    --red: #e5484d;
    --red-hover: #f0595e;
    --red-soft: #3a1a1c;

    --bubble-in: #20202a;
    --bubble-out: #5b47e0;
    --bubble-accent: #b3a9ff;

    --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.35), 0 2px 8px rgb(0 0 0 / 0.25);
    --shadow-md: 0 4px 12px rgb(0 0 0 / 0.35), 0 12px 32px rgb(0 0 0 / 0.35);
    --shadow-lg: 0 12px 28px rgb(0 0 0 / 0.45), 0 32px 64px rgb(0 0 0 / 0.5);
    --ring: 0 0 0 3px rgb(169 157 255 / 0.35);
    --focus: #a99dff;

    color-scheme: dark;
  }
}

/* ==========================================================================
   База
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-glow), var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 400 15px/1.45 var(--sans);
  font-feature-settings: 'ss01', 'cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font-family: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
::selection { background: var(--primary-soft-2); }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Тонкие полосы прокрутки */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 999px; background: var(--line-strong); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ==========================================================================
   Логотип
   ========================================================================== */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
  white-space: nowrap;
}
.brand svg {
  flex: none;
  width: 36px;
  height: 36px;
  padding: 7px;
  border-radius: 11px;
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: 0 4px 14px rgb(123 107 255 / 0.35), inset 0 1px 0 rgb(255 255 255 / 0.25);
}
a.brand { border-radius: 12px; }

/* ==========================================================================
   Шапка
   ========================================================================== */

.header {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  min-height: var(--header-h);
  padding: 12px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  backdrop-filter: saturate(1.6) blur(16px);
}
.header .brand { justify-self: start; }
.header .profile { justify-self: end; }

/* Сегментированный переключатель разделов */
.nav {
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
}
.nav-tab {
  flex: 1 1 auto;
  min-height: 36px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.18s var(--ease), color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.nav-tab:hover { color: var(--ink); }
.nav-tab[aria-current='page'] {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--line);
}

/* Шапка мастера */
.wizard-bar { display: grid; justify-items: center; gap: 8px; min-width: 0; }
.wizard-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 18px 4px 4px;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
}
.wizard-back {
  position: relative;
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-xs), 0 0 0 1px var(--line);
  color: var(--ink);
  font-size: 0;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.15s var(--ease);
}
.wizard-back::before, .chat-back::before {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  background: currentColor;
  -webkit-mask: var(--i-back) center / contain no-repeat;
  mask: var(--i-back) center / contain no-repeat;
}
.wizard-back[aria-label='Закрыть']::before {
  -webkit-mask-image: var(--i-close);
  mask-image: var(--i-close);
}
.wizard-back:hover { background: var(--surface-3); }
.wizard-back:active { transform: scale(0.94); }
.wizard-title {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dashes { display: flex; gap: 4px; }
.dashes i {
  width: 14px;
  height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
  transition: width 0.25s var(--ease), background-color 0.25s;
}
.dashes i.done { background: var(--primary); opacity: 0.55; }
.dashes i.current { width: 28px; background: var(--primary); }

/* Профиль */
.profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 100%;
  padding: 4px 4px 4px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  text-align: right;
  cursor: pointer;
  transition: background-color 0.15s;
}
.profile:hover { background: var(--surface-2); }
.profile > span:first-child { min-width: 0; }
.profile-name {
  display: block;
  overflow: hidden;
  max-width: 200px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-balance { display: block; color: var(--muted); font-size: 12px; line-height: 1.25; font-variant-numeric: tabular-nums; }
.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.18);
}

/* ==========================================================================
   Страница
   ========================================================================== */

.page {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px clamp(16px, 4vw, 40px) 64px;
}
.center { display: grid; justify-items: center; text-align: center; }

.page-head { display: grid; gap: 6px; margin-bottom: 24px; }
.page-title { font-size: clamp(24px, 3vw, 30px); font-weight: 700; line-height: 1.15; letter-spacing: -0.025em; }
.page-sub { max-width: 60ch; color: var(--muted); font-size: 15px; }

/* Главная */
#view-home .page-head + .home-actions { margin-top: -4px; }
.home-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.add-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 18px 0 8px;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-xs), 0 0 0 1px var(--line);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, box-shadow 0.15s, transform 0.15s var(--ease);
}
.add-btn br { display: none; }
.add-btn:hover { background: var(--surface-2); }
.add-btn:active { transform: translateY(1px); }
.add-btn span:first-child {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 20px;
  font-weight: 500;
  line-height: 1;
}
.add-btn span:first-child svg { width: 18px; height: 18px; }
/* Первая кнопка — главное действие */
.add-btn:first-child {
  background: var(--primary);
  box-shadow: 0 1px 2px rgb(23 23 31 / 0.1), 0 6px 16px rgb(91 71 224 / 0.25);
  color: var(--on-primary);
}
.add-btn:first-child:hover { background: var(--primary-hover); }
.add-btn:first-child span:first-child { background: rgb(255 255 255 / 0.18); color: #fff; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr));
  gap: 16px;
  margin-top: 24px;
}
.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 16px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: box-shadow 0.2s var(--ease), border-color 0.2s;
}
.cards .card { animation: rise 0.35s var(--ease) both; }
.cards .card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-md); }
.card-top { display: flex; align-items: center; gap: 12px; min-width: 0; }
.card-top > svg {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 2px;
  border-radius: 14px;
  color: var(--ink);
}
.card-titles { flex: 1; min-width: 0; }
.card-title { overflow: hidden; font-size: 16px; font-weight: 600; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.card-price { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.card-foot .btn { margin-top: 0; }

.link-danger {
  min-height: 32px;
  padding: 0 10px;
  margin-right: -10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--red);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s;
}
.link-danger:hover { background: var(--red-soft); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-ACTIVE { background: var(--green-soft); color: var(--green-ink); }
.status-PENDING { background: var(--amber-soft); color: var(--amber-ink); }

/* Пустое состояние главной: показывается, пока список подключений пуст */
.empty-home { display: none; }
.cards:empty { display: none; }
.cards:empty + .empty-home {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin-top: 24px;
  padding: 56px 24px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: rgb(255 255 255 / 0.02);
  text-align: center;
  /* Небольшая задержка, чтобы пустое состояние не мигало до загрузки списка */
  animation: rise 0.3s 0.5s var(--ease) both;
}
.empty-home-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: 8px;
  border-radius: 18px;
  background: var(--primary-soft);
  color: var(--primary-ink);
  box-shadow: inset 0 0 0 1px var(--primary-soft-2);
}
.empty-home h2 { font-size: 18px; font-weight: 600; }
.empty-home p { max-width: 44ch; color: var(--muted); font-size: 14px; }

/* ==========================================================================
   Мастер подключения
   ========================================================================== */

#view-wizard {
  width: min(600px, 100%);
  margin: 8px auto 0;
  padding: clamp(28px, 5vw, 48px) clamp(20px, 5vw, 48px);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  animation: rise 0.35s var(--ease) both;
}
.stage-title { font-size: clamp(22px, 3vw, 26px); font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; }
.stage-body { display: grid; justify-items: center; gap: 16px; width: 100%; margin-top: 28px; }
.stage-sub { font-size: 16px; font-weight: 600; line-height: 1.35; }
.stage-note { max-width: 520px; color: var(--ink-2); font-size: 14px; line-height: 1.5; }
.stage-note strong { color: var(--ink); font-weight: 600; }

.pick { display: grid; grid-template-columns: repeat(2, minmax(0, 168px)); justify-content: center; gap: 14px; width: 100%; }
.pick-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 132px;
  padding: 20px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.18s, box-shadow 0.18s var(--ease), transform 0.18s var(--ease), background-color 0.18s;
}
.pick-card svg { flex: none; width: 48px; height: 48px; color: var(--ink); }
.pick-card:hover:not(:disabled) {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft), var(--shadow-md);
  transform: translateY(-2px);
}
.pick-card:active:not(:disabled) { transform: translateY(0); }
.pick-card:disabled { background: var(--surface-2); border-style: dashed; cursor: not-allowed; }
.pick-card:disabled > :not(.soon) { opacity: 0.5; filter: grayscale(0.6); }
.soon {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

/* ==========================================================================
   Формы
   ========================================================================== */

.form { display: grid; gap: 10px; width: min(320px, 100%); }
.form-wide { width: min(400px, 100%); }

.input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: 400 15px var(--sans);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder { color: var(--placeholder); }
.input:hover:not(:focus) { border-color: color-mix(in srgb, var(--line-strong) 60%, var(--muted)); }
.input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.input:read-only { background: var(--surface-2); color: var(--muted); }
.input-big { height: 52px; padding: 0 16px; font-size: 16px; }
select.input {
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-position: right 12px center;
  background-size: 18px;
  background-repeat: no-repeat;
}

.form-error {
  color: var(--red);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

/* ==========================================================================
   Кнопки
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  margin-top: 8px;
  padding: 0 22px;
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 1px 2px rgb(23 23 31 / 0.1), inset 0 1px 0 rgb(255 255 255 / 0.12);
  transition: background-color 0.15s, box-shadow 0.15s, transform 0.12s var(--ease), opacity 0.15s;
}
.btn:hover { background: var(--primary-hover); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-big { min-height: 52px; padding: 0 40px; font-size: 16px; border-radius: 14px; }
.btn-dark { background: var(--ink); color: var(--bg); }
.btn-dark:hover { background: var(--ink-2); }
.btn-danger { margin-top: 0; background: var(--red); color: #fff; }
.btn-danger:hover { background: var(--red-hover); }
.btn-ghost {
  margin-top: 0;
  background: var(--surface-2);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}
.btn-ghost:hover { background: var(--surface-3); }
.btn-small { min-height: 34px; margin-top: 0; padding: 0 14px; border-radius: 10px; font-size: 13px; }

/* ==========================================================================
   QR, спиннер, ключ
   ========================================================================== */

.qr-note { margin-top: 12px; color: var(--muted); font-size: 13px; }
#qr-block { position: relative; width: 100%; padding-top: 12px; }
#qr-block::before {
  content: 'или';
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(320px, 100%);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: linear-gradient(var(--line), var(--line)) left center / calc(50% - 22px) 1px no-repeat,
              linear-gradient(var(--line), var(--line)) right center / calc(50% - 22px) 1px no-repeat;
  justify-content: center;
}
.qr {
  display: grid;
  place-items: center;
  width: 196px;
  height: 196px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff; /* QR всегда на светлом фоне, иначе не считается */
  box-shadow: var(--shadow-sm);
}
.qr img { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #e6e3ff;
  border-top-color: #5b47e0;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.key-field { display: grid; gap: 8px; width: min(520px, 100%); text-align: left; }
.key-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.key-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 6px 6px 6px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
}
.key-box code {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font: 500 13px/1.4 var(--mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.key-box .btn-ghost { background: var(--surface) !important; }
.key-box .btn-ghost:hover { background: var(--surface-3) !important; }
.card .key-box { min-height: 46px; padding: 5px 5px 5px 12px; border-radius: 12px; }
.card .key-box code { font-size: 12.5px; }

/* ==========================================================================
   Диалоги
   ========================================================================== */

.confirm {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  text-align: left;
}
.confirm[open] { animation: pop 0.22s var(--ease); }
.confirm::backdrop {
  background: rgb(10 10 16 / 0.45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.confirm .stage-sub { font-size: 18px; letter-spacing: -0.01em; }
.confirm .stage-note { margin-top: 8px; color: var(--muted); }
.confirm .form-error { margin-top: 10px; }
.confirm .input { margin-top: 12px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.confirm-actions .btn { margin-top: 0; }
.confirm-actions-wrap { flex-wrap: wrap; }

#new-chat-form { display: grid; gap: 0; margin-top: 4px; }
#new-chat-form .input + .input { margin-top: 8px; }

.forward-list {
  max-height: min(360px, 50dvh);
  margin: 12px -8px 0;
  padding: 0 4px;
  overflow-y: auto;
  text-align: left;
}
.forward-list .chat-item { padding: 8px; }
#forward-search { margin-top: 14px; }

/* ==========================================================================
   Контекстное меню
   ========================================================================== */

.ctx-menu {
  position: fixed;
  z-index: 6;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop 0.14s var(--ease);
  transform-origin: top left;
}
.ctx-menu button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.ctx-menu button:hover, .ctx-menu button:focus-visible { outline: none; background: var(--surface-2); }
.ctx-menu .is-danger { color: var(--red); }
.ctx-menu .is-danger:hover, .ctx-menu .is-danger:focus-visible { background: var(--red-soft); }

/* ==========================================================================
   Тост
   ========================================================================== */

.toast {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  right: 20px;
  z-index: 10;
  width: min(360px, calc(100vw - 32px));
  padding: 14px 16px 14px 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s var(--ease);
}
.toast::before {
  content: '✓';
  position: absolute;
  top: 14px;
  left: 14px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green-ink);
  font-size: 12px;
  font-weight: 700;
}
.toast.is-error::before { content: '!'; background: var(--red-soft); color: var(--red); }
.toast strong { display: block; font-size: 14px; font-weight: 600; line-height: 1.4; }
.toast p { margin-top: 2px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.toast p:empty { display: none; }

/* ==========================================================================
   Пустые страницы и настройки
   ========================================================================== */

.empty-page { display: grid; justify-items: center; gap: 10px; padding-top: 80px; text-align: center; }
.empty-page p { color: var(--muted); }

.settings { display: grid; gap: 14px; max-width: 560px; }
.settings > .card {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}
.settings > .page-head { margin-bottom: 10px; }
.settings .card-sub { white-space: normal; }
.settings .card .btn { margin-top: 0; }

/* ==========================================================================
   Мессенджер
   ========================================================================== */

.page:has(#view-chat:not([hidden])) { max-width: 1600px; padding-top: 20px; padding-bottom: 20px; }

.chat {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  height: calc(100vh - var(--header-h) - 40px);
  height: calc(100dvh - var(--header-h) - 40px);
  min-height: 460px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
.chat-side, .chat-pane { overflow: hidden; }
.chat-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.chat-list { flex: 1; min-height: 0; padding: 0 8px 8px; overflow-y: auto; }
.chat-new {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: none;
  min-height: 40px;
  margin: 12px;
  border: 0;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary-ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s;
}
.chat-new:hover { background: var(--primary-soft-2); }
.chat-list-note { padding: 40px 20px; color: var(--muted); font-size: 14px; text-align: center; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s;
}
.chat-item + .chat-item { margin-top: 1px; }
.chat-item:hover { background: var(--surface-2); }
.chat-item[aria-current='true'] { background: var(--primary-soft); }
.chat-item[aria-current='true'] .chat-network { box-shadow: 0 0 0 2px var(--primary-soft); }
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.chat-item-row + .chat-item-row { margin-top: 2px; }
.chat-item-name { overflow: hidden; font-size: 15px; font-weight: 600; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-time { flex: none; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chat-item-preview { overflow: hidden; color: var(--muted); font-size: 13.5px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-you { color: var(--ink-2); font-weight: 500; }
.chat-item-preview .ticks { color: var(--primary-ink); }
.chat-unread {
  flex: none;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Аватарки */
.chat-avatar { position: relative; flex: none; width: 50px; height: 50px; }
.chat-avatar-small { width: 40px; height: 40px; }
.chat-avatar-image {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 50%;
  background: linear-gradient(140deg, #8b7dff, #6a57f0 60%, #4e3fd1);
  color: #fff;
  font-size: 19px;
  font-weight: 600;
}
.chat-avatar-small .chat-avatar-image { font-size: 16px; }
.chat-avatar-image img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; }
.chat-online {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 13px;
  height: 13px;
  border: 2.5px solid var(--surface);
  border-radius: 50%;
  background: var(--green);
}
.chat-avatar-small .chat-online { width: 11px; height: 11px; border-width: 2px; top: 0; right: 0; }
.chat-item[aria-current='true'] .chat-online { border-color: var(--primary-soft); }
.chat-item:hover:not([aria-current='true']) .chat-online { border-color: var(--surface-2); }

/* Значок мессенджера: аккуратный кружок в углу аватарки (Max, Telegram) */
.chat-network {
  position: absolute;
  right: -2px;
  bottom: -2px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 0 0 2px var(--surface);
}
.chat-network svg { display: block; width: 100%; height: 100%; }
.chat-network[title='Max'] svg { width: 15px; height: 15px; }
.chat-item:hover:not([aria-current='true']) .chat-network { box-shadow: 0 0 0 2px var(--surface-2); }
.chat-avatar-small .chat-network { width: 17px; height: 17px; }
.chat-avatar-small .chat-network[title='Max'] svg { width: 13px; height: 13px; }

/* Логотипы мессенджеров: Max подстраивается под тему через currentColor */
#logo-max path { fill: currentColor; }

/* Правая часть */
.chat-pane { position: relative; display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); }
.chat-pane::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(600px 400px at 100% 0%, rgb(124 108 255 / 0.07), transparent 70%),
    radial-gradient(500px 360px at 0% 100%, rgb(255 143 163 / 0.05), transparent 70%);
}
.chat-pane > * { position: relative; z-index: 1; }
.chat-placeholder {
  display: grid;
  justify-items: center;
  gap: 14px;
  margin: auto;
  padding: 24px;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}
.chat-placeholder::before {
  content: '';
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--line);
  -webkit-mask: none;
}
.chat-placeholder::after {
  content: '';
  position: absolute;
  top: 24px;
  left: 50%;
  width: 32px;
  height: 32px;
  margin-left: -16px;
  background: var(--primary);
  -webkit-mask: var(--i-chat) center / contain no-repeat;
  mask: var(--i-chat) center / contain no-repeat;
  transform: translateY(16px);
}
.chat-placeholder { position: relative; }

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.chat-head-titles { min-width: 0; }
.chat-head .card-title { font-size: 15.5px; }
.chat-head .card-sub { font-size: 12.5px; }
.chat-back {
  position: relative;
  display: none;
  flex: none;
  width: 38px;
  height: 38px;
  margin-left: -6px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  font-size: 0;
  cursor: pointer;
}
.chat-back:hover { background: var(--surface-2); }

.chat-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 3px;
  padding: 16px clamp(12px, 3vw, 28px) 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.chat-day {
  align-self: center;
  margin: 12px 0 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  box-shadow: var(--shadow-xs), 0 0 0 1px var(--line);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

/* Пузыри */
.bubble {
  max-width: min(72%, 560px);
  padding: 8px 12px 6px;
  border-radius: 18px 18px 18px 6px;
  background: var(--bubble-in);
  color: var(--bubble-in-ink);
  box-shadow: var(--shadow-xs);
  font-size: 14.5px;
  line-height: 1.42;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  align-self: flex-start;
}
.bubble.is-out {
  border-radius: 18px 18px 6px 18px;
  background: var(--bubble-out);
  color: var(--bubble-out-ink);
  align-self: flex-end;
}
.bubble-sender { display: block; margin-bottom: 1px; color: var(--bubble-accent); font-size: 12.5px; font-weight: 600; }
.bubble-time { display: block; margin-top: 2px; font-size: 11px; opacity: 0.7; text-align: right; }

.msg-row {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(80%, 640px);
  align-self: flex-start;
}
.msg-row.is-out { flex-direction: row-reverse; align-self: flex-end; }
.msg-row .bubble { flex: 0 1 auto; min-width: 0; max-width: 100%; align-self: auto; }

.msg-react {
  flex: none;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-xs), 0 0 0 1px var(--line);
  font-size: 15px;
  line-height: 1;
  opacity: 0;
  transform: scale(0.85);
  cursor: pointer;
  transition: opacity 0.12s, transform 0.12s var(--ease);
}
.msg-row:hover .msg-react, .msg-react:focus-visible { opacity: 1; transform: none; }
.msg-react:hover { background: var(--surface-2); }

.reaction-picker {
  position: fixed;
  z-index: 5;
  display: flex;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop 0.14s var(--ease);
}
.reaction-picker.is-full {
  display: grid;
  grid-template-columns: repeat(8, 36px);
  max-height: 300px;
  overflow-y: auto;
  padding: 8px;
  border-radius: 18px;
}
.reaction-picker button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.12s var(--ease), background-color 0.12s;
}
.reaction-picker button:hover { background: var(--surface-2); transform: scale(1.15); }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.reaction-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 0;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-ink);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.12s;
}
.reaction-chip:hover { background: var(--primary-soft-2); }
.bubble.is-out .reaction-chip { background: rgb(255 255 255 / 0.18); color: #fff; }
.bubble.is-out .reaction-chip:hover { background: rgb(255 255 255 / 0.28); }
.reaction-chip.is-mine { background: var(--primary); color: var(--on-primary); }
.bubble.is-out .reaction-chip.is-mine { background: #fff; color: #4a37c9; }

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 2px;
  margin-bottom: -1px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bubble.is-out .bubble-meta { color: rgb(255 255 255 / 0.82); }
.ticks { margin-right: 4px; padding-right: 3px; font-size: 11.5px; letter-spacing: -3px; }
.bubble-meta .ticks { margin-right: 0; margin-left: 2px; }
.ticks.is-read { font-weight: 700; }
.bubble-edited { margin-right: 4px; font-style: italic; }

/* Голосовые */
.voice { display: flex; align-items: center; gap: 10px; min-width: min(240px, 60vw); padding: 2px 0; }
.voice-play, .video-play {
  display: grid;
  place-items: center;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  font-variant-emoji: text;
  cursor: pointer;
  transition: transform 0.12s var(--ease), background-color 0.15s;
}
.voice-play { width: 40px; height: 40px; padding-left: 2px; font-size: 13px; }
.voice-play:hover { background: var(--primary-hover); }
.voice-play:active, .video-play:active { transform: scale(0.94); }
.bubble.is-out .voice-play { background: #fff; color: #4a37c9; }
.voice-wave { display: flex; flex: 1; align-items: center; gap: 2px; height: 28px; cursor: pointer; }
.voice-wave i { flex: 1; min-height: 3px; border-radius: 2px; background: currentColor; opacity: 0.28; transition: opacity 0.1s; }
.voice-wave i.is-played { opacity: 1; }
.bubble:not(.is-out) .voice-wave i { background: var(--primary); }
.bubble:not(.is-out) .voice-wave i:not(.is-played) { opacity: 0.25; }
.voice-time { flex: none; min-width: 32px; font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; opacity: 0.85; }

/* Видео и «кружки» */
.video { position: relative; display: block; overflow: hidden; margin: 2px 0 6px; border-radius: 12px; background: #111; }
.video img, .video video { display: block; width: 100%; height: 100%; object-fit: cover; }
.video-note { width: 220px; height: 220px; border-radius: 50%; box-shadow: 0 0 0 3px rgb(255 255 255 / 0.15); }
.video-regular { width: min(340px, 60vw); aspect-ratio: 16 / 9; }
.video-play {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 52px;
  height: 52px;
  padding-left: 3px;
  background: rgb(15 15 20 / 0.55);
  color: #fff;
  font-size: 18px;
  transform: translate(-50%, -50%);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.video-play:hover { background: rgb(15 15 20 / 0.7); }
.video-play:active { transform: translate(-50%, -50%) scale(0.94); }
.video-duration {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgb(15 15 20 / 0.6);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.video-note .video-duration { right: 50%; bottom: 14px; transform: translateX(50%); }
/* «Кружок» без пузыря вокруг, время — плашкой под ним */
.bubble:has(> .video-note) { padding: 0; background: transparent; box-shadow: none; }
.bubble:has(> .video-note) .video-note { margin: 0 0 4px; }
.bubble:has(> .video-note) .bubble-meta {
  justify-content: center;
  width: max-content;
  margin: 0 auto;
  padding: 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  box-shadow: var(--shadow-xs);
  color: var(--muted);
}
.bubble:has(> .video-note) .reactions { justify-content: center; margin-bottom: 4px; }

/* Файлы, стикеры, вложения */
.bubble-file {
  position: relative;
  display: block;
  width: 100%;
  min-width: min(220px, 55vw);
  min-height: 52px;
  margin: 2px 0;
  padding: 15px 12px 15px 54px;
  overflow: hidden;
  line-height: 22px;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 0;
  border-radius: 12px;
  background: var(--primary-soft);
  color: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s;
}
.bubble-file::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 8px;
  width: 36px;
  height: 36px;
  margin-top: -18px;
  border-radius: 10px;
  background: var(--primary);
}
/* Скрипт пишет «📄 имя»: эмодзи заменяем нарисованным значком */
.bubble-file::first-letter { font-size: 0; }
.bubble-file::after {
  content: '';
  position: absolute;
  left: 17px;
  top: 50%;
  width: 18px;
  height: 18px;
  margin-top: -9px;
  background: #fff;
  -webkit-mask: var(--i-file) center / contain no-repeat;
  mask: var(--i-file) center / contain no-repeat;
}
.bubble-file:hover { background: var(--primary-soft-2); }
.bubble.is-out .bubble-file { background: rgb(255 255 255 / 0.16); }
.bubble.is-out .bubble-file:hover { background: rgb(255 255 255 / 0.24); }
.bubble.is-out .bubble-file::before { background-color: #fff; }
.bubble.is-out .bubble-file::after { background: #4a37c9; }

.bubble-sticker { display: block; width: 150px; height: 150px; object-fit: contain; }
.bubble:has(> .bubble-sticker:only-of-type) { background: transparent; box-shadow: none; }

.bubble-forward {
  display: block;
  margin-bottom: 4px;
  padding-left: 8px;
  border-left: 2px solid currentColor;
  color: var(--bubble-accent);
  font-size: 12.5px;
  font-weight: 600;
}
.bubble.is-out .bubble-forward { color: rgb(255 255 255 / 0.9); }
.bubble-reply {
  display: block;
  width: 100%;
  margin: 2px 0 6px;
  padding: 5px 10px;
  border: 0;
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  background: var(--primary-soft);
  color: inherit;
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s;
}
.bubble-reply:hover { background: var(--primary-soft-2); }
.bubble-reply strong { display: block; color: var(--bubble-accent); font-weight: 600; }
.bubble-reply span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.85; }
.bubble.is-out .bubble-reply { border-left-color: #fff; background: rgb(255 255 255 / 0.16); }
.bubble.is-out .bubble-reply:hover { background: rgb(255 255 255 / 0.24); }
.bubble.is-out .bubble-reply strong { color: #fff; }

.msg-row.is-flash .bubble { animation: flash 1.2s ease-out; }
.chat-messages.is-selecting .msg-row { cursor: pointer; }
.chat-messages.is-selecting .msg-react { display: none; }
.chat-messages.is-selecting .bubble { transition: box-shadow 0.15s; }
.msg-row.is-selected .bubble { box-shadow: 0 0 0 3px var(--primary), var(--shadow-sm); }
.bubble.is-out:is(.msg-row.is-selected .bubble) { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--primary); }

.bubble-album {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 190px));
  gap: 3px;
  margin: 0 -8px 6px;
  overflow: hidden;
  border-radius: 12px;
}
.bubble-album .bubble-photo { width: 100%; height: 160px; margin: 0; border-radius: 0; object-fit: cover; }
.bubble-photo {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 340px;
  margin: 0 0 6px;
  border-radius: 12px;
  object-fit: contain;
}
.bubble-attach { display: block; color: inherit; font-weight: 500; opacity: 0.9; }

/* Поле ввода */
.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.chat-composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 160px;
  padding: 11px 16px;
  border: 1px solid transparent;
  border-radius: 22px;
  outline: none;
  background: var(--surface-2);
  color: var(--ink);
  font: 400 15px/1.4 var(--sans);
  resize: none;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.chat-composer textarea::placeholder { color: var(--placeholder); }
.chat-composer textarea:focus { border-color: var(--primary); background: var(--surface); box-shadow: var(--ring); }
.chat-send {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 4px 12px rgb(91 71 224 / 0.3);
  cursor: pointer;
  transition: background-color 0.15s, transform 0.12s var(--ease);
}
.chat-send:hover { background: var(--primary-hover); }
.chat-send:active:not(:disabled) { transform: scale(0.92); }
.chat-send:disabled { opacity: 0.55; cursor: not-allowed; }
.chat-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.chat-icon:hover { background: var(--surface-2); color: var(--ink); }

.chat-context {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 8px 10px 8px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
}
.chat-context::before {
  content: '';
  flex: none;
  align-self: stretch;
  width: 3px;
  border-radius: 2px;
  background: var(--primary);
}
.chat-context + .chat-draft, .chat-context + .chat-draft + .chat-composer { border-top: 0; }
.chat-context + .chat-composer, .chat-context ~ .chat-composer:not([hidden]) { border-top: 0; }
.chat-context-body { flex: 1; min-width: 0; }
.chat-context-body strong { display: block; color: var(--primary-ink); font-weight: 600; }
.chat-context-body span { display: block; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.chat-context-cancel {
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.chat-context-cancel:hover { background: var(--surface-2); color: var(--ink); }

.chat-selection { align-items: center; }
.select-count { margin-right: auto; font-size: 14px; font-weight: 600; }

.chat-draft {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.chat-draft + .chat-composer { border-top: 0; }
.draft-item {
  position: relative;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 10.5px;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
}
.draft-item:has(img) { padding: 0; }
.draft-item img { width: 100%; height: 100%; object-fit: cover; }
.draft-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgb(15 15 20 / 0.65);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.draft-remove:hover { background: rgb(15 15 20 / 0.85); }
.chat-upload { padding: 8px 18px; border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 13px; }
.chat-upload + .chat-context, .chat-upload ~ .chat-draft { border-top: 0; }

/* Запись голосового */
.chat-recording { align-items: center; gap: 12px; }
.record-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); animation: pulse 1.1s ease-in-out infinite; }
.record-level { display: flex; flex: 1; align-items: center; gap: 2px; height: 32px; min-width: 0; overflow: hidden; }
.record-level i { flex: 1; min-height: 3px; max-width: 4px; border-radius: 2px; background: var(--primary); }
.record-time { min-width: 44px; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Вход
   ========================================================================== */

.auth {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 24px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 32px 16px;
}
.auth > .brand { font-size: 22px; }
.auth > .brand svg { width: 42px; height: 42px; padding: 8px; border-radius: 13px; }
.auth-card {
  display: grid;
  gap: 20px;
  width: min(400px, 100%);
  padding: clamp(24px, 5vw, 36px);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  animation: rise 0.4s var(--ease) both;
}
.auth-head { display: grid; gap: 6px; text-align: center; }
.auth-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.auth-head p { color: var(--muted); font-size: 14px; }
.auth-card .form { width: 100%; }
.auth-card .btn { width: 100%; min-height: 48px; font-size: 15px; }
.auth-foot { color: var(--muted); font-size: 12.5px; text-align: center; }

.tabs {
  display: flex;
  gap: 2px;
  width: 100%;
  margin-bottom: 6px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
}
.tabs button {
  flex: 1;
  min-height: 36px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.18s, color 0.18s, box-shadow 0.18s;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected='true'] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }

/* ==========================================================================
   Документация (старые классы, страница /docs/)
   ========================================================================== */

.doc { display: grid; gap: 14px; max-width: 760px; margin: 0 auto; }
.doc h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.doc-sub { color: var(--muted); }
.card-sub.doc-text { white-space: normal; }
.doc pre {
  margin: 8px 0 0;
  padding: 14px 16px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  font: 500 12.5px/1.6 var(--mono);
}

/* ==========================================================================
   Анимации
   ========================================================================== */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes pop { from { opacity: 0; transform: scale(0.96); } }
@keyframes msg-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(0.98); } }
@keyframes flash { 30% { box-shadow: 0 0 0 4px var(--primary); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .spinner { animation: spin 2.5s linear infinite !important; }
  .record-dot { animation: none !important; }
}

/* ==========================================================================
   Адаптивность
   ========================================================================== */

/* Планшет */
@media (max-width: 1100px) {
  .chat { grid-template-columns: minmax(260px, 300px) minmax(0, 1fr); }
}

@media (max-width: 960px) {
  :root { --header-h: 116px; }
  .header {
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: 10px;
    padding: 10px 16px;
  }
  .header .nav, .header .wizard-bar { grid-column: 1 / -1; grid-row: 2; }
  .header .nav { width: 100%; }
  .header .wizard-bar { justify-self: stretch; }
  .wizard-pill { width: 100%; }
  .brand { font-size: 18px; }
  .brand svg { width: 32px; height: 32px; padding: 6px; border-radius: 10px; }
  .profile { padding-left: 10px; }
  .avatar { width: 36px; height: 36px; font-size: 15px; }
  .page { padding: 24px 16px 48px; }
  .page:has(#view-chat:not([hidden])) { padding: 12px; }
  .chat { height: calc(100dvh - var(--header-h) - 24px); min-height: 380px; }
  .msg-react { opacity: 1; transform: none; }
}

/* Телефон и узкий планшет: одна колонка, чат на весь экран */
@media (max-width: 760px) {
  .chat { grid-template-columns: minmax(0, 1fr); border-radius: var(--radius); }
  .chat .chat-side { border-right: 0; }
  .chat .chat-pane { display: none; }
  .chat.is-open .chat-side { display: none; }
  .chat.is-open .chat-pane { display: flex; }
  .chat-back { display: block; }
  .msg-row { max-width: 92%; }
  .bubble { max-width: 88%; }
  .video-note { width: 190px; height: 190px; }

  /* Открытый чат занимает весь экран, как в мобильных мессенджерах */
  body:has(.chat.is-open:not([hidden])) .header { display: none; }
  .page:has(.chat.is-open:not([hidden])) { padding: 0; }
  .chat.is-open {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .chat.is-open .chat-head { padding: 8px 12px; min-height: 58px; }
  .chat.is-open .chat-composer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }

  .toast { top: auto; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); left: 16px; width: auto; margin: 0 auto; max-width: 420px; }

  .settings > .card { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 480px) {
  .profile-name { max-width: 110px; font-size: 13px; }
  .profile-balance { font-size: 11.5px; }
  .nav-tab { padding: 0 8px; font-size: 13.5px; }
  .home-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .add-btn { justify-content: center; padding: 0 12px 0 6px; font-size: 13.5px; }
  .pick { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .pick-card { min-height: 116px; }
  #view-wizard { padding: 24px 16px; border-radius: var(--radius-lg); }
  .btn-big { width: 100%; padding: 0 20px; }
  .card { padding: 16px; }
  .confirm { padding: 20px; }
  .confirm-actions { flex-wrap: wrap; }
  .confirm-actions .btn { flex: 1 1 auto; }
  .chat-composer { gap: 4px; padding-left: 8px; padding-right: 8px; }
  .chat-icon { width: 40px; }
  .video-regular { width: min(280px, 64vw); }
  .bubble-album { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bubble-album .bubble-photo { height: 120px; }
}

/* Синхронизация с BroneBoxy */
.broneboxy-form { display: flex; gap: 8px; margin-top: 12px; }
.broneboxy-form .input { flex: 1; min-width: 0; }
.broneboxy-form[hidden] { display: none; }
#broneboxy-card { display: block; }
