.connect-layout {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  width: 100%;
  margin-bottom: 24px;
  box-sizing: border-box;
}

.connect-fields {
  min-width: 0;
  padding: 22px 24px;
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--line);
}
.connect-fields .panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
}
.connect-fields .panel-head h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
.connect-fields .field {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.connect-fields .field label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
}
.connect-input-action {
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
}
.connect-input-action input {
  min-width: 0;
  flex: 1;
}
.connect-key-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.connect-test-btn {
  width: 100%;
  min-height: 42px;
  font-size: 14.5px;
}
.connect-result {
  min-height: 20px;
  font-size: 13px;
  color: var(--accent, #9aefd2);
  overflow-wrap: anywhere;
  margin: 0;
}
.connect-result:empty {
  display: none;
}
.connect-check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  margin: 0;
  color: var(--text);
  cursor: pointer;
}
.connect-check input {
  accent-color: var(--accent, #89b7a6);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.connect-api-params {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}
.connect-token-settings {
  border-block: 1px solid var(--line);
  margin: 0;
  padding: 0;
}
.connect-token-settings > summary {
  padding: 12px 0;
  color: var(--text);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}
.connect-token-settings small,
.connect-token-note {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.connect-token-settings small {
  margin-top: 6px;
}
.connect-token-note {
  margin: 10px 0 14px;
}
.connect-price {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
}
.connect-rate-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.connect-rate-heading h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 0;
}
.connect-rate-heading a {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.connect-rates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 0;
}
.connect-rates dt {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.connect-rates dd {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}
.connect-rate-note {
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 0;
}

.connect-main {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

.connect-agents-panel {
  padding: 22px 24px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--line);
  box-sizing: border-box;
}
.connect-agents-panel .panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.connect-agents-panel .panel-head h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
.connect-apps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}
.connect-app {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 64px;
  padding: 12px 14px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  box-sizing: border-box;
  font-family: inherit;
  outline: none;
  position: relative;
}
.connect-app:hover {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.06);
}
.connect-app.active {
  border-color: var(--accent, #7fa9a3);
  background: rgba(0, 214, 143, 0.08);
}
.connect-app > .icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--accent, #9aefd2);
}
.connect-app-icon {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 24px;
  flex-shrink: 0;
  margin: 0;
}
.connect-app-img {
  width: 22px;
  height: 22px;
  max-width: 22px;
  max-height: 22px;
  object-fit: contain;
  display: block;
}
.connect-app-info {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0;
}
.connect-app-info strong,
.connect-app strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}
.connect-app-info small,
.connect-app small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}
.connect-app-check {
  margin-left: auto;
  color: var(--accent, #00d68f);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.connect-app.active .connect-app-check {
  opacity: 1;
}
.connect-app-check .icon {
  width: 16px;
  height: 16px;
}

.connect-preview {
  padding: 22px 24px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025) !important;
  border: 1px solid var(--line) !important;
  box-sizing: border-box;
}
.connect-preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.connect-preview-head h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
#connect-file,
.connect-preview-head .mono {
  font-size: 13px;
  color: var(--muted);
  font-family: var(--mono);
  margin: 4px 0 0 0 !important;
  padding: 0 !important;
  display: block;
}
.connect-toolbar {
  display: flex;
  gap: 8px;
}
.connect-instructions {
  padding: 0 0 16px;
  border-bottom: 1px solid var(--line);
}
.connect-instructions h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px;
}
.connect-instructions p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
  margin: 0 0 10px;
}
.connect-instructions a {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.code-disclosure {
  padding-top: 14px;
}
.code-disclosure > summary {
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.code-disclosure pre {
  margin: 12px 0 0;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  max-height: 480px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
}
.connect-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 12px;
}

/* ---- Connection wizard: three numbered steps ---- */
.cw-layout { display: flex; flex-direction: column; gap: 18px; width: 100%; margin-bottom: 24px; }
.cw-row { display: grid; grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); gap: 18px; align-items: start; }
.cw-step {
  min-width: 0; padding: 22px 24px; border-radius: 24px; box-sizing: border-box;
  background: rgba(255, 255, 255, 0.025); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 16px;
}
.cw-step-head { display: flex; align-items: center; gap: 12px; }
.cw-step-head h2 { margin: 0; font-size: 20px; font-weight: 600; color: #f4f4f6; line-height: 1.3; }
.cw-step-num {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 32px; width: 32px; height: 32px;
  border-radius: 50%; background: #9aefd2; color: #090a0b; font-size: 16px; font-weight: 600;
}
.cw-step-lead { margin: -4px 0 0; font-size: 15px; line-height: 1.5; color: #9da0b3; }

.cw-app-group { display: flex; flex-direction: column; gap: 10px; }
.cw-app-group h3 { margin: 0; font-size: 15px; font-weight: 500; color: #c4c4d4; }
.cw-apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.cw-app {
  position: relative; display: flex; align-items: center; gap: 12px; min-width: 0; min-height: 52px; padding: 10px 14px;
  text-align: left; font-family: inherit; color: #eaeaec; cursor: pointer; box-sizing: border-box;
  border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, 0.04);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.cw-app:hover { background: rgba(255, 255, 255, 0.07); }
.cw-app.active { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.4); }
.cw-app:focus-visible { outline: 2px solid #9aefd2; outline-offset: 2px; }
.cw-app-info { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.cw-app-info strong { font-size: 15px; font-weight: 500; line-height: 1.3; }
.cw-app-info small { font-size: 15px; line-height: 1.35; color: #9da0b3; margin-top: 2px; }
.cw-app-check { display: flex; flex-shrink: 0; width: 18px; height: 18px; color: #9aefd2; opacity: 0; transition: opacity 0.15s ease; }
.cw-app-check .icon { width: 18px; height: 18px; }
.cw-app.active .cw-app-check { opacity: 1; }

.cw-more-apps { border-top: 1px solid var(--line); padding-top: 4px; }
.cw-more-apps > summary { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; font-weight: 500; color: #c4c4d4; cursor: pointer; }
.cw-more-apps > summary span { padding: 2px 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.07); font-size: 15px; color: #eaeaec; }
.cw-more-apps > summary::-webkit-details-marker { display: none; }
.cw-more-apps > summary { list-style: none; }
.cw-more-apps > summary::after { content: 'Показать ↓'; margin-left: auto; font-weight: 500; color: #9aefd2; white-space: nowrap; }
.cw-more-apps[open] > summary::after { content: 'Скрыть ↑'; }
.cw-more-apps[open] { display: flex; flex-direction: column; gap: 16px; }

.cw-field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.cw-field > label, .cw-field-label, .cw-key-label { font-size: 15px; font-weight: 500; color: #c4c4d4; }

/* Model picker: the chat dropdown, stretched to the field width. */
/* !important: mobile.css forces chat-page header sizing on every .chat-model-* below 900px. */
.cw-step .chat-model-picker { display: flex !important; position: relative !important; width: 100%; order: 0 !important; }
.cw-step .chat-model-trigger {
  width: 100% !important; min-height: 44px !important; height: auto !important; padding: 10px 14px !important;
  justify-content: flex-start !important; gap: 10px !important;
  font-size: 15px !important; font-weight: 550; border-radius: 16px !important; box-shadow: none;
}
.cw-step .chat-model-trigger .chat-model-name { font-size: 15px !important; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cw-step .chat-model-trigger .chat-model-chevron { margin-left: auto; }
.cw-step .chat-model-trigger .model-avatar-icon { width: 18px; height: 18px; }
.cw-step .chat-model-dropdown {
  position: absolute !important; top: calc(100% + 8px) !important; left: 0 !important; right: 0 !important;
  width: auto !important; max-width: none !important; max-height: none !important;
}
.cw-step .chat-model-dropdown #chat-model-list { max-height: min(420px, 55vh); overflow-y: auto; scrollbar-width: thin; }
.cw-step .cw-field select, .cw-step .cw-field input {
  min-height: 44px; font-size: 15px; border-radius: 8px; color: #f4f4f6;
  background-color: rgba(255, 255, 255, 0.04); border: 1px solid var(--line);
}
.cw-step .cw-field select optgroup { color: #9da0b3; font-weight: 600; }
.cw-step .cw-field select option { color: #f4f4f6; background: #16171a; }
.cw-error-text { font-size: 15px; color: #f2a7a7; }
.cw-error-text:empty { display: none; }
.cw-model-hint { font-size: 13.5px; color: #9da0b3; line-height: 1.45; margin-top: 4px; display: block; }

.cw-price {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 8px; background: rgba(255, 255, 255, 0.04);
  font-size: 15px; color: #9da0b3;
}
.cw-price strong { color: #f4f4f6; font-weight: 600; }
.cw-price a { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; color: #9aefd2; text-decoration: none; font-size: 15px; }

.cw-key-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.cw-key-btns {
  display: flex;
  gap: 8px;
  align-items: center;
}
.cw-key-btns .btn {
  min-height: 32px;
  padding: 5px 12px;
  font-size: 13.5px;
}
.cw-key-guest-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
  font-size: 13.5px;
  color: var(--muted);
}

.cw-key-status {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 8px; background: rgba(255, 255, 255, 0.04);
}
.cw-key-status p { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 15px; line-height: 1.5; color: #eaeaec; }
.cw-key-status p .icon { width: 18px; height: 18px; flex-shrink: 0; color: #9aefd2; }
.cw-key-status .loader { width: 16px; height: 16px; flex-shrink: 0; }
.cw-key-status.is-error p { color: #f2a7a7; }
.cw-key-status .btn { min-height: 38px; font-size: 15px; }
.cw-key-status .btn.primary { min-height: 44px; }
.cw-key .connect-input-action input { min-height: 44px; }

.cw-test { width: 100%; min-height: 44px; font-size: 15px; font-weight: 500; }
.cw-result { margin: -6px 0 0; font-size: 15px; line-height: 1.5; color: #eaeaec; overflow-wrap: anywhere; }
.cw-result:empty { display: none; }
.cw-check { display: flex; align-items: center; gap: 10px; min-height: 38px; font-size: 15px; color: #eaeaec; cursor: pointer; }
.cw-check input { width: 18px; height: 18px; accent-color: #9aefd2; }

.cw-more { border-top: 1px solid var(--line); padding-top: 4px; }
.cw-more > summary { padding: 10px 0; font-size: 15px; font-weight: 500; color: #c4c4d4; cursor: pointer; }
.cw-more[open] { display: flex; flex-direction: column; gap: 14px; }
.cw-more .connect-token-settings { border-bottom: 0; }
.cw-more .connect-token-settings > summary, .cw-more .connect-token-note, .cw-more .connect-token-settings small,
.cw-more .connect-token-settings label { font-size: 15px; }
.cw-more .connect-token-note, .cw-more .connect-token-settings small { color: #9da0b3; }

.cw-instructions { display: flex; flex-direction: column; gap: 8px; }
.cw-instructions p { margin: 0; font-size: 15px; line-height: 1.6; color: #c4c4d6; }
.cw-instructions .cw-where { color: #eaeaec; font-weight: 500; }
.cw-instructions .mono, .cw-instructions #connect-file {
  display: inline; margin: 0 !important; padding: 0 !important;
  font-family: var(--mono); font-size: 15px; color: #9aefd2; font-weight: 500; overflow-wrap: anywhere;
}
.cw-instructions a { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; color: #9aefd2; text-decoration: none; }
.cw-app-kind-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  color: #c4c4d6;
  margin-left: 8px;
  vertical-align: middle;
}
html.theme-light .cw-app-kind-badge,
[data-theme="light"] .cw-app-kind-badge {
  background: #f0f2f5;
  border-color: #dce1e8;
  color: #4b5563;
}
.cw-key-in-config {
  margin: 0; display: flex; align-items: center; gap: 8px; padding: 10px 14px; font-size: 15px; line-height: 1.5;
  border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, 0.04); color: #9da0b3;
}
.cw-key-in-config.is-ready { color: #eaeaec; }
.cw-key-in-config .icon { width: 18px; height: 18px; flex-shrink: 0; color: #9aefd2; }
.cw-code-wrap { min-width: 0; }
.cw-code code { font-size: 15px; font-family: inherit; color: inherit; background: none; padding: 0; }
.cw-code {
  margin: 0; padding: 16px; max-height: 420px; overflow: auto; scrollbar-width: thin;
  border: 1px solid var(--line); border-radius: 18px; background: rgba(0, 0, 0, 0.3);
  font-family: var(--mono); font-size: 15px; line-height: 1.6; color: #eaeaec; white-space: pre;
}
.cw-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.cw-actions .btn { min-height: 44px; font-size: 15px; font-weight: 500; }

html.theme-light .cw-step { background: #ffffff; border-color: #dce1e8; }
html.theme-light .cw-step-head h2, html.theme-light .cw-price strong { color: #11141a; }
html.theme-light .cw-step-num { background: #11141a; color: #ffffff; }
html.theme-light .cw-step-lead, html.theme-light .cw-app-info small, html.theme-light .cw-price,
html.theme-light .cw-key-in-config { color: #5e6573; }
html.theme-light .cw-app-group h3, html.theme-light .cw-field > label, html.theme-light .cw-field-label, html.theme-light .cw-key-label,
html.theme-light .cw-more > summary { color: #333742; }
html.theme-light .cw-app { background: #f8f9fa; border-color: #dce1e8; color: #11141a; }
html.theme-light .cw-app:hover { background: #f0f2f5; }
html.theme-light .cw-app.active { background: #f0f2f5; border-color: #11141a; }
html.theme-light .cw-app-check, html.theme-light .cw-key-status p .icon, html.theme-light .cw-key-in-config .icon { color: #11141a; }
html.theme-light .cw-price, html.theme-light .cw-key-status, html.theme-light .cw-key-in-config { background: #f8f9fa; border-color: #dce1e8; }
html.theme-light .cw-price a, html.theme-light .cw-instructions a { color: #11141a; text-decoration: underline; }
html.theme-light .cw-key-status p, html.theme-light .cw-result, html.theme-light .cw-check,
html.theme-light .cw-key-in-config.is-ready, html.theme-light .cw-instructions .cw-where { color: #11141a; }
html.theme-light .cw-instructions p, html.theme-light .cw-more .connect-token-note,
html.theme-light .cw-more .connect-token-settings small, html.theme-light .cw-model-hint { color: #333742; }
html.theme-light .cw-instructions .mono, html.theme-light .cw-instructions #connect-file { color: #11141a; }
html.theme-light .cw-key-status.is-error p, html.theme-light .cw-error-text { color: #b42318; }
html.theme-light .cw-code { background: #f8f9fa; border-color: #dce1e8; color: #11141a; }
html.theme-light .cw-more, html.theme-light .cw-more-apps { border-color: #dce1e8; }
html.theme-light .cw-more-apps > summary { color: #333742; }
html.theme-light .cw-more-apps > summary::after { color: #11141a; }
html.theme-light .cw-more-apps > summary span { background: #f0f2f5; color: #11141a; }
html.theme-light .cw-step .cw-field select, html.theme-light .cw-step .cw-field input { background-color: #ffffff; border-color: #d5d9e0; color: #11141a; }
html.theme-light .cw-step .cw-field select option { background: #ffffff; color: #11141a; }
html.theme-light .cw-step .cw-field select optgroup { color: #5e6573; }

@media(max-width: 1000px) {
  .cw-row { grid-template-columns: minmax(0, 1fr); }
}
@media(max-width: 500px) {
  .cw-step { padding: 18px 16px; }
  .cw-apps { grid-template-columns: 1fr; }
  .cw-price a { margin-left: 0; }
  .cw-actions .btn { flex: 1 1 100%; }
}

@media(max-width: 1200px) {
  .connect-layout {
    grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
    gap: 18px;
  }
  .connect-apps {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media(max-width: 850px) {
  .connect-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
  }
  .connect-apps {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media(max-width: 500px) {
  .connect-apps {
    grid-template-columns: 1fr;
  }
  .connect-fields, .connect-agents-panel, .connect-preview {
    padding: 18px 16px;
  }
}
