#ai-settings-modal {
  background: color-mix(in srgb, #0b1020 64%, transparent);
  backdrop-filter: blur(5px);
}

.ai-settings-card {
  width: min(1000px, calc(100vw - 32px));
  height: min(700px, calc(100dvh - 40px));
  max-height: calc(100dvh - 40px);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 64px color-mix(in srgb, #080b14 36%, transparent);
}

.ai-settings-header {
  position: relative;
  top: auto;
  flex: 0 0 76px;
  min-height: 76px;
  padding: 14px 18px;
  background: var(--panel);
  color: var(--text);
  z-index: 2;
}

.ai-settings-heading,
.ai-settings-heading-copy,
.ai-providers-title,
.ai-form-heading {
  min-width: 0;
}

.ai-settings-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-settings-mark,
.ai-panel-state-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 1px solid color-mix(in srgb, var(--accent) 36%, var(--panel-border));
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 12%, var(--panel-soft));
  color: var(--accent);
  font-size: .74rem;
  font-weight: 850;
  letter-spacing: 0;
}

.ai-settings-heading-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ai-settings-heading-copy h3 {
  margin: 0;
  color: var(--text);
  font-size: 1.08rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.ai-provider-summary {
  color: var(--muted);
  font-size: .75rem;
  font-weight: 650;
  line-height: 1.25;
}

.ai-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}

.ai-icon-button:hover {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--panel-border));
  background: color-mix(in srgb, var(--accent) 9%, var(--panel-soft));
  color: var(--accent);
}

.ai-icon-button:active {
  transform: translateY(1px);
}

.ai-icon-button:focus-visible,
.ai-provider-select:focus-visible,
.ai-provider-delete:focus-visible,
.ai-primary-button:focus-visible,
.ai-secondary-button:focus-visible,
.ai-switch input:focus-visible + .ai-switch-track {
  outline: 2px solid color-mix(in srgb, var(--accent) 58%, transparent);
  outline-offset: 2px;
}

.ai-settings-close-button span {
  display: block;
  font-size: 1.62rem;
  font-weight: 350;
  line-height: 1;
  transform: translateY(-1px);
}

.ai-settings-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0;
  gap: 0;
  overflow: hidden;
}

.ai-settings-layout {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  width: 100%;
  height: 100%;
  min-height: 0;
}

.ai-providers-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--panel-border);
  background: color-mix(in srgb, var(--panel-soft) 68%, var(--panel));
}

.ai-providers-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 62px;
  min-height: 62px;
  gap: 12px;
  padding: 12px 14px 12px 16px;
  border-bottom: 1px solid var(--panel-border);
}

.ai-providers-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: .82rem;
  font-weight: 780;
}

.ai-provider-count,
.ai-model-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: .68rem;
  font-weight: 750;
  line-height: 1;
}

.ai-provider-add-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 5px 14px color-mix(in srgb, var(--accent) 24%, transparent);
}

.ai-provider-add-button:hover {
  border-color: color-mix(in srgb, var(--accent) 78%, #fff);
  background: color-mix(in srgb, var(--accent) 88%, #fff);
  color: #fff;
}

.ai-provider-add-button span {
  font-size: 1.3rem;
  font-weight: 500;
  line-height: 1;
}

.ai-providers-list {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  padding: 10px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 30%, transparent) transparent;
}

.ai-provider-row {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  min-height: 60px;
  padding: 3px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  transition: background .15s ease, border-color .15s ease;
}

.ai-provider-row:hover {
  border-color: var(--panel-border);
  background: var(--panel);
}

.ai-provider-row.is-active {
  border-color: color-mix(in srgb, var(--accent) 34%, var(--panel-border));
  background: color-mix(in srgb, var(--accent) 9%, var(--panel));
}

.ai-provider-select {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  gap: 10px;
  min-width: 0;
  min-height: 52px;
  padding: 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.ai-provider-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: .63rem;
  font-weight: 850;
  letter-spacing: 0;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}

.ai-provider-row.is-active .ai-provider-mark {
  border-color: color-mix(in srgb, var(--accent) 36%, var(--panel-border));
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
  color: var(--accent);
}

.ai-provider-copy {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.ai-provider-name {
  overflow: hidden;
  color: var(--text);
  font-size: .82rem;
  font-weight: 760;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-provider-meta {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: .67rem;
  font-weight: 620;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-provider-status-dot {
  flex: 0 0 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--muted) 54%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--muted) 10%, transparent);
}

.ai-provider-status-dot.is-active {
  background: var(--ok);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ok) 14%, transparent);
}

.ai-provider-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  opacity: .45;
  transition: background .15s ease, color .15s ease, opacity .15s ease;
}

.ai-provider-delete span {
  font-size: 1.12rem;
  font-weight: 400;
  line-height: 1;
}

.ai-provider-row:hover .ai-provider-delete,
.ai-provider-delete:focus-visible {
  opacity: 1;
}

.ai-provider-delete:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.ai-provider-delete:disabled,
.ai-primary-button:disabled,
.ai-secondary-button:disabled {
  cursor: wait;
  opacity: .58;
}

.ai-provider-list-empty,
.ai-provider-list-error {
  padding: 20px 10px;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 650;
  text-align: center;
}

.ai-provider-list-error {
  color: var(--danger);
}

.ai-provider-skeleton {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-provider-skeleton span,
.ai-form-skeleton span {
  display: block;
  border-radius: 7px;
  background: color-mix(in srgb, var(--muted) 14%, var(--panel-soft));
  animation: ai-settings-pulse 1.2s ease-in-out infinite alternate;
}

.ai-provider-skeleton span {
  height: 60px;
}

.ai-provider-form-panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--panel);
}

.ai-provider-form {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.ai-form-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 76px;
  min-height: 76px;
  gap: 16px;
  padding: 13px 24px;
  border-bottom: 1px solid var(--panel-border);
}

.ai-form-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ai-form-kicker {
  overflow: hidden;
  color: var(--muted);
  font-size: .65rem;
  font-weight: 780;
  letter-spacing: 0;
  line-height: 1.2;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.ai-form-heading h4 {
  max-width: 520px;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.22;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-form-status {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: .7rem;
  font-weight: 740;
}

.ai-form-status > span:first-child {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.ai-form-status.is-active {
  border-color: color-mix(in srgb, var(--ok) 32%, var(--panel-border));
  background: color-mix(in srgb, var(--ok) 10%, var(--panel));
  color: var(--ok);
}

.ai-provider-form-fields {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  margin: 0;
}

.ai-form-scroll {
  flex: 1 1 auto;
  min-height: 0;
  padding: 22px 26px 8px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 30%, transparent) transparent;
}

.ai-form-section {
  margin: 0 0 20px;
  padding: 0 0 22px;
  border-bottom: 1px solid var(--panel-border);
}

.ai-form-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 24px;
  margin-bottom: 13px;
}

.ai-form-section-heading h5 {
  margin: 0;
  color: var(--text);
  font-size: .8rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0;
}

.ai-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px 14px;
}

.ai-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.ai-field-label,
.ai-status-setting-label {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  line-height: 1.2;
}

.ai-field-control {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  margin: 0;
  padding: 9px 11px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  outline: 0;
  background: color-mix(in srgb, var(--panel-soft) 86%, var(--panel));
  color: var(--text);
  color-scheme: light dark;
  font: inherit;
  font-size: .82rem;
  line-height: 1.35;
  letter-spacing: 0;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}

select.ai-field-control {
  cursor: pointer;
}

.ai-field-control:hover {
  border-color: color-mix(in srgb, var(--muted) 45%, var(--panel-border));
}

.ai-field-control:focus {
  border-color: color-mix(in srgb, var(--accent) 68%, var(--panel-border));
  background: var(--panel);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent);
}

.ai-field-control::placeholder {
  color: color-mix(in srgb, var(--muted) 76%, transparent);
  opacity: 1;
}

.ai-field-hint {
  color: var(--muted);
  font-size: .67rem;
  font-weight: 580;
  line-height: 1.35;
}

.ai-models-field {
  width: 100%;
}

.ai-models-input {
  display: block;
  min-height: 150px;
  max-height: 280px;
  resize: vertical;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: .75rem;
  line-height: 1.55;
}

.ai-model-count {
  min-width: auto;
  background: var(--panel-soft);
}

.ai-primary-button,
.ai-secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: .78rem;
  font-weight: 750;
  line-height: 1;
  letter-spacing: 0;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}

.ai-secondary-button {
  background: var(--panel-soft);
  color: var(--text);
}

.ai-secondary-button:hover {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--panel-border));
  background: color-mix(in srgb, var(--accent) 8%, var(--panel-soft));
  color: var(--accent);
}

.ai-primary-button {
  min-width: 112px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 25%, transparent);
}

.ai-primary-button:hover {
  border-color: color-mix(in srgb, var(--accent) 76%, #fff);
  background: color-mix(in srgb, var(--accent) 88%, #fff);
}

.ai-primary-button:active,
.ai-secondary-button:active {
  transform: translateY(1px);
}

.ai-discover-button {
  margin-top: 12px;
}

.ai-discover-button[hidden] {
  display: none;
}

.ai-status-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 0;
  border-bottom: 0;
}

.ai-status-setting-label {
  color: var(--text);
  font-size: .78rem;
  font-weight: 760;
}

.ai-switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  cursor: pointer;
  font-size: .73rem;
  font-weight: 700;
  user-select: none;
}

.ai-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.ai-switch-track {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 42px;
  width: 42px;
  height: 24px;
  padding: 2px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 22%, var(--panel-soft));
  transition: background .18s ease, border-color .18s ease;
}

.ai-switch-track > span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px color-mix(in srgb, #000 24%, transparent);
  transform: translateX(0);
  transition: transform .18s ease;
}

.ai-switch input:checked + .ai-switch-track {
  border-color: var(--ok);
  background: var(--ok);
}

.ai-switch input:checked + .ai-switch-track > span {
  transform: translateX(18px);
}

.ai-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 66px;
  gap: 9px;
  min-height: 66px;
  padding: 12px 24px;
  border-top: 1px solid var(--panel-border);
  background: var(--panel);
}

.ai-panel-state {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  height: 100%;
  min-height: 260px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.ai-panel-state h4 {
  margin: 0;
  color: var(--text);
  font-size: .92rem;
  letter-spacing: 0;
}

.ai-panel-state.is-error .ai-panel-state-mark {
  border-color: color-mix(in srgb, var(--danger) 34%, var(--panel-border));
  background: color-mix(in srgb, var(--danger) 10%, var(--panel-soft));
  color: var(--danger);
}

.ai-form-skeleton {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 28px;
}

.ai-form-skeleton span {
  width: 100%;
  height: 44px;
}

.ai-form-skeleton .ai-form-skeleton-title {
  width: 46%;
  height: 24px;
}

@keyframes ai-settings-pulse {
  from { opacity: .45; }
  to { opacity: .9; }
}

@media (max-width: 760px) {
  #ai-settings-modal {
    padding: 0;
  }

  .ai-settings-card {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .ai-settings-header {
    flex-basis: 68px;
    min-height: 68px;
    padding: 10px 14px;
  }

  .ai-settings-mark {
    width: 36px;
    height: 36px;
  }

  .ai-settings-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 142px minmax(0, 1fr);
  }

  .ai-providers-panel {
    border-right: 0;
    border-bottom: 1px solid var(--panel-border);
  }

  .ai-providers-header {
    flex-basis: 54px;
    min-height: 54px;
    padding: 9px 12px 9px 14px;
  }

  .ai-providers-list {
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 10px 10px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .ai-provider-row {
    flex: 0 0 238px;
    height: 64px;
    min-height: 60px;
  }

  .ai-provider-skeleton {
    flex-direction: row;
  }

  .ai-provider-skeleton span {
    width: 220px;
    height: 60px;
  }

  .ai-form-toolbar {
    flex-basis: 64px;
    min-height: 64px;
    padding: 10px 16px;
  }

  .ai-form-scroll {
    padding: 18px 16px 6px;
  }

  .ai-form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .ai-form-actions {
    padding: 10px 16px;
  }
}

@media (max-width: 420px) {
  .ai-provider-summary {
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ai-form-heading h4 {
    max-width: 210px;
  }

  .ai-form-status {
    padding: 0 8px;
  }

  .ai-form-actions .ai-primary-button,
  .ai-form-actions .ai-secondary-button {
    flex: 1 1 50%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-provider-skeleton span,
  .ai-form-skeleton span {
    animation: none;
  }

  .ai-icon-button,
  .ai-provider-row,
  .ai-provider-mark,
  .ai-provider-delete,
  .ai-field-control,
  .ai-primary-button,
  .ai-secondary-button,
  .ai-switch-track,
  .ai-switch-track > span {
    transition: none;
  }
}
