/* Provider Auth Multi-Account UI */
.provider-auth-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.provider-auth-section {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 12px 16px;
  background: var(--color-bg-secondary);
}

.provider-auth-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.provider-auth-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.provider-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--color-text);
}

.provider-company {
  font-size: 12px;
  color: var(--color-text-muted);
}

/* Reorder: a quiet text button beside Add Account, shown only with two or
   more accounts. While reordering it reads Done and the rows show arrows. */
.provider-reorder-toggle {
  margin-left: auto;
  margin-right: 8px;
  padding: 4px 6px;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--color-text-muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.provider-reorder-toggle:hover:not(:disabled),
.provider-reorder-toggle.is-active {
  color: var(--color-accent, #3f72ff);
}

.provider-reorder-toggle:hover:not(:disabled) {
  text-decoration: underline;
}

.provider-reorder-toggle.is-active {
  font-weight: 600;
}

.provider-reorder-toggle:focus-visible {
  outline: 2px solid var(--color-accent, #3f72ff);
  outline-offset: 1px;
}

.provider-reorder-toggle:disabled {
  cursor: default;
  opacity: 0.6;
}

.provider-reorder-hint {
  margin: -2px 0 10px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--color-text-muted);
}

.provider-move-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Announces each move to screen readers; the moved row is the visible cue. */
.provider-order-announcer {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.provider-accounts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.provider-no-accounts {
  color: var(--color-text-muted);
  font-size: 13px;
  font-style: italic;
  padding: 8px 0;
}

.provider-account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.provider-account-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

/* The task control, then the name and its badges. On a narrow screen the
   name wraps (long emails break anywhere) and the badges drop to the next
   line under it, so nothing runs past the card. */
.provider-account-label {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
}

.provider-account-label > input,
.provider-account-label > .account-inactive-spacer {
  margin-top: 2px;
}

.provider-account-title {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  min-width: 0;
}

.account-label-text {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  font-weight: 500;
  font-size: 13px;
  color: var(--color-text);
}

.account-type-badge,
.account-default-badge,
.account-task-note {
  white-space: nowrap;
}

.account-default-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  background: var(--color-success, #10b981);
  color: white;
  border-radius: 4px;
}

.account-task-note {
  font-size: 11px;
  color: var(--color-text-muted);
}

.account-long-lived-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
  border-radius: 4px;
  white-space: nowrap;
}

.provider-account-signin-status,
.provider-account-token-status {
  font-size: 12px;
  line-height: 1.4;
}

.provider-account-token-status.is-muted {
  color: var(--color-text-muted);
}

.provider-account-signin-status.is-warning,
.provider-account-token-status.is-warning {
  color: color-mix(in srgb, var(--color-warning) 75%, var(--color-text));
}

.provider-account-signin-status.is-error {
  color: var(--color-danger, #ef4444);
}

.ai-provider-long-lived-option {
  margin: 8px 0 0;
}

.ai-provider-long-lived-option label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
}

.ai-provider-modal-content .ai-provider-long-lived-option .form-hint {
  display: block;
  margin-top: 4px;
}

.account-type-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
}

.account-type-badge.oauth {
  background: rgba(63, 114, 255, 0.14);
  color: var(--color-accent);
}

.account-type-badge.api-key {
  background: rgba(14, 165, 233, 0.14);
  color: #0284c7;
}

.account-endpoint-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(99, 102, 241, 0.12);
  color: #4f46e5;
  white-space: nowrap;
}

.account-inactive-spacer {
  width: 16px;
  flex-shrink: 0;
}

.provider-account-row.is-task-account {
  background: var(--color-success-bg, rgba(16, 185, 129, 0.08));
  border-color: var(--color-success, #10b981);
}

.provider-account-row.is-rotation-ineligible .provider-account-info {
  opacity: 0.65;
}

/* "Tasks use": a segmented One account | Round robin switch. Native radios
   keep keyboard and screen-reader behavior; the labels draw the segments. */
.provider-task-selection {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin: 0 0 10px;
  padding: 8px 10px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.provider-task-selection-label {
  font-size: 12px;
  font-weight: 600;
}

.provider-task-mode {
  position: relative;
  display: flex;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  overflow: hidden;
}

.provider-task-mode input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.provider-task-mode label {
  padding: 4px 12px;
  font-size: 12px;
  color: var(--color-text-muted);
  cursor: pointer;
}

.provider-task-mode label + input + label {
  border-left: 1px solid var(--color-border);
}

.provider-task-mode input:not(:checked):not(:disabled) + label:hover {
  background: var(--color-bg-hover, var(--color-surface-muted));
  color: var(--color-text);
}

.provider-task-mode input:checked + label {
  background: var(--color-accent, #3f72ff);
  color: #fff;
}

.provider-task-mode input:focus-visible + label {
  outline: 2px solid var(--color-accent, #3f72ff);
  outline-offset: -2px;
}

.provider-task-mode input:disabled + label {
  opacity: 0.55;
  cursor: not-allowed;
}

.provider-task-selection-hint {
  flex: 1 1 240px;
  font-size: 12px;
  color: var(--color-text-muted);
}

.provider-task-selection .btn-small {
  margin-left: auto;
  padding: 4px 10px;
  font-size: 12px;
}

.provider-task-account-input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--color-success, #10b981);
}

.provider-account-email {
  font-size: 12px;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.provider-account-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 12px;
}

.provider-account-actions .btn-small {
  padding: 4px 10px;
  font-size: 12px;
}

.provider-account-actions .btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: all 0.15s ease;
}

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

.provider-account-actions .btn-icon.btn-danger:hover {
  background: var(--color-danger-bg, rgba(239, 68, 68, 0.1));
  color: var(--color-danger, #ef4444);
  border-color: var(--color-danger, #ef4444);
}

.provider-fallback-note {
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1.4;
  margin: -2px 0 10px;
}

.provider-account-warning {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 10px;
  padding: 9px 10px;
  color: var(--color-text);
  font-size: 12px;
  line-height: 1.45;
  background: color-mix(in srgb, var(--color-warning) 10%, var(--color-bg));
  border: 1px solid color-mix(in srgb, var(--color-warning) 55%, var(--color-border));
  border-radius: 6px;
}

.provider-account-warning svg {
  flex: 0 0 auto;
  margin-top: 1px;
  color: var(--color-warning);
}

.ai-provider-manager-desc {
  margin-top: 0;
}

.ai-provider-manager [data-ai-provider-message] {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ai-provider-manager .form-single-column,
.ai-provider-modal-content .form-single-column {
  display: flex;
  flex-direction: column;
  gap: 14px;
  /* settings.css sets align-items: start on .form-single-column for its own
     two-up grid; left as-is here every row would shrink to its content width
     instead of filling the modal. */
  align-items: stretch;
}

.ai-provider-manager .form-row,
.ai-provider-modal-content .form-row {
  display: grid;
  /* 150px keeps the longest label ("API Version (optional)") on one line. */
  grid-template-columns: minmax(150px, 0.35fr) minmax(0, 1fr);
  align-items: center;
  gap: 10px 14px;
}

.ai-provider-manager .form-row label,
.ai-provider-modal-content .form-row label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
}

.ai-provider-manager .form-hint,
.ai-provider-modal-content .form-hint {
  grid-column: 2;
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1.4;
  /* Overrides the negative margin-top settings.css gives .form-hint, which
     pulls the hint into the field above it once the row gap is only 10px. */
  margin: -4px 0 0;
}

.ai-provider-models {
  margin-top: 8px;
}

.ai-provider-runtime-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--color-text);
  font-size: 13px;
}

.ai-provider-model-actions {
  justify-content: flex-end;
}

.ai-provider-add-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}

.ai-provider-tab {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
}

.ai-provider-tab.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

.ai-provider-tab-content {
  display: none;
}

.ai-provider-tab-content.active {
  display: block;
}

/* The Add Account dialog's own result: a key the provider refused, or what the
   key check found when the key was saved anyway. The tone lives in the wash and
   border; the text keeps the body color so it stays readable on light themes. */
.ai-provider-add-notice {
  margin: 0 0 16px;
  padding: 10px 12px;
  color: var(--color-text);
  font-size: 13px;
  line-height: 1.45;
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.ai-provider-add-notice:focus {
  outline: none;
}

.ai-provider-add-notice.is-error {
  background: color-mix(in srgb, var(--color-danger, #e55368) 10%, var(--color-surface));
  border-color: color-mix(in srgb, var(--color-danger, #e55368) 60%, var(--color-border));
}

.ai-provider-add-notice.is-warning {
  background: color-mix(in srgb, var(--color-warning, #f4b740) 12%, var(--color-surface));
  border-color: color-mix(in srgb, var(--color-warning, #f4b740) 60%, var(--color-border));
}

.ai-provider-add-notice.is-info {
  background: color-mix(in srgb, var(--color-accent, #3b82f6) 10%, var(--color-surface));
  border-color: color-mix(in srgb, var(--color-accent, #3b82f6) 50%, var(--color-border));
}

/* Saved with a warning: only the result and Close remain. */
.modal[data-add-saved="true"] .ai-provider-add-tabs,
.modal[data-add-saved="true"] .ai-provider-tab-content {
  display: none;
}

/* Custom-endpoint fields are ordinary form rows: keeping them unboxed lines
   their labels and inputs up with Account Label / API Key / Endpoint Type
   above them. */
.apikey-endpoint-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.apikey-endpoint-fields .form-input {
  margin: 0;
}

@media (max-width: 720px) {
  .provider-auth-header-row,
  .provider-account-row {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .provider-account-actions {
    margin-left: 0;
    flex-wrap: wrap;
  }

  .ai-provider-manager .form-row,
  .ai-provider-modal-content .form-row {
    grid-template-columns: 1fr;
  }

  .ai-provider-manager .form-hint,
  .ai-provider-modal-content .form-hint {
    grid-column: 1;
  }
}

/* Device code sign-in (Add Account): the code with its copy button, where to
   enter it, whether the dialog is still waiting, and the flow switch. */
.ai-provider-device-code-value {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.ai-provider-device-code-copy {
  padding: 4px 10px;
  font-size: 12px;
}

.ai-provider-device-code-where,
.ai-provider-device-code-status {
  margin-top: 8px;
  font-size: 12px;
  color: var(--color-text-secondary, var(--color-text-muted));
}

.ai-provider-device-code-where a {
  color: var(--color-primary-text, var(--color-accent));
  font-weight: 500;
  word-break: break-all;
}

.ai-provider-modal-content .ai-provider-oauth-hint {
  display: block;
  margin: 0;
}

.ai-provider-oauth-alternates {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}

.ai-provider-oauth-alternates[hidden] {
  display: none;
}

.ai-provider-link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-primary-text, var(--color-accent));
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}

.ai-provider-link-button:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
