.ai-studio {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.ai-studio-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0px;
    flex-wrap: wrap;
    padding-bottom: 0.2rem;
    border-bottom: 1px solid var(--color-border-light);
}
.media-type-tabs {
  margin: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 5px 0px;
  border: none;
  background: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.2s;
  color: #444;
}

.tab-btn:hover {
  background: #eef3f7;
}

.tab-btn.active {
  background: var(--mt-blue-2);
  color: #194e60;
  border-color: var(--color-border-accent);
}

.model-selector {
  min-width: 0;
  flex: 1 1 0;
}

.model-selector select {
    width: -webkit-fill-available !important;
	max-width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 12px !important;
    padding: 14px 14px !important;
    margin: 0px!important;
    border-radius: 14px !important;
    border: 1px solid var(--line) !important;
    background: #f6f7f9 !important;
    color: #2c3a4a !important;
    cursor: pointer !important;
}

.ai-studio-main {
  display: flex;
  gap: 20px;
  flex: 1;
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--color-bg-alt);
  border-radius: 14px;
  border: 1px solid #e0eaf3;
  overflow: hidden;
  min-width: 0;
}

#chat-messages .msg-row .msg {
  max-width: min(680px, 100%);
  min-width: 0;
}

#chat-messages .msg-row .bubble,
#chat-messages .msg-row .plain {
  max-width: 100%;
  min-width: 0;
}

#chat-messages .msg-row pre {
  max-width: 100%;
  overflow-x: auto;
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.chat-message {
  max-width: min(80%, 100%);
  min-width: 0;
  padding: 12px 16px;
  border-radius: 12px;
  animation: fadeIn 0.3s ease;
  overflow-wrap: break-word;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
  align-self: flex-end;
  background: var(--mt-blue-2);
  color: #194e60;
}

.chat-message.bot {
  align-self: flex-start;
  background: transparent;
  color: #343f49;
  border: none;
}

/* Не трогаем <strong> внутри Markdown у ассистента — иначе весь жирный текст ломается в колонку */

.chat-message.loading .loading-status {
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0.9;
  font-weight: 500;
}

.chat-message.loading .loading-spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(108, 92, 231, 0.18);
  border-top-color: var(--accent-color, #6c5ce7);
  border-radius: 50%;
  flex: 0 0 auto;
  animation: loading-spin 0.9s linear infinite;
}

@keyframes loading-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.chat-message.loading .loading-heading {
  letter-spacing: 0.01em;
}

.chat-message.loading .loading-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.chat-message.loading .loading-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-color, #6c5ce7);
  opacity: 0.2;
  animation: dot-wave 1.4s ease-in-out infinite;
}

.chat-message.loading .loading-dot:nth-child(1) { animation-delay: 0s; }
.chat-message.loading .loading-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-message.loading .loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-wave {
  0%, 60%, 100% { opacity: 0.2; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

.chat-message.loading .loading-timer {
  font-variant-numeric: tabular-nums;
  opacity: 0.5;
  font-size: 11px;
  margin-top: 5px;
}

.chat-message.loading p {
  opacity: 0.6;
}

.chat-message img {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 10px;
}

.chat-message audio,
.chat-message video {
  max-width: 100%;
  margin-top: 10px;
}

/* Markdown / emoji: ответы ассистента (как в ChatGPT) */
#chat-messages .chat-md {
  font-size: 15px;
  line-height: 1.55;
  color: inherit;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
  min-width: 0;
  font-family: inherit, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
    "Noto Color Emoji", sans-serif;
}

#chat-messages .chat-md > *:first-child {
  margin-top: 0;
}

#chat-messages .chat-md > *:last-child {
  margin-bottom: 0;
}

#chat-messages .chat-md h1,
#chat-messages .chat-md h2,
#chat-messages .chat-md h3,
#chat-messages .chat-md h4 {
  font-weight: 600;
  line-height: 1.3;
  margin: 1.1em 0 0.45em;
  color: #1a2836;
}

#chat-messages .chat-md h1 { font-size: 1.35rem; }
#chat-messages .chat-md h2 { font-size: 1.2rem; }
#chat-messages .chat-md h3 { font-size: 1.08rem; }
#chat-messages .chat-md h4 { font-size: 1rem; }

#chat-messages .chat-md p {
  margin: 0.55em 0;
}

#chat-messages .chat-md ul,
#chat-messages .chat-md ol {
  margin: 0.55em 0;
  padding-left: 1.35em;
}

#chat-messages .chat-md ul {
  list-style: disc;
}

#chat-messages .chat-md ol {
  list-style: decimal;
}

#chat-messages .chat-md li {
  margin: 0.25em 0;
}

#chat-messages .chat-md blockquote {
  margin: 0.65em 0;
  padding: 0.35em 0 0.35em 0.85em;
  border-left: 3px solid #c5d6e3;
  color: #4a5a6a;
  background: rgba(232, 244, 248, 0.45);
  border-radius: 0 8px 8px 0;
}

#chat-messages .chat-md hr {
  border: none;
  border-top: 1px solid #e0eaf3;
  margin: 1em 0;
}

#chat-messages .chat-md a {
  color: #0d6efd;
  text-decoration: none;
}

#chat-messages .chat-md a:hover {
  text-decoration: underline;
}

#chat-messages .chat-md :not(pre) > code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 0.9em;
  background: #f0f4f8;
  border: 1px solid #dce6ef;
  padding: 0.12em 0.45em;
  border-radius: 6px;
  color: #1e3a4c;
}

#chat-messages .chat-md pre {
  position: relative;
  margin: 0.75em 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid #dce6ef;
  background: #f7fafc;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
  box-sizing: border-box;
}

#chat-messages .chat-md pre::-webkit-scrollbar {
  height: 6px;
}

#chat-messages .chat-md pre::-webkit-scrollbar-thumb {
  background: #c5d6e3;
  border-radius: 3px;
}

#chat-messages .chat-md pre code.hljs,
#chat-messages .chat-md pre > code {
  display: block;
  padding: 12px 14px 12px calc(14px + 2.6rem);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
  min-width: min-content;
  overflow-x: auto;
  background: transparent;
}

#chat-messages .chat-md .line-numbers-rows {
  position: absolute;
  top: 12px;
  left: 0;
  bottom: 12px;
  width: auto;
  min-width: 2.25rem;
  padding: 0 8px;
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #8a9bab;
  user-select: none;
  pointer-events: none;
  background: #eef3f8;
  border-right: 1px solid #dce6ef;
}

#chat-messages .chat-md .line-numbers-rows span {
  display: block;
}

#chat-messages .chat-md .code-toolbar {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
}

#chat-messages .chat-md .code-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid #dce6ef;
  background: #fff;
  color: #4b6076;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

#chat-messages .chat-md .code-btn:hover {
  background: #f3f7fb;
  color: #213447;
}

#chat-messages .chat-md table {
  border-collapse: collapse;
  margin: 0.75em 0;
  font-size: 0.95em;
  max-width: 100%;
  display: block;
  overflow-x: auto;
}

#chat-messages .chat-md th,
#chat-messages .chat-md td {
  border: 1px solid #dce6ef;
  padding: 6px 10px;
  text-align: left;
}

#chat-messages .chat-md th {
  background: #eef3f8;
  font-weight: 600;
}

.chat-input-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: white;
  border-top: 1px solid #e0eaf3;
  padding: 16px 20px;
}

.chat-textarea {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  color: #343f49;
  resize: none;
  padding: 0;
}

.chat-textarea:focus {
  outline: none;
}

.chat-input-buttons {
  display: flex;
  align-items: center;
  gap: 12px;
}

.button-ui.attach {
  width: 40px;
  height: 40px;
  border: 1px solid var(--color-border-mid);
  background: #f7f9fb;
  border-radius: var(--radius);
  font-size: 20px;
  color: #cbd4de;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.button-ui.attach:hover {
  color: #444;
  background: #eef3f7;
}

.settings-dashboard {
  width: 270px;
  background: white;
  border-radius: 14px;
  border: 1px solid #e0eaf3;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.settings-header {
}

.settings-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #343f49;
}

.settings-content {
  flex: 1;
  overflow-y: auto;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-section .no-settings {
  font-size: 14px;
  color: var(--color-text-muted);
  text-align: center;
  padding: 20px 0;
}

.parameter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.parameter-label-container {
  display: flex;
  align-items: center;
  gap: 6px;
}

.parameter-group label {
  font-size: 13px !important;
  font-weight: 500 !important;
  color: #2c3a4a !important;
  flex: 1;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
  line-height: 1.3;
}

.parameter-group label.required::after {
  content: ' *';
  color: #e74c3c;
}

.parameter-help-icon {
    width: 18px !important;
    height: 18px !important;
    border-radius: 50% !important;
    border: 1px solid var(--field-line) !important;
    background: #f5fbff !important;
    color: #5a7e9c !important;
    display: inline-grid !important;
    place-items: center !important;
    font-size: 12px !important; 
    line-height: 1 !important; 
    cursor: help !important; 
    position: relative !important;
    padding: 0 !important;
}



.parameter-tooltip {
  position: fixed;
  z-index: 1000;
  background: #2c3e50;
  color: white;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 260px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: tooltipFadeIn 0.2s ease;
  line-height: 1.4;
  pointer-events: none;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.parameter-input {
    border-radius: 10px !important;
    border: 1px solid var(--field-line) !important;
    background: var(--field) !important;
    padding: 10px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    color: #2c3a4a !important;
    cursor: pointer !important;
}

.parameter-input:focus {
  outline: none;
  border-color: var(--color-border-accent);
}

.parameter-input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.settings-divider {
  margin: 16px 0;
}

.collapsible-toggle {
    padding: 18px 16px;
    border-bottom: 1px solid var(--line);
    color: #2c7387;
    font-size: 16px;
    letter-spacing: .2px;
    position: relative;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    text-align: left;
}

.collapsible-toggle:hover {

}

.toggle-icon {
  font-size: 12px;
  transition: transform 0.2s;
}

.additional-section {
  overflow-y: auto;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  padding: 18px 16px 16px;
  opacity: 1;
}

.additional-section.collapsed {
  max-height: 0;
  padding-top: 0;
  opacity: 0;
  overflow: hidden;
}

@media (max-width: 1024px) {
  .ai-studio-main {
    flex-direction: column;
  }
  
  .chat-area {
    min-height: 400px;
  }
  
  .settings-dashboard {
    width: 100%;
    max-height: 350px;
  }
}

@media (max-width: 768px) {
  .ai-studio-header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .media-type-tabs {
    overflow-x: auto;
    padding-bottom: 5px;
  }
  
  .tab-btn {
    white-space: nowrap;
  }
  
  .chat-message {
    max-width: 95%;
  }
}

[data-theme="dark"] .ai-studio {
  --color-bg-input: #2a2a2a;
  --color-bg-alt: #1a1a1a;
}

[data-theme="dark"] .chat-messages {
  background: #1a1a1a;
}

[data-theme="dark"] .chat-message.bot {
  background: transparent;
  color: #e0e0e0;
}

[data-theme="dark"] #chat-messages .chat-md h1,
[data-theme="dark"] #chat-messages .chat-md h2,
[data-theme="dark"] #chat-messages .chat-md h3,
[data-theme="dark"] #chat-messages .chat-md h4 {
  color: #e8eef4;
}

[data-theme="dark"] #chat-messages .chat-md blockquote {
  border-left-color: #4a5f73;
  color: #b8c5d0;
  background: rgba(40, 50, 60, 0.5);
}

[data-theme="dark"] #chat-messages .chat-md :not(pre) > code {
  background: #2a3340;
  border-color: #3d4d5c;
  color: #d0dce6;
}

[data-theme="dark"] #chat-messages .chat-md pre {
  border-color: #3d4d5c;
  background: #222a33;
}

[data-theme="dark"] #chat-messages .chat-md .line-numbers-rows {
  background: #1e262e;
  border-right-color: #3d4d5c;
  color: #7a8b9a;
}

[data-theme="dark"] #chat-messages .chat-md th,
[data-theme="dark"] #chat-messages .chat-md td {
  border-color: #3d4d5c;
}

[data-theme="dark"] #chat-messages .chat-md th {
  background: #2a3340;
}

[data-theme="dark"] #chat-messages .chat-md a {
  color: #6eb6ff;
}

[data-theme="dark"] .chat-message.user {
  background: #3a4a5a;
  color: #e0e0e0;
}

[data-theme="dark"] .chat-input-area {
  background: #2a2a2a;
  border-top-color: #444;
}

[data-theme="dark"] .chat-textarea {
  color: #e0e0e0;
}

[data-theme="dark"] .settings-dashboard {
  background: #1a1a1a;
  border-color: #444;
}

[data-theme="dark"] .settings-header {
}

[data-theme="dark"] .settings-header h3 {
  color: #e0e0e0;
}

[data-theme="dark"] .parameter-group label {
  color: #e0e0e0;
}

[data-theme="dark"] .parameter-input {
  background: #2a2a2a;
  border-color: #555;
  color: #e0e0e0;
}

[data-theme="dark"] .collapsible-toggle {
  background: #2a2a2a;
  border-color: #555;
  color: #e0e0e0;
}

[data-theme="dark"] .collapsible-toggle:hover {
  background: #3a3a3a;
}

.error-container {
  /* padding: 12px 16px; */
  margin-top: 0;
}

.error-message {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  color: #991b1b;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.error-message.fade-out {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.auth-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: #e8f5e9;
  border: 1px solid #a5d6a7;
  border-radius: 14px;
  color: #2e7d32;
  text-align: center;
  font-size: 14px;
  line-height: 1.4;
  animation: slideIn 0.3s ease;
  position: relative;
}

.auth-prompt-buttons {
  display: flex;
  gap: 10px;
}

.auth-prompt-btn {
  padding: 8px 20px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.auth-prompt-login {
  background: #2e7d32;
  color: #fff;
}

.auth-prompt-login:hover {
  background: #1b5e20;
}

.auth-prompt-register {
  background: #fff;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}

.auth-prompt-register:hover {
  background: #f1f8e9;
}

.auth-prompt-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 18px;
  color: #2e7d32;
  cursor: pointer;
  line-height: 1;
}

.error-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.error-text {
  flex: 1;
  font-size: 14px;
}

.error-close {
  flex-shrink: 0;
  background: transparent;
  border: none;
  font-size: 18px;
  color: #991b1b;
  cursor: pointer;
  padding: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.error-close:hover {
  background: rgba(153, 27, 27, 0.1);
}

[data-theme="dark"] .error-message {
  background: #5c1a1a;
  border-color: #7c2d2d;
  color: #fca5a5;
}

[data-theme="dark"] .error-close {
  color: #fca5a5;
}

[data-theme="dark"] .error-close:hover {
  background: rgba(252, 165, 165, 0.1);
}

[data-theme="dark"] .parameter-help-icon {
  background: #3a4a5a;
  border-color: #555;
  color: #b8c8d8;
}

[data-theme="dark"] .parameter-help-icon:hover {
  background: #4a5a6a;
  color: #e0e0e0;
}

[data-theme="dark"] .parameter-tooltip {
  background: #4a5a6a;
  color: #e0e0e0;
}


.chat-input-buttons { display: flex; align-items: center; gap: 10px; }
.composer-spacer { flex: 1; }
.chat-textarea { width: 100%; resize: none; overflow: hidden; }

/* ==========================================================================
   AI Studio: Model selector (<select id="model-select">)
   ========================================================================== */

.ai-studio .settings-header .model-selector{
  position: relative;
  width: 100%;
}

/* Сам селект (закрытое состояние) */
.ai-studio .settings-header .model-selector select#model-select,
.ai-studio .settings-header .model-selector select.form-input-small{
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;

  width: 100%;
  min-width: 0;
  height: 46px;

  padding: 12px 44px 12px 14px;
  border-radius: 14px;

  border: 1px solid var(--field-line);
  background: var(--field);
  color: var(--ink);

  font: 500 14px/1.2 var(--font-base);
  outline: none;
  box-shadow: none;

  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

.ai-studio .settings-header .model-selector select#model-select:hover,
.ai-studio .settings-header .model-selector select.form-input-small:hover{
  border-color: var(--line-2);
  background: #fff;
}

.ai-studio .settings-header .model-selector select#model-select:focus,
.ai-studio .settings-header .model-selector select.form-input-small:focus{
  border-color: rgba(28,136,199,.55);
  box-shadow: 0 0 0 4px rgba(28,136,199,.12);
  background: #fff;
}

/* Стрелка справа (рисуем через mask, без правок DOM) */
.ai-studio .settings-header .model-selector::after{
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  pointer-events: none;

  background: var(--muted);
  opacity: .9;

  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/18px 18px no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/18px 18px no-repeat;
}

/* Best-effort: option/optgroup (не везде применяется) */
.ai-studio select#model-select optgroup{
  font-weight: 700;
  color: var(--ink);
}
.ai-studio select#model-select option{
  color: var(--ink);
}

.form-group.flex-align {
    display: flex;
    align-items: self-start;
    justify-content: space-between;
    gap: 0px;
    margin-top: 0px;
}

/* AI Studio: allow dropdown menu to overflow panel */
.ai-studio .settings-dashboard{
  overflow: visible; /* иначе .fselect-menu будет обрезаться */
}

.ai-studio .settings-header,
.ai-studio .model-selector{
  position: relative;
  z-index: 30;
}

/* на всякий случай поднимаем меню выше соседей */
.ai-studio .model-selector .fselect-menu{
  z-index: 60;
}

/* Выпадайка моделей — прижата к правому краю панели */
.ai-studio .model-selector .fselect-menu {
  left: auto;
  right: 0;
  min-width: 100%;
  max-height: 480px;
}

/* AI Studio: только кнопка выбора модели (триггер дропдауна) */
.ai-studio .model-selector .fselect{
  width: 100%;
}

/* если у тебя раньше была “стрелка” на контейнере, она даст дубль */
.ai-studio .settings-header .model-selector::after{
  content: none !important;
}

.ai-studio .model-selector .fselect-btn{
  width: 100%;
  min-width: 0;
  height: 46px;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;

  padding: 12px 14px;
  border-radius: 14px;

  border: 1px solid var(--field-line);
  background: var(--field);
  color: var(--ink);

  font: 500 14px/1.2 var(--font-base);

  cursor: pointer;
  user-select: none;
}

.ai-studio .model-selector .fselect-btn:hover{
  border-color: var(--line-2);
  background: #fff;
}

.ai-studio .model-selector .fselect-btn:focus,
.ai-studio .model-selector .fselect-btn:focus-visible{
  outline: none;
  border-color: rgba(28,136,199,.55);
  box-shadow: 0 0 0 4px rgba(28,136,199,.12);
  background: #fff;
}

/* Checkbox a bit nicer */
#additional-settings input[type="checkbox"].parameter-input {
  width: 18px;
  height: 18px;
  padding: 0;
  display: inline-block;
  justify-self: start;
  
    border-radius: 10px !important;
    border: 1px solid var(--field-line) !important;
    background: var(--field) !important;
}

.submit-button_v4:hover {
    box-shadow: none;
}

.ai-studio input[type="checkbox"].parameter-input{
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid var(--field-line);
  background: var(--field);
  cursor: pointer;
  display: inline-block;
  vertical-align: middle;
}

.ai-studio input[type="checkbox"].parameter-input:checked{
  background: var(--accent);
  border-color: rgba(28,136,199,.55);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 10'%3E%3Cpath d='M1 5l3 3 7-7' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 12px 12px;
}

.ai-studio input[type="checkbox"].parameter-input:focus-visible{
  outline: none;
  box-shadow: 0 0 0 4px rgba(28,136,199,.12);
}

    @media (max-width: 720px){
		  .sidebar {
		flex: 0 0 auto;
		width: 100%;
	}
    }


@media (max-width: 768px) {
    .main .flex {
        flex-direction: column-reverse;
    }
}

/* AI Studio header: mobile 2 rows x 3 tabs */
@media (max-width: 576px){
      .ai-studio-header .topbar-inner {
        flex-wrap: nowrap;
 
        gap: 10px;
        margin: 0px;
        padding: 0px;

        width: calc(100% - 4rem);
    }

  /* toggle остается сверху слева */
  .ai-studio-header .sidebar-toggle{
    flex: 0 0 auto;
  }

  /* табы уходят на новую строку и становятся сеткой 3x2 */
  .ai-studio-header .media-type-tabs{
    flex: 1 0 100%;
    width: 100%;

    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .ai-studio-header .media-type-tabs .tab{
    width: 100%;
    justify-content: center;
    padding: 10px 8px;
    min-height: 42px;
  }

  .ai-studio-header .media-type-tabs .tab .chat-icon{
    width: 18px;
    height: 18px;
  }

  .ai-studio-header .media-type-tabs .tab span{
    font-size: 12px;
    line-height: 1.1;
  }
}

@media (max-width: 768px) {
    body.is-sidebar-collapsed .sidebar {
        flex: auto !important;
        width: 100% !important;
        display: flex;
        margin: 0px;
        padding: 0px;
        flex-direction: row;
        min-width: 84px;
        padding-right: 0;
    }
	.divider {
   display: none;
}
aside {

        border-bottom: none;
    }
}

body {
    min-height: 100vh;
}



.send.submit-button_v4,
.stop-gen-btn.submit-button_v4 {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
}

#stop-generate-btn {
  display: none;
  color: #c0392b;
}

#chat[data-state="generating"] #stop-generate-btn {
  display: inline-flex !important;
}

#chat[data-state="generating"] #send-btn {
  display: none !important;
}

.stop-gen-btn:hover {
  background: #fde8e8 !important;
}

.composer {
    display: flex;
    gap: 10px;
    align-items: center;
    border: 1px solid #e6eef5;
    border-radius: 10px;
    padding: 10px 10px;
    background: #fff;
}
.chat-footer {
    padding: 14px;
}
.button-ui.attach {
    display: none;
}
.chat-shell .chat-footer {
    background: #fff;
}
.composer .chat-textarea {
    min-height: auto;
    max-height: 160px;
    resize: none;
	border: 0;
    outline: 0;
    flex: 1;
    padding: 6px 4px;
	font-size: 1rem;
	color: #222;
}


.ai-studio .menu-item::before {
    display: none;
}

button:hover, input[type="button"]:hover, input[type="submit"]:hover, input[type="reset"]:hover {
    background-color: inherit;
}

.content {
    overflow-x: unset;
}

section.content.ai-studio .ai-studio-main {
    flex: 1 1 auto;
    min-height: 0;
}

.settings-accordion .card-title {
    font-weight: 400;
}

.bubble p {
    margin: 0rem !important;
}

.toggle-icon .acc-chev{
  display: block;
  width: 20px;
  height: 20px;
}

.toggle-icon.is-open .acc-chev{
  transform: rotate(180deg);
}

.toggle-icon .acc-chev{ transition: transform .18s ease; }

.toggle-icon .acc-chev{
  display:block;
  width:20px;
  height:20px;
  transition: transform .18s ease;
}
.toggle-icon.is-open .acc-chev{ transform: rotate(180deg); }

/* ── AI Studio: chat fills viewport height ──────────────────────────
   Desktop (≥769px): pass height through body → main → .flex → section
   so the chat area reaches the bottom of the visible viewport and
   does NOT resize as messages are added.
   ─────────────────────────────────────────────────────────────────── */
@media (min-width: 769px) {
  /* 1. main becomes a flex column so its height (from flex-grow:1) flows down */
  body:has(.content.ai-studio) main.main {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  /* 2. Inner .flex row stretches to fill main; no wrapping (wrap kills height) */
  body:has(.content.ai-studio) main.main > .flex {
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
    flex-wrap: nowrap;
  }

  /* 3. Sidebar stretches to fill the row so history can grow to full height */
  body:has(.content.ai-studio) main.main > .flex > .sidebar {
    align-self: stretch;
  }

  /* 4. Content section stretches to fill the row */
  section.content.ai-studio {
    min-height: 0;
    overflow: hidden;
  }

  /* 5. settings aside: fill height, scroll internally */
  .ai-studio-main > aside.side {
    overflow-y: auto;
  }
}

/* Mobile / tablet (≤768px): natural height, no viewport constraint */
@media (max-width: 768px) {
  section.content.ai-studio {
    overflow: visible;
  }
  section.content.ai-studio .ai-studio-main {
    min-height: 400px;
  }
  /* restore wrap so sidebar can move below content */
  body:has(.content.ai-studio) main.main > .flex {
    flex-wrap: wrap;
    align-items: flex-start;
  }
}

/* ===== AI Studio responsive redesign ===== */
section.content.ai-studio {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-width: 0;
}

.ai-studio-header {
  padding: clamp(0.4rem, 0.7vw, 0.6rem);
  border: 1px solid #dbe6f2;
  border-radius: 14px;
  background: linear-gradient(180deg, #fafdff, #f3f8fc);
  box-shadow: 0 12px 28px rgba(16, 24, 40, 0.05);
}

.ai-studio-header .topbar-inner {
  width: 100%;
  margin: 0;
  align-items: stretch;
  gap: clamp(0.5rem, 0.8vw, 0.75rem);
}

.ai-studio-header .sidebar-toggle {
  width: 36px;
  height: 36px;
  border-radius: 14px;
}

.ai-studio-header .media-type-tabs {
  width: 100%;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.ai-studio-header .media-type-tabs .tab {
  width: 100%;
  min-height: 42px;
  padding: 0.4rem 0.75rem;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid #dbe6f2;
  border-radius: 14px;
  background: #fff;
}

/* Убираем подчёркивание при hover, делаем фоновую подсветку как у active */
.ai-studio-header .media-type-tabs .tab span::after {
  display: none !important;
}

.ai-studio-header .media-type-tabs .tab:hover {
  background: var(--mt-blue-2);
  border-color: var(--color-border-accent);
  color: #194e60;
}

.ai-studio-header .media-type-tabs .tab.active {
  background: var(--mt-blue-2);
  border-color: var(--color-border-accent);
  color: #194e60;
}

.ai-studio-header .media-type-tabs .tab .chat-icon {
  width: 20px;
  height: 20px;
}

.ai-studio-header .media-type-tabs .tab span {
  font-size: 13px;
  line-height: 1.2;
}

.ai-studio .divider {
  display: none;
}

/* Chat занимает всё доступное место, панель настроек — мин 320px у правого края */
section.content.ai-studio .ai-studio-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 340px);
  gap: clamp(1rem, 1.5vw, 1.5rem);
  align-items: stretch;
  min-height: calc(100dvh - 13rem);
}

.chat-shell.chat-area,
.chat-shell.chat-area[data-state="idle"],
.chat-shell.chat-area[data-state="generating"],
.chat-shell.chat-area[data-state="expanded"] {
  min-height: 0;
  height: 100%;
  max-height: none;
  align-self: stretch;
  border: 1px solid #e0eaf3;
  border-radius: 14px;
  box-shadow: 0 12px 28px rgba(16, 24, 40, 0.05);
}

.chat-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.chat-messages {
  padding: 1.25rem 1.25rem 0;
}

.chat-footer {
  position: sticky;
  bottom: 0;
  padding: 1rem 1.25rem calc(1rem + env(safe-area-inset-bottom, 0));
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fff 24%);
}

.chat-shell .chat-footer {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fff 24%);
}

.composer {
  align-items: flex-end;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 14px;
}

.button-ui.attach {
  display: none !important;
}

.send.submit-button_v4,
.stop-gen-btn.submit-button_v4 {
  width: 48px;
  height: 48px;
  border-radius: 14px;
}

.composer .chat-textarea {
  min-height: 48px;
  max-height: 32dvh;
  padding: 0.7rem 0.35rem;
  font-size: 16px;
}

.ai-studio-main > .side {
  min-height: 0;
  height: 100%;
  min-width: 320px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, #f8fbff, #f2f7fc);
  box-shadow: none;
  overflow: visible;
}

.settings-header {
  width: 100%;
  min-width: 0;
}

.model-selector,
.model-selector select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.model-selector {
  margin: 0;
  min-width: 0 !important;
  flex: 1 1 0;
}

.model-selector .form-group.flex-align {
  margin: 0;
  gap: 0;
}

.settings-content {
  min-height: 0;
  overflow: auto;
}

/* 13" экраны (1024-1440px): сужаем правую панель чтобы всё влезло */
@media (max-width: 1440px) and (min-width: 1025px) {
  section.content.ai-studio .ai-studio-main {
    grid-template-columns: minmax(0, 1fr) 310px;
    gap: clamp(0.75rem, 1vw, 1rem);
  }

  .ai-studio-main > .side {
    min-width: 310px;
  }
}

@media (max-width: 1024px) {
  .ai-studio-header .media-type-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  section.content.ai-studio .ai-studio-main {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .chat-shell.chat-area,
  .ai-studio-main > .side {
    min-height: 0;
  }

  .ai-studio-main > .side {
    flex: 1 1 auto;
  }

  /* На планшете выпадайка на всю ширину контейнера */
  .ai-studio .model-selector .fselect-menu {
    left: 0;
    right: 0;
    min-width: unset;
  }
}

@media (max-width: 768px) {
  .ai-studio-header {
    padding: 1rem;
    border-radius: 14px;
  }

  .ai-studio-header .topbar-inner {
    flex-wrap: wrap;
  }

  .ai-studio-header .media-type-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .ai-studio-header .media-type-tabs .tab {
    min-height: 76px;
    padding: 0.75rem 0.5rem;
  }

  .ai-studio-header .media-type-tabs .tab .chat-icon {
    width: 24px;
    height: 24px;
  }

  .chat-shell.chat-area {
    min-height: min(72dvh, 760px);
  }

  .chat-footer,
  .chat-shell .chat-footer {
    padding: 0.85rem 0.85rem calc(0.85rem + env(safe-area-inset-bottom, 0));
  }

  .chat-message {
    max-width: 100%;
  }

  .composer {
    gap: 0.5rem;
  }

  .ai-studio-main > .side {
    border-radius: 14px;
    min-height: 0;
    padding: 1rem;
    background: linear-gradient(180deg, #f8fbff, #f4f8fc);
  }
}

@media (max-width: 560px) {
  .ai-studio-header .sidebar-toggle {
    width: 44px;
    height: 44px;
  }

  .ai-studio-header .media-type-tabs .tab span {
    font-size: 13px;
  }

  .chat-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .chat-title,
  .header-actions {
    width: 100%;
  }

  .send.submit-button_v4,
  .stop-gen-btn.submit-button_v4 {
    width: 44px;
    height: 44px;
  }
}

@media (orientation: landscape) and (max-width: 900px) {
  .chat-shell.chat-area {
    min-height: 82dvh;
  }

  .composer .chat-textarea {
    max-height: 24dvh;
  }
}

/* Category filter buttons */
.category-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 0 14px;
}

.category-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1.5px solid #c5d5e0;
  border-radius: 8px;
  background: #fff;
  color: #5a7a8a;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.category-btn:hover {
  border-color: #7eb8a0;
  color: #3a8a6a;
}

.category-btn.active {
  background: #e8f5ee;
  border-color: #5aaa7a;
  color: #2a7a5a;
  font-weight: 500;
}

.category-btn .cat-icons {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.category-btn .cat-icons svg {
  flex-shrink: 0;
}

.category-btn .cat-label {
  font-size: 11px;
}

/* Задача 7: увеличить фрейм истории генераций в 2 раза */
body:has(.content.ai-studio) .sidebar .history .gen-list {
  flex: 1 1 auto;
  min-height: 280px;
  max-height: none;
  overflow-y: auto;
}

/* Загрузка изображений для image-to-image моделей */
.image-upload {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.image-upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 10px;
  border: 1.5px dashed #bcd3e5;
  border-radius: 10px;
  background: #f8fbff;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-align: center;
  font-size: 12px;
  color: #5a7e9c;
}

.image-upload-zone:hover,
.image-upload-zone.dragover {
  background: #eef5fc;
  border-color: #7bb0d6;
}

.image-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid #bcd3e5;
  border-radius: 8px;
  background: #fff;
  color: #2c3a4a;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.image-upload-btn:hover {
  background: #f0f7fb;
}

.image-upload-hint {
  font-size: 11px;
  color: #8aa3b8;
  line-height: 1.3;
}

.image-upload-url-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.image-upload-url-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--field-line);
  background: var(--field);
  color: #2c3a4a;
  font-size: 12px;
}

.image-upload-url-add {
  padding: 0 12px;
  border: 1px solid #bcd3e5;
  background: #fff;
  color: #2c3a4a;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.image-upload-url-add:hover {
  background: #f0f7fb;
}

.image-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.image-preview-grid:empty {
  display: none;
}

.image-preview-item {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #dbe6f2;
  background: #f0f4f8;
}

.image-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.image-preview-remove:hover {
  background: rgba(0, 0, 0, 0.8);
}