/* Native-style settings window */
.settings-shell {
  --settings-bg: var(--bg-secondary);
  --settings-surface: var(--surface-hover);
  --settings-surface-inset: var(--surface);
  --settings-border: var(--overlay-medium);
  --settings-border-strong: var(--overlay-heavy);
  --settings-text: var(--text);
  --settings-text-secondary: var(--text-dim);
  --settings-accent: var(--semantic-info);
  --settings-green: var(--status-live);
  --settings-yellow: var(--yellow);
  --settings-red: var(--semantic-critical);

  height: 100vh;
  background: var(--settings-bg);
  color: var(--settings-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  padding: 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Tab bar — macOS segmented control style */
.settings-tabs {
  display: flex;
  justify-content: center;
  gap: 0;
  padding: 12px 16px 0;
  background: var(--settings-bg);
  border-bottom: 1px solid var(--settings-border);
}

.settings-tab {
  background: none;
  border: 1px solid var(--settings-border-strong);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  color: var(--settings-text-secondary);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 7px 20px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  margin-bottom: -1px;
}

.settings-tab:hover {
  color: var(--settings-text);
  background: var(--overlay-subtle);
}

.settings-tab.active {
  color: var(--settings-text);
  background: var(--settings-surface);
  border-bottom-color: var(--settings-surface);
}

/* Status bar */
.settings-action-status {
  margin: 0;
  padding: 0 20px;
  min-height: 20px;
  line-height: 20px;
  font-size: 11px;
  color: var(--settings-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-action-status.ok { color: var(--settings-green); }
.settings-action-status.error { color: var(--settings-red); }

/* Tab panels */
.settings-tab-panels {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 20px;
}

.settings-tab-panel {
  display: none;
}

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

.settings-content {
  min-height: 0;
}

/* Runtime config panel overrides for settings window */
.settings-runtime-panel {
  cursor: default;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  border: none;
  background: none;
}

.settings-runtime-panel .panel-header {
  display: none;
}

.settings-runtime-panel .panel-resize-handle {
  display: none;
}

.settings-runtime-panel .panel-content {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: visible;
  padding: 0;
}

.settings-runtime-panel .runtime-config-summary {
  font-size: 12px;
  color: var(--settings-text-secondary);
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--settings-surface);
  border-radius: 8px;
}

.settings-runtime-panel .runtime-config-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 8px;
}

.settings-runtime-panel .runtime-feature {
  margin: 0;
  background: var(--settings-surface);
  border: 1px solid var(--settings-border);
  border-radius: 8px;
  padding: 10px 12px;
}

.settings-runtime-panel .runtime-feature.available {
  border-color: var(--settings-border);
}

.settings-runtime-panel .runtime-feature-header label {
  font-size: 13px;
  font-weight: 500;
}

.settings-runtime-panel .runtime-pill {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
}

.settings-runtime-panel .runtime-pill.ok {
  color: var(--settings-green);
  border-color: color-mix(in srgb, var(--settings-green) 30%, transparent);
}

.settings-runtime-panel .runtime-pill.warn {
  color: var(--settings-yellow);
  border-color: color-mix(in srgb, var(--settings-yellow) 30%, transparent);
}

.settings-runtime-panel .runtime-pill.staged {
  color: var(--settings-green);
  border-color: color-mix(in srgb, var(--settings-green) 30%, transparent);
  opacity: 0.7;
}

.settings-runtime-panel .runtime-secret-row input {
  background: var(--settings-surface-inset);
  border: 1px solid var(--settings-border-strong);
  border-radius: 6px;
  color: var(--settings-text);
  padding: 6px 10px;
  font-size: 12px;
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
  transition: border-color 0.15s;
}

.settings-runtime-panel .runtime-secret-row input:focus {
  outline: none;
  border-color: var(--settings-accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--settings-accent) 25%, transparent);
}

.settings-runtime-panel .runtime-secret-row input::placeholder {
  color: var(--text-ghost);
}

.settings-runtime-panel .runtime-secret-meta {
  color: var(--text-faint);
}

.settings-runtime-panel .runtime-secret-status.ok {
  color: var(--settings-green);
}

.settings-runtime-panel .runtime-secret-status.warn {
  color: var(--settings-yellow);
}

.settings-runtime-panel .runtime-secret-status.staged {
  color: var(--settings-green);
  opacity: 0.7;
}

.settings-runtime-panel .runtime-feature-fallback.fallback {
  color: var(--settings-yellow);
}

.settings-runtime-panel input[type="checkbox"] {
  accent-color: var(--settings-accent);
}

/* Validation feedback */
.runtime-secret-check {
  color: var(--settings-green);
  font-size: 14px;
  margin-left: 6px;
  display: none;
}

.runtime-secret-check.visible {
  display: inline;
}

.runtime-secret-hint {
  color: var(--settings-red);
  font-size: 11px;
}

.settings-runtime-panel .runtime-secret-row input.valid-staged {
  border-color: color-mix(in srgb, var(--settings-green) 50%, transparent);
}

.settings-runtime-panel .runtime-secret-row input.invalid {
  border-color: var(--settings-red);
}

/* Signup link icon */
.runtime-secret-key {
  display: flex;
  align-items: center;
  gap: 4px;
  grid-area: key;
}

.runtime-secret-link {
  color: var(--settings-text-secondary);
  text-decoration: none;
  font-size: 12px;
  line-height: 1;
  opacity: 0.5;
  transition: opacity 0.15s, color 0.15s;
}

.runtime-secret-link:hover {
  color: var(--settings-accent);
  opacity: 1;
}

/* Footer with OK / Cancel */
.settings-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--settings-border);
  background: var(--settings-bg);
  flex-shrink: 0;
}

.settings-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 20px;
  border-radius: 6px;
  cursor: pointer;
  min-width: 70px;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
}

.settings-btn-secondary {
  background: var(--settings-surface);
  border: 1px solid var(--settings-border-strong);
  color: var(--settings-text);
}

.settings-btn-secondary:hover {
  background: var(--overlay-medium);
}

.settings-btn-primary {
  background: var(--settings-accent);
  border: 1px solid var(--settings-accent);
  color: var(--accent);
}

.settings-btn-primary:hover {
  background: color-mix(in srgb, var(--settings-accent) 85%, black);
  border-color: color-mix(in srgb, var(--settings-accent) 85%, black);
}

/* Debug tab */
.debug-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.debug-actions button {
  border: 1px solid var(--settings-border-strong);
  background: var(--settings-surface);
  color: var(--settings-text);
  font: inherit;
  font-size: 12px;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.debug-actions button:hover {
  background: var(--overlay-medium);
}

/* Diagnostics */
.settings-diagnostics {
  border: 1px solid var(--settings-border);
  background: var(--settings-surface);
  border-radius: 8px;
  padding: 12px 14px;
}

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

.diag-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.diag-toggles {
  display: flex;
  gap: 16px;
}

.diag-toggles label {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  color: var(--settings-text-secondary);
}

.diag-toggles input[type="checkbox"] {
  accent-color: var(--settings-accent);
}

.diag-traffic-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.diag-traffic-bar h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--settings-text-secondary);
}

.diag-traffic-bar h3 span {
  opacity: 0.6;
}

.diag-traffic-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.diag-traffic-controls label {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--settings-text-secondary);
  cursor: pointer;
}

.diag-traffic-controls button {
  border: 1px solid var(--settings-border-strong);
  background: var(--settings-surface-inset);
  color: var(--settings-text-secondary);
  font: inherit;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.diag-traffic-controls button:hover {
  background: var(--overlay-light);
  color: var(--settings-text);
}

.diag-traffic-log {
  max-height: 300px;
  overflow-y: auto;
  font-size: 11px;
}

.diag-empty {
  color: var(--settings-text-secondary);
  font-style: italic;
  margin: 10px 0;
  font-size: 12px;
}

.diag-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
  font-size: 11px;
}

.diag-table th {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid var(--settings-border);
  color: var(--settings-text-secondary);
  font-weight: 500;
  font-size: 10px;
  position: sticky;
  top: 0;
  background: var(--settings-surface);
}

.diag-table td {
  padding: 3px 8px;
  border-bottom: 1px solid var(--overlay-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

.diag-table td:nth-child(3) {
  max-width: 260px;
}

tr.diag-ok td { color: var(--settings-text-secondary); }
tr.diag-warn td { color: var(--settings-yellow); }
tr.diag-err td { color: var(--settings-red); }

@media (max-width: 860px) {
  .debug-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .settings-runtime-panel .runtime-config-list {
    grid-template-columns: 1fr;
  }
}
