/* Settings page layout */
.page {
  width: 900px;
  max-width: 100%;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}

.pageTitle {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

/* Tabs */
.tabBar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-default);
  margin-bottom: var(--space-5);
  overflow-x: auto;
}

.tab {
  padding: var(--space-2-5) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-tertiary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease;
  display: flex;
  align-items: center;
  gap: var(--space-1-5);
}

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

.tabActive {
  color: var(--text-primary);
  border-bottom-color: var(--accent-primary);
}

/* Sections */
.section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}

.sectionHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.sectionTitle {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-1-5);
}

.sectionHeaderActions {
  display: flex;
  gap: var(--space-1-5);
}

.sectionHeaderBtn {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px 10px;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-default);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.sectionHeaderBtn:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.sectionHint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-bottom: var(--space-4);
}

/* Provider list */
.providerList {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.providerCard {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-default);
  transition: border-color 0.15s ease;
}

.providerCard:hover {
  border-color: var(--border-hover);
}

.providerIcon {
  font-size: var(--text-lg);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

.providerLogoImg {
  width: 28px !important;
  height: 28px !important;
  max-width: 28px;
  max-height: 28px;
  object-fit: contain;
  display: block;
}

.providerInfo {
  flex: 1;
  min-width: 0;
}

.providerName {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
}

.providerMeta {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}

.providerActions {
  display: flex;
  gap: var(--space-1);
  flex-shrink: 0;
}

.emptyState {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}

/* Provider type selection grid */
.providerTypeGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.providerTypeCard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-3);
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  text-align: center;
}

.providerTypeCard:hover {
  border-color: var(--accent-primary);
  background: var(--bg-tertiary);
}

.providerTypeIcon {
  font-size: var(--text-xl);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  margin-bottom: var(--space-3);
  color: var(--text-primary);
}

.providerTypeLogo {
  width: 40px !important;
  height: 40px !important;
  max-width: 40px;
  max-height: 40px;
  object-fit: contain;
  display: block;
}

.providerTypeName {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
}

.providerTypeDesc {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.3;
}

/* Form */
.formSection {
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}

.formSection :global(.formGroup) {
  margin-bottom: var(--space-4);
}

.formSection :global(.formGroup):last-child {
  margin-bottom: 0;
}

.formHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.apiKeyLink {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--accent-primary);
  text-decoration: none;
  margin-bottom: var(--space-4);
}

.apiKeyLink:hover {
  text-decoration: underline;
}

.formTitle {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-3);
}

.formActions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-default);
}

/* Secret input */
.secretInputWrapper {
  position: relative;
}

.secretInputWrapper input {
  padding-right: var(--space-8);
}

.secretToggle {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: var(--space-1);
  display: flex;
  align-items: center;
}

.secretToggle:hover {
  color: var(--text-primary);
}

/* Headers editor */
.headerRow {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1-5) var(--space-2);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-1);
}

.headerKey {
  font-size: var(--text-xs);
  color: var(--accent-primary);
  font-weight: var(--font-medium);
}

.headerValue {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  flex: 1;
}

.headerRemove {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
}

.headerRemove:hover {
  color: var(--text-error);
}

.headerAdd {
  display: flex;
  gap: var(--space-1);
  align-items: center;
}

/* Advanced params grid */
.advancedGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
}

.reasoningControl {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(140px, 180px);
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-default);
}

.reasoningControl :global(.formHint) {
  grid-column: 1 / -1;
  margin: 0;
}

.reasoningControl select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

/* Test connection */
.testSection {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.testResult {
  display: flex;
  /* flex-start, not center: a diagnostic message can be several lines and the
     icon must stay on the first one. */
  align-items: flex-start;
  gap: var(--space-1-5);
  font-size: var(--text-xs);
  line-height: 1.5;
  padding: var(--space-1-5) var(--space-2);
  border-radius: var(--radius-default);
  max-width: 500px;
  /* Wrap rather than clip: the agent-unreachable message names the command to
     run, so truncating it would defeat the point (issue #184). */
  overflow-wrap: anywhere;
}

.testResult svg {
  flex-shrink: 0;
  margin-top: 0.15em;
}

.testSuccess {
  color: var(--text-success);
  background: var(--bg-success-subtle);
}

.testError {
  color: var(--text-error);
  background: var(--bg-error-subtle);
}

/* Spinner */
.spin {
  animation: spin 1s linear infinite;
}

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

/* Checkbox label */
.checkboxLabel {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.checkboxLabel input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
  accent-color: var(--color-primary, #e53e3e);
}

/* Settings fields grid */
.settingsGrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

/* Segmented control (used by Bedrock auth method picker) */
.segmentedControl {
  display: inline-flex;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-default);
  overflow: hidden;
  background: var(--bg-tertiary);
}

.segmentedOption {
  padding: var(--space-1-5) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--text-tertiary);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.segmentedOption + .segmentedOption {
  border-left: 1px solid var(--border-default);
}

.segmentedOption:hover {
  color: var(--text-secondary);
}

.segmentedOptionActive {
  color: var(--text-primary);
  background: var(--bg-secondary);
}

/* Agent-offline preflight (issue #184). Shown above the Test button when the
   agent container is unreachable, so an infrastructure outage is not read as a
   fault in the endpoint the operator just configured. */
.agentOfflineBanner {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-2-5);
  border-radius: var(--radius-default);
  font-size: var(--text-xs);
  line-height: 1.5;
  color: var(--status-warning-text);
  background: var(--status-warning-bg);
  border: 1px solid var(--status-warning);
}

.agentOfflineBanner svg {
  flex-shrink: 0;
}

.agentOfflineRetry {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
  margin-left: auto;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--status-warning);
  border-radius: var(--radius-default);
  background: transparent;
  color: inherit;
  font-size: var(--text-xs);
  cursor: pointer;
}

.agentOfflineRetry:hover {
  background: var(--bg-hover);
}
