/* Settings Page Styles */

/* ============================================================
   CONTENT CARDS (shared with environments)
   ============================================================ */

.content-card {
  background: var(--color-surface);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-card);
  overflow: visible;
}

.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h3,
.card-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
}

.card-body {
  padding: 24px;
}

/* ============================================================
   FORM ELEMENTS
   ============================================================ */

.form-single-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 700px;
}

.form-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 16px;
  align-items: center;
}

.form-row label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  text-align: left;
}

.form-row .form-input,
.form-row .form-textarea {
  margin: 0;
}

.form-hint {
  grid-column: 2;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: -12px;
  line-height: 1.4;
}

.form-hint code {
  background: var(--color-surface-elevated);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
  font-size: 11px;
}

/* Subsections within cards */
.subsection {
  padding: 16px 0;
  border-top: 1px solid var(--color-border);
}

.subsection:first-child {
  padding-top: 0;
  border-top: none;
}

.subsection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.subsection-header h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}

.subsection-header .toggle-switch {
  flex-shrink: 0;
}

/* Keepalive agent sections */
#keepalive-agents-container {
  display: flex;
  flex-direction: column;
  max-width: 500px;
}

.keepalive-agent-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--color-border);
}

.keepalive-agent-section:first-child {
  padding-top: 0;
}

.keepalive-agent-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.keepalive-agent-header,
.keepalive-agent-row {
  display: grid;
  grid-template-columns: 180px 120px;
  align-items: center;
}

.keepalive-agent-header {
  margin-bottom: 10px;
}

.keepalive-agent-header h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}

.keepalive-agent-row {
  margin-bottom: 6px;
}

.keepalive-agent-row label {
  font-size: 13px;
  color: var(--color-text-muted);
}

.keepalive-agent-row .form-input {
  width: 100%;
}

.keepalive-agent-status {
  margin-left: 180px;
  font-size: 12px;
  color: var(--color-text-muted);
}

.apikey-test-btn {
  flex-shrink: 0;
}

/* API key endpoint extensions */
.apikey-endpoint-section {
  margin-top: 10px;
}

.apikey-endpoint-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.apikey-endpoint-label {
  font-size: 12px;
  color: var(--color-text-muted);
}

.apikey-endpoint-fields {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-medium);
  background: var(--color-surface-muted);
}

.apikey-endpoint-field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text);
}

.apikey-endpoint-fields .form-input {
  margin: 0;
  font-size: 13px;
}

.apikey-endpoint-field-hint {
  grid-column: auto;
  margin-top: 0;
}

/* ============================================================
   LAYOUT
   ============================================================ */

.settings-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 32px;
  min-height: calc(100vh - 200px);
}

@media (max-width: 768px) {
  .settings-layout {
    grid-template-columns: 1fr;
  }

  .settings-sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--color-surface);
    padding-bottom: 12px;
    padding-right: 0;
    border-bottom: 1px solid var(--color-border);
    max-height: none;
    overflow: visible;
    scrollbar-gutter: auto;
  }

  .settings-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .settings-nav-label {
    width: 100%;
  }

  .settings-nav-item {
    flex: 0 0 auto;
  }
}

/* ============================================================
   SIDEBAR NAVIGATION
   ============================================================ */

.settings-sidebar {
  position: sticky;
  top: 24px;
  align-self: start;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.settings-nav-label {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 0 12px;
  color: var(--color-text);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  line-height: 1.15;
  opacity: 0.78;
  text-transform: uppercase;
}

.settings-nav-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.settings-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: none;
  border: none;
  border-radius: var(--radius-medium);
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  width: 100%;
}

.settings-nav-item:hover {
  background: var(--color-surface-muted);
  color: var(--color-text);
}

.settings-nav-item.active {
  background: var(--color-accent);
  color: white;
}

.settings-nav-item.active svg {
  stroke: white;
}

.settings-nav-item svg {
  flex-shrink: 0;
  transition: stroke 0.2s ease;
}

/* ============================================================
   PANELS
   ============================================================ */

.settings-panels {
  min-width: 0;
}

.settings-panel {
  display: none;
}

.settings-panel.active {
  display: block;
}

/* ============================================================
   CARD ACTIONS
   ============================================================ */

.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-muted);
}

/* Responsive form layout */
@media (max-width: 640px) {
  .form-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .form-hint {
    grid-column: 1;
    margin-top: 0;
  }
}

/* ============================================================
   AI PROVIDERS
   ============================================================ */

.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-surface-muted);
}

.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);
}

.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-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.provider-account-row.is-default {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.45);
}

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

.provider-account-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.account-label-text {
  font-weight: 500;
  font-size: 13px;
  color: var(--color-text);
}

.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-round-robin-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
  border-radius: 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(var(--color-accent-rgb), 0.14);
  color: var(--color-accent);
}

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

.account-active-check {
  color: var(--color-success, #10b981);
  flex-shrink: 0;
}

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

.provider-account-email {
  color: var(--color-text-muted);
  font-size: 12px;
  white-space: normal;
  overflow-wrap: anywhere;
}

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

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

.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;
}

/* ============================================================
   GIT PROVIDERS
   ============================================================ */

.git-providers-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.git-provider-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--color-surface-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-medium);
}

.git-provider-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.git-provider-name {
  font-weight: 500;
  font-size: 14px;
}

.git-provider-type {
  color: var(--color-text-muted);
  font-size: 13px;
  padding: 2px 8px;
  background: var(--color-surface);
  border-radius: var(--radius-small);
}

.git-provider-actions {
  display: flex;
  gap: 4px;
}

/* ============================================================
   LOADING STATE
   ============================================================ */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px;
  color: var(--color-text-muted);
}

.loading-spinner {
  animation: spin 1s linear infinite;
}

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

/* ============================================================
   FORM ENHANCEMENTS
   ============================================================ */

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
}

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

/* ============================================================
   TEXT UTILITIES
   ============================================================ */

.text-muted {
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 1.5;
}

/* ============================================================
   KEEPALIVE STATUS
   ============================================================ */

.keepalive-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.keepalive-status-row span {
  font-size: 12px;
  color: var(--color-text-muted);
}

/* ============================================================
   TOKEN EXPIRY CONTROLS
   ============================================================ */

.token-expiry-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.token-expiry-suffix {
  font-size: 14px;
  color: var(--color-text-muted);
}

.setup-repo-auth-controls {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

#setup-repo-auth-mode {
  min-width: 240px;
  max-width: 320px;
}

.setup-repo-auth-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

#setup-repo-auth-provider {
  max-width: 360px;
}

.setup-repo-auth-test-result {
  padding: 10px 14px;
  border-radius: var(--radius-medium);
  border: 1px solid var(--color-border);
  background: var(--color-surface-muted);
  font-size: 13px;
  line-height: 1.4;
}

.setup-repo-auth-test-result.success {
  border-color: rgba(16, 185, 129, 0.45);
  background: rgba(16, 185, 129, 0.08);
  color: var(--color-success, #10b981);
}

.setup-repo-auth-test-result.working {
  border-color: rgba(var(--color-accent-rgb), 0.35);
  background: rgba(var(--color-accent-rgb), 0.08);
  color: var(--color-accent);
}

.setup-repo-auth-test-result.working::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin 0.8s linear infinite;
}

.setup-repo-auth-test-result.error {
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.08);
  color: var(--color-danger, #ef4444);
}

#test-setup-repo-auth-btn.is-working {
  position: relative;
  padding-right: 34px;
  pointer-events: none;
}

#test-setup-repo-auth-btn.is-working::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============================================================
   EMAIL TEST RESULT
   ============================================================ */

.email-test-result {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-medium);
  font-size: 13px;
  background: var(--color-surface-muted);
  border: 1px solid var(--color-border);
}

.email-test-result.success {
  background: var(--color-success-bg, rgba(34, 197, 94, 0.1));
  border-color: var(--color-success, #22c55e);
  color: var(--color-success, #22c55e);
}

.email-test-result.error {
  background: var(--color-error-bg, rgba(239, 68, 68, 0.1));
  border-color: var(--color-error, #ef4444);
  color: var(--color-error, #ef4444);
}

/* ============================================================
   CODE FONT
   ============================================================ */

.code-font {
  font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
  font-size: 13px;
}

/* ============================================================
   MODAL DROPDOWN FIX - Use fixed positioning for dropdowns
   ============================================================ */

/* Allow settings modal dropdowns to escape modal boundaries using fixed positioning */
#git-provider-modal .custom-select-dropdown,
#github-app-setup-wizard-modal .custom-select-dropdown {
  position: fixed;
  z-index: 10001;
}

/* ============================================================
   INLINE ERROR/SUCCESS MESSAGES
   ============================================================ */

.inline-message {
  padding: 10px 14px;
  border-radius: var(--radius-medium);
  font-size: 13px;
  margin-bottom: 16px;
}

.inline-message.error {
  background: var(--color-error-bg, rgba(239, 68, 68, 0.1));
  border: 1px solid var(--color-error, #ef4444);
  color: var(--color-error, #ef4444);
}

.inline-message.success {
  background: var(--color-success-bg, rgba(34, 197, 94, 0.1));
  border: 1px solid var(--color-success, #22c55e);
  color: var(--color-success, #22c55e);
}

.inline-message.info {
  background: var(--color-accent-muted, rgba(59, 130, 246, 0.1));
  border: 1px solid var(--color-accent, #3b82f6);
  color: var(--color-accent, #3b82f6);
}

/* ============================================================
   SSO TABS
   ============================================================ */

.sso-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0;
}

.sso-tab {
  padding: 10px 16px;
  background: none;
  border: none;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: -1px;
  transition: all 0.2s ease;
}

.sso-tab:hover {
  color: var(--color-text);
}

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

.sso-tab-content {
  display: none;
}

.sso-tab-content.active {
  display: block;
}

.sso-field-description {
  font-size: 12px;
  color: var(--color-text-muted);
  margin: -12px 0 16px 0;
  padding-left: 216px; /* 200px label + 16px gap */
  line-height: 1.4;
}

@media (max-width: 640px) {
  .sso-field-description {
    padding-left: 0;
    margin-top: -4px;
  }

  .setup-repo-auth-controls {
    flex-wrap: wrap;
  }

  #setup-repo-auth-mode {
    flex-basis: 100%;
    width: 100%;
  }
}

/* SSO Test Result */
.sso-test-result {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-medium);
  font-size: 13px;
  background: var(--color-surface-muted);
  border: 1px solid var(--color-border);
}

.sso-test-result.success {
  background: var(--color-success-bg, rgba(34, 197, 94, 0.1));
  border-color: var(--color-success, #22c55e);
  color: var(--color-success, #22c55e);
}

.sso-test-result.error {
  background: var(--color-error-bg, rgba(239, 68, 68, 0.1));
  border-color: var(--color-error, #ef4444);
  color: var(--color-error, #ef4444);
}

/* ============================================================
   PROVIDER TYPE SELECTION
   ============================================================ */

.provider-type-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.provider-type-option {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-medium);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  width: 100%;
}

.provider-type-option:hover {
  background: var(--color-surface-muted);
  border-color: var(--color-border-strong);
}

.provider-type-option:active {
  transform: scale(0.98);
}

.provider-type-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--color-surface-muted);
  border-radius: var(--radius-medium);
  color: var(--color-text);
}

.provider-type-icon svg {
  width: 24px;
  height: 24px;
}

.provider-type-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.provider-type-info strong {
  font-size: 14px;
  color: var(--color-text);
}

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

/* Medium modal size for wizards */
.modal-content.modal-medium {
  max-width: 560px;
}

/* ============================================================
   MODAL INLINE MESSAGES
   ============================================================ */

.modal-inline-message {
  padding: 10px 14px;
  border-radius: var(--radius-medium);
  font-size: 13px;
  margin-bottom: 16px;
}

.modal-inline-message.error {
  background: var(--color-error-bg, rgba(239, 68, 68, 0.1));
  border: 1px solid var(--color-error, #ef4444);
  color: var(--color-error, #ef4444);
}

.modal-inline-message.success {
  background: var(--color-success-bg, rgba(34, 197, 94, 0.1));
  border: 1px solid var(--color-success, #22c55e);
  color: var(--color-success, #22c55e);
}

/* ============================================================
   CA CERTIFICATES
   ============================================================ */

.ca-certificates-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ca-cert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--color-surface-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-medium);
}

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

.ca-cert-name-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.ca-cert-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--color-text);
}

.ca-cert-subject {
  font-size: 13px;
  color: var(--color-text-muted);
}

.ca-cert-expiry {
  font-size: 13px;
  color: var(--color-text-muted);
}

.ca-cert-expiry.expiring-soon {
  color: var(--color-warning, #f59e0b);
}

.ca-cert-expiry.expired {
  color: var(--color-error, #ef4444);
}

.ca-cert-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* Certificate Viewer Modal */
.cert-viewer {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.cert-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cert-section h4 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cert-fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-left: 12px;
  border-left: 2px solid var(--color-border);
}

.cert-field {
  display: flex;
  gap: 8px;
  font-size: 13px;
  line-height: 1.4;
}

.cert-field dt {
  color: var(--color-text-muted);
  min-width: 180px;
  flex-shrink: 0;
}

.cert-field dd {
  color: var(--color-text);
  word-break: break-word;
  margin: 0;
}

.fingerprint {
  font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
  font-size: 11px;
  word-break: break-all;
}

.cert-expired {
  color: var(--color-error, #ef4444);
}

/* Empty state */
.ca-certificates-empty {
  text-align: center;
  padding: 32px;
  color: var(--color-text-muted);
  font-size: 14px;
}

/* Certificate file import */
.ca-cert-file-import {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.ca-cert-file-import input[type="file"] {
  display: none;
}

.ca-cert-file-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--color-surface-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-medium);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ca-cert-file-label:hover {
  background: var(--color-surface);
  border-color: var(--color-border-strong);
}

.ca-cert-file-name {
  font-size: 13px;
  color: var(--color-text-muted);
}
