/* ============ Blaze — Flutter-копия темы ============ */

:root {
  --ui-scale: 1.0;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --radius: 8px;
}

:root[data-theme="dark"] {
  --bg: #050505;
  --surface: #161616;
  --surface-highest: #202020;
  --text: #D4D4D4;
  --border: rgba(212, 212, 212, 0.15);
  --secondary: rgba(212, 212, 212, 0.6);
  --tertiary: rgba(212, 212, 212, 0.45);
  --row-hover: rgba(212, 212, 212, 0.08);
  --row-selected: #161616;
  --button-bg: #D4D4D4;
  --button-fg: #050505;
  --danger: rgba(212, 212, 212, 0.8);
  --danger-strong: #EB5757;
  --danger-soft: rgba(212, 212, 212, 0.2);
  --scroll-thumb: rgba(212, 212, 212, 0.25);
  --scrim: rgba(22, 22, 22, 0.75);
}

:root[data-theme="light"] {
  --bg: #FFFFFF;
  --surface: #F0F0F0;
  --surface-highest: #E7E7E7;
  --text: #101010;
  --border: rgba(16, 16, 16, 0.15);
  --secondary: rgba(16, 16, 16, 0.6);
  --tertiary: rgba(16, 16, 16, 0.45);
  --row-hover: rgba(16, 16, 16, 0.08);
  --row-selected: #F0F0F0;
  --button-bg: #101010;
  --button-fg: #FFFFFF;
  --danger: rgba(16, 16, 16, 0.8);
  --danger-strong: #EB5757;
  --danger-soft: rgba(16, 16, 16, 0.2);
  --scroll-thumb: rgba(16, 16, 16, 0.25);
  --scrim: rgba(16, 16, 16, 0.75);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  flex-direction: column;
  width: calc(100vw / var(--ui-scale));
  height: calc(var(--view-height, 100dvh) / var(--ui-scale));
  zoom: var(--ui-scale);
}

.overlay-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  zoom: var(--ui-scale);
  z-index: 1000;
}
.overlay-root > * { pointer-events: auto; }

button {
  font-family: var(--font);
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

svg {
  display: block;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 4px;
}
::-webkit-scrollbar-track { background: transparent; }

/* ============ Popups (account) ============ */

.popup {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  z-index: 1100;
  animation: pop-in 0.12s ease-out;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes slide-in-right {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.popup-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.popup-header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  margin: -4px;
  background: transparent;
  border: none;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
}
.popup-header-user:hover { background: var(--row-hover); }
.popup-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-highest);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  flex: 0 0 auto;
}
.popup-name { font-size: 13px; font-weight: 600; }
.popup-sub { font-size: 11px; color: var(--secondary); }

.popup-menu {
  padding: 4px;
}
.popup-menu-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 6px;
  font-size: 13px;
  text-align: left;
  transition: background 0.1s;
}
.popup-menu-row:hover { background: var(--row-hover); }
.popup-menu-row svg { width: 16px; height: 16px; color: var(--secondary); flex: 0 0 auto; }

.popup-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ============ Sidebar ============ */

.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 260px;
  flex: 0 0 260px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sb-logo-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}
.sb-logo {
  width: 28px;
  height: 28px;
  color: var(--text);
  flex: 0 0 auto;
}
.sb-title {
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
}

.sb-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 12px 12px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  transition: background 0.15s;
}
.sb-item:hover { background: var(--row-hover); }
.sb-item.active { background: var(--row-hover); }
.sb-item svg { width: 16px; height: 16px; flex: 0 0 auto; }

.sb-history {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px;
  min-height: 0;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  transition: background 0.1s;
}
.chat-item:hover { background: var(--row-hover); }
.chat-item.active { background: var(--row-selected); }

.ci-pin svg { width: 12px; height: 12px; color: var(--tertiary); flex: 0 0 auto; }

.ci-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.ci-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ci-sub {
  font-size: 12px;
  color: var(--tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ci-actions {
  display: none;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}
.chat-item:hover .ci-actions { display: flex; }
.ci-btn {
  width: 22px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  color: var(--secondary);
}
.ci-btn:hover { background: var(--row-selected); }
.ci-btn svg { width: 14px; height: 14px; }

.sb-footer {
  padding: 8px;
}

.sb-account {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  text-align: left;
  transition: background 0.15s;
}
.sb-account:hover { background: var(--row-hover); }

.sb-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-highest);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex: 0 0 auto;
  overflow: hidden;
}
.sb-avatar img,
.popup-avatar img,
.ss-item-avatar img,
.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.sb-acc-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sb-acc-name { font-size: 13px; font-weight: 600; }
.sb-acc-email { font-size: 11px; color: var(--secondary); }

.empty-history {
  padding: 16px 12px;
  font-size: 12px;
  color: var(--tertiary);
  text-align: center;
}

/* ============ Content / Chat Page ============ */

.content {
  flex: 1;
  min-width: 0;
  position: relative;
  background: var(--bg);
}

.page { height: 100%; }

.chat-page {
  display: flex;
  flex-direction: column;
  position: relative;
}

.chat-page.empty {
  justify-content: center;
}

.chat-page.empty .chat-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.chat-page.empty .chat-scroll {
  flex: 0 1 auto;
  overflow: visible;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.scroll-bottom-btn {
  position: absolute;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  z-index: 20;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.14));
  background: var(--bg-elev, #2a2a33);
  color: var(--text, #fff);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.scroll-bottom-btn svg {
  width: 22px;
  height: 22px;
}

.scroll-bottom-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.scroll-bottom-btn:hover {
  background: var(--accent, #5b7cff);
}

@media (max-width: 600px) {
  .scroll-bottom-btn {
    bottom: 84px;
  }
}


.kb-open .chat-page.empty .chat-scroll {
  flex: 1;
  justify-content: center;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 12px 28px 4px 28px;
  flex: 0 0 auto;
}
.chat-header-title { font-size: 18px; font-weight: 800; }

.plan-badge {
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--row-hover);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  transition: background 0.15s;
}
.plan-badge:hover { background: var(--row-selected); }

.chat-messages {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 28px 8px 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.placeholder-phrase {
  text-align: center;
  font-size: 14px;
  color: var(--tertiary);
  padding: 8px 0 4px 0;
}

.msg-markdown .katex-display {
  margin: 8px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.msg-markdown .katex-display > .katex {
  font-size: 1.1em;
}

.chat-page.empty .chat-messages {
  padding: 0 48px;
}

.chat-page.empty .placeholder-phrase {
  font-size: 26px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  padding: 0;
}

.chat-page.empty .composer-pin {
  padding-top: 24px;
}

.message { display: flex; flex-direction: column; }

.message.user {
  align-items: flex-end;
}

.msg-bubble {
  max-width: 360px;
  padding: 8px 14px;
  border-radius: 16px 16px 4px 16px;
  background: var(--surface-highest);
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  user-select: text;
}
.msg-bubble.overflow { max-height: calc(16px * 1.55 * 7); overflow: hidden; }

.msg-bubble a, .msg-markdown a {
  color: var(--accent, #4f8cff);
  text-decoration: underline;
  word-break: break-word;
}

.inline-link {
  color: var(--accent, #4f8cff);
  text-decoration: none;
  margin-left: 6px;
}
.il-inner {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: underline;
  vertical-align: middle;
  line-height: 1.4;
  white-space: nowrap;
  transition: color 0.15s ease;
}
.inline-link:hover .il-inner {
  color: var(--accent-hover, #6fa0ff);
}
.il-fav {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  border-radius: 3px;
  object-fit: contain;
  background: transparent;
}
.il-label {
  font-size: inherit;
  font-weight: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
}

.md-hr {
  border: none;
  height: 1px;
  margin: 12px 0;
  background: var(--border, rgba(255, 255, 255, 0.12));
}



.msg-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 360px;
}

.msg-expand {
  margin-top: 6px;
  display: flex;
  justify-content: center;
  color: var(--secondary);
  width: 20px;
  height: 20px;
}
.msg-expand svg { width: 20px; height: 20px; }
.msg-expand.expanded { transform: rotate(180deg); }

.message.assistant {
  align-items: stretch;
}

.msg-markdown {
  font-size: 16px;
  line-height: 1.55;
  user-select: text;
  word-break: break-word;
}
.msg-markdown p { margin: 0 0 8px 0; }
.msg-markdown p:last-child { margin-bottom: 0; }
.msg-markdown h1, .msg-markdown h2, .msg-markdown h3 {
  font-weight: 700;
  margin: 10px 0 6px 0;
  line-height: 1.3;
}
.msg-markdown h1 { font-size: 20px; }
.msg-markdown h2 { font-size: 18px; }
.msg-markdown h3 { font-size: 16px; }
.msg-markdown strong { font-weight: 700; }
.msg-markdown em { font-style: italic; }
.msg-markdown del { text-decoration: line-through; }
.msg-markdown blockquote {
  border-left: 3px solid var(--border);
  padding-left: 12px;
  color: var(--secondary);
  margin: 8px 0;
}
.msg-markdown code {
  font-family: Consolas, monospace;
  font-size: 14px;
  background: var(--row-hover);
  padding: 1px 5px;
  border-radius: 4px;
}
.msg-markdown pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin: 8px 0;
  overflow-x: auto;
  position: relative;
}
.msg-markdown pre code {
  background: transparent;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
}
.msg-markdown pre .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--secondary);
  background: var(--row-hover);
  opacity: 0;
  transition: opacity 0.15s;
}
.msg-markdown pre:hover .copy-btn { opacity: 1; }
.msg-markdown pre .copy-btn svg { width: 14px; height: 14px; }
.msg-markdown ul { padding-left: 22px; margin: 6px 0; list-style: disc; }
.msg-markdown ol { padding-left: 22px; margin: 6px 0; list-style: decimal; }
.msg-markdown li { margin: 2px 0; }
.msg-markdown table {
  border-collapse: collapse;
  width: fit-content;
  max-width: 100%;
  margin: 10px auto;
  display: block;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
}
.msg-markdown td, .msg-markdown th {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.msg-markdown tr:last-child td { border-bottom: none; }
.msg-markdown tr:first-child td {
  background: var(--surface-highest);
  font-weight: 600;
  color: var(--text);
}
.msg-markdown tbody tr:hover td { background: var(--row-hover); }
.msg-markdown mark, .md-hl {
  background: color-mix(in srgb, var(--button-bg) 26%, transparent);
  color: inherit;
  padding: 0 4px;
  border-radius: 4px;
}

.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 4px;
  align-self: flex-start;
  opacity: 0;
  transition: opacity 0.15s;
}
.message:hover .msg-actions { opacity: 1; }
.msg-action {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--secondary);
}
.msg-action:hover { background: var(--row-hover); color: var(--text); }
.msg-action svg { width: 14px; height: 14px; }
.msg-action.filled { color: var(--text); }

/* ============ Composer ============ */

.composer-pin {
  flex: 0 0 auto;
  padding: 14px 28px 18px 28px;
}
.composer {
  max-width: 960px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
}

.composer-attachments {
  display: flex;
  gap: 8px;
  padding: 8px 10px 0 10px;
  overflow-x: auto;
}

.attach-tile {
  position: relative;
  width: 80px;
  height: 80px;
  flex: 0 0 80px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--secondary);
}
.attach-tile img { width: 100%; height: 100%; object-fit: cover; }
.attach-tile svg { width: 24px; height: 24px; }
.attach-tile-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attach-tile-remove svg { width: 10px; height: 10px; }

.composer-input-wrap { padding: 14px 14px 0 14px; }

.composer-input {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  max-height: calc(16px * 1.45 * 5);
  min-height: 24px;
  user-select: text;
}
.composer-input::placeholder { color: var(--tertiary); }

.composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 10px 10px;
}
.composer-spacer { flex: 1; }

.attach-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--secondary);
  transition: background 0.15s;
}
.attach-btn:hover { background: var(--row-hover); }
.attach-btn svg { width: 18px; height: 18px; }

.model-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  min-width: 0;
  transition: background 0.15s;
}
.model-selector:hover { background: var(--row-hover); }

.img-cancel-btn {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--danger, #e5484d);
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
}
.img-cancel-btn:hover { background: var(--row-hover); }
.img-cancel-btn svg { width: 14px; height: 14px; flex: 0 0 auto; }
.model-selector img { width: 16px; height: 16px; object-fit: contain; flex: 0 0 auto; }
.model-selector span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

.send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--button-bg);
  color: var(--button-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s, background 0.2s;
}
.send-btn:disabled { opacity: 1; }
.send-btn.sending { background: var(--danger-soft); color: var(--danger); opacity: 1; }
.send-btn svg { width: 14px; height: 14px; }

/* auth / registration */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  z-index: 1600;
  animation: fade-in 0.2s ease-out;
}
.auth-panel {
  width: min(420px, 100vw);
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-radius: 0;
  padding: 40px 28px 32px 28px;
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.5);
  animation: slide-in-right 0.25s ease-out;
  display: flex;
  flex-direction: column;
}
.auth-panel > :first-child { margin-top: auto; }
.auth-panel > :last-child { margin-bottom: auto; }
.auth-toolbar {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 5;
}
.auth-tool {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--text) 4%, transparent);
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
  color: color-mix(in srgb, var(--text) 70%, transparent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  transition: background 0.15s, color 0.15s;
}
.auth-tool:hover { background: color-mix(in srgb, var(--text) 10%, transparent); color: var(--text); }
.auth-tool svg { width: 16px; height: 16px; }
.auth-title {
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.4px;
  text-align: center;
  margin-bottom: 36px;
}
.auth-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--text) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--text) 20%, transparent);
  font-size: 13px;
  color: var(--text);
}
.auth-banner[hidden] { display: none; }
.auth-banner svg { width: 16px; height: 16px; flex: 0 0 auto; }
.auth-label {
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--text) 50%, transparent);
  margin-bottom: 6px;
  text-align: center;
}
.auth-input {
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
  display: block;
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
  border-radius: 24px;
  padding: 16px;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  outline: none;
  user-select: text;
  transition: border-color 0.15s, opacity 0.15s;
}
.auth-input::placeholder { color: color-mix(in srgb, var(--text) 20%, transparent); }
.auth-input:focus { border-color: color-mix(in srgb, var(--text) 30%, transparent); }
.auth-input:disabled { opacity: 0.6; }
.auth-submit-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 80px;
  margin-top: 16px;
}
.auth-submit {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px color-mix(in srgb, var(--text) 15%, transparent);
}
.auth-submit[hidden] { display: none; }
.auth-submit.loading { background: color-mix(in srgb, var(--text) 50%, transparent); }
.auth-submit svg { width: 28px; height: 28px; }
.auth-submit .auth-spinner { width: 24px; height: 24px; display: none; }
.auth-submit.loading .auth-arrow { display: none; }
.auth-submit.loading .auth-spinner { display: block; }

.auth-email-sub {
  font-size: 13px;
  line-height: 1.5;
  color: color-mix(in srgb, var(--text) 60%, transparent);
  text-align: center;
  margin-bottom: 36px;
}
.auth-title-lg {
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.8px;
  text-align: center;
  margin-bottom: 8px;
}
.auth-title-big {
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.4px;
  text-align: center;
  margin-bottom: 24px;
}
.auth-sub {
  font-size: 14px;
  color: color-mix(in srgb, var(--text) 65%, transparent);
  text-align: center;
  margin-bottom: 40px;
}
.auth-back-wrap { text-align: center; margin-top: 8px; }
.auth-back {
  font-size: 14px;
  color: color-mix(in srgb, var(--text) 50%, transparent);
  padding: 6px 10px;
  border-radius: 8px;
}
.auth-back:hover { color: var(--text); }
.auth-back:disabled { opacity: 0.5; cursor: default; }

.auth-methods {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 320px;
  margin: 0 auto;
}
.auth-method {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 56px;
  border-radius: 28px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--text) 4%, transparent), color-mix(in srgb, var(--text) 10%, transparent));
  border: 1px solid color-mix(in srgb, var(--text) 8%, transparent);
  transition: border-color 0.15s;
}
.auth-method:hover { border-color: color-mix(in srgb, var(--text) 25%, transparent); }
.auth-method svg { width: 20px; height: 20px; color: color-mix(in srgb, var(--text) 80%, transparent); }
.auth-method span {
  font-size: 13px;
  font-weight: 500;
  color: color-mix(in srgb, var(--text) 70%, transparent);
  padding: 0 8px;
  text-align: center;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px auto 14px;
  max-width: 320px;
  color: color-mix(in srgb, var(--text) 30%, transparent);
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: color-mix(in srgb, var(--text) 10%, transparent);
}

.auth-qr-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
  height: 48px;
  border-radius: 24px;
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
  color: color-mix(in srgb, var(--text) 75%, transparent);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.auth-qr-btn:hover {
  border-color: color-mix(in srgb, var(--text) 28%, transparent);
  color: var(--text);
}
.auth-qr-btn svg { width: 18px; height: 18px; }

.auth-qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 30px;
}
.auth-qr-wrap {
  padding: 12px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.auth-qr-wrap img {
  display: block;
  width: 200px;
  height: 200px;
  image-rendering: pixelated;
}
.auth-qr-status {
  font-size: 13px;
  color: var(--secondary);
  text-align: center;
  max-width: 280px;
  line-height: 1.5;
}
.auth-qr-status.error { color: var(--danger, #e0533d); }
.auth-qr-countdown {
  font-size: 12px;
  color: color-mix(in srgb, var(--text) 35%, transparent);
}
.auth-qr-actions {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 18px;
}
.auth-qr-actions .auth-back { margin-top: 0; }

/* ---------- Сканер QR (настройки → Устройства) ---------- */

.qr-scan-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-scan-card {
  width: min(460px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.qr-scan-title {
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}
.qr-scan-sub {
  font-size: 12px;
  color: var(--secondary);
  text-align: center;
  line-height: 1.5;
}
.qr-scan-viewport {
  position: relative;
  aspect-ratio: 1;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
  border: 2px solid var(--border);
}
.qr-scan-viewport video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.qr-scan-viewport::after {
  content: '';
  position: absolute;
  inset: 18%;
  border: 2px solid rgba(212, 212, 212, 0.7);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}
.qr-scan-status {
  font-size: 12px;
  color: var(--secondary);
  text-align: center;
  min-height: 16px;
  line-height: 1.4;
}
.qr-scan-status.error { color: var(--danger, #e0533d); }
.qr-scan-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}
.qr-scan-btn {
  background: var(--surface-highest);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 22px;
  font-size: 13px;
  cursor: pointer;
}
.qr-scan-btn:hover { background: var(--row-hover); }
.qr-scan-btn.primary {
  background: var(--button-bg);
  color: var(--button-fg);
  border-color: transparent;
}

.auth-code-wrap { position: relative; }
.auth-code-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 40px;
}
.auth-code-box {
  flex: 1 1 0;
  min-width: 0;
  max-width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--text) 15%, transparent);
  border-radius: 4px;
  transition: border-color 0.1s, border-width 0.1s;
}
.auth-code-box.active {
  border-color: var(--text);
  border-width: 1.5px;
}
.auth-code-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: text;
  border: none;
  outline: none;
  background: transparent;
}
.auth-resend { text-align: center; margin-top: 8px; }

.auth-legal {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 360px;
  margin: 0 auto;
  border: 1px solid color-mix(in srgb, var(--text) 8%, transparent);
  border-radius: 12px;
  padding: 8px 8px 8px 12px;
  cursor: pointer;
}
.auth-legal-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--text) 30%, transparent);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  transition: background 0.1s, border-color 0.1s;
}
.auth-legal-check.checked {
  background: var(--text);
  border-color: var(--text);
}
.auth-legal-check.checked svg { width: 14px; height: 14px; color: var(--bg); }
.auth-legal-label {
  flex: 1;
  font-size: 13px;
  color: color-mix(in srgb, var(--text) 80%, transparent);
}
.auth-legal-open {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: color-mix(in srgb, var(--text) 40%, transparent);
  flex: 0 0 auto;
}
.auth-legal-open:hover { background: var(--row-hover); }
.auth-legal-open svg { width: 14px; height: 14px; }
.auth-legal-btns {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 32px;
}
.auth-legal-btn {
  width: 100%;
  height: 44px;
  border-radius: 22px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
}
.auth-legal-btn.solid {
  background: var(--text);
  color: var(--bg);
}
.auth-legal-btn.solid.disabled {
  background: color-mix(in srgb, var(--text) 30%, transparent);
}
.auth-legal-btn.outline {
  border: 1px solid color-mix(in srgb, var(--text) 20%, transparent);
  color: var(--text);
}
.auth-legal-btn.outline.disabled {
  color: color-mix(in srgb, var(--text) 40%, transparent);
}

.auth-dash-input {
  width: min(280px, 100%);
  margin: 0 auto;
  display: block;
  background: transparent;
  border: 1px dashed color-mix(in srgb, var(--text) 20%, transparent);
  border-radius: 16px;
  padding: 24px;
  color: var(--text);
  font-family: var(--font);
  font-size: 22px;
  outline: none;
  text-align: center;
  user-select: text;
}
.auth-dash-input::placeholder {
  font-size: 22px;
  color: color-mix(in srgb, var(--text) 20%, transparent);
}

.auth-circle-wrap {
  display: flex;
  justify-content: center;
  margin-top: 40px;
}
.auth-circle {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px color-mix(in srgb, var(--text) 15%, transparent);
  transition: background 0.25s;
}
.auth-circle.loading { background: color-mix(in srgb, var(--text) 50%, transparent); }
.auth-circle svg { width: 28px; height: 28px; }
.auth-circle .auth-spinner { width: 24px; height: 24px; display: none; }
.auth-circle.loading .auth-arrow { display: none; }
.auth-circle.loading .auth-spinner { display: block; }

/* typing indicator */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 6px 0;
}
.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--secondary);
  animation: blink 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* model thinking indicator */
.thinking-block {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  padding: 2px 0;
  font-size: 0.8em;
  font-style: italic;
  color: var(--secondary);
  opacity: 0.75;
  max-height: 120px;
  overflow: hidden;
  word-break: break-word;
}
.thinking-block::before {
  content: '';
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  margin-top: 2px;
  border-radius: 50%;
  background: var(--secondary);
  animation: blink 1.2s infinite;
}

/* ============ Model Popup ============ */

.model-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 1150;
}

.model-panel {
  position: fixed;
  top: 120px;
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, calc(100vw - 32px));
  background: var(--surface);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.model-body {
  display: flex;
  align-items: stretch;
  gap: 16px;
  padding: 14px 16px 16px;
}
.model-limits {
  flex: 1 1 50%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.model-models {
  flex: 1 1 50%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 1px solid var(--border);
  padding-left: 16px;
}
.model-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--secondary);
  padding: 0 2px;
}
.model-tabs { display: none; }
.model-tab {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary);
  padding: 2px 4px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.model-tab.active { color: var(--text); border-bottom-color: var(--button-bg); }

.model-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px 16px;
  background: var(--surface-highest);
  border-bottom: 1px solid var(--border);
}
.model-title { font-size: 13px; font-weight: 600; }
.model-close {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  margin-left: auto;
  color: var(--secondary);
}
.model-close:hover { background: var(--row-hover); }
.model-close svg { width: 14px; height: 14px; }

.gauge { position: relative; width: 84px; height: 84px; flex: 0 0 auto; }
.gauge svg { transform: rotate(-90deg); }
.gauge-track { fill: none; stroke: var(--row-selected); }
.gauge-fill {
  fill: none;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s ease, stroke 0.3s ease;
}
.gauge-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text);
}

.usage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--secondary);
}
.usage-row b { font-weight: 600; color: var(--text); }

.model-panel .limit-gauge {
  background: var(--surface-highest);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
}
.model-panel .limit-gauge-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
}
.model-panel .limit-gauge-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.model-panel .gauge-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
}
.model-panel .gauge-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--button-bg);
  transition: width 0.3s ease, background 0.3s ease;
}
.model-panel .gauge-meta {
  display: flex;
  font-size: 12px;
  color: var(--secondary);
  margin-top: 7px;
}
.model-panel .gauge-meta-top { justify-content: flex-end; }
.model-panel .gauge-meta-bottom { justify-content: flex-start; }
.model-panel .gauge-total { font-weight: 600; color: var(--secondary); }
.model-panel .gauge-used { font-weight: 600; color: var(--text); }

.usage-cols {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
}
.usage-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 8px;
}
.usage-col-value { font-size: 14px; font-weight: 700; }
.usage-col-label { font-size: 10px; color: var(--secondary); }
.limit-group { display: flex; flex-direction: column; gap: 4px; }
.limit-group-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--secondary);
  padding: 0 16px;
}
.limit-group .usage-cols { padding: 0 16px; }

.model-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 10px;
}

.model-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  padding: 2px;
}
.model-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  font-size: 13px;
  text-align: left;
  background: var(--surface-highest);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.model-item:hover { background: var(--row-hover); border-color: var(--row-hover); }
.model-item.selected { background: var(--row-selected); border-color: var(--button-bg); }
.model-item img { width: 20px; height: 20px; flex: 0 0 auto; object-fit: contain; }
.model-item-name { font-weight: 600; flex: 1; color: var(--secondary); }
.model-item.selected .model-item-name { color: var(--text); }
.model-item-mult { font-size: 11px; font-weight: 600; color: var(--secondary); }

/* ============ Gallery ============ */

.gallery-page {
  display: flex;
  flex-direction: column;
}

.gallery-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 18px 28px 0 28px;
}
.gallery-title { font-size: 15px; font-weight: 800; }

.gallery-hero {
  text-align: center;
  color: var(--tertiary);
  font-size: 13px;
  padding: 8px 40px;
}

.gallery-grid-wrap {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 20px 28px 28px 28px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
}

.gallery-tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: var(--surface);
}
.gallery-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gallery-tile-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(5, 5, 5, 0.6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}
.gallery-tile:hover .gallery-tile-delete { opacity: 1; }
.gallery-tile-delete:hover { background: rgba(5, 5, 5, 0.85); }
.gallery-tile-delete svg { width: 12px; height: 12px; }

.gallery-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--tertiary);
  padding: 40px 0;
  text-align: center;
}
.gallery-empty svg { width: 28px; height: 28px; }

.add-sample-btn {
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--row-hover);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s;
}
.add-sample-btn:hover { background: var(--row-selected); }

/* Photo preview */
.photo-preview {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 5, 0.92);
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}
.photo-preview img {
  max-width: 90%;
  max-height: 85%;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.preview-counter {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
}
.preview-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.08);
  transition: background 0.15s;
}
.preview-nav.prev { left: 16px; }
.preview-nav.next { right: 16px; }
.preview-nav:hover { background: rgba(255, 255, 255, 0.18); }
.preview-nav svg { width: 20px; height: 20px; }
.preview-caption { font-size: 13px; color: rgba(255, 255, 255, 0.7); }
.preview-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.8);
}
.preview-close:hover { background: rgba(255, 255, 255, 0.12); }
.preview-close svg { width: 16px; height: 16px; }

/* Gallery picker */
.gallery-picker {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 5, 0.85);
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.gp-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 760px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.gp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.gp-title { font-size: 15px; font-weight: 700; }
.gp-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--secondary);
}
.gp-close:hover { background: var(--row-hover); }
.gp-close svg { width: 14px; height: 14px; }
.gp-grid-wrap { flex: 1; overflow-y: auto; min-height: 0; padding: 16px; }
.gp-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.gp-tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: var(--surface);
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.gp-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gp-tile.selected { border-color: var(--button-bg); box-shadow: 0 0 0 1px var(--button-bg); }
.gp-check {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--button-bg);
  color: var(--button-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}
.gp-check svg { width: 12px; height: 12px; }
.gp-tile.selected .gp-check { opacity: 1; }
.gp-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--tertiary);
  padding: 40px 0;
  text-align: center;
}
.gp-empty svg { width: 28px; height: 28px; }
.gp-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.gp-btn {
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--row-hover);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}
.gp-btn:hover { background: var(--row-selected); }
.gp-btn-primary { background: var(--button-bg); color: var(--button-fg); }
.gp-btn-primary:hover { background: var(--button-bg); opacity: 0.85; }
.gp-btn:disabled { opacity: 0.5; cursor: default; }
.gp-btn:disabled:hover { background: var(--row-hover); }

/* ============ Purchase / Upgrade ============ */

.purchase-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.54);
  z-index: 1500;
}

.purchase-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(1000px, calc(100vw - 40px));
  height: min(760px, calc(100vh - 80px));
  background: var(--surface);
  border-radius: 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 1510;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: pop-in 0.15s ease-out;
}

.purchase-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  flex: 0 0 auto;
  background: var(--surface-highest);
  border-bottom: 1px solid var(--border);
}
.purchase-head-title { font-size: 13px; font-weight: 600; }
.purchase-head-close {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--secondary);
}
.purchase-head-close:hover { background: var(--row-hover); }
.purchase-head-close svg { width: 14px; height: 14px; }

.purchase-body {
  flex: 1;
  min-height: 0;
}
.purchase-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* ============ Settings ============ */

.settings-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  opacity: 0.75;
  z-index: 1120;
}

.settings-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(1120px, calc(100vw - 40px));
  height: min(860px, calc(100vh - 82px));
  background: var(--surface);
  border-radius: 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 1130;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  flex: 0 0 auto;
  background: var(--surface-highest);
  border-bottom: 1px solid var(--border);
}
.settings-head-title { font-size: 13px; font-weight: 600; }
.settings-back {
  display: none;
  width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--secondary);
}
.settings-back:hover { background: var(--row-hover); }
.settings-back svg { width: 16px; height: 16px; }
.settings-head-close {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--secondary);
}
.settings-head-close:hover { background: var(--row-hover); }
.settings-head-close svg { width: 14px; height: 14px; }

.settings-body {
  flex: 1;
  display: flex;
  min-height: 0;
  border-top: 1px solid var(--border);
}

.settings-sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--surface-highest);
  padding: 8px;
  overflow-y: auto;
}

.ss-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  margin-bottom: 2px;
  transition: background 0.1s;
}
.ss-item:hover { background: var(--row-hover); }
.ss-item.active {
  background: var(--row-selected);
  font-weight: 700;
}
.ss-item svg { width: 16px; height: 16px; flex: 0 0 auto; }
.ss-item.active svg { color: var(--text); }
.ss-item:not(.active) svg { color: var(--secondary); }

.ss-item-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-highest);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex: 0 0 auto;
}
.ss-item-acc-text { display: flex; flex-direction: column; min-width: 0; text-align: left; }
.ss-item-acc-name {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ss-item-acc-sub {
  font-size: 10px;
  color: var(--secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.settings-content-inner {
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: 40px;
}
.page-feedback {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.page-feedback .settings-section-title {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 18px;
}

.settings-section { margin-bottom: 32px; }
.settings-section:last-child { margin-bottom: 0; }
.settings-section-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.settings-section-subtitle { font-size: 12px; color: var(--secondary); margin-bottom: 10px; }

.settings-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.sc-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}
.sc-row + .sc-row { border-top: 1px solid var(--border); }
.sc-row-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--row-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--secondary);
  flex: 0 0 auto;
}
.sc-row-icon svg { width: 16px; height: 16px; }
.sc-row-body { flex: 1; min-width: 0; }
.sc-row-title { font-size: 13px; font-weight: 600; }
.sc-row-desc { font-size: 12px; color: var(--secondary); }
.sc-row-value { font-size: 13px; color: var(--secondary); }
.composer-feedback {
  max-width: 520px;
  margin: 0 auto;
  background: var(--surface-highest);
}
.composer-feedback .composer-input { max-height: calc(16px * 1.45 * 3); }
.composer-feedback .composer-actions { padding: 4px 8px 6px 8px; }
.composer-feedback .model-selector { color: var(--secondary); padding: 3px 6px; }
.composer-feedback .send-btn { width: 26px; height: 26px; }
.composer-feedback .send-btn svg { width: 12px; height: 12px; }
.composer-feedback .send-btn:disabled { opacity: 0.5; }

.sc-action-btn {
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--row-hover);
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s;
}
.sc-action-btn:hover { background: var(--row-selected); }
.sc-action-btn.danger {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
}
.sc-action-btn.danger:hover { background: var(--row-hover); }
.sc-action-btn.primary {
  background: var(--button-bg);
  color: var(--button-fg);
  padding: 10px 20px;
  font-size: 13px;
}
.sc-action-btn.primary:hover { opacity: 0.9; }
.sc-action-btn.primary:disabled { opacity: 0.5; cursor: default; }

.devices-loading {
  padding: 16px 14px;
  font-size: 13px;
  color: var(--secondary);
}
.device-remove-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--danger);
  flex: 0 0 auto;
  transition: background 0.15s;
}
.device-remove-btn:hover { background: var(--row-hover); }
.device-remove-btn svg { width: 14px; height: 14px; }

.sc-input {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  user-select: text;
}
.sc-input:focus { border-color: var(--secondary); }
.sc-input::placeholder { color: var(--tertiary); }
textarea.sc-input { resize: vertical; min-height: 100px; }

/* switch */
.switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex: 0 0 auto;
}
.switch input { display: none; }
.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--row-selected);
  border: 1px solid var(--border);
  transition: background 0.2s;
}
.switch .thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--secondary);
  transition: left 0.2s, background 0.2s;
}
.switch input:checked + .track { background: var(--button-bg); }
.switch input:checked + .track .thumb { left: 20px; background: var(--button-fg); }

/* theme cards */
.theme-cards { display: flex; gap: 16px; }
.theme-card {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s;
}
.theme-card.selected { border-color: var(--secondary); }
.theme-card-preview {
  height: 80px;
  border-radius: 8px;
  margin-bottom: 8px;
}
.theme-card-label { font-size: 13px; font-weight: 600; }
.theme-card-desc { font-size: 11px; color: var(--secondary); }
.theme-card-radio {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: transparent;
}
.theme-card.selected .theme-card-radio { border-color: var(--text); }
.theme-card.selected .theme-card-radio::after {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: var(--text);
}

/* ui scale */
.scale-value { font-size: 24px; font-weight: 800; margin-bottom: 4px; }
.scale-row { display: flex; align-items: center; gap: 12px; }
input[type="range"].scale-range {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--row-selected);
  outline: none;
}
input[type="range"].scale-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
}

/* language list */
.lang-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  font-size: 13px;
  text-align: left;
  transition: background 0.1s;
}
.lang-row:hover { background: var(--row-hover); }
.lang-row svg { width: 20px; height: 20px; color: var(--secondary); flex: 0 0 auto; }
.lang-code { font-weight: 700; width: 34px; flex: 0 0 auto; }
.lang-name { color: var(--secondary); }
.lang-check { margin-left: auto; color: var(--text); }
.lang-check svg { width: 16px; height: 16px; color: var(--text); }

/* profile card */
.profile-card { margin-bottom: 24px; }
.profile-banner {
  height: 120px;
  border-radius: 12px 12px 0 0;
  background: linear-gradient(135deg, var(--surface-highest), var(--surface));
  position: relative;
  background-size: cover;
  background-position: center;
}
.profile-banner.clickable { cursor: pointer; }
.profile-banner-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  opacity: 0;
  transition: opacity 0.15s;
  background: rgba(0, 0, 0, 0.28);
}
.profile-banner:hover .profile-banner-hint { opacity: 1; }
.profile-banner:has(.profile-avatar:hover) .profile-banner-hint { opacity: 0; }
.profile-banner-hint svg { width: 18px; height: 18px; }
.profile-avatar {
  position: absolute;
  bottom: -48px;
  left: 50%;
  transform: translateX(-50%);
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--surface-highest);
  border: 4px solid var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 700;
  overflow: visible;
}
.profile-avatar.clickable { cursor: pointer; }
.profile-avatar::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  opacity: 0;
  transition: opacity 0.15s;
}
.profile-avatar.clickable:hover::after { opacity: 1; }
.profile-avatar-hint {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  background: rgba(0, 0, 0, 0.28);
  font-size: 11px;
  line-height: 1.1;
  text-align: center;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 3;
}
.profile-avatar.clickable:hover .profile-avatar-hint { opacity: 1; }
.profile-avatar-hint svg { width: 18px; height: 18px; }
.profile-info { text-align: center; padding: 56px 0 16px 0; }
.profile-name { font-size: 16px; font-weight: 700; }
.profile-username { font-size: 13px; color: var(--secondary); }

/* crop dialog */
.crop-overlay {
  position: fixed;
  inset: 0;
  z-index: 1550;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}
.crop-dialog {
  background: var(--surface);
  border: 1px solid var(--border, rgba(212, 212, 212, 0.15));
  border-radius: 16px;
  padding: 18px 20px 20px 20px;
  width: min(640px, calc(100vw - 48px));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.crop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.crop-title { font-size: 17px; font-weight: 700; }
.crop-close {
  background: transparent;
  border: none;
  color: var(--secondary);
  cursor: pointer;
  padding: 4px;
}
.crop-close svg { width: 18px; height: 18px; }
.crop-subtitle { font-size: 12px; color: var(--secondary); }
.crop-stage {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  background: #000;
  touch-action: none;
}
.crop-stage.round { border-radius: 50%; }
.crop-canvas { display: block; width: 100%; height: auto; }
.crop-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.55);
}
.crop-stage.round .crop-mask { border-radius: 50%; }
.crop-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.crop-btn {
  padding: 9px 20px;
  border-radius: 10px;
  border: 1px solid var(--border, rgba(212, 212, 212, 0.2));
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
}
.crop-btn.primary {
  background: var(--button-bg);
  border-color: transparent;
  color: var(--button-fg);
}
.crop-btn.primary:hover { filter: brightness(1.1); }

/* usage card (ai page) */
.usage-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}
.usage-card-left { display: flex; flex-direction: column; align-items: center; gap: 10px; flex: 0 0 auto; }
.usage-card-title { font-size: 15px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.usage-card-title img { width: 28px; height: 28px; }

/* shortcuts */
.key-chip {
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--row-hover);
  font-size: 12px;
  font-weight: 600;
  flex: 0 0 auto;
}
.shortcut-label { font-size: 13px; }
.shortcut-desc { font-size: 12px; color: var(--secondary); }

/* status dot */
.status-row { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text); flex: 0 0 auto; }

/* ============ Context menu ============ */

.context-menu {
  position: fixed;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  z-index: 1300;
  animation: pop-in 0.1s ease-out;
}
.cm-title {
  padding: 6px 10px 2px 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--tertiary);
}
.cm-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  text-align: left;
  transition: background 0.1s;
}
.cm-item:hover { background: var(--row-hover); }
.cm-item svg { width: 14px; height: 14px; color: var(--secondary); flex: 0 0 auto; }

/* ============ Dialog / Toast ============ */

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  opacity: 0.75;
  z-index: 1400;
}
.dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  z-index: 1410;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: pop-in 0.15s ease-out;
}
.dialog-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.dialog-text { font-size: 13px; color: var(--secondary); margin-bottom: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-btn {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s;
}
.dialog-btn:hover { background: var(--row-hover); }
.dialog-btn.primary {
  background: var(--button-bg);
  color: var(--button-fg);
}
.dialog-btn.primary:hover { opacity: 0.9; }
.dialog-btn.danger { color: var(--danger); }
.dialog-btn.primary.danger { color: var(--danger-strong); }

.dialog-input-label { font-size: 11px; font-weight: 600; color: var(--secondary); margin: 10px 0 4px 0; text-transform: uppercase; letter-spacing: 0.5px; }

.search-panel { width: min(560px, calc(100vw - 32px)); }
.search-panel .model-list { max-height: 480px; }
.search-input-wrap { padding: 12px 16px 0; }

.search-results {
  display: flex;
  flex-direction: column;
}
.search-result {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 10px 16px;
  text-align: left;
  transition: background 0.1s;
}
.search-result:hover { background: var(--row-hover); }
.search-result-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-sub {
  font-size: 11px;
  color: var(--tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-results-empty {
  padding: 14px 16px;
  font-size: 12px;
  color: var(--tertiary);
  text-align: center;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  text-align: center;
  background: var(--surface-highest);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13px;
  z-index: 1500;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

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

.burger-btn {
  display: none;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text);
}
.burger-btn svg { width: 18px; height: 18px; }
.burger-btn:hover { background: var(--row-hover); }

.sb-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 899;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

/* Планшеты */
@media (max-width: 1024px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
  .gallery-grid-wrap { padding: 20px 24px 28px 24px; }
.auth-panel {
    width: 100%;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
    padding: 64px 28px 32px 28px;
  }
}

/* Мобильные устройства */
@media (max-width: 767px) {
  .burger-btn { display: flex; }

  .sb-scrim { display: block; }
  .sb-scrim.visible { opacity: 1; pointer-events: auto; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 84vw);
    flex: none;
    z-index: 900;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
  }
  .sidebar.open { transform: translateX(0); }

  .chat-header { padding: 12px 14px 4px 14px; }
  .gallery-head { padding: 14px 14px 0 14px; }

  .chat-messages {
    padding: 10px 14px 8px 14px;
    gap: 10px;
  }
  .chat-page.empty .chat-messages { padding: 0 24px; }
  .chat-page.empty .placeholder-phrase { font-size: 22px; }

  .msg-wrap { max-width: 100%; }
  .msg-bubble { max-width: 90vw; overflow-wrap: break-word; }
  .msg-bubble.overflow { max-height: calc(16px * 1.55 * 6); }

  .composer-pin { padding: 10px 12px 12px 12px; }
  .composer-actions { gap: 4px; padding: 8px 8px 10px 8px; }
  .attach-btn { width: 38px; height: 38px; }
  .send-btn { width: 38px; height: 38px; }
  .model-selector { padding: 7px 8px; }

  .chat-item .ci-actions { display: flex; }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
  }
  .gallery-grid-wrap { padding: 16px 12px 24px 12px; }

  .auth-panel {
    width: 100%;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
    padding: 64px 20px 28px 20px;
  }
.auth-title { font-size: 22px; margin-bottom: 28px; }
  .auth-title-lg { font-size: 26px; }
  .auth-title-big { font-size: 24px; }
  .auth-code-box { font-size: 18px; }
  .auth-method svg { width: 20px; height: 20px; }
  .auth-input { max-width: none; }
  .auth-methods { max-width: none; }
  .auth-legal { max-width: none; }
  .auth-dash-input { width: 100%; }

  .model-panel {
    top: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    transform: none;
    border-radius: 14px;
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
  }
  .model-title { display: none; }
  .model-tabs {
    display: flex;
    gap: 8px;
    padding: 0;
  }
  .model-body { flex-direction: column; gap: 0; padding: 12px 16px 16px; }
  .model-models { border-left: none; border-top: none; padding-left: 0; padding-top: 0; }
  .model-limits, .model-models { display: none; }
  .model-limits.active, .model-models.active { display: flex; }
  .model-section-title { display: none; }
  .model-list { max-height: 38vh; }

  .settings-dialog {
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: auto;
    height: auto;
    max-width: none;
    border-radius: 0;
    transform: none;
  }
  .settings-dialog.mobile .settings-back { display: flex; }
  .settings-dialog.mobile.menu .settings-back {
    visibility: hidden;
    pointer-events: none;
  }
  .settings-dialog.mobile .settings-body { flex-direction: column; }
  .settings-dialog.mobile .settings-sidebar {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow-y: auto;
    padding: 8px;
    gap: 2px;
  }
  .settings-dialog.mobile .ss-item {
    flex: 0 0 auto;
    width: 100%;
    white-space: nowrap;
    padding: 12px;
  }
  .settings-dialog.mobile.menu .settings-content { display: none; }
  .settings-dialog.mobile.page .settings-sidebar { display: none; }
  .settings-dialog.mobile .settings-content {
    padding: 16px;
    transition: transform 0.25s ease;
  }
  .settings-dialog.mobile .settings-content.dragging { transition: none; }


  .purchase-dialog {
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: auto;
    height: auto;
    border-radius: 0;
    transform: none;
  }

  .theme-cards { gap: 10px; }
  .theme-card { min-width: 0; }

  .usage-card { padding: 12px; gap: 12px; }

  .sc-input { font-size: 16px; }

  .toast { bottom: 16px; }

.preview-close { top: 8px; right: 10px; }

  .preview-nav.prev { left: 8px; }
  .preview-nav.next { right: 8px; }
}

/* Сенсорные устройства: элементы, видимые только при наведении */
@media (hover: none) {
  .msg-actions { opacity: 1; }
  .msg-markdown pre .copy-btn { opacity: 1; }
  .gallery-tile-delete { opacity: 1; }
  .profile-banner-hint { opacity: 0.6; }
  .profile-avatar-hint {
    opacity: 1;
    font-size: 10px;
    gap: 3px;
  }
}


/* ===== ��������� ����������� ===== */
.attach-btn.active {
  background: var(--button-bg);
  color: var(--button-fg);
}

.img-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 10px 14px 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 13px;
  color: var(--secondary);
  animation: pop-in 0.15s ease-out;
}
.img-chip button {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--button-bg);
  color: var(--button-fg);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.img-chip svg { width: 16px; height: 16px; flex: 0 0 auto; }
.img-chip button svg { width: 14px; height: 14px; }

.msg-photos {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 6px;
  margin-top: 8px;
  width: min(420px, 100%);
}
.msg-photo {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #000;
  cursor: zoom-in;
}
.message.user .msg-wrap { align-items: flex-end; }
.message.user .msg-photos { margin-left: auto; }

.img-generating {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
}
.img-gen-rect {
  width: 260px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  background: var(--surface-highest);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.img-gen-rect::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, var(--surface-raised, rgba(255,255,255,0.08)) 50%, transparent 80%);
  background-size: 200% 100%;
  animation: img-shimmer 1.3s linear infinite;
}
.img-gen-label {
  color: var(--secondary);
  font-size: 13px;
}
.img-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--button-bg);
  animation: img-spin 0.8s linear infinite;
  flex: 0 0 auto;
  position: relative;
  z-index: 1;
}
@keyframes img-spin { to { transform: rotate(360deg); } }
@keyframes img-shimmer { to { background-position: -200% 0; } }

/* ============ Blaze AI page redesign ============ */

.ai-hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, var(--surface), var(--surface-highest, var(--surface)));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 8px;
}
.ai-hero::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--plan-accent, var(--button-bg)), transparent);
  opacity: 0.9;
}
.ai-hero .plan-badge {
  color: var(--plan-accent, var(--text));
  background: color-mix(in srgb, var(--plan-accent, var(--text)) 16%, transparent);
}
.ai-hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.ai-hero-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 800;
}
.ai-hero-badge svg { width: 22px; height: 22px; color: var(--button-bg, var(--text)); }
.ai-usage {
  display: flex;
  align-items: center;
  gap: 18px;
}
.ai-usage .gauge { width: 96px; height: 96px; flex: 0 0 auto; }
.ai-usage .gauge svg { width: 96px; height: 96px; }
.ai-usage .gauge-label { font-size: 16px; font-weight: 800; }
.ai-usage .gauge-fill { filter: drop-shadow(0 0 5px color-mix(in srgb, var(--plan-accent, #888) 40%, transparent)); }
.ai-usage-stats {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.ai-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.ai-stat-val { font-size: 15px; font-weight: 700; color: var(--text); }
.ai-stat-label { font-size: 12px; color: var(--secondary); }
.ai-usage-foot {
  margin-top: 14px;
  font-size: 12px;
  color: var(--secondary);
}
.ai-sub {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.model-list { padding: 6px; }
.model-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
.model-card:hover { background: var(--row-hover); transform: translateY(-1px); }
.model-card.selected {
  background: var(--row-selected);
  box-shadow: inset 3px 0 0 var(--plan-accent, var(--button-bg));
}
.model-card .sc-row-icon { flex: 0 0 auto; }
.model-mult {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary);
}
.model-check {
  display: flex;
  align-items: center;
  color: var(--plan-accent, var(--button-bg, var(--text)));
}
.model-check svg { width: 18px; height: 18px; }

/* ===== Subscription card ===== */
.sub-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}
.sub-card.free { border-style: dashed; }
.sub-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sub-plan-badge { font-size: 20px; font-weight: 800; letter-spacing: 0.5px; }
.sub-status {
  font-size: 12px;
  color: var(--secondary);
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--row-hover);
}
.sub-status.active { color: var(--plan-accent, var(--button-bg)); background: color-mix(in srgb, var(--plan-accent, var(--button-bg)) 16%, transparent); }
.sub-card-desc {
  font-size: 13px;
  color: var(--secondary);
  margin-bottom: 14px;
  line-height: 1.4;
}
.sub-card-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.sub-card-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}
.sub-card-row span { color: var(--secondary); }
.sub-card-row b { font-weight: 600; color: var(--text); }
.sub-card-actions { display: flex; gap: 8px; margin-bottom: 14px; }
.sub-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--row-hover);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s ease, background 0.15s ease;
}
.sub-btn svg { width: 16px; height: 16px; }
.sub-btn:hover { background: var(--row-selected); }
.sub-btn.primary {
  background: var(--button-bg, var(--text));
  color: var(--button-text, #fff);
  border-color: transparent;
}
.sub-btn.primary:hover { filter: brightness(1.08); }
.sub-btn.danger {
  width: 100%;
  flex: none;
  color: var(--danger, #ff5a5a);
  background: transparent;
  border-color: var(--danger-border, rgba(255, 90, 90, 0.4));
  margin-top: 4px;
}
.sub-btn.danger:hover { background: rgba(255, 90, 90, 0.08); }
.sub-renew {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.sub-renew-text { min-width: 0; }
.sub-renew-title { font-size: 13px; font-weight: 600; }
.sub-renew-desc { font-size: 11px; color: var(--secondary); margin-top: 2px; }
.sub-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .2px;
  line-height: 1;
}
.sub-chip svg { width: 12px; height: 12px; }
.sub-chip.ok { background: rgba(67,160,71,.14); color: var(--success); }
.sub-chip.warn { background: rgba(212,212,212,.08); color: var(--text-secondary); cursor: pointer; border: 1px solid var(--border-strong); }
.sub-chip.warn:hover { background: var(--hover); color: var(--text-primary); }

.msg-action.spinning svg { animation: msg-spin 1s linear infinite; }
@keyframes msg-spin { to { transform: rotate(360deg); } }
