.profile-settings-layout {
  display: grid;
  grid-template-columns: minmax(190px, 230px) minmax(0, 1fr);
  align-items: start;
  gap: var(--fs-page-gap);
  min-width: 0;
}

.profile-settings-nav {
  position: sticky;
  z-index: 10;
  top: calc(var(--fs-control-height) + var(--fs-page-gap));
  display: grid;
  gap: var(--fs-space-1);
  padding: var(--fs-space-3);
}

.profile-settings-nav__label {
  padding: var(--fs-space-2) var(--fs-space-3);
  color: var(--fs-color-text-secondary);
  font-size: var(--fs-text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.profile-settings-nav a {
  min-height: var(--fs-control-height);
  padding: 10px var(--fs-space-3);
  color: var(--fs-color-text);
  border-radius: var(--fs-radius-md);
  font-size: var(--fs-text-md);
  font-weight: 500;
  text-decoration: none;
}

.profile-settings-nav a:hover {
  background: var(--fs-color-surface-hover);
}

.profile-settings-nav a:focus-visible {
  outline: 0;
  box-shadow: var(--fs-focus-ring);
}

.profile-settings {
  display: grid;
  gap: var(--fs-page-gap);
  min-width: 0;
}

.profile-section {
  scroll-margin-top: calc(var(--fs-control-height) + var(--fs-space-6));
  overflow: clip;
}

.profile-section > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--fs-space-4);
  min-height: 58px;
  padding: var(--fs-space-3) var(--fs-space-4);
  cursor: pointer;
  list-style: none;
}

.profile-section > summary::-webkit-details-marker {
  display: none;
}

.profile-section > summary:hover {
  background: var(--fs-color-surface-hover);
}

.profile-section > summary:focus-visible {
  outline: 0;
  box-shadow: inset var(--fs-focus-ring);
}

.profile-section > summary > span:first-child {
  display: grid;
  gap: var(--fs-space-1);
  min-width: 0;
}

.profile-section > summary strong {
  color: var(--fs-color-text);
  font-size: var(--fs-text-lg);
  font-weight: 600;
}

.profile-section > summary small,
.profile-section__content p,
.profile-form__hint,
.profile-custom-background__content small,
.profile-background-option__content small,
.profile-background-layout small,
.profile-switch-option small {
  color: var(--fs-color-text-secondary);
  font-size: var(--fs-text-sm);
  line-height: 1.4;
}

.profile-section__chevron {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  margin-right: var(--fs-space-1);
  border-right: 2px solid var(--fs-color-text-secondary);
  border-bottom: 2px solid var(--fs-color-text-secondary);
  transform: rotate(45deg);
  transition: transform 0.16s ease;
}

.profile-section[open] .profile-section__chevron {
  transform: rotate(225deg);
}

.profile-section__content {
  padding: var(--fs-space-4);
  background: var(--fs-color-surface);
  border-top: 1px solid var(--fs-color-border-subtle);
}

.profile-telegram-settings {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--fs-space-4);
}

.profile-telegram-settings__copy {
  display: grid;
  gap: var(--fs-space-1);
  min-width: 0;
}

.profile-telegram-settings__copy p,
.profile-telegram-settings__copy small {
  margin: 0;
}

.profile-telegram-settings__copy small:not(:empty) {
  color: var(--fs-color-danger-text);
}

.profile-telegram-settings form {
  flex: 0 0 auto;
}

.profile-photo-settings {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: center;
  gap: var(--fs-space-4);
}

.profile-avatar {
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  overflow: hidden;
  color: var(--fs-color-primary-text);
  background: var(--fs-color-primary-subtle);
  border: 1px solid var(--fs-color-primary-line);
  border-radius: 50%;
  font-size: var(--fs-text-2xl);
  font-weight: 700;
  text-transform: uppercase;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-photo-settings__controls,
.profile-form,
.profile-background-form,
.profile-background-layout-form,
.profile-background-blur-form,
.profile-quick-access-form,
.profile-news-form,
.profile-custom-background__content {
  display: grid;
  gap: var(--fs-space-3);
  min-width: 0;
}

.profile-photo-settings__controls p,
.profile-form__hint {
  margin: 0;
}

.profile-form {
  max-width: 680px;
}

.profile-password-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.profile-password-form > .fs-field:first-child,
.profile-password-form > .profile-form__hint,
.profile-password-form > .profile-form__actions {
  grid-column: 1 / -1;
}

.profile-form__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--fs-space-2);
}

.profile-upload-form {
  display: flex;
  align-items: end;
  gap: var(--fs-space-2);
  min-width: 0;
}

.profile-upload-form .fs-file-field {
  flex: 1 1 auto;
  min-width: 0;
}

.profile-background-settings,
.profile-workspace-settings {
  display: grid;
  gap: var(--fs-space-5);
}

.profile-backgrounds,
.profile-background-layouts,
.profile-background-blur {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--fs-space-2);
  margin: 0;
  padding: 0;
  border: 0;
}

.profile-backgrounds legend,
.profile-background-layouts legend,
.profile-background-blur legend {
  grid-column: 1 / -1;
  margin-bottom: var(--fs-space-1);
  color: var(--fs-color-text-secondary);
  font-size: var(--fs-text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.profile-background-option {
  position: relative;
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 20px;
  align-items: center;
  gap: var(--fs-space-3);
  min-width: 0;
  padding: var(--fs-space-2);
  background: var(--fs-color-surface-subtle);
  border: 1px solid var(--fs-color-border);
  border-radius: var(--fs-radius-md);
  cursor: pointer;
}

.profile-background-option:hover,
.profile-background-layout:hover {
  background: var(--fs-color-surface-hover);
}

.profile-background-option:has(input:checked),
.profile-background-layout:has(input:checked) {
  background: var(--fs-color-selected-subtle);
  border-color: var(--fs-color-selected-line);
}

.profile-background-option:has(input:focus-visible),
.profile-background-layout:has(input:focus-visible),
.profile-quick-access-option:has(input:focus-visible),
.profile-switch-option:has(input:focus-visible) {
  outline: 0;
  box-shadow: var(--fs-focus-ring);
}

.profile-background-option input,
.profile-quick-access-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.profile-background-option__preview {
  display: block;
  width: 96px;
  height: 60px;
  border: 1px solid var(--fs-color-border-subtle);
  border-radius: var(--fs-radius-md);
}

.profile-background-option__content {
  display: grid;
  gap: var(--fs-space-1);
  min-width: 0;
}

.profile-background-option__mark {
  width: 18px;
  height: 18px;
  border: 2px solid var(--fs-color-border);
  border-radius: 50%;
}

.profile-background-option:has(input:checked) .profile-background-option__mark {
  border: 5px solid var(--fs-color-primary);
}

.profile-background-secondary {
  display: grid;
  grid-template-columns: minmax(260px, 0.75fr) minmax(0, 1fr);
  gap: var(--fs-space-3);
  padding-top: var(--fs-space-4);
  border-top: 1px solid var(--fs-color-border-subtle);
}

.profile-background-presentation,
.profile-background-blur-form {
  display: grid;
  align-content: start;
  gap: var(--fs-space-3);
  min-width: 0;
}

.profile-background-blur {
  grid-template-columns: 1fr;
}

.profile-background-blur__level {
  display: grid;
  gap: var(--fs-space-2);
  padding: var(--fs-space-2);
  background: var(--fs-color-surface-subtle);
  border: 1px solid var(--fs-color-border-subtle);
  border-radius: var(--fs-radius-md);
}

.profile-background-blur__level > span {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--fs-space-2);
}

.profile-background-blur__level output {
  color: var(--fs-color-primary-text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.profile-background-blur__level input[type="range"] {
  width: 100%;
  accent-color: var(--fs-color-primary);
}

.profile-background-layout {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: var(--fs-space-2);
  padding: var(--fs-space-2);
  background: var(--fs-color-surface-subtle);
  border: 1px solid var(--fs-color-border);
  border-radius: var(--fs-radius-md);
  cursor: pointer;
}

.profile-background-layout input {
  margin: 2px 0 0;
  accent-color: var(--fs-color-primary);
}

.profile-background-layout span {
  display: grid;
  gap: var(--fs-space-1);
}

.profile-custom-background {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  align-items: center;
  gap: var(--fs-space-3);
  min-width: 0;
  padding: var(--fs-space-3);
  background: var(--fs-color-surface-subtle);
  border: 1px solid var(--fs-color-border-subtle);
  border-radius: var(--fs-radius-md);
}

.profile-custom-background__preview {
  display: grid;
  place-items: center;
  min-height: 112px;
  padding: var(--fs-space-3);
  color: var(--fs-color-text-secondary);
  background: var(--fs-color-canvas);
  border: 1px dashed var(--fs-color-border);
  border-radius: var(--fs-radius-md);
  font-size: var(--fs-text-sm);
  text-align: center;
}

.profile-custom-background__preview--image {
  background-image: url("/profile/background-image");
  background-position: top left;
  background-repeat: repeat;
  background-size: auto;
  border-style: solid;
}

.profile-custom-background__preview--image[data-workspace-background-layout="fit"] {
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
}

.profile-custom-background__preview--image[data-workspace-background-layout="fill"] {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.profile-custom-background__preview--image[data-workspace-background-layout="center"] {
  background-position: center;
  background-repeat: no-repeat;
  background-size: auto;
}

.profile-quick-access-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--fs-space-2);
}

.profile-quick-access-option {
  position: relative;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: var(--fs-space-2);
  min-height: 52px;
  padding: var(--fs-space-2) var(--fs-space-3);
  background: var(--fs-color-surface-subtle);
  border: 1px solid var(--fs-color-border);
  border-radius: var(--fs-radius-md);
  cursor: pointer;
}

.profile-quick-access-option:has(input:checked) {
  color: var(--fs-color-selected-text);
  background: var(--fs-color-selected);
  border-color: var(--fs-color-selected-line);
}

.profile-quick-access-option__icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
}

.profile-quick-access-option__icon img {
  width: 22px;
  height: 22px;
}

.profile-selection-count {
  margin-right: auto;
  color: var(--fs-color-text-secondary);
  font-size: var(--fs-text-sm);
  font-variant-numeric: tabular-nums;
}

.profile-news-form {
  justify-items: start;
}

.profile-switch-option {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: start;
  gap: var(--fs-space-2);
  width: 100%;
  padding: var(--fs-space-3);
  background: var(--fs-color-surface-subtle);
  border: 1px solid var(--fs-color-border-subtle);
  border-radius: var(--fs-radius-md);
}

.profile-switch-option input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  accent-color: var(--fs-color-primary);
}

.profile-switch-option span {
  display: grid;
  gap: var(--fs-space-1);
}

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

  .profile-settings-nav {
    top: calc(var(--fs-control-height) + var(--fs-page-gap));
    grid-template-columns: repeat(5, minmax(max-content, 1fr));
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .profile-settings-nav__label {
    display: none;
  }

  .profile-settings-nav a {
    text-align: center;
    white-space: nowrap;
  }

  .profile-background-secondary {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .profile-page {
    gap: 7px;
  }

  .profile-page > .fs-page-heading-card {
    position: static;
    min-height: 50px;
    padding: 9px 14px;
    background-size: 250px auto;
    border-radius: 15px;
  }

  .profile-settings-layout {
    gap: 7px;
  }

  .profile-settings-nav {
    position: relative;
    top: auto;
    display: flex;
    gap: 4px;
    padding: 6px;
    overflow-x: auto;
    border-radius: 15px;
    box-shadow: none;
    scroll-padding-inline: 6px;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .profile-settings-nav::-webkit-scrollbar {
    display: none;
  }

  .profile-settings-nav a {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 9px 12px;
    background: var(--fs-color-surface-subtle);
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: var(--fs-text-sm);
    line-height: 1;
    scroll-snap-align: start;
  }

  .profile-settings-nav a:hover,
  .profile-settings-nav a:focus-visible {
    color: var(--fs-color-primary-text);
    background: var(--fs-color-primary-subtle);
    border-color: var(--fs-color-primary-line);
  }

  .profile-settings {
    display: block;
    overflow: hidden;
    background: var(--fs-color-surface);
    border: 1px solid var(--fs-color-border-subtle);
    border-radius: 15px;
    box-shadow: var(--fs-shadow-sm);
  }

  .profile-section,
  .profile-section:last-child {
    border: 0;
    border-bottom: 1px solid var(--fs-color-border-subtle);
    border-radius: 0;
    box-shadow: none;
  }

  .profile-section:last-child {
    border-bottom: 0;
  }

  .profile-section > summary {
    min-height: 62px;
    padding: 13px 16px;
    background: var(--fs-color-surface);
  }

  .profile-section > summary strong {
    font-size: var(--fs-text-md);
  }

  .profile-section > summary small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .profile-section__content {
    padding: 16px;
    background: color-mix(in srgb, var(--fs-color-surface-subtle) 58%, var(--fs-color-surface));
  }

  .profile-photo-settings,
  .profile-password-form,
  .profile-backgrounds,
  .profile-background-layouts,
  .profile-custom-background,
  .profile-quick-access-options {
    grid-template-columns: 1fr;
  }

  .profile-avatar {
    width: 82px;
    height: 82px;
  }

  .profile-photo-settings {
    justify-items: center;
  }

  .profile-photo-settings__controls {
    width: 100%;
  }

  .profile-background-option {
    grid-template-columns: 80px minmax(0, 1fr) 18px;
  }

  .profile-background-option__preview {
    width: 80px;
    height: 54px;
  }

  .profile-custom-background__preview {
    min-height: 132px;
  }

  .profile-password-form > .fs-field:first-child,
  .profile-password-form > .profile-form__hint,
  .profile-password-form > .profile-form__actions {
    grid-column: auto;
  }

  .profile-upload-form {
    align-items: stretch;
    flex-direction: column;
  }

  .profile-telegram-settings {
    align-items: stretch;
    flex-direction: column;
  }

  .profile-form__actions,
  .profile-form__actions .action-button,
  .profile-upload-form .action-button,
  .profile-telegram-settings form,
  .profile-telegram-settings .action-button {
    width: 100%;
  }

  .profile-switch-option {
    grid-template-columns: 22px minmax(0, 1fr);
    padding: 12px;
    background: var(--fs-color-surface);
  }
}
