/* ===========================================
   Config Page
   =========================================== */

/* Layout Container */
.config-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  height: calc(100vh - 160px);
  margin: 0 -16px -32px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--panel);
  overflow: hidden;
  overflow: clip;
  animation: config-enter 0.3s var(--ease-out);
}

@keyframes config-enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile: adjust margins to match mobile .content padding (4px 4px 16px) */
@media (max-width: 600px) {
  .config-layout {
    margin: 0;
    /* safest: no negative margin cancellation on mobile */
  }
}

/* Small mobile: even smaller padding */
@media (max-width: 400px) {
  .config-layout {
    margin: 0;
  }
}

/* Search */
.config-search {
  display: grid;
  gap: 5px;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
}

.config-search__input-row {
  position: relative;
}

.config-search__icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

.config-search__input {
  width: 100%;
  padding: 8px 34px 8px 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  font-size: 12.5px;
  outline: none;
  transition:
    border-color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease,
    background var(--duration-fast) ease;
}

.config-search__input::placeholder {
  color: var(--muted);
}

.config-search__input:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
  background: var(--bg-hover);
}

:root[data-theme-mode="light"] .config-search__input {
  background: white;
}

:root[data-theme-mode="light"] .config-search__input:focus {
  background: white;
}

.config-search__clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.config-search__clear:hover {
  background: var(--border-strong);
  color: var(--text);
}

/* Mode Toggle */
.config-mode-toggle {
  display: flex;
  padding: 3px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  gap: 1px;
}

:root[data-theme-mode="light"] .config-mode-toggle {
  background: white;
}

.config-mode-toggle__btn {
  flex: 1;
  padding: 6px 12px;
  border: none;
  border-radius: calc(var(--radius-md) - 3px);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background var(--duration-fast) ease,
    color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
}

.config-mode-toggle__btn:hover:not(.active) {
  color: var(--text);
  background: var(--bg-hover);
}

.config-mode-toggle__btn.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 1px 3px var(--accent-subtle);
}

/* ===========================================
   Main Content
   =========================================== */

.config-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--panel);
  overflow: hidden;
  /* fallback for older browsers */
  overflow: clip;
}

/* Actions Bar */
.config-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: var(--bg-accent);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

:root[data-theme-mode="light"] .config-actions {
  background: var(--bg-hover);
}

.config-actions__left,
.config-actions__right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.config-changes-badge {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--accent-subtle);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  animation: badge-enter 0.2s var(--ease-out);
}

@keyframes badge-enter {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.config-status {
  font-size: 12.5px;
  color: var(--muted);
}

.config-top-tabs {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--bg-accent);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

:root[data-theme-mode="light"] .config-top-tabs {
  background: var(--bg-hover);
}

.config-search--top {
  padding: 0;
  border-bottom: none;
  min-width: 200px;
  max-width: 320px;
  flex: 0 1 320px;
}

.config-top-tabs__scroller {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1 1 auto;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.config-top-tabs__scroller::-webkit-scrollbar {
  display: none;
}

.config-top-tabs__tab {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 5px 12px;
  background: var(--bg-elevated);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition:
    border-color var(--duration-fast) ease,
    background var(--duration-fast) ease,
    color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
}

:root[data-theme-mode="light"] .config-top-tabs__tab {
  background: white;
}

.config-top-tabs__tab:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.config-top-tabs__tab.active {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  background: var(--accent-subtle);
}

/* Diff Panel */
.config-diff {
  margin: 12px 20px 0;
  border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
  border-radius: var(--radius-lg);
  background: var(--accent-subtle);
  overflow: hidden;
  animation: badge-enter 0.2s var(--ease-out);
}

.config-diff__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
}

.config-diff__summary::-webkit-details-marker {
  display: none;
}

.config-diff__chevron {
  width: 16px;
  height: 16px;
  transition: transform var(--duration-normal) var(--ease-out);
}

.config-diff__chevron svg {
  width: 100%;
  height: 100%;
}

.config-diff[open] .config-diff__chevron {
  transform: rotate(180deg);
}

.config-diff__content {
  padding: 0 16px 16px;
  display: grid;
  gap: 8px;
}

.config-diff__item {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  font-size: 11.5px;
  font-family: var(--mono);
}

:root[data-theme-mode="light"] .config-diff__item {
  background: white;
}

.config-diff__path {
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}

.config-diff__values {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.config-diff__from {
  color: var(--danger);
  opacity: 0.85;
}

.config-diff__arrow {
  color: var(--muted);
}

.config-diff__to {
  color: var(--ok);
}

/* Section Hero */
.config-section-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-accent);
}

:root[data-theme-mode="light"] .config-section-hero {
  background: var(--bg-hover);
}

.config-section-hero__icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--accent-subtle);
  padding: 5px;
  flex-shrink: 0;
}

.config-section-hero__icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
}

.config-section-hero__text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.config-section-hero__title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.config-section-hero__desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* Content Area */
.config-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
  min-width: 0;
  scroll-behavior: smooth;
}

/* ===========================================
   Appearance Section
   =========================================== */

.settings-appearance {
  display: grid;
  gap: 18px;
}

.settings-appearance__section {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  padding: 18px;
  display: grid;
  gap: 14px;
}

.settings-appearance__heading {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--text-strong);
}

.settings-appearance__hint {
  margin: -8px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

.settings-theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.settings-theme-card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition:
    border-color var(--duration-fast) ease,
    background var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease,
    transform var(--duration-fast) ease;
}

.settings-theme-card:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
  transform: translateY(-1px);
}

.settings-theme-card--active {
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, var(--bg-elevated));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 14%, transparent);
}

.settings-theme-card__icon,
.settings-theme-card__check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.settings-theme-card__icon svg,
.settings-theme-card__check svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
}

.settings-theme-card__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-strong);
}

/* Roundness options */
.settings-roundness__options {
  display: flex;
  gap: 6px;
}

.settings-roundness__btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  cursor: pointer;
  transition:
    background var(--duration-fast) ease,
    border-color var(--duration-fast) ease;
}

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

.settings-roundness__btn.active {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.settings-roundness__swatch {
  width: 28px;
  height: 20px;
  background: var(--bg-muted);
  border: 1.5px solid var(--border-strong);
  transition: border-radius var(--duration-fast) ease;
}

.settings-roundness__btn.active .settings-roundness__swatch {
  border-color: var(--accent);
}

.settings-roundness__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.settings-roundness__btn.active .settings-roundness__label {
  color: var(--accent);
}

.settings-info-grid {
  display: grid;
  gap: 10px;
}

.settings-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
}

.settings-info-row__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.settings-info-row__value {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-align: right;
}

.settings-status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--muted);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--muted) 14%, transparent);
}

.settings-status-dot--ok {
  background: var(--ok);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 14%, transparent);
}

.config-raw-field textarea {
  min-height: 500px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
}

.config-raw-field .config-raw-toggle {
  width: 32px;
  height: 32px;
  padding: 6px;
  min-width: 32px;
}

/* Loading State */
.config-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 80px 24px;
  color: var(--muted);
  animation: fade-in 0.2s var(--ease-out);
}

.config-loading__spinner {
  width: 32px;
  height: 32px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
}

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

/* Empty State */
.config-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 80px 24px;
  text-align: center;
  animation: fade-in 0.3s var(--ease-out);
}

.config-empty__icon {
  font-size: 48px;
  opacity: 0.25;
}

.config-empty__text {
  color: var(--muted);
  font-size: 14px;
  max-width: 320px;
  line-height: 1.5;
}

/* ===========================================
   Section Cards
   =========================================== */

.config-form--modern {
  display: grid;
  gap: 14px;
  width: 100%;
  min-width: 0;
}

.config-section-card {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  overflow: hidden;
  transition:
    border-color var(--duration-normal) ease,
    box-shadow var(--duration-normal) ease;
  animation: section-card-enter 0.25s var(--ease-out) backwards;
}

@keyframes section-card-enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.config-section-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

:root[data-theme-mode="light"] .config-section-card {
  background: white;
}

:root[data-theme-mode="light"] .config-section-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.config-section-card__header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  background: var(--bg-accent);
  border-bottom: 1px solid var(--border);
}

:root[data-theme-mode="light"] .config-section-card__header {
  background: var(--bg-hover);
}

.config-section-card__icon {
  width: 30px;
  height: 30px;
  color: var(--accent);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--accent-subtle);
  padding: 6px;
}

.config-section-card__icon svg {
  width: 100%;
  height: 100%;
}

.config-section-card__titles {
  flex: 1;
  min-width: 0;
}

.config-section-card__title {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.config-section-card__desc {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.config-section-card__content {
  padding: 16px 18px;
  min-width: 0;
}

/* Staggered entrance for sequential cards */
.config-form--modern .config-section-card:nth-child(1) {
  animation-delay: 0ms;
}
.config-form--modern .config-section-card:nth-child(2) {
  animation-delay: 40ms;
}
.config-form--modern .config-section-card:nth-child(3) {
  animation-delay: 80ms;
}
.config-form--modern .config-section-card:nth-child(4) {
  animation-delay: 120ms;
}
.config-form--modern .config-section-card:nth-child(5) {
  animation-delay: 160ms;
}
.config-form--modern .config-section-card:nth-child(n + 6) {
  animation-delay: 200ms;
}

/* ===========================================
   Form Fields
   =========================================== */

.cfg-fields {
  display: grid;
  gap: 14px;
}

.cfg-fields--inline {
  gap: 10px;
}

.cfg-field {
  display: grid;
  gap: 6px;
}

.cfg-field--error {
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--danger-subtle);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.cfg-field--error .cfg-input,
.cfg-field--error .cfg-textarea,
.cfg-field--error .cfg-select,
.cfg-field--error .cfg-number {
  border-color: transparent;
  box-shadow: none;
}

.cfg-field--error .cfg-input:focus,
.cfg-field--error .cfg-textarea:focus,
.cfg-field--error .cfg-select:focus {
  border-color: var(--border);
  box-shadow: none;
}

.cfg-field__label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}

.cfg-field__help {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.45;
}

.cfg-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cfg-tag {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 2px 8px;
  font-size: 11px;
  color: var(--muted);
  background: var(--bg-elevated);
  white-space: nowrap;
}

:root[data-theme-mode="light"] .cfg-tag {
  background: white;
}

.cfg-field__error {
  font-size: 12px;
  color: var(--danger);
}

/* Text Input */
.cfg-input-wrap {
  display: flex;
  gap: 10px;
}

.cfg-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-accent);
  font-size: 13px;
  outline: none;
  transition:
    border-color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease,
    background var(--duration-fast) ease;
}

.cfg-input::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

.cfg-input:hover:not(:focus) {
  border-color: var(--border-strong);
}

.cfg-input:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
  background: var(--bg-hover);
}

:root[data-theme-mode="light"] .cfg-input {
  background: white;
  border-color: var(--border);
}

:root[data-theme-mode="light"] .cfg-input:hover:not(:focus) {
  border-color: var(--border-strong);
}

:root[data-theme-mode="light"] .cfg-input:focus {
  background: white;
}

.cfg-input--sm {
  padding: 6px 10px;
  font-size: 12px;
}

.cfg-input__reset {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition:
    background var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.cfg-input__reset:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.cfg-input__reset:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Textarea */
.cfg-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-accent);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  resize: vertical;
  outline: none;
  transition:
    border-color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
}

.cfg-textarea:hover:not(:focus) {
  border-color: var(--border-strong);
}

.cfg-textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

:root[data-theme-mode="light"] .cfg-textarea {
  background: white;
  border-color: var(--border);
}

.cfg-textarea--sm {
  padding: 8px 12px;
  font-size: 12px;
}

/* Redacted (click-to-reveal) */
.cfg-input--redacted,
.cfg-textarea--redacted {
  cursor: pointer;
  opacity: 0.7;
}

/* Number Input */
.cfg-number {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-accent);
  transition: border-color var(--duration-fast) ease;
}

.cfg-number:hover {
  border-color: var(--border-strong);
}

:root[data-theme-mode="light"] .cfg-number {
  background: white;
}

.cfg-number__btn {
  width: 38px;
  border: none;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 16px;
  font-weight: 300;
  cursor: pointer;
  transition: background var(--duration-fast) ease;
}

.cfg-number__btn:hover:not(:disabled) {
  background: var(--bg-hover);
}

.cfg-number__btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

:root[data-theme-mode="light"] .cfg-number__btn {
  background: var(--bg-hover);
}

:root[data-theme-mode="light"] .cfg-number__btn:hover:not(:disabled) {
  background: var(--border);
}

.cfg-number__input {
  width: 72px;
  padding: 9px;
  border: none;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: transparent;
  font-size: 13px;
  text-align: center;
  outline: none;
  appearance: textfield;
  -moz-appearance: textfield;
}

.cfg-number__input::-webkit-outer-spin-button,
.cfg-number__input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Select */
.cfg-select {
  padding: 8px 36px 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--bg-accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  font-size: 13px;
  cursor: pointer;
  outline: none;
  appearance: none;
  transition:
    border-color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
}

.cfg-select:hover:not(:focus) {
  border-color: var(--border-strong);
}

.cfg-select:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

:root[data-theme-mode="light"] .cfg-select {
  background-color: white;
  border-color: var(--border);
}

/* Segmented Control */
.cfg-segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-accent);
  gap: 1px;
}

:root[data-theme-mode="light"] .cfg-segmented {
  background: var(--bg-hover);
}

.cfg-segmented__btn {
  padding: 6px 14px;
  border: none;
  border-radius: calc(var(--radius-md) - 3px);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition:
    background var(--duration-fast) ease,
    color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
}

.cfg-segmented__btn:hover:not(:disabled):not(.active) {
  color: var(--text);
  background: var(--bg-hover);
}

.cfg-segmented__btn.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 1px 3px var(--accent-subtle);
}

.cfg-segmented__btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Toggle Row */
.cfg-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-accent);
  cursor: pointer;
  transition:
    background var(--duration-fast) ease,
    border-color var(--duration-fast) ease;
}

.cfg-toggle-row:hover:not(.disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.cfg-toggle-row.disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

:root[data-theme-mode="light"] .cfg-toggle-row {
  background: white;
}

:root[data-theme-mode="light"] .cfg-toggle-row:hover:not(.disabled) {
  background: var(--bg-hover);
}

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

.cfg-toggle-row__label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
}

.cfg-toggle-row__help {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
}

/* Toggle Switch */
.cfg-toggle {
  position: relative;
  flex-shrink: 0;
}

.cfg-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.cfg-toggle__track {
  display: block;
  width: 40px;
  height: 22px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  position: relative;
  transition:
    background var(--duration-normal) var(--ease-out),
    border-color var(--duration-normal) var(--ease-out);
}

:root[data-theme-mode="light"] .cfg-toggle__track {
  background: var(--border);
}

.cfg-toggle__track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition:
    transform var(--duration-normal) var(--ease-spring),
    background var(--duration-normal) ease;
}

.cfg-toggle input:checked + .cfg-toggle__track {
  background: var(--ok-subtle);
  border-color: rgba(34, 197, 94, 0.4);
}

.cfg-toggle input:checked + .cfg-toggle__track::after {
  transform: translateX(18px);
  background: var(--ok);
}

.cfg-toggle input:focus + .cfg-toggle__track {
  box-shadow: var(--focus-ring);
}

/* Object (collapsible) */
.cfg-object {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  overflow: hidden;
  transition: border-color var(--duration-fast) ease;
}

.cfg-object:hover {
  border-color: var(--border-strong);
}

:root[data-theme-mode="light"] .cfg-object {
  background: transparent;
}

.cfg-object__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
  transition: background var(--duration-fast) ease;
  border-radius: calc(var(--radius-md) - 1px);
}

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

.cfg-object__header::-webkit-details-marker {
  display: none;
}

.cfg-object__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.cfg-object__title-wrap {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.cfg-object__chevron {
  width: 18px;
  height: 18px;
  color: var(--muted);
  transition: transform var(--duration-normal) var(--ease-out);
}

.cfg-object__chevron svg {
  width: 100%;
  height: 100%;
}

.cfg-object[open] .cfg-object__chevron {
  transform: rotate(180deg);
}

.cfg-object__help {
  padding: 0 12px 10px;
  font-size: 12px;
  color: var(--muted);
}

.cfg-object__content {
  padding: 12px;
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--border);
}

/* Array */
.cfg-array {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.cfg-array__header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  background: var(--bg-accent);
  border-bottom: 1px solid var(--border);
}

:root[data-theme-mode="light"] .cfg-array__header {
  background: var(--bg-hover);
}

.cfg-array__label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.cfg-array__title {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 6px;
}

.cfg-array__count {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 10px;
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
}

:root[data-theme-mode="light"] .cfg-array__count {
  background: white;
}

.cfg-array__add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--duration-fast) ease;
}

.cfg-array__add:hover:not(:disabled) {
  background: var(--bg-hover);
}

.cfg-array__add:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.cfg-array__add-icon {
  width: 14px;
  height: 14px;
}

.cfg-array__add-icon svg {
  width: 100%;
  height: 100%;
}

.cfg-array__help {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.cfg-array__empty {
  padding: 36px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.cfg-array__items {
  display: grid;
  gap: 1px;
  background: var(--border);
}

.cfg-array__item {
  background: var(--panel);
}

.cfg-array__item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-accent);
  border-bottom: 1px solid var(--border);
}

:root[data-theme-mode="light"] .cfg-array__item-header {
  background: var(--bg-hover);
}

.cfg-array__item-index {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cfg-array__item-remove {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition:
    background var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.cfg-array__item-remove svg {
  width: 16px;
  height: 16px;
}

.cfg-array__item-remove:hover:not(:disabled) {
  background: var(--danger-subtle);
  color: var(--danger);
}

.cfg-array__item-remove:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.cfg-array__item-content {
  padding: 12px;
}

/* Map (custom entries) */
.cfg-map {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.cfg-map__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  background: var(--bg-accent);
  border-bottom: 1px solid var(--border);
}

:root[data-theme-mode="light"] .cfg-map__header {
  background: var(--bg-hover);
}

.cfg-map__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.cfg-map__add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--duration-fast) ease;
}

.cfg-map__add:hover:not(:disabled) {
  background: var(--bg-hover);
}

.cfg-map__add-icon {
  width: 14px;
  height: 14px;
}

.cfg-map__add-icon svg {
  width: 100%;
  height: 100%;
}

.cfg-map__empty {
  padding: 28px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.cfg-map__items {
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
}

.cfg-map__item {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-accent);
}

:root[data-theme-mode="light"] .cfg-map__item {
  background: white;
}

.cfg-map__item-header {
  display: grid;
  grid-template-columns: minmax(0, 300px) auto;
  gap: 8px;
  align-items: center;
}

.cfg-map__item-key {
  min-width: 0;
}

.cfg-map__item-value {
  min-width: 0;
}

.cfg-map__item-value > .cfg-fields {
  gap: 10px;
}

.cfg-map__item-remove {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition:
    background var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.cfg-map__item-remove svg {
  width: 16px;
  height: 16px;
}

.cfg-map__item-remove:hover:not(:disabled) {
  background: var(--danger-subtle);
  color: var(--danger);
}

/* Pill variants */
.pill--sm {
  padding: 5px 12px;
  font-size: 11px;
}

.pill--ok {
  border-color: rgba(34, 197, 94, 0.35);
  color: var(--ok);
}

.pill--danger {
  border-color: rgba(239, 68, 68, 0.35);
  color: var(--danger);
}

/* ===========================================
   Mobile Responsiveness
   =========================================== */

@media (max-width: 768px) {
  .config-layout {
    height: calc(100vh - 100px);
    height: calc(100dvh - 100px);
    margin: 0 -8px -16px;
    border-radius: var(--radius-md);
  }

  .config-actions {
    flex-wrap: wrap;
    padding: 14px 16px;
  }

  .config-actions__left,
  .config-actions__right {
    width: 100%;
    justify-content: center;
  }

  .config-top-tabs {
    flex-wrap: wrap;
    padding: 12px 16px;
  }

  .config-search--top {
    flex: 1 1 100%;
    max-width: none;
  }

  .config-top-tabs__scroller {
    flex: 1 1 auto;
  }

  .config-actions__left .config-mode-toggle__btn {
    flex: 1 1 50%;
  }

  .config-section-hero {
    padding: 14px 16px;
  }

  .config-content {
    padding: 16px;
  }

  .settings-theme-grid {
    grid-template-columns: 1fr;
  }

  .settings-info-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .settings-info-row__value {
    text-align: left;
  }

  .config-section-card__header {
    padding: 14px 16px;
  }

  .config-section-card__content {
    padding: 14px 16px;
  }

  .cfg-toggle-row {
    padding: 12px 14px;
  }

  .cfg-map__item {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .cfg-map__item-header {
    grid-template-columns: 1fr auto;
  }

  .cfg-map__item-remove {
    justify-self: end;
  }
}

@media (max-width: 480px) {
  .config-section-card__icon {
    width: 30px;
    height: 30px;
  }

  .config-section-card__title {
    font-size: 16px;
  }

  .cfg-segmented {
    flex-wrap: wrap;
  }

  .cfg-segmented__btn {
    flex: 1 0 auto;
    min-width: 70px;
  }
}
