/* ─── Profile / Settings Tabs ──────────────────────
   Extracted from inline <style> in app/views/shared/_settings_tabs.html.erb
   and app/views/profiles/show.html.erb. Body-level <style> tags caused
   layout shifts on Turbo navigation because the rules only applied after
   the new body parsed, briefly leaving fixed-positioning ancestors in an
   uncomputed state. Loading these from the stylesheet keeps them stable
   across navigations. */

/* ─── Settings Tabs (shared) ─────────────────── */
.settings-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0;
  /* Allow horizontal scroll on narrow viewports so labels like
     "Personalization" don't clip the row. */
  overflow-x: auto;
  scrollbar-width: none;
}

.settings-tabs::-webkit-scrollbar {
  display: none;
}

.settings-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: var(--font-body);
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .settings-tabs {
    margin-bottom: 1rem;
    /* Negative inset so the scrollable row spans the page padding —
       lets the active tab indicator reach the screen edge cleanly. */
    margin-left: -1rem;
    margin-right: -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .settings-tab {
    gap: 0.375rem;
    padding: 0.5rem 0.625rem;
    font-size: 0.75rem;
  }

  .settings-tab svg {
    width: 13px;
    height: 13px;
  }
}

.settings-tab svg {
  opacity: 0.5;
  transition: opacity 0.15s ease;
}

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

.settings-tab:hover svg {
  opacity: 0.7;
}

.settings-tab.active {
  color: var(--gold-primary);
  border-bottom-color: var(--gold-primary);
}

.settings-tab.active svg {
  opacity: 1;
  color: var(--gold-primary);
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  animation: settingsFadeIn 0.2s ease;
}

@keyframes settingsFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Profile container ──────────────────────── */
.settings-container {
  max-width: none;
}

.panel-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

.panel-column {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.panel-section {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 1.25rem;
}

.panel-section-header {
  margin-bottom: 1.25rem;
  padding-bottom: 0.875rem;
  border-bottom: 1px solid var(--border-subtle);
}

.panel-section-header h3 {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.25rem;
  letter-spacing: 0.01em;
}

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

.panel-section .form-group {
  margin-bottom: 1rem;
}

.panel-section .form-group:last-child {
  margin-bottom: 0;
}

/* ─── Profile Identity ─────────────────────── */
.profile-identity {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.875rem;
  background: var(--bg-base);
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.profile-avatar {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  border: 2px solid var(--border-subtle);
  background: var(--bg-base);
}

.profile-name {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.profile-email {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

/* ─── Connection Cards ─────────────────────── */
.connections-list {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
}

.connection-card {
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  overflow: hidden;
}

.connection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.connection-service {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  font-size: 0.8125rem;
  color: var(--text-primary);
}

.connection-service svg {
  color: var(--text-muted);
}

.connection-body {
  padding: 0.625rem 0.75rem;
}

.connection-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.connection-result {
  margin-top: 0.75rem;
  padding: 0.625rem 0.875rem;
  border-radius: 6px;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.connection-result.result-success {
  background: var(--success-bg);
  border: 1px solid rgba(34, 197, 94, 0.2);
  color: var(--success);
}

.connection-result.result-error {
  background: var(--error-bg);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: var(--error);
}

.connection-result-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

/* ─── Memory ─────────────────────────────── */
.memory-facts-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.memory-fact-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  font-size: 0.8125rem;
  color: var(--text-primary);
}

.memory-fact-text {
  flex: 1;
  line-height: 1.4;
}

.btn-memory-delete {
  background: none;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.6875rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.btn-memory-delete:hover {
  color: var(--error);
  border-color: var(--error);
  background: var(--error-bg);
}

.memory-empty-state {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
  background: var(--bg-base);
  border: 1px dashed var(--border-subtle);
  border-radius: 8px;
}

.memory-empty-state p {
  margin: 0;
}

/* ─── Form Actions ──────────────────────────── */
.settings-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding-top: 1.5rem;
  margin-top: 1.5rem;
  border-top: 1px solid var(--border-subtle);
}

.panel-columns-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

#tab-personalization .panel-columns-3 {
  align-items: stretch;
}

.panel-column-stretch {
  display: flex;
  flex-direction: column;
}

.panel-section-stretch {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.panel-section-stretch .form-group-stretch {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
}

.form-textarea-stretch {
  flex: 1;
  resize: vertical;
  min-height: 120px;
}

/* ─── Theme Selector ─────────────────────────── */
.theme-selector {
  display: flex;
  gap: 0.75rem;
}

.theme-option {
  flex: 1;
  cursor: pointer;
  border: 2px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.5rem;
  transition: all 0.2s ease;
  text-align: center;
}

.theme-option:hover {
  border-color: var(--border-medium);
}

.theme-option.active {
  border-color: var(--gold-primary);
  box-shadow: 0 0 0 1px var(--gold-primary);
}

.theme-radio-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-preview {
  display: flex;
  height: 48px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.375rem;
}

.theme-preview-sidebar {
  width: 20%;
  min-width: 16px;
}

.theme-preview-content {
  flex: 1;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.theme-preview-header {
  height: 6px;
  border-radius: 2px;
  width: 50%;
}

.theme-preview-line {
  height: 4px;
  border-radius: 2px;
  width: 80%;
}

.theme-preview-line.short {
  width: 55%;
}

/* Themis Dark preview */
.theme-preview-themis_dark {
  background: #161719;
}
.theme-preview-themis_dark .theme-preview-sidebar {
  background: #0e1012;
  border-right: 1px solid #2e3036;
}
.theme-preview-themis_dark .theme-preview-header {
  background: #d4a853;
}
.theme-preview-themis_dark .theme-preview-line {
  background: #2e3036;
}

/* Themis Light preview */
.theme-preview-themis_light {
  background: #faf9f7;
}
.theme-preview-themis_light .theme-preview-sidebar {
  background: #f5f4f1;
  border-right: 1px solid #e2dfd8;
}
.theme-preview-themis_light .theme-preview-header {
  background: #8b6914;
}
.theme-preview-themis_light .theme-preview-line {
  background: #e2dfd8;
}

/* Themis Minimal preview */
.theme-preview-themis_minimal {
  background: #ffffff;
}
.theme-preview-themis_minimal .theme-preview-sidebar {
  background: #f4f4f5;
  border-right: 1px solid #e4e4e7;
}
.theme-preview-themis_minimal .theme-preview-header {
  background: #18181b;
}
.theme-preview-themis_minimal .theme-preview-line {
  background: #e4e4e7;
}

.theme-option-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.theme-option.active .theme-option-label {
  color: var(--gold-primary);
}

/* ─── Responsive ────────────────────────────── */
@media (max-width: 960px) {
  .panel-columns-3,
  .connections-list {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .panel-columns,
  .panel-columns-3,
  .connections-list {
    grid-template-columns: 1fr;
  }
}
