@use '../../../shared/styles/settings-shared' as settings;

.main-container {
  @include settings.settings-page-container;
}

@include settings.settings-page-header;

.settings-title {
  @include settings.settings-page-title;
  margin-bottom: 0.75rem;
}

.settings-description {
  @include settings.settings-page-description;
}

.settings-card {
  @include settings.settings-card;
}

.section-header {
  @include settings.settings-section-header;
}

.section-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;

  @media (max-width: 767px) {
    flex-direction: column;
    align-items: stretch;

    p-button {
      align-self: flex-end;
    }
  }
}

.section-header-text {
  flex: 1;
}

.section-title {
  @include settings.settings-section-title;
}

.section-description {
  @include settings.settings-section-description;
}

.section-body {
  @include settings.settings-section-body;
}

// Authentication Methods List
.auth-methods-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.auth-method-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
  border: 1px solid var(--p-content-border-color);
  border-left: 3px solid var(--p-content-border-color);
  border-radius: 6px;
  padding: 1rem;
  transition: border-color 0.2s ease, background 0.2s ease;

  &:hover:not(.is-locked) {
    background: color-mix(in srgb, var(--ground-background) 40%, var(--p-surface-800) 60%);
  }

  &.is-active {
    border-left-color: var(--p-green-500);
  }

  &.is-locked {
    opacity: 0.8;
  }

  @media (max-width: 600px) {
    flex-direction: column;
    gap: 0.75rem;
  }
}

.auth-method-content {
  flex: 1;
  min-width: 0;
}

.auth-method-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.auth-method-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
  color: var(--p-primary-color);
  border-radius: 8px;
  flex-shrink: 0;

  .pi {
    font-size: 1rem;
  }

  &.oidc {
    background: color-mix(in srgb, var(--p-orange-500) 15%, transparent);
    color: var(--p-orange-500);
  }
}

.auth-method-info {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.auth-method-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--p-text-color);
}


.auth-method-status {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--p-text-muted-color);

  &.active {
    color: var(--p-green-400);
  }
}

.auth-method-description {
  font-size: 0.875rem;
  color: var(--p-text-muted-color);
  line-height: 1.5;
  margin: 0;
  padding-left: calc(36px + 0.75rem);

  @media (max-width: 600px) {
    padding-left: 0;
  }
}

.config-hint {
  display: block;
  color: var(--p-orange-400);
  font-weight: 500;
  margin-top: 0.25rem;
}

// Configuration Grid
.config-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;

  @media (max-width: 900px) {
    grid-template-columns: 1fr 1fr;
  }

  @media (max-width: 600px) {
    grid-template-columns: 1fr;
  }
}

.config-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;

  @media (max-width: 600px) {
    grid-template-columns: 1fr;
  }
}

.config-item {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;

  &.full-width {
    grid-column: 1 / -1;
  }

  &.span-2 {
    grid-column: span 2;

    @media (max-width: 600px) {
      grid-column: span 1;
    }
  }

  label {
    font-weight: 600;
    color: var(--p-text-color);
    font-size: 0.8125rem;
  }

  input {
    width: 100%;
  }
}

.field-hint {
  font-size: 0.75rem;
  color: var(--p-text-muted-color);
  line-height: 1.4;
}

// Claims Section
.claims-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--p-content-border-color);
}

.subsection-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--p-text-color);
  margin: 0 0 0.25rem 0;
}

.subsection-description {
  font-size: 0.75rem;
  color: var(--p-text-muted-color);
  line-height: 1.4;
  margin: 0 0 0.75rem 0;
}

.claims-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;

  @media (max-width: 900px) {
    grid-template-columns: 1fr 1fr;
  }

  @media (max-width: 600px) {
    grid-template-columns: 1fr;
  }
}

// Provider Actions Row
.provider-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--p-content-border-color);

  @media (max-width: 600px) {
    flex-direction: column;
    align-items: stretch;
  }
}

.test-results-inline {
  flex: 1;
  min-width: 0;
}

.provider-action-buttons {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

// Test Connection Results
.test-results-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  border-radius: 6px;
  background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
  border: 1px solid var(--p-content-border-color);
  cursor: pointer;
  user-select: none;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--p-text-color);
  transition: background 0.15s ease;

  &:hover {
    background: color-mix(in srgb, var(--ground-background) 40%, var(--p-surface-800) 60%);
  }

  .toggle-chevron {
    font-size: 0.75rem;
    color: var(--p-text-muted-color);
    transition: transform 0.2s ease;
    margin-left: auto;

    &.expanded {
      transform: rotate(90deg);
    }
  }
}

.test-results-details {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.5rem 0.875rem 0.625rem;
  border: 1px solid var(--p-content-border-color);
  border-top: none;
  border-radius: 0 0 6px 6px;
  background: color-mix(in srgb, var(--ground-background) 60%, var(--p-surface-800) 40%);
}

.test-check-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.1875rem 0;
  font-size: 0.8125rem;

  .check-name {
    font-weight: 500;
    color: var(--p-text-color);
    white-space: nowrap;
  }

  .check-message {
    color: var(--p-text-muted-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .pi {
    font-size: 0.8125rem;
    flex-shrink: 0;
  }
}

// Provisioning Toggle
.provisioning-toggle {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
  border: 1px solid var(--p-content-border-color);
  border-left: 3px solid var(--p-primary-color);
  border-radius: 6px;
  padding: 1rem;

  @media (max-width: 600px) {
    flex-direction: column;
    gap: 0.75rem;
  }
}

.toggle-content {
  flex: 1;
  min-width: 0;
}

.toggle-info {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  margin-bottom: 0.5rem;
}

.toggle-label {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--p-text-color);
}

.toggle-status {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--p-text-muted-color);

  &.active {
    color: var(--p-green-400);
  }
}

.toggle-description {
  font-size: 0.875rem;
  color: var(--p-text-muted-color);
  line-height: 1.5;
  margin: 0;
}

// Default Settings (Permissions & Libraries)
.default-settings {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--p-content-border-color);
}

.permissions-group,
.libraries-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.group-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--p-text-color);
  margin: 0;
}

.permissions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.625rem;
  padding-left: 0.5rem;
}

.permission-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;

  label {
    font-size: 0.875rem;
    color: var(--p-text-color);
    cursor: pointer;
  }
}

.libraries-select {
  width: 100%;
  max-width: 400px;
}

// Info Panel
.info-panel-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.info-panel-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.info-panel-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--p-text-muted-color);
}

.info-panel-value-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.info-panel-value {
  flex: 1;
  font-size: 0.8125rem;
  padding: 0.375rem 0.625rem;
  background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
  border: 1px solid var(--p-content-border-color);
  border-radius: 4px;
  color: var(--p-text-color);
  word-break: break-all;
}
