/* ============================================================
   DeepSeek Web — тема оформления
   ============================================================ */

:root {
  --accent: #4d6bfe;
  --accent-hover: #3d5bf0;
  --accent-soft: rgba(77, 107, 254, 0.1);
  --accent-soft-2: rgba(77, 107, 254, 0.18);

  --bg: #ffffff;
  --bg-sidebar: #f9fafb;
  --bg-elevated: #ffffff;
  --bg-hover: #eff1f5;
  --bg-active: #e7eaf0;
  --bg-input: #ffffff;
  --bg-code: #f6f7f9;

  --text: #1f2328;
  --text-2: #5c6470;
  --text-3: #98a1ad;

  --border: #e6e8ec;
  --border-strong: #d6dae1;

  --user-bubble: #eff2ff;
  --user-bubble-text: #1f2328;

  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.1);
  --success: #30a46c;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.09);
  --shadow-lg: 0 24px 64px rgba(16, 24, 40, 0.18);

  --radius: 14px;
  --sidebar-w: 268px;
  --content-w: 780px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #212327;
  --bg-sidebar: #191a1c;
  --bg-elevated: #2a2c31;
  --bg-hover: #2b2e33;
  --bg-active: #34373d;
  --bg-input: #2a2c31;
  --bg-code: #191a1c;

  --text: #e9eaec;
  --text-2: #a2a8b3;
  --text-3: #71767f;

  --border: #34373d;
  --border-strong: #42464e;

  --user-bubble: #2f3441;
  --user-bubble-text: #e9eaec;

  --danger: #ff6369;
  --danger-soft: rgba(255, 99, 105, 0.14);
  --success: #3dd68c;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

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

button {
  cursor: pointer;
  background: none;
  border: 0;
}

a {
  color: var(--accent);
  text-decoration: none;
}

svg {
  display: block;
}

::selection {
  background: var(--accent-soft-2);
}

/* Скроллбары */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

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

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

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

/* ============================================================
   Каркас
   ============================================================ */

.app {
  display: flex;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--text-2);
  transition: background 0.15s ease, color 0.15s ease;
  flex: none;
}

.icon-btn svg {
  width: 19px;
  height: 19px;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

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

/* ============================================================
   Сайдбар
   ============================================================ */

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  transition: margin-left 0.22s ease, transform 0.22s ease;
  z-index: 40;
}

.app.collapsed .sidebar {
  margin-left: calc(var(--sidebar-w) * -1);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 14px 10px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  min-width: 0;
}

.brand-logo {
  width: 30px;
  height: 22px;
  flex: none;
}

.brand-name {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.sidebar-close {
  width: 32px;
  height: 32px;
}

.sidebar-close svg {
  width: 17px;
  height: 17px;
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 6px 12px 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.new-chat svg {
  width: 17px;
  height: 17px;
  color: var(--accent);
}

.new-chat span {
  flex: 1;
  text-align: left;
}

.new-chat kbd {
  font-family: var(--font);
  font-size: 10.5px;
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  background: var(--bg-sidebar);
}

.new-chat:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px 8px;
  padding: 0 10px;
  height: 34px;
  border-radius: 10px;
  background: var(--bg-hover);
  border: 1px solid transparent;
  transition: border-color 0.15s, background 0.15s;
}

.sidebar-search:focus-within {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

.sidebar-search svg {
  width: 15px;
  height: 15px;
  color: var(--text-3);
  flex: none;
}

.sidebar-search input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  outline: 0;
  font-size: 13px;
  color: var(--text);
}

.sidebar-search input::placeholder {
  color: var(--text-3);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.chat-group-label {
  padding: 12px 10px 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-3);
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 10px;
  border-radius: 10px;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
  position: relative;
}

.chat-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.chat-item.active {
  background: var(--bg-active);
  color: var(--text);
}

.chat-item > svg {
  width: 15px;
  height: 15px;
  flex: none;
  opacity: 0.6;
}

.chat-item .chat-title {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-delete-btn {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  opacity: 0;
  transition: opacity 0.14s, background 0.14s, color 0.14s;
  flex: none;
}

.chat-delete-btn svg {
  width: 14px;
  height: 14px;
}

.chat-item:hover .chat-delete-btn,
.chat-item.active .chat-delete-btn {
  opacity: 1;
}

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

.chat-empty {
  padding: 18px 12px;
  font-size: 12.5px;
  color: var(--text-3);
  text-align: center;
}

.sidebar-foot {
  padding: 8px 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-action {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text-2);
  font-size: 13.5px;
  transition: background 0.14s, color 0.14s;
  text-align: left;
}

.side-action svg {
  width: 17px;
  height: 17px;
  flex: none;
}

.side-action:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.side-note {
  padding: 8px 10px 0;
  font-size: 11px;
  color: var(--text-3);
}

.theme-icon-sun {
  display: none;
}

[data-theme="dark"] .theme-icon-sun {
  display: block;
}

[data-theme="dark"] .theme-icon-moon {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

/* ============================================================
   Основная область
   ============================================================ */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

.topbar {
  height: 56px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid transparent;
}

.only-mobile {
  display: none;
}

.app.collapsed .only-mobile {
  display: inline-flex;
}

.model-picker {
  position: relative;
}

.model-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 10px;
  color: var(--text);
  font-size: 14.5px;
  font-weight: 500;
  transition: background 0.15s;
}

.model-btn:hover {
  background: var(--bg-hover);
}

.model-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  flex: none;
}

.model-btn .chev {
  width: 15px;
  height: 15px;
  color: var(--text-3);
  transition: transform 0.18s;
}

.model-picker.open .chev {
  transform: rotate(180deg);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 2px;
}

/* ============================================================
   Лента чата
   ============================================================ */

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 20px 0;
}

.chat-scroll > .message,
.chat-scroll > .welcome {
  max-width: var(--content-w);
  margin-left: auto;
  margin-right: auto;
}

/* Приветствие */
.welcome {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 8px 24px;
  animation: fade-up 0.4s ease both;
}

.welcome-logo {
  width: 62px;
  height: 46px;
  margin-bottom: 18px;
}

.welcome h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin: 0 0 6px;
}

.welcome p {
  color: var(--text-2);
  font-size: 15px;
  margin: 0 0 30px;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 620px;
}

.prompt-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.45;
  transition: border-color 0.15s, background 0.15s, transform 0.15s, color 0.15s;
}

.prompt-card svg {
  width: 17px;
  height: 17px;
  flex: none;
  margin-top: 1px;
  color: var(--accent);
}

.prompt-card:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

/* Сообщения */
.message {
  display: flex;
  gap: 12px;
  padding: 16px 0;
  animation: fade-up 0.25s ease both;
  position: relative;
}

.message.user {
  justify-content: flex-end;
}

.message .avatar {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.message .avatar svg {
  width: 24px;
  height: 18px;
}

.message.user .avatar {
  display: none;
}

.message .message-bubble {
  min-width: 0;
  max-width: 100%;
}

.msg-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.message.user .msg-main {
  flex: 0 1 auto;
  align-items: flex-end;
  max-width: 78%;
}

.message.user .msg-actions {
  justify-content: flex-end;
}

.message.bot .msg-main {
  align-items: stretch;
}

.message.user .message-bubble {
  max-width: 100%;
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-radius: 18px;
  padding: 10px 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .message-bubble img {
  display: block;
  max-width: 100%;
  max-height: 240px;
  border-radius: 12px;
  object-fit: cover;
}

.message.bot .message-bubble {
  flex: 1;
  padding-top: 1px;
}

.message-content {
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.message-content > *:first-child {
  margin-top: 0;
}

.message-content > *:last-child {
  margin-bottom: 0;
}

/* Markdown */
.message-content p {
  margin: 0 0 12px;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
  margin: 22px 0 10px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.message-content h1 {
  font-size: 22px;
}

.message-content h2 {
  font-size: 19px;
}

.message-content h3 {
  font-size: 17px;
}

.message-content h4 {
  font-size: 15.5px;
}

.message-content ul,
.message-content ol {
  margin: 0 0 12px;
  padding-left: 24px;
}

.message-content li {
  margin: 4px 0;
}

.message-content li > p {
  margin: 0 0 4px;
}

.message-content blockquote {
  margin: 12px 0;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-2);
}

.message-content hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.message-content a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-content strong {
  font-weight: 600;
}

.message-content code {
  font-family: var(--mono);
  font-size: 0.87em;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
}

.message-content pre {
  margin: 12px 0;
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-code);
}

.code-block {
  margin: 12px 0;
}

.code-block pre {
  margin: 0;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top: 0;
}

.message-content pre code {
  display: block;
  padding: 14px 16px;
  overflow-x: auto;
  background: none;
  border: 0;
  border-radius: 0;
  font-size: 13px;
  line-height: 1.55;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-3);
  background: var(--bg-sidebar);
}

.code-head button {
  font-size: 11.5px;
  color: var(--text-2);
  padding: 2px 7px;
  border-radius: 6px;
}

.code-head button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13.5px;
}

.message-content th,
.message-content td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
}

.message-content th {
  background: var(--bg-sidebar);
  font-weight: 600;
}

/* Размышления */
.thinking-box {
  margin: 4px 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-sidebar);
  overflow: hidden;
}

.thinking-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  text-align: left;
}

.thinking-head svg {
  width: 15px;
  height: 15px;
  color: var(--accent);
  flex: none;
}

.thinking-head .chev {
  margin-left: auto;
  width: 14px;
  height: 14px;
  color: var(--text-3);
  transition: transform 0.2s;
}

.thinking-box.open .thinking-head .chev {
  transform: rotate(180deg);
}

.thinking-body {
  display: none;
  padding: 0 14px 12px;
  font-size: 13.5px;
  color: var(--text-2);
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.thinking-box.open .thinking-body {
  display: block;
  animation: fade-up 0.2s ease both;
}

.thinking-body > *:first-child {
  margin-top: 0;
}

.thinking-body > *:last-child {
  margin-bottom: 0;
}

.thinking-box.streaming .thinking-head .label::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.1s infinite;
}

/* Действия под сообщением */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.15s;
}

.message:hover .msg-actions,
.message:focus-within .msg-actions {
  opacity: 1;
}

.msg-actions button {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  transition: background 0.14s, color 0.14s;
}

.msg-actions button svg {
  width: 15px;
  height: 15px;
}

.msg-actions button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.msg-actions button.on {
  color: var(--accent);
}

.msg-actions .spacer {
  flex: 1;
}

.msg-meta {
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 6px;
}

.error-box {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
  cursor: pointer;
}

.error-box strong {
  font-weight: 600;
}

.error-box span {
  font-size: 12.5px;
  opacity: 0.85;
  word-break: break-word;
}

/* Индикатор набора */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  animation: bounce 1.2s infinite ease-in-out;
}

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

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

/* Кнопка вниз */
.scroll-btn {
  position: absolute;
  right: 24px;
  bottom: 130px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.18s, transform 0.18s;
  z-index: 15;
}

.scroll-btn svg {
  width: 17px;
  height: 17px;
}

.scroll-btn.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* ============================================================
   Поле ввода
   ============================================================ */

.composer-wrap {
  flex: none;
  width: 100%;
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 8px 20px 14px;
}

.composer {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  padding: 10px 12px 8px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s, box-shadow 0.18s;
}

.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

#user-input {
  display: block;
  width: 100%;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font-size: 15px;
  line-height: 1.55;
  max-height: 200px;
  padding: 4px 0 8px;
  color: var(--text);
}

#user-input::placeholder {
  color: var(--text-3);
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.toggles {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border-radius: 15px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  transition: all 0.15s;
}

.toggle svg {
  width: 15px;
  height: 15px;
}

.toggle:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.toggle.active {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}

.attach-btn {
  cursor: pointer;
}

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s, transform 0.15s, opacity 0.15s;
  flex: none;
}

.send-btn svg {
  width: 18px;
  height: 18px;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.send-btn:disabled {
  background: var(--bg-active);
  color: var(--text-3);
  cursor: not-allowed;
}

.send-btn.stop {
  background: var(--text);
  color: var(--bg);
}

.attach-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 0 0 8px;
}

.attach-preview.show {
  display: flex;
}

.attach-preview img {
  height: 56px;
  max-width: 120px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.attach-preview button {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-hover);
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.attach-preview button svg {
  width: 14px;
  height: 14px;
}

.attach-preview button:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.composer-note {
  margin: 8px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-3);
}

/* ============================================================
   Выпадающее меню моделей
   ============================================================ */

.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 270px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  z-index: 60;
}

.model-picker.open .dropdown {
  display: block;
  animation: fade-up 0.16s ease both;
}

.model-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  text-align: left;
  transition: background 0.14s;
}

.model-option:hover {
  background: var(--bg-hover);
}

.model-option.active {
  background: var(--accent-soft);
}

.model-option .mo-text {
  flex: 1;
  min-width: 0;
}

.model-option .mo-name {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
}

.model-option .mo-desc {
  display: block;
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 1px;
}

.model-option .mo-check {
  width: 16px;
  height: 16px;
  color: var(--accent);
  opacity: 0;
  flex: none;
  margin-top: 2px;
}

.model-option.active .mo-check {
  opacity: 1;
}

/* ============================================================
   Модальное окно настроек
   ============================================================ */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.45);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: min(88dvh, 780px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  animation: pop 0.2s ease both;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 14px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal-body {
  padding: 6px 22px 20px;
  overflow-y: auto;
}

.settings-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-child {
  border-bottom: 0;
  padding-bottom: 4px;
}

.settings-section h3 {
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
}

.field {
  margin-bottom: 16px;
}

.field:last-child {
  margin-bottom: 0;
}

.field > label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 7px;
  color: var(--text);
}

.field .value {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 1px 7px;
}

.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13.5px;
  outline: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field textarea {
  resize: vertical;
  min-height: 84px;
  line-height: 1.5;
  font-family: var(--font);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 4px;
  background: var(--border-strong);
  outline: 0;
}

.field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-elevated);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.field input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid var(--bg-elevated);
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.hint {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--text-3);
  line-height: 1.45;
}

.field.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.field.row > div {
  flex: 1;
}

.field.row > div > label {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 11px;
}

.segmented button {
  flex: 1;
  padding: 7px 6px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}

.segmented button:hover {
  color: var(--text);
}

.segmented button.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex: none;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: var(--border-strong);
  transition: background 0.18s;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(18px);
}

.data-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-2);
}

.btn.ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
}

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

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

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: var(--bg-sidebar);
}

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

#ctx-menu {
  position: fixed;
  min-width: 190px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 5px;
  z-index: 120;
  animation: fade-up 0.13s ease both;
}

.ctx-label {
  padding: 6px 10px 5px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.13s, color 0.13s;
}

.ctx-item svg {
  width: 15px;
  height: 15px;
  flex: none;
}

.ctx-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.ctx-item.danger {
  color: var(--danger);
}

.ctx-item.danger:hover {
  background: var(--danger-soft);
}

.ctx-item.ok {
  color: var(--success);
}

.ctx-sep {
  height: 1px;
  background: var(--border);
  margin: 5px 4px;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 14px);
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  max-width: 90vw;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

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

@keyframes fade-up {
  from {
    transform: translateY(6px);
  }

  to {
    transform: translateY(0);
  }
}

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

  to {
    opacity: 1;
  }
}

@keyframes pop {
  from {
    transform: translateY(10px) scale(0.98);
  }

  to {
    transform: translateY(0) scale(1);
  }
}

@keyframes bounce {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }

  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@keyframes pulse {

  0%,
  100% {
    opacity: 0.25;
  }

  50% {
    opacity: 1;
  }
}

/* ============================================================
   Адаптив
   ============================================================ */

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    margin-left: 0;
  }

  .app.collapsed .sidebar {
    margin-left: 0;
  }

  .app.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .app.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 16, 0.4);
    z-index: 35;
    animation: fade-in 0.18s ease both;
  }

  .only-mobile,
  .app.collapsed .only-mobile {
    display: inline-flex;
  }

  .sidebar-close {
    display: none;
  }

  .topbar {
    height: 52px;
  }

  .chat-scroll {
    padding: 4px 14px 0;
  }

  .composer-wrap {
    padding: 6px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .composer {
    border-radius: 18px;
    padding: 8px 10px 7px 14px;
  }

  .message.user .msg-main {
    max-width: 88%;
  }

  .scroll-btn {
    right: 16px;
    bottom: 122px;
  }

  .prompt-grid {
    grid-template-columns: 1fr;
  }

  .welcome h1 {
    font-size: 24px;
  }

  .welcome-logo {
    width: 54px;
    height: 40px;
  }

  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal-card {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
    animation: slide-up 0.22s ease both;
  }
}

@media (max-width: 520px) {
  .toggle span {
    display: none;
  }

  .toggle {
    padding: 0 9px;
  }

  .model-btn {
    font-size: 13.5px;
    padding: 6px 8px;
  }

  .new-chat kbd {
    display: none;
  }

  .welcome {
    padding-top: 24px;
  }
}

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

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
